Skip to content

Commit

Permalink
resolve Hugovdberg#488
Browse files Browse the repository at this point in the history
  • Loading branch information
AlcibiadesCleinias committed Jul 24, 2021
1 parent 3cd459a commit 8bb7429
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
31 changes: 16 additions & 15 deletions PIconnect/PIData.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
TimestampCalculation,
get_enumerated_value,
)
from PIconnect.time import to_af_time_range


class PISeries(Series):
Expand Down Expand Up @@ -214,11 +215,11 @@ def recorded_values(
filtered values are always left out entirely.
Args:
start_time (str): String containing the date, and possibly time,
start_time (str or datetime): Containing the date, and possibly time,
from which to retrieve the values. This is parsed, together
with `end_time`, using
:afsdk:`AF.Time.AFTimeRange <M_OSIsoft_AF_Time_AFTimeRange__ctor_1.htm>`.
end_time (str): String containing the date, and possibly time,
end_time (str or datetime): Containing the date, and possibly time,
until which to retrieve values. This is parsed, together
with `start_time`, using
:afsdk:`AF.Time.AFTimeRange <M_OSIsoft_AF_Time_AFTimeRange__ctor_1.htm>`.
Expand All @@ -237,7 +238,7 @@ def recorded_values(
`ValueError` is raised.
"""

time_range = AF.Time.AFTimeRange(start_time, end_time)
time_range = to_af_time_range(start_time, end_time)
boundary_type = self.__boundary_types.get(boundary_type.lower())
filter_expression = self._normalize_filter_expression(filter_expression)
if boundary_type is None:
Expand Down Expand Up @@ -275,11 +276,11 @@ def interpolated_values(self, start_time, end_time, interval, filter_expression=
and filtered values are always left out entirely.
Args:
start_time (str): String containing the date, and possibly time,
start_time (str or datetime): Containing the date, and possibly time,
from which to retrieve the values. This is parsed, together
with `end_time`, using
:afsdk:`AF.Time.AFTimeRange <M_OSIsoft_AF_Time_AFTimeRange__ctor_1.htm>`.
end_time (str): String containing the date, and possibly time,
end_time (str or datetime): Containing the date, and possibly time,
until which to retrieve values. This is parsed, together
with `start_time`, using
:afsdk:`AF.Time.AFTimeRange <M_OSIsoft_AF_Time_AFTimeRange__ctor_1.htm>`.
Expand All @@ -293,7 +294,7 @@ def interpolated_values(self, start_time, end_time, interval, filter_expression=
Returns:
PISeries: Timeseries of the values returned by the SDK
"""
time_range = AF.Time.AFTimeRange(start_time, end_time)
time_range = to_af_time_range(start_time, end_time)
interval = AF.Time.AFTimeSpan.Parse(interval)
filter_expression = self._normalize_filter_expression(filter_expression)
pivalues = self._interpolated_values(time_range, interval, filter_expression)
Expand Down Expand Up @@ -321,10 +322,10 @@ def summary(
Return one or more summary values over a single time range.
Args:
start_time (str): String containing the date, and possibly time,
start_time (str or datetime): Containing the date, and possibly time,
from which to retrieve the values. This is parsed, together
with `end_time`, using :afsdk:`AF.Time.AFTimeRange <M_OSIsoft_AF_Time_AFTimeRange__ctor_1.htm>`.
end_time (str): String containing the date, and possibly time,
end_time (str or datetime): Containing the date, and possibly time,
until which to retrieve values. This is parsed, together
with `start_time`, using :afsdk:`AF.Time.AFTimeRange <M_OSIsoft_AF_Time_AFTimeRange__ctor_1.htm>`.
summary_types (int or PIConsts.SummaryType): Type(s) of summaries
Expand All @@ -342,7 +343,7 @@ def summary(
pandas.DataFrame: Dataframe with the unique timestamps as row index
and the summary name as column name.
"""
time_range = AF.Time.AFTimeRange(start_time, end_time)
time_range = to_af_time_range(start_time, end_time)
summary_types = int(summary_types)
calculation_basis = int(calculation_basis)
time_type = int(time_type)
Expand Down Expand Up @@ -372,11 +373,11 @@ def summaries(
Return one or more summary values for each interval within a time range
Args:
start_time (str): String containing the date, and possibly time,
start_time (str or datetime): Containing the date, and possibly time,
from which to retrieve the values. This is parsed, together
with `end_time`, using
:afsdk:`AF.Time.AFTimeRange <M_OSIsoft_AF_Time_AFTimeRange__ctor_1.htm>`.
end_time (str): String containing the date, and possibly time,
end_time (str or datetime): Containing the date, and possibly time,
until which to retrieve values. This is parsed, together
with `start_time`, using
:afsdk:`AF.Time.AFTimeRange <M_OSIsoft_AF_Time_AFTimeRange__ctor_1.htm>`.
Expand All @@ -398,7 +399,7 @@ def summaries(
pandas.DataFrame: Dataframe with the unique timestamps as row index
and the summary name as column name.
"""
time_range = AF.Time.AFTimeRange(start_time, end_time)
time_range = to_af_time_range(start_time, end_time)
interval = AF.Time.AFTimeSpan.Parse(interval)
summary_types = int(summary_types)
calculation_basis = int(calculation_basis)
Expand Down Expand Up @@ -435,11 +436,11 @@ def filtered_summaries(
Return one or more summary values for each interval within a time range
Args:
start_time (str): String containing the date, and possibly time,
start_time (str or datetime): String containing the date, and possibly time,
from which to retrieve the values. This is parsed, together
with `end_time`, using
:afsdk:`AF.Time.AFTimeRange <M_OSIsoft_AF_Time_AFTimeRange__ctor_1.htm>`.
end_time (str): String containing the date, and possibly time,
end_time (str or datetime): String containing the date, and possibly time,
until which to retrieve values. This is parsed, together
with `start_time`, using
:afsdk:`AF.Time.AFTimeRange <M_OSIsoft_AF_Time_AFTimeRange__ctor_1.htm>`.
Expand Down Expand Up @@ -472,7 +473,7 @@ def filtered_summaries(
pandas.DataFrame: Dataframe with the unique timestamps as row index
and the summary name as column name.
"""
time_range = AF.Time.AFTimeRange(start_time, end_time)
time_range = to_af_time_range(start_time, end_time)
interval = AF.Time.AFTimeSpan.Parse(interval)
filter_expression = self._normalize_filter_expression(filter_expression)
calculation_basis = get_enumerated_value(
Expand Down
22 changes: 22 additions & 0 deletions PIconnect/time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from datetime import datetime
from typing import Union

from PIconnect.AFSDK import AF


def to_af_time_range(start_time: Union[str, datetime], end_time: Union[str, datetime]):
"""to_af_time_range
Return AF.Time.AFTimeRange object from datetime or string
using :afsdk:`AF.Time.AFTimeRange <M_OSIsoft_AF_Time_AFTimeRange__ctor_1.htm>`.
If string is used, it is assumed that user knows the format
that should be passed to AF.Time.AFTimeRange.
"""

if isinstance(start_time, datetime):
start_time = start_time.isoformat()
if isinstance(end_time, datetime):
end_time = end_time.isoformat()

return AF.Time.AFTimeRange(start_time, end_time)

0 comments on commit 8bb7429

Please sign in to comment.