scenario_tool_interface package¶
This module provides access to the Scenario-Tool’s REST API to create and run scenarios and manage models
Submodules¶
-
class
scenario_tool_interface.sti.
AccessLevel
[source]¶ Bases:
enum.Enum
An enumeration.
-
ADMIN
= 4¶
-
CONSULTANT
= 3¶
-
DEMO
= 1¶
-
PARTICIPANT
= 2¶
-
SUPERADMIN
= 5¶
-
-
class
scenario_tool_interface.sti.
ScenarioToolInterface
(api_url='https://stable-api.harc-dev.com.au/api', results_url='https://stable-sql.harc-dev.com.au/resultsdb/')[source]¶ Bases:
object
-
archive_project
(project)[source]¶ Share a project
- Parameters
project – project id
username – share user name
-
check_status
(scenario: int)[source]¶ Return status of current simulation.
returns:
{ status: status code (int), status_text: status description } // CREATED = 1 // BASE_IN_QUEUE = 2 // BASE_RUNNING = 3 // BASE_COMPLETE = 4 // PA_IN_QUEUE = 5 // PA_RUNNING = 6 // PA_COMPLETE = 7 // COMPLETE = 8
-
create_assessment_model
(filename, model_id=None)[source]¶ Creates a new assessment model and a default version tagged as 0.0.1 the data must be of the shape:
{ name: "some name", description: "some desc", //optionally add assessment model stage of development //1 = ALPHA //2 = BETA //3 = UNDER DEVELOPMENT //default is 3 stage: 2 //must specify one of: model_id: <model_id> //by default will use the active version of this model model_version_id: <model_version_id> //if present will use this model version id }
returns:
{ assessment_model_id: <the id of the new assessment model>, assessment_model_version_id: <id of the new default version> }
-
create_dash_tile_template
(json)[source]¶ Define tile template (see doc)
- Parameters
json –
- Returns
dash_tile_template_id
- Return type
-
create_datasource
(project_id, name, source_type='file', upload_id=None)[source]¶ Upload a geojson file and return id
-
create_node
(filename, model_id=None, access_level=5)[source]¶ Create a new node
- Parameters
filename – point to json file containing the node description
model_id – model id in json file will be replaced by this. If not set model_id from json file
access_level – access level of node
:type str :type int :type int :return: node_id :rtype: int
-
create_query_template
(json, access_level)[source]¶ Define tile template (see doc)
- Parameters
json –
:param access_level :type geojson: str :type access_level: int :return: query_template_id :rtype: int
-
create_scenario
(project, parent, name='Baseline')[source]¶ Creates a new scenario. The provides the shell for the new scenarios. Scenario are derived from the base line or any other scenario in the project. To modify the environment workflow may be defined and executed.
- Parameters
project – project id
parent – parent scenario id
name – name of scenario
:type int :type int :type str :return: scenario id :rtype: int
-
deactivate_assessment_model
(node_id)[source]¶ Deactivate assessment model
- Parameters
node_id (int) – node id
-
download_geojson
(scenario_id, layer_name)[source]¶ Download layer as geojson file
- Parameters
scenario_id – scenario id
layern_name –
:type int :type string :return: geojson string
-
edit_dash_tile_template
(template_id, json=None, active=True)[source]¶ Define tile template (see doc)
- Parameters
json –
- Returns
dash_tile_template_id
- Return type
-
get_data_model
(data_model_id: int) → dict[source]¶ Get data model
- Parameters
data_model_id (int) – model to be queried for results
- Returns
dict of data model
:rtype dict
-
get_database_id
(scenario_id)[source]¶ Returns database ID to run data analysis
- Parameters
scenario_1_id – scenario id
- Returns
data base id needed for query
-
get_database_structure
(scenario_id: int) → dict[source]¶ Get database structure
- Parameters
scenario_id (int) – scenario to be queried for results
- Returns
dict of tables and their attributes
:rtype dict
-
get_default_parameter_dict
(node_id: int) → dict[source]¶ Returns default parameter dict for a node
- Parameters
node_id (int) –
- Returns
Parameter dict
:rtype dict
-
get_default_region_parameters
(region_id: int) → dict[source]¶ Returns the default region parameters as dictionary
- Parameters
region_id – id of the region
- Returns
parameter dictionary
:rtype dict
-
get_node_id
(name, owner_id=None)[source]¶ Return node id to be used in simulation. If multiple nodes with the same id are identified the first node belonging to the user is returned first. If owner_id is set only the node owned by the user is returned
:rtype int
-
get_nodes
()[source]¶ Return list of available nodes
- Returns
returns a dict of all scenario
- Return type
-
get_project_databases
(project_id, folder='.', scenario_id=None)[source]¶ Download project databases. Databases will be downloaded into folder/project_id.zip For larger projects it is recommended to defined the scenario_id to be downloaded. Otherwise the download might fail
-
get_region
(region_name: str) → int[source]¶ Returns region currently supported is Melbourne
- Parameters
region_name – region id
- Returns
region id
-
get_results
(scenario_id: int, results_tables: list) → dict[source]¶ Get results from scenario tool interface for tables defined in the results tables list.
- Parameters
- Returns
dict with dict for each tables with results as a numpy array. We recommend to use the numpy array to create a pandas dataframe.
:rtype dict
-
get_scenarios
(project_id)[source]¶ Get a list of scenarios in a project
- Parameters
project_id – project ID
:type int :return: returns a dict of all scenario :rtype: dict
-
link_dash_tile_assessment_model
(dash_tile_template_id, assessment_model_id)[source]¶ Link dash tile with assessment model
-
link_dash_tile_query_prototype
(dash_tile_template_id, query_prototype_id)[source]¶ Link query prototype with assessment model
-
link_query_prototype_assessment_model
(query_prototype_id, assessment_model_id)[source]¶ Link query prototype with assessment model
-
login
(username: str, password: str)[source]¶ - Parameters
username – registered user name (email address)
password – top secret password
-
run_query
(scenario_id, query)[source]¶ Run a query on the scenario spatialite database. The database supports SQLite and Spatialite commands Only read access is supported! To find out which data are stored in the database read the dynamind_table_definitions
- Parameters
scenario_id (int) – scenario id
query – SQL query
:type query str :return: query result :rtype: dict
-
set_model_access_level
(node_id, access_level)[source]¶ Set the access level of the performance assessment model
-
set_node_properties
(node_id, properties)[source]¶ Set the access level of the parent node
- Parameters
node_id (int) – node id
properties – dict
returns:
-
set_scenario_workflow
(scenario_id, node_data)[source]¶ Set the workflow for a scenario. The workflow is defined by a series of nodes defined by the node_data The node_data have following structure
[{ name: node_id, area: geojson_id, parameters: { parameter.value = 1, paramter2.value = 2, } }, ... ]
The nodes in the workflow are executed as defined in the data structure
Share a project
- Parameters
project – project id
username – share user name
-
show_scenarios
(project_id)[source]¶ Prints a list of the scenarios in a project
- Parameters
project_id (int) – project id
-
update_assessment_model
(assessment_model_id, filename, model_id)[source]¶ Creates a new assessment model and a default version tagged as 0.0.1 the data must be of the shape:
- Parameters
{ name: "some name", description: "some desc", //optionally add assessment model stage of development //1 = ALPHA //2 = BETA //3 = UNDER DEVELOPMENT //default is 3 stage: 2 //must specify one of: model_id: <model_id> //by default will use the active version of this model model_version_id: <model_version_id> //if present will use this model version id }
returns:
{ assessment_model_id: <the id of the new assessment model>, assessment_model_version_id: <id of the new default version> }
-
update_node
(node_id, filename, model_id=None, access_level=5)[source]¶ Update an existing node
- Parameters
node_id – id of node
filename – point to json file containing the node description
model_id – model id in json file will be replaced by this. If not set model_id from json file
access_level – access level of node
:type str :type str :type int :type int :return: node_id :rtype: int
-
upload_dynamind_model
(name: str, filename: str) → int[source]¶ Uploads a new model to the server
- Parameters
name – model name
filename – dynamind file
:type str :return: model_id :rtype: int
-