Skip to content

Commit

Permalink
Merge pull request #33 from gisce/NEW_get_summer/winter_curve
Browse files Browse the repository at this point in the history
New Extraer curvas de verano/invierno de una curva
  • Loading branch information
tinogis authored Nov 27, 2023
2 parents 353a2fa + 9d7138f commit a5beda9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
25 changes: 25 additions & 0 deletions powerprofile/powerprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,31 @@ 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):
"""
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(
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):
"""
Expand Down
39 changes: 39 additions & 0 deletions spec/powerprofile_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down

0 comments on commit a5beda9

Please sign in to comment.