prodata package#
Subpackages#
- prodata.preprocessing package
- Submodules
- prodata.preprocessing.checkers module
- prodata.preprocessing.datapreprocess module
- prodata.preprocessing.disaggregator module
- prodata.preprocessing.filters module
- prodata.preprocessing.markers module
- prodata.preprocessing.transformers module
- Module contents
Submodules#
prodata.deserialization module#
DataFrame deserialization helpers.
Flatten nested API responses (lists of dicts, lists of strings, machine “properties” lists) into flat DataFrame columns. Grouped here because none of them need instance state.
Used by prodata.proquery.ProQuery’s get_df and input_df methods to deserialize raw API responses into DataFrames.
- prodata.deserialization.deserialize_df(df: DataFrame, property_columns: bool = False, **kwargs) DataFrame#
Checks for list columns in the DataFrame, iterates over each row of the list column to extract any keys and values that exist within each list. These key-value pairs are then used to create a new set of columns in the resulting DataFrame.
ALl empty columns will be dropped.
- Parameters:
df – pd.Dataframe
property_columns – bool set machine properties key as column
- Returns:
A fully deserialized DataFrame.
prodata.proquery module#
- class prodata.proquery.ProApiConfig#
Bases:
ConfigurationExtended proapi Configuration that stores additional OAuth2 token metadata.
- class prodata.proquery.ProQuery(client_id: str | None = None, client_secret: str | None = None, username: str | None = None, password: str | None = None, url: str | None = None, timeout: int | None = None, retries: int | Retry | None = None, access_token: str | None = None, auto_refresh_token: bool = False, min_token_lifetime: timedelta = datetime.timedelta(seconds=3600))#
Bases:
objectClient wrapper around the Proemion API (‘proapi’ package) for scientific/data-processing use.
Four ways to call endpoints: raw responses via .api (ApiHandler), or the higher-level
get_resp(),get_df(),input_df()wrappers - see their docstrings for details.Authenticates on init, either client-based (client_id/client_secret, also settable via the PROEMION_API_CLIENT_ID/PROEMION_API_CLIENT_SECRET env vars) or user-based (username/password). For white-label deployments, pass ‘url’ (without version) instead of the default https://dataportal.proemion.com/api.
- Parameters:
client_id – Proemion API client id.
client_secret – Proemion API client secret.
username – Proemion user.
password – Proemion password.
url – Overrides the base url (without version).
timeout – Default request timeout in seconds; applied by get_resp()/ get_df()/get_timeseries() unless ‘_request_timeout’ is passed.
retries – Default retry policy for the urllib3 pool manager - an int for a simple retry count, or a urllib3.Retry for full control.
access_token – Skip authentication and use this token directly.
auto_refresh_token – Re-authenticate automatically once the token is close to expiring, using the original credentials. False by default, since enabling it keeps ‘client_secret’/’password’ in memory for the instance’s lifetime instead of dropping them after login. No effect if ‘access_token’ was used instead.
min_token_lifetime – Refresh once less than this much time is left on the token. Only relevant with auto_refresh_token=True.
- authenticate(client_id: str | None = None, client_secret: str | None = None, username: str | None = None, password: str | None = None)#
Authenticate proapi client with the API.
If client_id and client_secret are not provided checks environment variables for existence. Prioritizes client over username authentication if both are present.
- Parameters:
client_id (str) – Proemion API client id
client_secret (str) – Proemion API client secret
username (str) – Proemion user
password (str) – Proemion password
- Raises:
ValueError if none of 'client_id' and 'username' is provided. –
urllib3.exceptions.HTTPError if the request itself fails. –
- check_area_presence(df: DataFrame, _from: int | float | tuple | datetime, to: int | float | tuple | datetime, areas: list, check_column: str = 'machine_id') DataFrame#
Check if an entity was present during a machines presence in the given geo areas
An entity can be everything from the machine itself to a DTC. The DF of entities to check always needs to have the column ‘machine_id’. For a rows machine_id the area presences are queried.
By default, the presence of the machines itself is checked, check_column=’machine_id’. As long as a single presence is given the machine will be marked as present in the area, regardless of count and duration of the presences between _from and to.
In case the entity df are not machines, then the optional column ‘check_column’ of type (datetime) needs to be populated. This date is checked for the machine_id’s area presence instead of the machine itself. Example: check_column=’start’ (Start date of DTCs)
- Parameters:
df (pd.DataFrame) – DF to check for presences.
_from – Start time to query presences for. Can be an int, tuple or
see (datetime object. (-> for further info)
:param
time_conversion.convert_to_posix()): :param to: End time to query presences for. Can be an int, tuple or :param datetime object. (-> for further info see: :paramtime_conversion.convert_to_posix()): :param areas: The area ids to check presences for. :type areas: list :param check_column: Optional, the date column to check for :type check_column: str :param presences for.:Returns: Df with additional (boolean) columns per checked area. The resulting column(s) are named: {check_column}_in_area_{area_id}
- get_df(func: Callable, to_datetime: bool = True, time_delta: float | None = None, **kwargs) DataFrame#
Wrapper method that offers the same features as
get_resp()but in addition converts the data to a deserialized DataFrame- Parameters:
func – The method that calls the desired endpoint.
to_datetime (bool) – Choose whether the columns of the DataFrame containing time values should be converted to datetime objects or kept as posix timestamps.
time_delta (float) – The value in days to calculate the time range parameters ‘_from’ and ‘to’ with. (-> for further info see
time_conversion.convert_to_posix())**kwargs – if property_columns=True - instead of flat property columns, returns properties with key as column and values as rows
- Returns:
The requested data as a pd.DataFrame.
- get_dtcs(machines: list | Series, _from: int | float | tuple | datetime | None = None, to: int | float | tuple | datetime | None = None, q: str | None = None, time_delta: float | None = None, sort: str = 'start', to_datetime: bool = True, as_dataframe: bool = True)#
Gets all DTCs of the given machines.
- Parameters:
machines – List or pd.Series of machine id’s to query for.
_from – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
time_conversion.convert_to_posix())to – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
:param
time_conversion.convert_to_posix()): :param q: The query to execute for filtering. :type q: str :param time_delta: The value in days to calculate the time rangeparameters ‘_from’ and ‘to’ with. (-> for further info see
time_conversion.convert_to_posix())- Parameters:
sort (str) – The name of the property we want to use for sorting.
to_datetime (bool) – Choose whether the columns of the DataFrame containing time values should be converted to datetime objects or kept as posix timestamps.
as_dataframe – Sets the return type. If true -> pd.DataFrame - if false -> list
- Returns: A list of dicts or a pd.DataFrame containing the DTC’s of
each machine.
- get_measurements(machines: list | Series, signals: list | Series | None = None, _from: int | float | tuple | datetime | None = None, to: int | float | tuple | datetime | None = None, time_delta: float | None = None, to_datetime: bool = True, as_dataframe: bool = True)#
Gets last measurements of the given machine list and signals. If no signals provided, returns measurements for all signals. Optionally returns as DataFrame.
- Parameters:
machines – List or pd.Series of machine id’s to query for.
signals – The names of signals to fetch. Can be a list or pd.Series.
_from – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
time_conversion.convert_to_posix())to – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
:param
time_conversion.convert_to_posix()): :param time_delta: The value in days to calculate the time rangeparameters ‘_from’ and ‘to’ with. (-> for further info see
time_conversion.convert_to_posix())- Parameters:
to_datetime (bool) – Choose whether the columns of the DataFrame containing time values should be converted to datetime objects or kept as posix timestamps.
as_dataframe (bool) – Sets the return type. If true -> pd.DataFrame - if false -> list
- Returns: A list of dicts or a pd.DataFrame containing the latest values
of the signals for each machine.
- get_resp(func: Callable, time_delta: float | None = None, **kwargs) list#
Wrapper method that offers additional features compared to a direct call over API.some_api….
Offers time conversion (-> see
time_conversion.convert_to_posix()), time range handling (-> seerequest_handling.time_range_handler()) and pagination handling (-> seerequest_handling.pagination_handler())- Parameters:
func – The method that calls the desired endpoint.
time_delta (float) – The value in days to calculate the time range parameters ‘_from’ and ‘to’ with. (-> for further info see
time_conversion.convert_to_posix())**kwargs – The functions’ parameters.
- Returns:
The requested data as a list.
- get_timeseries(machine_id: str, signals: list[str], aggregation: str = 'raw', bucket: str | int = 'hour', _from: int | float | tuple | datetime | None = None, to: int | float | tuple | datetime | None = None, time_delta: float | None = None, time_zone: str | None = None, as_dataframe: bool = True, **kwargs)#
Queries timeseries for a machine and its signals.
- Parameters:
machine_id (str) – Machine ID.
signals (list) – The signal names to query.
aggregation (str) – The function to aggregate with. Possible functions are: min, max, average, std, sum, raw, avg_serial_diff, cumulative_sum or delta.
bucket (str) (int) – Denotes the number of milliseconds in each fixed time bucket to aggregate to. Predefined string options are: hour, day, week or single (end - start). If none of these fits the use case the bucket can be set up manually using an int value.
_from – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
time_conversion.convert_to_posix())to – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
:param
time_conversion.convert_to_posix()): :param time_delta: The value in days to calculate the time rangeparameters ‘_from’ and ‘to’ with. (-> for further info see
time_conversion.convert_to_posix())- Parameters:
time_zone (str) – An identifier of a time-zone in which to interpret
sizes (calendar-based bucket) – as defined by TZ-database (e.g. “Europe/Berlin”). Required only if bucketSize specifies a calendar-based period. Will be ignored if a fixed bucket size is used.
- :paramas defined by TZ-database (e.g. “Europe/Berlin”).
Required only if bucketSize specifies a calendar-based period. Will be ignored if a fixed bucket size is used.
- Parameters:
as_dataframe (bool) – Sets the return type. If true -> pd.DataFrame - if false -> list
**kwargs – Additional endpoints args like: ‘_request_timeout’.
Returns: A list of dicts or a pd.DataFrame containing the timeseries of each signal.
- get_timeseries_based_dtcs(machines: list, source_signal_key: str, spn_signal_key: str, fmi_signal_key: str, _from: int | float | tuple | datetime, to: int | float | tuple | datetime) DataFrame#
Get the DTCs for the given machines using timeseries data. :param machines: machines to request DTCs for :type machines: list :param source_signal_key: signal key of the source address :type source_signal_key: str :param spn_signal_key: signal key of the spn id :type spn_signal_key: str :param fmi_signal_key: signal key of the fmi :type fmi_signal_key: str :param _from: The starting time. Can be an integer, tuple or datetime :param object. (-> for further info see: :param
time_conversion.convert_to_posix()): :param to: The end time. Can be an integer, tuple or datetime :param object. (-> for further info see: :paramtime_conversion.convert_to_posix()):Returns: df with DTCs
- input_df(func: Callable, data: Series | DataFrame, params_col_names: dict | None = None, body_col_names: dict | list | None = None, to_datetime: bool = True, rsql_cols: list | None = None, **kwargs) DataFrame#
This function is used for mass operations.
You can pass in a pd.DataFrame or pd.Series. The method will iterate over every row and update the parameters (**kwargs) and then call the given function. Parameters set with values of the DataFrame are being updated every iteration while parameters set in **kwargs are static (used for every request). Any exceptions raised by func are caught, and their status code and message are added to the result.
- Parameters:
func – The method that calls the desired endpoint.
data – pd.Series or pd.DataFrame
params_col_names (dict) – A dict that describes what column to use
{'id' (to get the value used for the parameter.) – ‘id_column’, …}
column. (The key represents the kwarg and the value the name of the)
body_col_names (dict, list) – A copy of the request body where the
can (values in curly brackets represent the column name where you)
value. (right. '{}' in 'q' indicating a dynamic)
body (Simple request)
{
"oemExternalKey" – “{the column name
oemExternalKeys (where the values of the)
are}"
}
to_datetime (bool) – Chose weather or not the columns of the
datetime (DataFrame containing time values should be converted to)
timestamps. (objects or kept as posix)
rsql_cols (list) – A list of column names that will be used to get
to (the values for the 'q' parameter. Values will be read from left)
value.
Example – rsql_cols=[‘machine_id’, ‘filename’]
filename=={}" (-> corresponding 'q' parameter q="machine.id=={} and)
**kwargs – The functions’ parameters.
- Returns:
A deserialized DataFrame that contains the DataFrame you passed in, the response message and response code as well the response data (if any).
- internal_get_clfs_as_json(machine_id: str, _from: int | float | tuple | datetime | None = None, to: int | float | tuple | datetime | None = None, as_dataframe: bool = True)#
Method requires access to private endpoints.
Get all the clfs. If neither _from nor to are specified, the time range of last 1 hour is applied. Time range cannot be larger than 1 hour.
- Parameters:
machine_id – machine_id (str) Machine ID.
_from – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
time_conversion.convert_to_posix())to – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
:param
time_conversion.convert_to_posix()): :param as_dataframe: Returns the clfs in a DataFrame with selected columns- Returns: A dict containing all the clf data or a DataFrame containing
the most important data of the clfs.
- class prodata.proquery.TimeseriesQuery(machine_id: str, start: int, end: int, signals: list[str], aggregation: str, bucket: int | str, time_zone: str)#
Bases:
objectCarries and formats data for timeseries requests.
- aggregation: str#
- bucket: int | str#
- property delta: timedelta#
- end: int#
- halve_by_range() tuple[Self, Self]#
Halve the query by range.
Returns: tuple of two queries (lower half, upper half)
- machine_id: str#
- signals: list[str]#
- split_by_signal() list[Self]#
Split and return one query per signal.
Returns: list of queries per signal
- start: int#
- time_zone: str#
- to_data() dict#
Formats query as request data.
- prodata.proquery.refresh_token(method: Callable) Callable#
Decorator for methods that call the Proemion API directly.
If ‘auto_refresh_token’ was enabled and the access token has less than ‘min_token_lifetime’ left (or is already expired), re-runs authenticate() with the original credentials before the wrapped call.
prodata.request_handling module#
Generic Proemion API request-orchestration helpers.
Handle two API limitations that are the same for every endpoint: result pagination (limit/offset) and the 2-year max time-range per request. Grouped here because they only need pagination_limit passed in, not instance state.
Used by prodata.proquery.ProQuery.get_resp, which dispatches to these functions directly instead of via its own methods.
- prodata.request_handling.pagination_handler(func: Callable, pagination_limit: int = 1000, **kwargs) list#
Helper method that handles ‘limit’ and ‘offset’ and allows to bypass the API’s result limit.
There are 2 optional parameters that every method has. offset - The number of results to skip from start of the result set. limit - The number of results to return after offset (default: 20,
max. 1000).
- Problems: - 20 results per request as a default is not ideal since you
usually want all the results (also 1000 results as a max is in some cases not enough).
If you set a ‘limit’ you also have to set an ‘offset’ and vice versa.
So this method helps to get all the data as a default instead of only the first 20 results. If you only want a specific number of results you need to set the limit. There is a logic implemented which allows you to only use ‘limit’ and ‘offset’ in same cases:
no limit and no offset -> limit = ‘infinity’, offset = 0
limit and no offset -> limit = limit, offset = 0
no limit and offset -> limit = ‘infinity’, offset = offset
limit and offset -> limit = limit, offset = offset
- Parameters:
func – The method that calls the desired endpoint.
pagination_limit – The page size to request when no explicit ‘limit’ is given in kwargs.
**kwargs – The functions’ parameters.
- Returns:
A list of the requested results.
- prodata.request_handling.response_to_list(response_objs) list#
Converts the different response types to a list of dicts. This makes the data easier to use in other methods.
- Parameters:
response_objs – These can be classes or list classes
- Returns:
A list of dicts containing the response data.
- prodata.request_handling.time_range_handler(func: Callable, limit_offset: bool | None = None, pagination_limit: int = 1000, **kwargs) list#
Helper methods that divides request of time ranges over 2 years into multiple requests.
This needs to be done since there is an API limit only allowing request with time ranges (from-to) less than 2 years. This method will also call
pagination_handler().- Parameters:
func – The method that calls the desired endpoint.
limit_offset (bool) – Weather or not the function has ‘_from’ and ‘to’ as parameters.
pagination_limit – Forwarded to
pagination_handler()when limit_offset is True.**kwargs – The functions’ parameters.
prodata.time_conversion module#
Time/timestamp conversion helpers.
Convert between the time representations ProQuery’s public API accepts and the posix-millis / datetime formats it works with internally. Grouped here because none of them need instance state.
Used by prodata.proquery.ProQuery’s own methods (get_resp, get_df, get_dtcs, get_measurements, get_timeseries, …) to convert their ‘_from’ and ‘to’ time arguments and result DataFrames.
- prodata.time_conversion.convert_column_to_datetime(column: Series, unit: str = 'ms') Series#
Convert a series
Tries to handle a FloatingPointError that is a bug in pandas (> 2.1.4) to_datetime method: pandas-dev/pandas#58419 If the error appears, the column is split in NaN and not NaN parts and datetime conversion is only applied to the none NaN timestamps.
- Parameters:
column – pandas Series with timestamps to convert
unit – pd.to_datetime() timestamp unit default is milliseconds
- Returns:
Series as datetime
- prodata.time_conversion.convert_time_cols(df: DataFrame) DataFrame#
Converts every column of a DataFrame that contains posix timestamps to datetime objects.
- Parameters:
df (pd.DataFrame) – The DataFrame to convert.
- Returns:
The converted DataFrame where every time column now contains datetime objects as values.
- prodata.time_conversion.convert_to_posix(*args: int | float | tuple | datetime, delta: float | None = None) tuple#
Converts various types of date representations to posix time millis.
The different *arg types: - datetime objects: instances of :class: datetime - tuples: (Year, Month, Day, Hour, Minute, Second) where Year, Month and Day are required - posix timestamps: e.g. 1640995200 or 1640995200000. If the posix timestamp is in seconds it will be converted to millis.
If the delta is populated the method will return a tuple with the start value (now - delta) and the end value (now).
- Parameters:
*args – A various number of time representations.
delta (float) – The time range in days to calculate the timestamps
with.
- Returns:
Returns a tuple of posix timestamps in millis of the given *args in the given order.
- prodata.time_conversion.parse_time_value(value: int | float | tuple | datetime) datetime#
Normalize a single time value to a timezone-aware datetime.
- Parameters:
value – A datetime object, a (year, month, day, …) tuple, or a POSIX timestamp in seconds or milliseconds.
- Returns:
The equivalent UTC datetime.
- Raises:
ValueError – If value is none of the accepted types, or a tuple without at least year, month and day.
Module contents#
- class prodata.ProQuery(client_id: str | None = None, client_secret: str | None = None, username: str | None = None, password: str | None = None, url: str | None = None, timeout: int | None = None, retries: int | Retry | None = None, access_token: str | None = None, auto_refresh_token: bool = False, min_token_lifetime: timedelta = datetime.timedelta(seconds=3600))#
Bases:
objectClient wrapper around the Proemion API (‘proapi’ package) for scientific/data-processing use.
Four ways to call endpoints: raw responses via .api (ApiHandler), or the higher-level
get_resp(),get_df(),input_df()wrappers - see their docstrings for details.Authenticates on init, either client-based (client_id/client_secret, also settable via the PROEMION_API_CLIENT_ID/PROEMION_API_CLIENT_SECRET env vars) or user-based (username/password). For white-label deployments, pass ‘url’ (without version) instead of the default https://dataportal.proemion.com/api.
- Parameters:
client_id – Proemion API client id.
client_secret – Proemion API client secret.
username – Proemion user.
password – Proemion password.
url – Overrides the base url (without version).
timeout – Default request timeout in seconds; applied by get_resp()/ get_df()/get_timeseries() unless ‘_request_timeout’ is passed.
retries – Default retry policy for the urllib3 pool manager - an int for a simple retry count, or a urllib3.Retry for full control.
access_token – Skip authentication and use this token directly.
auto_refresh_token – Re-authenticate automatically once the token is close to expiring, using the original credentials. False by default, since enabling it keeps ‘client_secret’/’password’ in memory for the instance’s lifetime instead of dropping them after login. No effect if ‘access_token’ was used instead.
min_token_lifetime – Refresh once less than this much time is left on the token. Only relevant with auto_refresh_token=True.
- authenticate(client_id: str | None = None, client_secret: str | None = None, username: str | None = None, password: str | None = None)#
Authenticate proapi client with the API.
If client_id and client_secret are not provided checks environment variables for existence. Prioritizes client over username authentication if both are present.
- Parameters:
client_id (str) – Proemion API client id
client_secret (str) – Proemion API client secret
username (str) – Proemion user
password (str) – Proemion password
- Raises:
ValueError if none of 'client_id' and 'username' is provided. –
urllib3.exceptions.HTTPError if the request itself fails. –
- check_area_presence(df: DataFrame, _from: int | float | tuple | datetime, to: int | float | tuple | datetime, areas: list, check_column: str = 'machine_id') DataFrame#
Check if an entity was present during a machines presence in the given geo areas
An entity can be everything from the machine itself to a DTC. The DF of entities to check always needs to have the column ‘machine_id’. For a rows machine_id the area presences are queried.
By default, the presence of the machines itself is checked, check_column=’machine_id’. As long as a single presence is given the machine will be marked as present in the area, regardless of count and duration of the presences between _from and to.
In case the entity df are not machines, then the optional column ‘check_column’ of type (datetime) needs to be populated. This date is checked for the machine_id’s area presence instead of the machine itself. Example: check_column=’start’ (Start date of DTCs)
- Parameters:
df (pd.DataFrame) – DF to check for presences.
_from – Start time to query presences for. Can be an int, tuple or
see (datetime object. (-> for further info)
:param
time_conversion.convert_to_posix()): :param to: End time to query presences for. Can be an int, tuple or :param datetime object. (-> for further info see: :paramtime_conversion.convert_to_posix()): :param areas: The area ids to check presences for. :type areas: list :param check_column: Optional, the date column to check for :type check_column: str :param presences for.:Returns: Df with additional (boolean) columns per checked area. The resulting column(s) are named: {check_column}_in_area_{area_id}
- get_df(func: Callable, to_datetime: bool = True, time_delta: float | None = None, **kwargs) DataFrame#
Wrapper method that offers the same features as
get_resp()but in addition converts the data to a deserialized DataFrame- Parameters:
func – The method that calls the desired endpoint.
to_datetime (bool) – Choose whether the columns of the DataFrame containing time values should be converted to datetime objects or kept as posix timestamps.
time_delta (float) – The value in days to calculate the time range parameters ‘_from’ and ‘to’ with. (-> for further info see
time_conversion.convert_to_posix())**kwargs – if property_columns=True - instead of flat property columns, returns properties with key as column and values as rows
- Returns:
The requested data as a pd.DataFrame.
- get_dtcs(machines: list | Series, _from: int | float | tuple | datetime | None = None, to: int | float | tuple | datetime | None = None, q: str | None = None, time_delta: float | None = None, sort: str = 'start', to_datetime: bool = True, as_dataframe: bool = True)#
Gets all DTCs of the given machines.
- Parameters:
machines – List or pd.Series of machine id’s to query for.
_from – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
time_conversion.convert_to_posix())to – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
:param
time_conversion.convert_to_posix()): :param q: The query to execute for filtering. :type q: str :param time_delta: The value in days to calculate the time rangeparameters ‘_from’ and ‘to’ with. (-> for further info see
time_conversion.convert_to_posix())- Parameters:
sort (str) – The name of the property we want to use for sorting.
to_datetime (bool) – Choose whether the columns of the DataFrame containing time values should be converted to datetime objects or kept as posix timestamps.
as_dataframe – Sets the return type. If true -> pd.DataFrame - if false -> list
- Returns: A list of dicts or a pd.DataFrame containing the DTC’s of
each machine.
- get_measurements(machines: list | Series, signals: list | Series | None = None, _from: int | float | tuple | datetime | None = None, to: int | float | tuple | datetime | None = None, time_delta: float | None = None, to_datetime: bool = True, as_dataframe: bool = True)#
Gets last measurements of the given machine list and signals. If no signals provided, returns measurements for all signals. Optionally returns as DataFrame.
- Parameters:
machines – List or pd.Series of machine id’s to query for.
signals – The names of signals to fetch. Can be a list or pd.Series.
_from – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
time_conversion.convert_to_posix())to – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
:param
time_conversion.convert_to_posix()): :param time_delta: The value in days to calculate the time rangeparameters ‘_from’ and ‘to’ with. (-> for further info see
time_conversion.convert_to_posix())- Parameters:
to_datetime (bool) – Choose whether the columns of the DataFrame containing time values should be converted to datetime objects or kept as posix timestamps.
as_dataframe (bool) – Sets the return type. If true -> pd.DataFrame - if false -> list
- Returns: A list of dicts or a pd.DataFrame containing the latest values
of the signals for each machine.
- get_resp(func: Callable, time_delta: float | None = None, **kwargs) list#
Wrapper method that offers additional features compared to a direct call over API.some_api….
Offers time conversion (-> see
time_conversion.convert_to_posix()), time range handling (-> seerequest_handling.time_range_handler()) and pagination handling (-> seerequest_handling.pagination_handler())- Parameters:
func – The method that calls the desired endpoint.
time_delta (float) – The value in days to calculate the time range parameters ‘_from’ and ‘to’ with. (-> for further info see
time_conversion.convert_to_posix())**kwargs – The functions’ parameters.
- Returns:
The requested data as a list.
- get_timeseries(machine_id: str, signals: list[str], aggregation: str = 'raw', bucket: str | int = 'hour', _from: int | float | tuple | datetime | None = None, to: int | float | tuple | datetime | None = None, time_delta: float | None = None, time_zone: str | None = None, as_dataframe: bool = True, **kwargs)#
Queries timeseries for a machine and its signals.
- Parameters:
machine_id (str) – Machine ID.
signals (list) – The signal names to query.
aggregation (str) – The function to aggregate with. Possible functions are: min, max, average, std, sum, raw, avg_serial_diff, cumulative_sum or delta.
bucket (str) (int) – Denotes the number of milliseconds in each fixed time bucket to aggregate to. Predefined string options are: hour, day, week or single (end - start). If none of these fits the use case the bucket can be set up manually using an int value.
_from – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
time_conversion.convert_to_posix())to – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
:param
time_conversion.convert_to_posix()): :param time_delta: The value in days to calculate the time rangeparameters ‘_from’ and ‘to’ with. (-> for further info see
time_conversion.convert_to_posix())- Parameters:
time_zone (str) – An identifier of a time-zone in which to interpret
sizes (calendar-based bucket) – as defined by TZ-database (e.g. “Europe/Berlin”). Required only if bucketSize specifies a calendar-based period. Will be ignored if a fixed bucket size is used.
- :paramas defined by TZ-database (e.g. “Europe/Berlin”).
Required only if bucketSize specifies a calendar-based period. Will be ignored if a fixed bucket size is used.
- Parameters:
as_dataframe (bool) – Sets the return type. If true -> pd.DataFrame - if false -> list
**kwargs – Additional endpoints args like: ‘_request_timeout’.
Returns: A list of dicts or a pd.DataFrame containing the timeseries of each signal.
- get_timeseries_based_dtcs(machines: list, source_signal_key: str, spn_signal_key: str, fmi_signal_key: str, _from: int | float | tuple | datetime, to: int | float | tuple | datetime) DataFrame#
Get the DTCs for the given machines using timeseries data. :param machines: machines to request DTCs for :type machines: list :param source_signal_key: signal key of the source address :type source_signal_key: str :param spn_signal_key: signal key of the spn id :type spn_signal_key: str :param fmi_signal_key: signal key of the fmi :type fmi_signal_key: str :param _from: The starting time. Can be an integer, tuple or datetime :param object. (-> for further info see: :param
time_conversion.convert_to_posix()): :param to: The end time. Can be an integer, tuple or datetime :param object. (-> for further info see: :paramtime_conversion.convert_to_posix()):Returns: df with DTCs
- input_df(func: Callable, data: Series | DataFrame, params_col_names: dict | None = None, body_col_names: dict | list | None = None, to_datetime: bool = True, rsql_cols: list | None = None, **kwargs) DataFrame#
This function is used for mass operations.
You can pass in a pd.DataFrame or pd.Series. The method will iterate over every row and update the parameters (**kwargs) and then call the given function. Parameters set with values of the DataFrame are being updated every iteration while parameters set in **kwargs are static (used for every request). Any exceptions raised by func are caught, and their status code and message are added to the result.
- Parameters:
func – The method that calls the desired endpoint.
data – pd.Series or pd.DataFrame
params_col_names (dict) – A dict that describes what column to use
{'id' (to get the value used for the parameter.) – ‘id_column’, …}
column. (The key represents the kwarg and the value the name of the)
body_col_names (dict, list) – A copy of the request body where the
can (values in curly brackets represent the column name where you)
value. (right. '{}' in 'q' indicating a dynamic)
body (Simple request)
{
"oemExternalKey" – “{the column name
oemExternalKeys (where the values of the)
are}"
}
to_datetime (bool) – Chose weather or not the columns of the
datetime (DataFrame containing time values should be converted to)
timestamps. (objects or kept as posix)
rsql_cols (list) – A list of column names that will be used to get
to (the values for the 'q' parameter. Values will be read from left)
value.
Example – rsql_cols=[‘machine_id’, ‘filename’]
filename=={}" (-> corresponding 'q' parameter q="machine.id=={} and)
**kwargs – The functions’ parameters.
- Returns:
A deserialized DataFrame that contains the DataFrame you passed in, the response message and response code as well the response data (if any).
- internal_get_clfs_as_json(machine_id: str, _from: int | float | tuple | datetime | None = None, to: int | float | tuple | datetime | None = None, as_dataframe: bool = True)#
Method requires access to private endpoints.
Get all the clfs. If neither _from nor to are specified, the time range of last 1 hour is applied. Time range cannot be larger than 1 hour.
- Parameters:
machine_id – machine_id (str) Machine ID.
_from – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
time_conversion.convert_to_posix())to – The starting time. Can be an integer, tuple or datetime object. (-> for further info see
:param
time_conversion.convert_to_posix()): :param as_dataframe: Returns the clfs in a DataFrame with selected columns- Returns: A dict containing all the clf data or a DataFrame containing
the most important data of the clfs.
- pagination_limit: int#
- proapi_client: ApiClient#
- proapi_config: Configuration#
- timeout: int | None#