AnsweredAssumed Answered

Python Recalculation Script drops data

Question asked by biker2000on on Jun 25, 2018
Latest reply on Jun 27, 2018 by biker2000on

I have written a Python script based on this post: Automatic Backfill using SDK (Python)

 

I am able to find all of the correct analyses and looking in the logs it fires every 4 hours as configured.

# -*- coding: utf-8 -*-

#Allows us to import the AFSDK
import sys
import time
sys.path.append('E:\\PI\\PIPC\\AF\\PublicAssemblies\\4.0\\')

#pythonnet module let's us import CLR for AFSDK use
import clr
clr.AddReference('OSIsoft.AFSDK')

from System.Collections.Generic import List
from OSIsoft.AF import *
from OSIsoft.AF.PI import *
from OSIsoft.AF.Asset import *
from OSIsoft.AF.Analysis import *
from OSIsoft.AF.Data import *
from OSIsoft.AF.Time import *
from OSIsoft.AF.Search import *

afservers = PISystems()
afserver = afservers.DefaultPISystem
DB = afserver.Databases.DefaultDatabase
myAnalysisService = afserver.AnalysisService
timerange = AFTimeRange('*-1d','*')
print(afserver.Name)   
#%% queue individual plow mixer recalculations
analysislist = List[AFAnalysis]()   #initializes a C# list
search = AFAnalysisSearch(DB, 'All recalced analyses',"Category:'PMRecalc'").FindAnalyses()
for analysis in search:
    analysislist.Add(analysis)
    print('Target Element: {0} \tAnalysis: {1}'.format(analysis.Target, analysis.Name))
   
myAnalysisService.QueueCalculation(analysislist, timerange, myAnalysisService.CalculationMode.DeleteExistingData)
print('all analyses queued for recalculation')

 

The problem that I am having is that when it recalculates the data through Python and the analysis service queue calculation method, it drops data as shown below:

 

before-recalc.png

 

However, you can see in the next screenshot that when recalculated with PI System Explorer manually, all data is written correctly:

 

after-recalc.png

 

The purpose of this recalculation is to update the event frame calculation once new lab data is entered. It is entered using a VBA script in a ProcessBook display so I cannot trigger the AF recalc at insertion time.

 

Any ideas?

Outcomes