Expression Script Examples: Difference between revisions
Jump to navigation
Jump to search
Line 30: | Line 30: | ||
targetDatatable.Import(dataAsDf, #{"Append":true}); | targetDatatable.Import(dataAsDf, #{"Append":true}); | ||
WriteLog(`${CountTop(dataAsDf.Rows)} rows written to datatable`); | WriteLog(`${CountTop(dataAsDf.Rows)} rows written to datatable`); | ||
</pre> | |||
Get all models in the system and store them to a datatable. | |||
<pre> | |||
let newDatatable = Project | |||
.CreateDatatable("Models list " + ToString(Now, "dd.MM.yyyy HH:mm:ss")) | |||
.AddColumn("Model name", "String") | |||
.AddColumn("Project name", "String") | |||
.AddColumn("Created time", "DateTime") | |||
.AddColumn("Cases", "Integer"); | |||
let startTime = Now; | |||
let modelsData = ToDataFrame( | |||
Models.([Name, Project.Name, CreatedDate, NCases]), | |||
["Model name", "Project name", "Created time", "Cases"] | |||
); | |||
WriteLog(`Listing models took ${(Now - startTime).TotalSeconds.Round(2)} seconds.`); | |||
newDatatable.Import(modelsData); | |||
WriteLog(`Datatable ${newDatatable.Id} created.`); | |||
</pre> | </pre> |
Revision as of 09:28, 28 June 2021
Expression language can be used to write scripts in QPR ProcessAnalyzer. See how expression scripts can be created in the Managing_Scripts#Creating_Script. For documentation for the syntax, functions and entities can be found from the main page in the KPI Expression Language section.
Examples
Contact to a web service, fetch some data, and store it to a datatable.
let datatableName = "Web Service Data"; let webServiceData = ParseJson(ReadWebService( #{"Address": "https://processanalyzer.onqpr.com/qprpa/api/serverinfo"} )); let targetDatatable = Project.Datatables.Where(name==datatableName); if (Count(targetDatatable) == 0) { targetDatatable = Project.CreateDatatable(datatableName) .AddColumn("Setting name", "String") .AddColumn("Setting value", "String") .AddColumn("Data read", "DateTime"); } else { targetDatatable = targetDatatable[0]; } let currentTime = Now; let dataAsDf = ToDataFrame( webServiceData.keys.{ let key = _; [key, webServiceData[key], currentTime]; }, ["Setting name", "Setting value", "Data read"] ); targetDatatable.Import(dataAsDf, #{"Append":true}); WriteLog(`${CountTop(dataAsDf.Rows)} rows written to datatable`);
Get all models in the system and store them to a datatable.
let newDatatable = Project .CreateDatatable("Models list " + ToString(Now, "dd.MM.yyyy HH:mm:ss")) .AddColumn("Model name", "String") .AddColumn("Project name", "String") .AddColumn("Created time", "DateTime") .AddColumn("Cases", "Integer"); let startTime = Now; let modelsData = ToDataFrame( Models.([Name, Project.Name, CreatedDate, NCases]), ["Model name", "Project name", "Created time", "Cases"] ); WriteLog(`Listing models took ${(Now - startTime).TotalSeconds.Round(2)} seconds.`); newDatatable.Import(modelsData); WriteLog(`Datatable ${newDatatable.Id} created.`);