Beispiel #1
0
 def get_period_by_date(self, date_time, holidays=None, magn='te'):
     station = get_station(date_time)
     if not holidays:
         holidays = get_holidays(date_time.year)
     date = date_time.date()
     if (calendar.weekday(date.year, date.month, date.day) in (5, 6)
             or date in holidays):
         holiday = True
     else:
         holiday = False
     periods = self.energy_periods
     if magn == 'tp':
         periods = self.power_periods
     for period in periods.values():
         if period.holiday == holiday or not self.has_holidays_periods:
             if period.daytype:
                 zone = period.geom_zone
                 daytype = get_daytype_by_date_and_zone(
                     date_time, zone, holidays
                 )
                 periods_ranges = period.periods_by_zone_and_day[zone][daytype]
                 range_list = periods_ranges[int(period.code[-1]) - 1]
             else:
                 range_list = getattr(period, '%s_hours' % station)
             for range_h in range_list:
                 if range_h[0] <= date_time.hour < range_h[1]:
                     return period
         elif magn == 'tp':
             if period.daytype:
                 zone = period.geom_zone
                 daytype = get_daytype_by_date_and_zone(
                     date_time, zone, holidays
                 )
                 periods_ranges = period.periods_by_zone_and_day[zone][daytype]
                 range_list = periods_ranges[int(period.code[-1]) - 1]
             else:
                 if holiday and self.has_holidays_hours_in_periods:
                     if period.holiday_hours:
                         range_list = getattr(period, 'holiday_hours')
                     else:
                         continue
                 else:
                     range_list = getattr(period, '%s_hours' % station)
             for range_h in range_list:
                 if range_h[0] <= date_time.hour < range_h[1]:
                     return period
     return None
Beispiel #2
0
 def get_period_by_date(self, date_time):
     station = get_station(date_time)
     date = date_time.date()
     holidays = get_holidays(date.year)
     if (calendar.weekday(date.year, date.month, date.day) in (5, 6)
             or date in holidays):
         holiday = True
     else:
         holiday = False
     # Map hour 0 to 24
     hour = date_time.hour or 24
     for period in self.periods:
         if period.holiday == holiday or not self.has_holidays_periods:
             for range_h in getattr(period, '%s_hours' % station):
                 if range_h[0] < hour <= range_h[1]:
                     return period
     return None
Beispiel #3
0
    def get_period_by_date(self, date_time):
        datetime_previous_hour = date_time - timedelta(hours=1)
        station = get_station(datetime_previous_hour)
        date = datetime_previous_hour.date()
        holidays = get_holidays(date.year)
        if (calendar.weekday(date.year, date.month, date.day) in (5, 6) or
                date in holidays):
            holiday = True
        else:
            holiday = False

        # Map hour 0 to 24
        hour = date_time.hour or 24
        for period in self.periods:
            if period.holiday == holiday or not self.has_holidays_periods:
                for range_h in getattr(period, '%s_hours' % station):
                    if range_h[0] < hour <= range_h[1]:
                        return period
        return None
Beispiel #4
0
    def apply_31A_LB_cof(self, balance, start_date, end_date):
        consumptions = balance.copy()
        period_hours = self.hours_by_period
        holidays_list = get_holidays(start_date.year)
        (workdays, holidays) = get_num_of_workdays_holidays(
            start_date, end_date, holidays_list
        )

        cofs = {}
        for period in period_hours:
            if period > 'P3':
                cofs[period] = period_hours.get(period, 0) * holidays
            else:
                cofs[period] = period_hours.get(period, 0) * workdays
        for period, consumption in balance.items():
            consumptions[period] = round(
                consumption * (1 + self.losses), 2
            ) + round(0.01 * cofs[period] * self.kva, 2)

        return consumptions
Beispiel #5
0
    def apply_31A_LB_cof(self, balance, start_date, end_date):
        consumptions = balance.copy()
        period_hours = self.hours_by_period
        holidays_list = get_holidays(start_date.year)
        (workdays, holidays) = get_num_of_workdays_holidays(
            start_date, end_date, holidays_list
        )

        cofs = {}
        for period in period_hours:
            if period > 'P3':
                cofs[period] = period_hours.get(period, 0) * holidays
            else:
                cofs[period] = period_hours.get(period, 0) * workdays
        for period, consumption in balance.items():
            consumptions[period] = round(
                consumption * (1 + self.losses), 2
            ) + round(0.01 * cofs[period] * self.kva, 2)

        return consumptions
Beispiel #6
0
from datetime import date

from enerdata.datetime.holidays import get_holidays
from expects import *

with description('The holidays modules'):
    with it('Has to return the Spain holidays of 2015'):
        holidays = get_holidays(2015)
        expect(list(holidays)).to(contain_only(*[
            date(2015, 1, 1),
            date(2015, 1, 6),
            date(2015, 4, 3),
            date(2015, 5, 1),
            date(2015, 8, 15),
            date(2015, 10, 12),
            date(2015, 11, 1),
            date(2015, 12, 6),
            date(2015, 12, 8),
            date(2015, 12, 25)
        ]))