====Python Model (Method)==== The **python model** method is a [[style|function method]] that launches a Python script with a calling convention specifically designed to run calculations or machine learning models as an API. ===Additional Info.json Parameters=== This method requires a **path** parameter - this is the path to the Python script. This path can include [[substitutions|substitutions]]. It should also include a **style** parameter. The value of this parameter should be 'query' (run the AI model with user-provided inputs), or **stream** (run the AI model with recorded history). The 'query' and 'stream' versions of this function take very different parameters. ===Query Parameters=== Your function should have one input for every input of your AI. "parameters": [ { "name": "Temperature", "type": "float", "tag": "temp", "mapping": "Floor Temperature", "source": "Floor.Temperature - Current", "default": 24.5 }] In the example above, we create a parameter called 'temp' of type 'float'. It's human-readable name is 'Temperature'. When the data arrives in the Python script, the name will be 'Floor Temperature'. In the user-interface, the default value will be 24.5 degrees, but pressing 'Sync With ARDI' will load the temperature from the live Floor Temperature value. ===Stream Parameters=== "parameters": [ { "name": "Time", "type": "timerange", "tag": "start", "startname": "start", "endname": "end" }, { "name": "Range", "type": "string", "tag": "range", "default": "10 minutes" }, { "name": "Samples", "type": "integer", "tag": "grain", "default": 200 } ] Above are the expected parameters for a 'stream' function - the start and end times for the data, and a desired resolution. ===How It Works=== When writing your script, you'll use the **ardifunctions.py** library, which will handle ingesting all of the data for you. Below is an example file... import ardifunctions import pandas as pd import numpy as np defaults = {} defaults['Floor Temperature'] = 18 dfunc = ardifunctions.DynamicFunction("http://localhost/s/op") dfunc.query = "'Floor' ASSET AIPOINTS" dfunc.Defaults(defaults) dfunc.ParseParameters() def Calculate(inputs,results): return {'Output Value': inputs['Floor Temperature'] * 1.2} dfunc.SingleCalc = Calculate dfunc.Execute() This will call the **Calculate** function - which is given a dictionary of parameter values - to calculate the output value(s). This same code works for both the 'query' or 'stream' version of the function - the only difference is that when called on a range of time rather than an instant, the 'Calculate' function will be called many times rather than just once. ===Making Solutions More Efficient=== If using machine learning models or other algorithms that work well with bulk data, you can use [[Bulk Calculation Functions]].