Ejemplo n.º 1
0
    def values(self) -> List[Tuple[datetime, float]]:
        interval_obj = get_human_interval(self.interval)
        interval_def = human_to_interval(self.interval)
        inclusive = False
        dt = self.start

        if interval_def.interval < 1440:
            inclusive = True

        # return as list rather than generate
        timeseries_data = []

        # rewind back one interval
        if inclusive:
            # dt -= interval_obj
            pass

        for v in self.data:
            timeseries_data.append((dt, v))
            dt = dt + interval_obj

        # @TODO do some sanity checking here
        # if dt != self.last:
        #     raise Exception(
        #         "Mismatch between start, last and interval size. Got {} and {}".format(
        #             dt, self.last
        #         )
        #     )

        return timeseries_data
Ejemplo n.º 2
0
    def length(self) -> int:
        """Return the number of buckets in the range"""
        _comp = self.start
        _delta = get_human_interval(self.trunc)
        count = 1

        while _comp <= self.end:
            _comp += _delta
            count += 1

        return count
Ejemplo n.º 3
0
    def values(self) -> List[Tuple[datetime, float]]:
        interval_obj = get_human_interval(self.interval)
        dt = self.start

        # return as list rather than generate
        xy_values = []

        for v in self.data:
            dt = dt + interval_obj
            xy_values.append((strip_timezone(dt), v))

        return xy_values
Ejemplo n.º 4
0
    def values(self) -> List[Tuple[date, Optional[float]]]:
        interval_obj = get_human_interval(self.interval)
        dt = self.start

        # return as list rather than generate
        xy_values = []

        if self.interval in ["5m", "30m", "1h"]:
            dt = dt + interval_obj

        for v in self.data:
            if isinstance(dt, datetime):
                dt = strip_timezone(dt)

            xy_values.append((dt, v))
            dt = dt + interval_obj

        return xy_values
Ejemplo n.º 5
0
def run_energy_update_archive(
    year: Optional[int] = None,
    months: Optional[List[int]] = None,
    days: Optional[int] = None,
    regions: Optional[List[str]] = None,
    fueltech: Optional[str] = None,
    network: NetworkSchema = NetworkNEM,
    run_clear: bool = False,
) -> None:

    date_range = get_date_range(network=network)

    years: List[int] = []

    if not year:
        years = [i for i in range(YEAR_EARLIEST, DATE_CURRENT_YEAR + 1)]
    else:
        years = [year]

    if not months:
        months = list(range(1, 13))

    if not regions:
        regions = ["NSW1", "QLD1", "VIC1", "TAS1", "SA1"]

    # @TODO remove this and give APVI regions
    if network == NetworkAPVI:
        regions = ["WEM"]

    fueltechs = [fueltech]

    if not fueltech:
        fueltechs = [i for i in load_fueltechs().keys()]

    for y in years:
        for month in months:
            date_min = datetime(
                year=y,
                month=month,
                day=1,
                hour=0,
                minute=0,
                second=0,
                tzinfo=NetworkWEM.get_timezone(),
            )

            date_max = date_min + get_human_interval("1M")

            if days:
                date_max = datetime(
                    year=y,
                    month=month,
                    day=1 + days,
                    hour=0,
                    minute=0,
                    second=0,
                    tzinfo=NetworkWEM.get_timezone(),
                )

            date_min = date_min - timedelta(minutes=10)
            date_max = date_max + timedelta(minutes=10)

            if date_max > date_range.end:
                date_max = date_range.end

            if date_min > date_max:
                # slack_message("Reached end of energy archive")
                logger.debug("Reached end of archive {} {}".format(
                    date_min, date_max))
                break

            for region in regions:
                for fueltech_id in fueltechs:
                    run_energy_calc(
                        date_min,
                        date_max,
                        region=region,
                        fueltech_id=fueltech_id,
                        network=network,
                        run_clear=run_clear,
                    )
