跳转至

foundryts.functions.time_range(foundryts.functions.time_range)

foundryts.functions.time_range(start=None, end=None)

Returns a function that filters a single time series to the specified time-range.

Each time-range acts as an individual series. Setting a time-range for your query makes them more efficient as your query will only read the points in the time-range, instead of all the points in the time series. This is also useful for doing operations on intervals of time series.

  • Parameters:
  • start (int , str , datetime.datetime , optional) – Inclusive starting point of the time-range. Integers are interpreted as the number of nanoseconds. For more human-readable durations, you can provide a datetime.timedelta object or a string that will be parsed as a pandas.Timedelta. String inputs should follow the format recognized by pandas.to_timedelta, such as ‘1 day’, ‘1 hour’, ‘10 minutes’, or ’42s’. (default is the first point of the time series)
  • end (int , str , datetime.datetime , optional) – Exclusive end point of the time-range. Integers are interpreted as the number of nanoseconds. For more human-readable durations, you can provide a datetime.timedelta object or a string that will be parsed as a pandas.Timedelta. String inputs should follow the format recognized by pandas.to_timedelta, such as ‘1 day’, ‘1 hour’, ‘10 minutes’, or ’42s’. (default is the last point of the time series)
  • Returns: A function that accepts a single time series as input and returns the filtered time-range.
  • Return type: (FunctionNode) -> FunctionNode

Dataframe schema

Column name Type Description
timestamp pandas.Timestamp Timestamp of the point
value float str

Examples

>>> series = F.points((1, 1.0), (101, 2.0), (200, 4.0), (201, 8.0), name="series")
>>> series.to_pandas()
                    timestamp  value
0 1970-01-01 00:00:00.000000001    1.0
1 1970-01-01 00:00:00.000000101    2.0
2 1970-01-01 00:00:00.000000200    4.0
3 1970-01-01 00:00:00.000000201    8.0
>>> time_range = F.time_range(start=200, end=202)(series)
>>> time_range.to_pandas()
                      timestamp  value
0 1970-01-01 00:00:00.000000200    4.0
1 1970-01-01 00:00:00.000000201    8.0
>>> smaller_time_range = F.time_range(start=200, end=201)(series)
>>> smaller_time_range.to_pandas()
                    timestamp  value
0 1970-01-01 00:00:00.000000200    4.0
>>> unbounded_start_range = F.time_range(end=201)(series)
>>> unbounded_start_range.to_pandas()
                      timestamp  value
0 1970-01-01 00:00:00.000000001    1.0
1 1970-01-01 00:00:00.000000101    2.0
2 1970-01-01 00:00:00.000000200    4.0
>>> unbounded_end_range = F.time_range(start=101)(series)
>>> unbounded_end_range.to_pandas()
                      timestamp  value
0 1970-01-01 00:00:00.000000101    2.0
1 1970-01-01 00:00:00.000000200    4.0
2 1970-01-01 00:00:00.000000201    8.0

中文翻译


foundryts.functions.time_range

foundryts.functions.time_range(start=None, end=None)

返回一个函数,用于将单个时间序列(time series)过滤到指定的时间范围(time-range)。

每个时间范围作为一个独立的序列。为查询设置时间范围可以提高效率,因为查询只会读取该时间范围内的数据点,而非时间序列中的所有数据点。这对于对时间序列的区间执行操作也非常有用。

  • 参数:
  • start (int , str , datetime.datetime , 可选) – 时间范围的起始点(包含)。整数被解释为纳秒数。如需更易读的持续时间,可提供 datetime.timedelta 对象或将被解析为 pandas.Timedelta 的字符串。字符串输入应遵循 pandas.to_timedelta 识别的格式,例如 '1 day'、'1 hour'、'10 minutes' 或 '42s'。(默认为时间序列的第一个数据点)
  • end (int , str , datetime.datetime , 可选) – 时间范围的结束点(不包含)。整数被解释为纳秒数。如需更易读的持续时间,可提供 datetime.timedelta 对象或将被解析为 pandas.Timedelta 的字符串。字符串输入应遵循 pandas.to_timedelta 识别的格式,例如 '1 day'、'1 hour'、'10 minutes' 或 '42s'。(默认为时间序列的最后一个数据点)
  • 返回: 一个函数,接受单个时间序列作为输入,并返回过滤后的时间范围。
  • 返回类型: (FunctionNode) -> FunctionNode

数据框模式(Dataframe schema)

列名 类型 描述
timestamp pandas.Timestamp 数据点的时间戳
value float str

示例

>>> series = F.points((1, 1.0), (101, 2.0), (200, 4.0), (201, 8.0), name="series")
>>> series.to_pandas()
                    timestamp  value
0 1970-01-01 00:00:00.000000001    1.0
1 1970-01-01 00:00:00.000000101    2.0
2 1970-01-01 00:00:00.000000200    4.0
3 1970-01-01 00:00:00.000000201    8.0
>>> time_range = F.time_range(start=200, end=202)(series)
>>> time_range.to_pandas()
                      timestamp  value
0 1970-01-01 00:00:00.000000200    4.0
1 1970-01-01 00:00:00.000000201    8.0
>>> smaller_time_range = F.time_range(start=200, end=201)(series)
>>> smaller_time_range.to_pandas()
                    timestamp  value
0 1970-01-01 00:00:00.000000200    4.0
>>> unbounded_start_range = F.time_range(end=201)(series)
>>> unbounded_start_range.to_pandas()
                      timestamp  value
0 1970-01-01 00:00:00.000000001    1.0
1 1970-01-01 00:00:00.000000101    2.0
2 1970-01-01 00:00:00.000000200    4.0
>>> unbounded_end_range = F.time_range(start=101)(series)
>>> unbounded_end_range.to_pandas()
                      timestamp  value
0 1970-01-01 00:00:00.000000101    2.0
1 1970-01-01 00:00:00.000000200    4.0
2 1970-01-01 00:00:00.000000201    8.0