Augmenting Standard Analysis with Historical Caching 3.0
Historical Cache Functionality
This article describes how to use the historical cache functionality built into Sepasoft analysis to speed up part of gathering historical data. Note that this only works with sequential historical data, such as a list of downtime events, or a list of runs, or analysis comparing consecutive shifts. If the analysis is grouped by some sequential data point (Operation UUID, State Event Sequence, Line State Event Begin, etc), this may help. It does respect existing setting values, if any are used.
Python Function
|
def run_historical_analysis(lookback_hours, cache_key, analysis_name=None, analysis_setting=None): if not analysis_setting: analysis_setting = system.mes.analysis.getMESAnalysisSettings(analysis_name) current_end_date = system.date.now() current_start_date = system.date.setTime(current_end_date, system.date.getHour24(current_end_date), 0, 0) current_analysis_dataset = system.mes.analysis.executeAnalysis(current_start_date, current_end_date, analysis_setting).getDataset() historical_start_date = system.date.addHours(current_start_date, -lookback_hours) existing_setting_values = analysis_setting.getSettingValues() analysis_setting.setSettingValues("%s,Cache Expiration=43200,Historical Cache Key=%s" % (existing_setting_values, cache_key)) historical_analysis_dataset = system.mes.analysis.executeAnalysis(historical_start_date, current_start_date, analysis_setting).getDataset() data_to_add = [] for row_num in range(current_analysis_dataset.getRowCount()): row_data = [] for col_num in range(current_analysis_dataset.getColumnCount()): row_data.append(current_analysis_dataset.getValueAt(row_num, col_num)) data_to_add.append(row_data) return system.dataset.addRows(historical_analysis_dataset, data_to_add) |
Usage:
Do the following to execute this function with an existing analysis setting object or one that you have created from scratch:
Usage with a pre-loaded or existing analysis setting
|
analysis = system.mes.analysis.getMESAnalysisSettings("Downtime Events") results = run_historical_analysis(400, "blah", analysis_setting=analysis) |
Otherwise, you can simply name the analysis you wish to use, like so:
Usage with just the name of an analysis setting
|
results = run_historical_analysis(400, "blah", analysis_name="Downtime Events") |