Ejemplo n.º 6
0
    def get_range(self) -> DatetimeRange:
        """Return a DatetimeRange from the time series for queries"""
        start = self.start
        end = self.end

        # If its a forward looking forecast
        # jump out early
        if self.forecast:
            start = self.end + timedelta(minutes=self.interval.interval)
            end = self.end + get_human_interval(self.forecast_period)

            start = start.astimezone(self.network.get_fixed_offset())
            end = end.astimezone(self.network.get_fixed_offset())

            return DatetimeRange(start=start, end=end, interval=self.interval)

        # subtract the period (ie. 7d from the end for start if not all)
        if self.period == human_to_period("all"):
            start = date_trunc(start, self.interval.trunc)
            start = start.replace(
                hour=0, minute=0, second=0, tzinfo=self.network.get_fixed_offset()
            )

            # If its all per month take the end of the last month
            if self.interval == human_to_interval("1M"):
                end = date_trunc(get_end_of_last_month(end), "day")
                end = end.replace(
                    hour=23, minute=59, second=59, tzinfo=self.network.get_fixed_offset()
                )

            self.year = None

        else:
            start = self.end - get_human_interval(self.period.period_human)

        if self.year:
            if self.year > end.year:
                raise Exception("Specified year is great than end year")

            start = start.replace(
                year=self.year,
                month=1,
                day=1,
                hour=0,
                minute=0,
                second=0,
                tzinfo=self.network.get_fixed_offset(),
            )

            end = datetime(
                year=self.year,
                month=12,
                day=31,
                hour=23,
                minute=59,
                second=59,
                tzinfo=self.network.get_fixed_offset(),
            )

            if self.year == CUR_YEAR:
                today = datetime.now(tz=self.network.get_fixed_offset())

                end = datetime(
                    year=CUR_YEAR, month=today.month, day=today.day, hour=23, minute=59, second=59
                )

                end = end - timedelta(days=1)

                end = end.replace(tzinfo=self.network.get_fixed_offset())

                if self.end.date() < today.date():
                    end = self.end

        if self.month:
            start = datetime(
                year=self.month.year,
                month=self.month.month,
                day=1,
                hour=0,
                minute=0,
                second=0,
                tzinfo=self.network.get_fixed_offset(),
            )

            end = start + get_human_interval("1M") - timedelta(days=1)

            end = end.replace(
                hour=23,
                minute=59,
                second=59,
            )

        # localize times
        if not start.tzinfo or start.tzinfo != self.network.get_fixed_offset():
            start = start.astimezone(self.network.get_fixed_offset())

        if not end.tzinfo or end.tzinfo != self.network.get_fixed_offset():
            end = end.astimezone(self.network.get_fixed_offset())

        dtr = DatetimeRange(start=start, end=end, interval=self.interval)

        return dtr
Ejemplo n.º 7
0
def valid_trunc(trunc: str) -> str:
    get_human_interval(trunc)
    return trunc
Ejemplo n.º 8
0
def run_energy_update_archive(
    year: Optional[int] = None,
    months: Optional[List[int]] = None,
    days: Optional[int] = None,
    regions: Optional[List[str]] = None,
    fueltech: Optional[str] = None,
    network: NetworkSchema = NetworkNEM,
) -> None:

    date_range = get_date_range(network=network)

    years: List[int] = [year]

    if not year:
        years = [i for i in range(CUR_YEAR, YEAR_EARLIEST - 1, -1)]

    if not months:
        months = list(range(1, 13))

    if not regions:
        regions = [i.code for i in get_network_regions(network)]

    fueltechs = [fueltech]

    if not fueltech:
        fueltechs = [i for i in load_fueltechs().keys()]

    for y in years:
        for month in months:
            date_min = datetime(year=y,
                                month=month,
                                day=1,
                                hour=0,
                                minute=0,
                                second=0,
                                tzinfo=FixedOffset(600))

            date_max = date_min + get_human_interval("1M")

            if days:
                date_max = datetime(
                    year=y,
                    month=month,
                    day=1 + days,
                    hour=0,
                    minute=0,
                    second=0,
                    tzinfo=FixedOffset(600),
                )

            date_min = date_min - timedelta(minutes=10)
            date_max = date_max + timedelta(minutes=10)

            if date_max > date_range.end:
                date_max = date_range.end

            if date_min > date_max:
                slack_message("Reached end of energy archive")
                logger.debug("reached end of archive")
                break

            for region in regions:
                for fueltech_id in fueltechs:
                    run_energy_calc(region,
                                    date_min,
                                    date_max,
                                    fueltech_id=fueltech_id,
                                    network=network)