A TimeSeries instance can be normalized by different time granularity levels. Valid values for normalization levels required by pycast.common.TimeSeries.normalize() are stored in pycast.common.timeseries.NormalizationLevels.
Those levels include:
- “second”
- “minute”
- “hour”
- “day”
- “week”
- “2week”
- “4week”
Fusion methods that can be used to fusionate multiple data points within the same time bucket. This might sort the list it is used on. Valid values for fusion methods required by pycast.common.TimeSeries.normalize() are stored in pycast.common.timeseries.FusionMethods.
Valid fusion methods are:
- “sum”: Sums up all valid values stored in the specific time bucket
- “mean”: Calculates the mean value within the time bucket
- “median”: Calculates the median of the given time bucket values. In the case the number of entries within that bucket is even, the larger of the both values will be chosen as median.
Interpolation methods that can be used for interpolation missing time buckets. Valid values for interpolation methods required by pycast.common.TimeSeries.normalize() are stored in pycast.common.timeseries.InterpolationMethods.
Valid values for interpolation methods are:
- “linear”: Use linear interpolation to calculate the missing values
Bases: pycast.common.pycastobject.PyCastObject
A TimeSeries instance stores all relevant data for a real world time series.
Warning: | TimeSeries instances are NOT thread-safe. |
---|
Creates a new TimeSeries instance containing the data of self and otherTimeSeries.
Parameters: | otherTimeSeries (TimeSeries) – TimeSeries instance that will be merged with self. |
---|---|
Returns: | Returns a new TimeSeries instance containing the data entries of self and otherTimeSeries. |
Return type: | TimeSeries |
Returns a new clone of the TimeSeries.
Returns: | Returns a TimeSeries containing the same data and configuration as self. |
---|---|
Return type: | TimeSeries |
Returns if self and the other TimeSeries are equal.
Parameters: | otherTimeSeries (TimeSeries) – TimeSeries instance that is compared with self. |
---|---|
Returns: | True if the TimeSeries objects are equal, False otherwise. |
Return type: | boolean |
Returns the item stored at the TimeSeries index-th position.
Parameters: | index (integer) – Position of the element that should be returned. Starts at 0 |
---|---|
Returns: | Returns a list containing [timestamp, data] lists. |
Return type: | list |
Raise: | Raises an IndexError if the index is out of range. |
Initializes the TimeSeries.
Parameters: |
|
---|
Returns an iterator that can be used to iterate over the data stored within the TimeSeries.
Returns: | Returns an iterator for the TimeSeries. |
---|---|
Return type: | Iterator |
Returns the number of data entries stored in the TimeSeries.
Returns: | Returns an Integer representing the number on data entries stored within the TimeSeries. |
---|---|
Return type: | integer |
Returns if self and the other MultiDimensionalTimeSeries are equal.
Sets the item at the index-th position of the TimeSeries.
Parameters: |
|
---|---|
Raise: | Raises an IndexError if the index is out of range. |
Returns a string representation of the TimeSeries.
Returns: | Returns a string representing the TimeSeries in the format: “TimeSeries([timestamp, data], [timestamp, data], [timestamp, data])”. |
---|---|
Return type: | string |
Checks, if the TimeSeries is normalized.
Returns: | Returns True if all data entries of the TimeSeries have an equal temporal distance, False otherwise. |
---|
Adds a new data entry to the TimeSeries.
Parameters: |
|
---|
Applies the given ForecastingAlgorithm or SmoothingMethod from the pycast.methods module to the TimeSeries.
Parameters: | method (BaseMethod) – Method that should be used with the TimeSeries. For more information about the methods take a look into their corresponding documentation. |
---|---|
Raise: | Raises a StandardError when the TimeSeries was not normalized and hte method requires a normalized TimeSeries |
Converts the given float representing UNIX-epochs into an actual timestamp.
Parameters: |
|
---|---|
Returns: | Returns the timestamp as defined in format. |
Return type: | string |
Converts the given timestamp into a float representing UNIX-epochs.
Parameters: |
|
---|---|
Returns: | Returns an float, representing the UNIX-epochs for the given timestamp. |
Return type: | float |
Creates a new TimeSeries instance from the data stored inside a two dimensional list.
Parameters: |
|
---|---|
Returns: | Returns a TimeSeries instance containing the data from datalist. |
Return type: | TimeSeries |
Initializes the TimeSeries’s data from the given SQL cursor.
You need to set the time stamp format using TimeSeries.set_timeformat().
Parameters: | sqlcursor (SQLCursor) – Cursor that was holds the SQL result for any given “SELECT timestamp, value, ... FROM ...” SQL query. Only the first two attributes of the SQL result will be used. |
---|---|
Returns: | Returns the number of entries added to the TimeSeries. |
Return type: | integer |
Returns if the TimeSeries is normalized.
Returns: | Returns True if the TimeSeries is normalized, False otherwise. |
---|---|
Return type: | boolean |
Returns if the TimeSeries is sorted.
Returns: | Returns True if the TimeSeries is sorted ascending, False in all other cases. |
---|---|
Return type: | boolean |
Normalizes the TimeSeries data points.
If this function is called, the TimeSeries gets ordered ascending automatically. The new timestamps will represent the center of each time bucket. Within a normalized TimeSeries, the temporal distance between two consecutive data points is constant.
Parameters: |
|
---|---|
Raise: | Raises a ValueError if a normalizationLevel, fusionMethod or interpolationMethod hanve an unknown value. |
Samples with replacement from the TimeSeries. Returns the sample and the remaining timeseries. The original timeseries is not changed.
Parameters: | percentage (float) – How many percent of the original timeseries should be in the sample |
---|---|
Returns: | A tuple containing (sample, rest) as two TimeSeries. |
Return type: | tuple(TimeSeries,TimeSeries) |
Raise: | Raises a ValueError if percentage is not in (0.0, 1.0). |
Sets the TimeSeries global time format.
Parameters: | format (string) – Format of the timestamp. This is used to convert the timestamp from UNIX epochs when the TimeSeries gets serialized by TimeSeries.to_json() and TimeSeries.to_gnuplot_datafile(). For valid examples take a look into the time.strptime() documentation. |
---|
Sorts the data points within the TimeSeries according to their occurrence inline.
Parameters: | ascending (boolean) – Determines if the TimeSeries will be ordered ascending or descending. If this is set to descending once, the ordered parameter defined in TimeSeries.__init__() will be set to False FOREVER. |
---|---|
Returns: | Returns self for convenience. |
Return type: | TimeSeries |
Returns a sorted copy of the TimeSeries, preserving the original one.
As an assumption this new TimeSeries is not ordered anymore if a new value is added.
Parameters: | ascending (boolean) – Determines if the TimeSeries will be ordered ascending or descending. |
---|---|
Returns: | Returns a new TimeSeries instance sorted in the requested order. |
Return type: | TimeSeries |
Dumps the TimeSeries into a gnuplot compatible data file.
Parameters: | datafilepath (string) – Path used to create the file. If that file already exists, it will be overwritten! |
---|---|
Returns: | Returns True if the data could be written, False otherwise. |
Return type: | boolean |