How to use graph data type using by pl/python in AgensGraph? - plpython

I am using AgensGraph.
I know the PostgreSQL supports pl/python driver.
So I think the AgensGraph supports it, too.
If I want to use a graph data type using by pl/python, is the way same with general data?

In order to use PL/Python in AgensGraph you need to Create the plpythonu language.
A good example for PL/Python in AgensGraph would be as following:
Enabling the module
CREATE LANGUAGE plpythonu;
Creating sample data
CREATE (a:person {id:1,name:'Bob'});
Creating PL/Python function
CREATE OR REPLACE FUNCTION firstname()
RETURNS void
AS $$
#Python source code starts
records = plpy.execute("MATCH (a:person) RETURN a.name AS sample")
plpy.info(records[0]['sample'])
#Python source code ends
$$ LANGUAGE plpythonu;
Calling the function
SELECT firstname();
You can find more information in the following link:
AgensGraph

Related

AfterEffects Script - Create Excel data using script

nice to meet you!
I'm currently making an AfterEffect script that writes layer information to Excel, but no matter how much I research, I can't find a way to do it. If someone knows how to do it, can you tell me?
Actually, I'm Japanese and I don't understand English very well, so I used Google Translate to write the sentences, so I'm glad if it's conveyed well.
Layer information can be obtained from the API using the Layer object which can be accessed directly like so: app.project.item(index).layer(index) or by looping through a CompItem's layers like so:
var theComp = app.project.activeItem;
for (var i = 1; i <= theComp.numLayers; i++){
// layers in a comp are indexed from 1, rather than 0
theLayer = theComp.layer(i);
<do something with theLayer>
}
You can write this to a CSV XML or JSON file using the File.write() or File.writeln() methods of the File object. These can easily be imported into Excel.
Because the version of Javascript that extendscript uses dates back to 1995, it doesn't have native JSON.stringify() or XML.write() methods, so to create JSON or XML you will need Javascript implementations like this one for XML and this one for JSON. If you search for core JS polyfill for these functions there are dozens around.

Amazon Neptune: How to create custom vertex id in Python using tinkerpop/gremlinpython package?

As outlined here https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-differences.html custom vertex ids can only be set with the unquoted id property, i.e., g.addV('label1').property(id, 'customid'). How can one accomplish this using the gremlinpython package? I see an id function in gremlin_python.process.graph_traversal, but I get an UnsupportedOperationException (as expected) when attempting to use that.
You should just have to import T which is the class that hold the id and label members:
from gremlin_python.process.traversal import T
then use it as:
g.addV('label1').property(T.id, 'customid').iterate()
You can of course choose to import id from T so as to make the syntax synonymous with the example Gremlin in your question such that you may omit the T - some folks prefer that style.
It may be worth looking at the reference documentation for other common imports that Gremlin uses.

How to retrieve non-zeroes using gurobipy?

I am using gurobipy to read LP files. The command
model=gurobipy.read("name.lp", env=env) gives me the number of rows, columns, and non-zeroes. However, I need to retrieve the number of non-zeroes. I don't believe there is a function that does this automatically (i.e. model.getnonzeros() )
Is there a way to obtain the non-zeros? How would I write python code to be able to do this if there isn't a built in function?
Consulted resources
Get constraints in matrix format from gurobipy
Ok I figured it out - perusing the Gurobi reference manual, in chapter 6, Python API overview, I see there is an attribute called "NumNZs" that can be called as:
print(model.getAttr("NumNZs"))
This will give the non-zeroes

Getting the result of an excel formula in python

I need to open a .xlsx-file (without writing to it) in python, to change some fields and get the output after the formulas in some fields were calculated; I only know the input fields, the output field and the name of the sheet.
To write some code: Here is how it would look like if I would have created the library
file = excel.open("some_file.xlsx")
sheet = file[sheet_name]
for k, v in input_fields.items():
sheet[k] = v
file.do_calculations()
print(sheet[output_field])
Is there an easy way to do this? Wich library should I use to get the result of the formulas after providing new values for some fields?
Is there a better way than using something like pyoo, maybe something that doesn't require another application (a python library is clearly better) to be installed?
I'll just thank you in advance.
I now came up with a (very ugly) solution.
I am now reading the xml within the xlsx-file, and I am now using eval and some regular expressions to find out wich fields are needed; and I have defined some functions to run the calculations.
It works, but it would be great if there were a better solution.
If the resulting library is ready, and I don't forget to do this; I'll add a link to the library (that'll be hosted on Github) to this answer to my own question.

SubSonic 3 Using Insert.Into<> without having to specify column names and values?

I'm just starting to use SubSonic 3 and I'm struggling with a basic insert operation.
I would like to insert a new row into a table with all columns and values as specified by an entity object. However the only examples I can find look like you have to specify each column and value, which to me isn't a big step up from doing the raw SQL insert!
myDB.Insert.Into<MyTable>(m => m.Col1, m=m.Col2, etc).Values(col1Val, col2Val,...)
I'm not using the ActiveRecord template which I know from 2.x can do this and there doesn't seem to a Repository.tt template with the version I downloaded (SubSonic.Core 3.0.0.3).
So is this possible?
Is there a Repository.tt template available for v3.0.0.3?
Thanks,
Canice.
You will not need a Repository.tt all you need is to instantiate an instance of SimpleRepository and call the Insert method which takes a type as generic argument and instance which is persisted.
You can take a look at the simple repository tests on github:
https://github.com/subsonic/SubSonic-3.0/blob/master/SubSonic.Tests/Repositories/SimpleRepositoryTests.cs

Resources