def test_getRawFreq(self) -> None: """tests the function that gets raw frequency data """ appDbConnStr = self.jsonConf['appDbConnStr'] mRepo = MetricsDataRepo(appDbConnStr) startDt = dt.datetime(2021, 2, 1) samples = mRepo.getRawFreq(startDt, startDt) self.assertFalse(len(samples) == 0)
def fetchSection2_1FrequencyDurationCurve(appDbConnStr: str, startDt: dt.datetime, endDt: dt.datetime) -> dict: mRepo = MetricsDataRepo(appDbConnStr) frequencyData = mRepo.getRawFreq(startDt,endDt) df = pd.DataFrame(frequencyData) frequencyDataVals = deriveDurationVals(df['frequency'],0.01) maxFreq = round(df['frequency'].max(),2) minFreq = round(df['frequency'].min(),2) meanFreq = round(df['frequency'].mean(),2) pltTitle = 'Frequency Duration Curve for {0} Max={1} , Min={2} , Avg={3} '.format(startDt.strftime('%b-%y') , maxFreq,minFreq,meanFreq) fig, ax = plt.subplots(figsize=(7.5, 4.5)) ax.set_title(pltTitle) ax.set_ylabel('Freq (HZ)') ax.set_xlabel('% of time') # ax.xaxis.set_major_locator(mdates.DayLocator(interval=2)) # ax.xaxis.set_major_formatter(mdates.DateFormatter('%d')) ax.plot( frequencyDataVals['perc_exceeded'],frequencyDataVals['bins'], color='orange') ax.yaxis.grid(True) ax.xaxis.grid(True) ax.legend( loc='best', ncol=4, borderaxespad=0.) plt.xticks(np.arange(0,110,10)) ax.set_xlim(xmin=0 , xmax= 100) ax.set_ylim(ymin=49.6, ymax=50.4) fig.subplots_adjust(bottom=0.25, top=0.8) ax.set_facecolor("#ffffcc") fig.patch.set_facecolor('#cbcbcb') fig.savefig('assets/section_2_2_frequencyDurationCurve.png') # plt.show() # plt.close() secData: dict = {} return secData
def fetchSection1_4_1Context(appDbConnStr: str, startDt: dt.datetime, endDt: dt.datetime) -> ISection_1_4_1: mRepo = MetricsDataRepo(appDbConnStr) # get WR demand hourly values for this month and prev yr month # Load Shedding(MW) # initialize demand rows dem_data_1_4_1: List[IDemDataRow_1_4_1] = [] constList: List[IConstituentConfig] = getConstituentsMappings() for con in constList: cTag = con["entity_tag"] cName = con["display_name"] cDemVals = mRepo.getEntityMetricHourlyData(cTag, 'Demand(MW)', startDt, endDt) cLsVals = mRepo.getEntityMetricHourlyData(cTag, 'Load Shedding(MW)', startDt, endDt) cDemDf = pd.DataFrame(cDemVals + cLsVals) cDemDf = cDemDf.pivot(index="time_stamp", columns="metric_name", values="data_value") cDemDf["Req"] = cDemDf["Demand(MW)"] + cDemDf["Load Shedding(MW)"] # get max month demand met maxDem = cDemDf["Demand(MW)"].max() maxDemDt = cDemDf["Demand(MW)"].idxmax().to_pydatetime() maxDemDateStr = dt.datetime.strftime(maxDemDt, "%d-%m-%Y") maxDemTimeStr = dt.datetime.strftime(maxDemDt, "%H:%M") freqSamples = mRepo.getRawFreq(maxDemDt, maxDemDt) freqAtMaxDem = 50 if len(freqSamples) > 0: freqAtMaxDem = freqSamples[0]["frequency"] maxReq = cDemDf["Req"].max() maxReqDt = cDemDf["Req"].idxmax() lsAtMaxReq = cDemDf["Load Shedding(MW)"].loc[maxReqDt] maxReqDateStr = dt.datetime.strftime(maxReqDt.to_pydatetime(), "%d-%m-%Y") maxReqTimeStr = dt.datetime.strftime(maxReqDt.to_pydatetime(), "%H:%M") freqSamples = mRepo.getRawFreq(maxDemDt, maxDemDt) freqAtMaxReq = 50 if len(freqSamples) > 0: freqAtMaxReq = freqSamples[0]["frequency"] freqCorrAtMaxReq = 0 # TODO find freq correction at max req demMetAtMaxReq = maxReq - lsAtMaxReq if freqAtMaxReq < 50: freqCorrAtMaxReq = 0.035 * demMetAtMaxReq * (50 - freqAtMaxReq) reqPlusFreqCorrAtMaxReq = maxReq + freqCorrAtMaxReq dem_data_1_4_1.extend([{ 'state_name': cName, 'catered': "", 'ls': "", 'freq_corr': "", 'pc': "", 'tot_dem': "", 'peak_date': "", 'peak_time': "", 'freq_at_peak': "" }, { 'state_name': "Registered", 'catered': round(maxDem), 'ls': "", 'freq_corr': "", 'pc': "", 'tot_dem': round(maxDem), 'peak_date': maxDemDateStr, 'peak_time': maxDemTimeStr, 'freq_at_peak': round(freqAtMaxDem, 3) }, { 'state_name': "Un-Restricted", 'catered': round(demMetAtMaxReq), 'ls': round(lsAtMaxReq, 1), 'freq_corr': round(freqCorrAtMaxReq, 1), 'pc': "0", 'tot_dem': round(reqPlusFreqCorrAtMaxReq), 'peak_date': maxReqDateStr, 'peak_time': maxReqTimeStr, 'freq_at_peak': round(freqAtMaxReq, 3) }]) secData: ISection_1_4_1 = {'dem_data_1_4_1': dem_data_1_4_1} return secData