def doIntradayRevision(startTime: dt.datetime, endTime: dt.datetime, configDict: dict) -> bool: """perform intraday revsion Args: startTime (dt.datetime): startTime endTime (dt.datetime): endTime configDict (dict): application dictionary Returns: bool: returns True if revision successfull else false """ conString: str = configDict['con_string_mis_warehouse'] obj_forecastedDemandFetchRepo = ForecastedDemandFetchRepo(conString) obj_forecastedDemandFetchForRevisionRepo = ForecastedDemandFetchForRevisionRepo( conString) obj_revisedForecastInsertionRepo = RevisedDemandForecastInsertionRepo( conString) isRevisionSuccessCount = 0 countRevision = 0 # listOfEntity =['WRLDCMP.SCADA1.A0046945','WRLDCMP.SCADA1.A0046948','WRLDCMP.SCADA1.A0046953','WRLDCMP.SCADA1.A0046957','WRLDCMP.SCADA1.A0046962','WRLDCMP.SCADA1.A0046978','WRLDCMP.SCADA1.A0046980','WRLDCMP.SCADA1.A0047000'] listOfEntity = ['WRLDCMP.SCADA1.A0047000'] for entity in listOfEntity: #fetch last 6 block actual demand actualDemandDf = fetchDemandDataFromApi(startTime, endTime, entity, configDict) #fetch last 6 block forecasted demand forecastedDemandDf = obj_forecastedDemandFetchRepo.fetchForecastedDemand( startTime, endTime, entity) #calculate avg bias error avgBiasError = calculateAvgBiasError(actualDemandDf, forecastedDemandDf) # print(f"avg bias error = {avgBiasError}") # avgbiasErrorPercentage = avgBiasError*100 if abs(avgBiasError * 100) > 1: countRevision = countRevision + 1 # do revision in next time blocks from B+3 revisedForecastData: List[ Tuple] = obj_forecastedDemandFetchForRevisionRepo.fetchForecastedDemandForRevision( startTime, endTime, entity, avgBiasError) # print(revisedForecastData) # insert revised forecasted demand in db isRevisionSuccess = obj_revisedForecastInsertionRepo.insertRevisedDemandForecast( revisedForecastData) if isRevisionSuccess: isRevisionSuccessCount = isRevisionSuccessCount + 1 if isRevisionSuccessCount == countRevision: return True else: return False
def createMinWiseDemand_purityPercent(startDate: dt.datetime, endDate: dt.datetime, configDict: dict) -> bool: """ create minwise demand data and daywise purity percentage of each entity Args: startDate (dt.datetime): start date endDate (dt.datetime): end date configDict (dict): apllication configuration dictionary Returns: bool: return true if insertion is success. """ conString: str = configDict['con_string_mis_warehouse'] #creating instance of classes obj_purityPercentageInsRepo = PurityPercentageInsertionRepo(conString) obj_minWiseInsertionRepo = MinWiseDemandInsertionRepo(conString) puritySuccessCount = 0 demandSuccessCount = 0 currDate = startDate # Iterating through each day and inserting demand and purity percentage while currDate <= endDate: demand_purity_dict: Idemand_purity_dict = fetchDemandDataFromApi( currDate, configDict) isInsertionSuccessPurity = obj_purityPercentageInsRepo.insertPurityPercentage( demand_purity_dict['purityPercentage']) if isInsertionSuccessPurity: puritySuccessCount = puritySuccessCount + 1 isInsertionSuccessMinWiseDemand = obj_minWiseInsertionRepo.insertMinWiseDemand( demand_purity_dict['data']) if isInsertionSuccessMinWiseDemand: demandSuccessCount = demandSuccessCount + 1 currDate += dt.timedelta(days=1) numOfDays = (endDate - startDate).days #checking whether data is inserted for each day or not if puritySuccessCount == numOfDays + 1 and demandSuccessCount == numOfDays + 1: return True else: return False