Xsession(): login to an Object Analytics Instance and init a Xsession instance
Copy from xplain import Xsession
s = Xsession (url = "http://myhost:8080" , user = "me" ,password = "secret1" )
Xsession.startup(file_name) : load a XView (xstartup) file to setup a new xplain session
Copy from xplain import Xsession
s = Xsession (url = "http://myhost:8080" , user = "me" ,
password = "secret1" )
s . startup ( "myXview" )
If you use the xplain python package locally in your python environment, then you do need to setup a startup.
If you use the xplain python package at XOE in ObjectExplorer, then you do not need to setup a startup.
Xsession.load_from_session_id(session_id) : load xplain session by given exisiting session id, in order to enable shared session between python and Object Analytics
Copy import xplain
x = xplain . Xsession ()
x . load_from_session_id ( "C8DCE9C450ED83FF4E679EE840A072FF" )
Xsession.execute_query() : execute a query
Copy import xplain
s = xplain . Xsession ()
query = {
"requestName" : "myRequest" ,
"aggregations" : [
{
"object" : "AU-Diagnosen" ,
"dimension" : "Diagnose" ,
"type" : "SUM"
}
] ,
"groupBys" : [ {
"attribute" : {
"object" : "Hospital Diagnose" ,
"dimension" : "Diagnose" ,
"attribute" : "Type"
} ]
}
}
df = s . execute_query (query)
Xsession.open_query() : execute an open query
Copy import xplain
s = xplain . Xsession ()
query = {
"requestName" : "myRequest" ,
"aggregations" : [
{
"object" : "AU-Diagnosen" ,
"dimension" : "Diagnose" ,
"type" : "SUM"
}
] ,
"groupBys" : [ {
"attribute" : {
"object" : "Hospital Diagnose" ,
"dimension" : "Diagnose" ,
"attribute" : "Type"
} ]
}
}
df = s . open_query (query)
Xsession.run() : To run a xplain method
perform xplain web api method and broadcast the change to other client sharing with same session id, if Python session is sharing the same session with Object Analytics, Object Analytics will be get updated.
Copy x = xplain . Xsession ()
x . run ({ "method" : "clearAllSelections" })
Xession.perform(): Send POST request against entry point /xplainsession with payload as json, returns results as JSON
Copy x = xplain . Xsession ()
teenager_list = r . perform ({
"method" : "getChildren" ,
"object" : "Patient" ,
"dimension" : "Age" ,
"attribute" : "Age Group" ,
"state" : "Teenager"
})
Xsession.get_result(query_name): get the result of a given query name as data frame.
Copy import xplain
s = xplain . Xsession ()
query = {
"requestName" : "myRequest" ,
"aggregations" : [
{
"object" : "AU-Diagnosen" ,
"dimension" : "Diagnose" ,
"type" : "SUM"
}
] ,
"groupBys" : [ {
"attribute" : {
"object" : "Hospital Diagnose" ,
"dimension" : "Diagnose" ,
"attribute" : "Type"
} ]
}
}
s . execute_query (query)
df = s . get_result ( "myRequest" )
3 different ways to perform a query
Following example shows how to count Items grouped by Item Type where Item Category = 10.0 in 3 different ways
References:
xplain.Query_config
Copy '''
This example demostrate 3 different ways to execute a query
to count Items groupped by Item Type where Item Category = 10.0
'''
import xplain
x = xplain . Xsession (url = "https://xoebp.xplain-data.com" )
## Option 1: in object oriented way with query object
# step 1: config the query
my_query = xplain . Query_config (name = "myExample" )
my_query . add_aggregation (object_name = "Items" , dimension_name = "Item ID" , type = "COUNT" )
my_query . add_groupby (object_name = "Items" ,
dimension_name = "Item Type" ,
attribute_name = "Item Type" )
my_query . add_selection (object_name = "Items" ,
dimension_name = "Item Category" ,
attribute_name = "Item Category" ,
selected_states = [ "10.0" ])
# step 2: run query with query config object
x . execute_query (my_query)
print (my_query. to_json ())
## Option 2. run with execute_query method and use query config JSON as parameter
x . execute_query ({
'requestName' : 'myExample2' ,
'aggregations' : [{
'object' : 'Items' ,
'dimension' : 'Item ID' ,
'type' : 'COUNT'
}],
'groupBys' : [
{
'subGroupings' :
[
{
'attribute' :
{
'object' : 'Items' ,
'dimension' : 'Item Type' ,
'attribute' : 'Item Type'
}
}
]
}],
'selections' : [
{ 'attribute' :
{ 'object' : 'Items' ,
'dimension' : 'Item Category' ,
'attribute' : 'Item Category' },
'selectedStates' : [ '10.0' ]}
]
})
## Option 3: use run method and xplain Web API
# https://docs.xplain-data.de/xplaindoc/interfaces/webapi.html
# https://docs.xplain-data.de/xplaindoc/interfaces/webapi.html#executequery
x . run ({
"method" : "executeQuery" ,
"request" : {
'requestName' : 'myExample3' ,
'aggregations' : [{
'object' : 'Items' ,
'dimension' : 'Item ID' ,
'type' : 'COUNT'
}],
'groupBys' : [
{
'subGroupings' :
[
{
'attribute' :
{
'object' : 'Items' ,
'dimension' : 'Item Type' ,
'attribute' : 'Item Type'
}
}
]
}],
'selections' : [
{ 'attribute' :
{ 'object' : 'Items' ,
'dimension' : 'Item Category' ,
'attribute' : 'Item Category' },
'selectedStates' : [ '10.0' ]}
]
}
})