@@ -716,19 +716,11 @@ def get_series(
716716
717717 See also: https://cumulocity.com/api/core/#operation/getMeasurementSeriesResource
718718 """
719- # The 'series' parameter has to be added through a hack; it
720- # may be a list and because 'series' is by default converted to
721- # the 'valueFragmentSeries' parameter
722-
723- if series :
724- series = series if isinstance (series , str ) else ',' .join (series )
725-
726719 base_query = self ._prepare_query (
727720 resource = f'{ self .resource } /series' ,
728721 expression = expression ,
729722 source = source ,
730- # this is a non-mapped parameter
731- aggregationType = aggregation ,
723+ aggregationType = aggregation , # this is a non-mapped parameter
732724 series = series ,
733725 before = before ,
734726 after = after ,
@@ -738,14 +730,81 @@ def get_series(
738730 ** kwargs )
739731 return Series (self .c8y .get (base_query ))
740732
733+ def collect_series (
734+ self ,
735+ expression : str = None ,
736+ source : str = None ,
737+ aggregation : str = None ,
738+ series : str | Sequence [str ] = None ,
739+ before : str | datetime = None ,
740+ after : str | datetime = None ,
741+ min_age : timedelta = None ,
742+ max_age : timedelta = None ,
743+ reverse : bool = None ,
744+ value : str = None ,
745+ timestamps : bool | str = None ,
746+ ** kwargs
747+ ):
748+ """Query the database for series values.
749+
750+ This function is functionally the same as using the `get_series` function
751+ with an immediate `collect` on the result.
752+
753+ Args:
754+ expression (str): Arbitrary filter expression which will be
755+ passed to Cumulocity without change; all other filters
756+ are ignored if this is provided
757+ source (str): Database ID of a source device
758+ aggregation (str): Aggregation type
759+ series (str|Sequence[str]): Series' to query and collect; If
760+ multiple series are collected each element in the result will
761+ be a tuple. If omitted, all available series are collected.
762+ before (datetime|str): Datetime object or ISO date/time string.
763+ Only measurements assigned to a time before this date are
764+ included.
765+ after (datetime|str): Datetime object or ISO date/time string.
766+ Only measurements assigned to a time after this date are
767+ included.
768+ min_age (timedelta): Timedelta object. Only measurements of
769+ at least this age are included.
770+ max_age (timedelta): Timedelta object. Only measurements with
771+ at most this age are included.
772+ reverse (bool): Invert the order of results, starting with the
773+ most recent one.
774+ value (str): Which value (min/max) to collect. If omitted, both
775+ values will be collected, grouped as 2-tuples.
776+ timestamps (bool|str): Whether each element in the result list will
777+ be prepended with the corresponding timestamp. If True, the
778+ timestamp string will be included; Use 'datetime' or 'epoch' to
779+ parse the timestamp string.
780+
781+ Returns:
782+ A simple list or list of tuples (potentially nested) depending on the
783+ parameter combination.
784+
785+ See also: https://cumulocity.com/api/core/#operation/getMeasurementSeriesResource
786+ """
787+ result = self .get_series (
788+ expression = expression ,
789+ source = source ,
790+ aggregation = aggregation ,
791+ series = series ,
792+ before = before ,
793+ after = after ,
794+ min_age = min_age ,
795+ max_age = max_age ,
796+ reverse = reverse ,
797+ ** kwargs )
798+ return result .collect (
799+ series = series ,
800+ value = value ,
801+ timestamps = timestamps )
802+
741803 def delete_by (
742804 self ,
743805 expression : str = None ,
744806 type : str = None ,
745807 source : str | int = None ,
746- # value_fragment_type: str = None,
747- # value_fragment_series: str = None,
748- # series: str = None,
749808 date_from : str | datetime = None ,
750809 date_to : str | datetime = None ,
751810 before : str | datetime = None ,
@@ -785,9 +844,6 @@ def delete_by(
785844 expression = expression ,
786845 type = type ,
787846 source = source ,
788- # value_fragment_type=value_fragment_type,
789- # value_fragment_series=value_fragment_series,
790- # series=series,
791847 date_from = date_from ,
792848 date_to = date_to ,
793849 before = before ,
0 commit comments