From 91f02898670ccd99d125c8a42022695a27d5659a Mon Sep 17 00:00:00 2001 From: tinogis Date: Mon, 27 Nov 2023 18:20:32 +0100 Subject: [PATCH 1/3] NEW get_summer/winter_curve --- powerprofile/powerprofile.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/powerprofile/powerprofile.py b/powerprofile/powerprofile.py index 5ec57bf..4634981 100644 --- a/powerprofile/powerprofile.py +++ b/powerprofile/powerprofile.py @@ -540,6 +540,30 @@ def extract(self, cols): return new + def get_summer_curve(self): + return self.get_season_curve(dst=True) + + def get_winter_curve(self): + return self.get_season_curve(dst=False) + + def get_season_curve(self, dst=True): + """ + + :param dst: + :return: + """ + df = self.curve.copy() + df['dst'] = df.apply( + lambda row: True if TIMEZONE.normalize(row[self.datetime_field]).dst() else False, axis=1 + ) + df = df[df['dst'] == dst] + + res = self.__class__(datetime_field=self.datetime_field) + data = df.to_dict('records') + res.load(data) + + return res + # Dump data def to_csv(self, cols=None, header=True): """ From 6569efacb8dfbb53c9eb68f468eb693cb015df34 Mon Sep 17 00:00:00 2001 From: tinogis Date: Mon, 27 Nov 2023 18:21:14 +0100 Subject: [PATCH 2/3] TEST get_summer/winter_curve --- spec/powerprofile_spec.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/spec/powerprofile_spec.py b/spec/powerprofile_spec.py index eb47e3c..c20202d 100644 --- a/spec/powerprofile_spec.py +++ b/spec/powerprofile_spec.py @@ -449,6 +449,45 @@ def read_csv(txt): pp = self.powpro_subcurve_testing3.get_complete_daily_subcurve() expect((pp.curve)).to(equal(None)) + with context('complete season curve'): + with before.all: + self.curve_season_testing = [] + self.start = LOCAL_TZ.localize(datetime(2020, 1, 1, 1, 0, 0)) + self.end = LOCAL_TZ.localize(datetime(2022, 1, 1, 0, 0, 0)) + + num_hours = int((self.end - self.start).total_seconds() / 3600) + 1 + for hours in range(0, num_hours): + self.curve_season_testing.append( + {'timestamp': LOCAL_TZ.normalize(self.start + timedelta(hours=hours)), 'value': 100 + hours} + ) + self.powpro_season_testing = PowerProfile(datetime_field='timestamp') + self.powpro_season_testing.load(self.curve_season_testing) + + self.total_registers = self.powpro_season_testing.samples + + winter_pp = self.powpro_season_testing.get_winter_curve() + # Abril no és hivern + expect(LOCAL_TZ.localize(datetime(2020, 4, 1, 0)) not in winter_pp.curve.timestamp).to(be_true) + # Novembre és hivern + expect(LOCAL_TZ.localize(datetime(2020, 11, 1, 0)) not in winter_pp.curve.timestamp).to(be_true) + + self.winter_registers = winter_pp.samples + expect(self.winter_registers).to(be_below(self.total_registers)) + + summer_pp = self.powpro_season_testing.get_summer_curve() + # Abril és estiu" + expect(LOCAL_TZ.localize(datetime(2020, 4, 1, 0)) in summer_pp.curve.timestamp).to(be_true) + # Novembre no és estiu + expect(LOCAL_TZ.localize(datetime(2020, 11, 1, 0)) not in summer_pp.curve.timestamp).to(be_true) + + self.summer_registers = summer_pp.samples + expect(self.summer_registers).to(be_below(self.total_registers)) + + + expect(self.summer_registers + self.winter_registers).to(be_equal(self.total_registers)) + + + with context('accessing data'): with before.all: self.curve = [] From 9d7138f84d2bc585fb2e9e25e8ea2e1173a2f1fd Mon Sep 17 00:00:00 2001 From: tinogis Date: Mon, 27 Nov 2023 18:55:54 +0100 Subject: [PATCH 3/3] FIX function description --- powerprofile/powerprofile.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/powerprofile/powerprofile.py b/powerprofile/powerprofile.py index 4634981..d6622bf 100644 --- a/powerprofile/powerprofile.py +++ b/powerprofile/powerprofile.py @@ -548,9 +548,10 @@ def get_winter_curve(self): def get_season_curve(self, dst=True): """ - - :param dst: - :return: + Returns a new partial profile with only the summer registers (dst=True) or the winter registers (false) using + DST change time of local timezone + :param dst: boolean True(summer) False(winter) + :return: new profile """ df = self.curve.copy() df['dst'] = df.apply(