MutliViz Analysis Classes

Utility classes for working with the results from the analysis requests, like summarizing, plotting and exporting to a pandas dataFrame.

Basic usage:

>>> result = parse_results(session.get_analysis_results(request_id))  # call API
>>> result.plot() # plot results
>>> result.summary() # print summary table
>>> df = result.to_df() # convert to dataframe
>>> result.save_pkl() # save to pickle file

The parse function will detect the kind of request and return an object of the correct feature class.

mvg.analysis_classes.parse_results(results, t_zone=None, t_unit=None)

Parses the result from a get_analysis_results call and returns an instance of the analysis class.

Parameters
  • results (dict) – Dictionary with the server response form a get_analysis_results call.

  • t_zone (str) – timezone, if None, times will remain in epoch time [Europe/Stockholm].

  • t_unit (str) – time unit for conversion from epoch time [ms].

Returns

Object of the correct analysis class

Return type

subclass to Analysis

Raises

KeyError – If a either the dictionary is not well formed or no implementation for the analysis class exists.

Analysis Classes Base Class

class mvg.features.analysis.Analysis(results, t_zone='Europe/Stockholm', t_unit='ms')

Bases: object

Root class for analysis system classes.

check_status()
feature()

feature from request

Returns

feature

Return type

str

inputs()

inputs to the request algortihm

Returns

inputs

Return type

dict

plot(interactive=True, time_format=None)

Pro forma ancestor function.

Parameters
  • interactive (bool) – True: show plot, False: save plot

  • time_format (str, optional) – strftime format specifier for tick_x_lables. If not given only dates are shown. To show dates and time use %y%m%d-%H:%M:%S

Returns

plot file name – name of plot file (or emtpy string in case of interactive plot)

Return type

str

raw_results()

Raw results as returned by server :returns: raw_results :rtype: dict

request_id()

request_id from request

Returns

request_id

Return type

str

results()

results dict as returned from request

Returns

results

Return type

dict

save_df(file_name=None)

Save a dataframe with the analysis results. In case of filname is not given, filename will be <request_id>.csv Format of the dataframe depends on specific analysis. Will raise an exception in case no results are available.

Parameters

file_name (str) – filename to save dataframe under.

Returns

Actually used file path

Return type

str

save_json(file_name=None, raw=False)

Saves the request result from the API JSON In case of filname is not given, filename will be <request_id>.json

Parameters
  • file_name (str) – filename to save object under.

  • raw (boolean) – return only alogrithm results [false, default] return full request response [true]

Returns

Actually used file path

Return type

str

save_pkl(file_name=None)

Serializes the analysis object as pickle file. In case of filname is not given, filename will be <request_id>.pkl

Parameters

file_name (str) – filename to save object under.

Returns

Actually used file path

Return type

str

sources()

sources to the request algortihm

Returns

sources

Return type

list

status()

status from request

Returns

status

Return type

str

summary()

Print header for summary function. Called as super() from specific analysis class. Will raise an exception in case request was not successful

to_df()

Return a dataframe with the analysis results. :returns: Dataframe with analysis results :rtype: dataFrame

Analysis Class for ModeId Feature

class mvg.features.modeid.ModeId(results, t_zone='Europe/Stockholm', t_unit='ms')

Bases: mvg.features.analysis.Analysis

mode_table(show_uncertain=False)

Show mode table which gives start time for each consecutive period of equal labels, including number of rows and time difference. Will also show datetimes if timezone is given when instatiating class.

Parameters

show_uncertain (bool) – wheter to consider uncertain labels in the table (False)

Returns

mode_table – Dataframe showing times when modes change.

Return type

df

plot(interactive=True, time_format=None)

Generate a basic plot on ModeId.

Parameters
  • interactive (bool) – True: show plot, False: save plot

  • time_format (str, optional) – strftime format specifier for tick_x_lables. If not given only dates are shown. To show dates and time use %y%m%d-%H:%M:%S

Returns

plot file name – name of plot file (or emtpy string in case of interactive plot)

Return type

str

summary()

Print summary on ModeId.

Returns

Summary table

Return type

dataFrame

Analysis Class for BlackSheep Feature

class mvg.features.blacksheep.BlackSheep(results, t_zone='Europe/Stockholm', t_unit='ms')

Bases: mvg.features.analysis.Analysis

plot(interactive=True, time_format=None)

Generate a (not so) basic plot for BlackSheep Will show per atypical asset changes to and from atypical modes

Parameters
  • interactive (bool) – True: show plot, False: save plot

  • time_format (str, optional) – strftime format specifier for tick_x_lables. If not given only dates are shown. To show dates and time use %y%m%d-%H:%M:%S

Returns

plot file name – name of plot file (or emtpy string in case of interactive plot)

Return type

str

summary()

Print summary on BlackSheep

Returns

Summary tables

Return type

atypical assets and stats

Analysis Class for RMS Feature

class mvg.features.rms.RMS(results, t_zone='Europe/Stockholm', t_unit='ms')

Bases: mvg.features.analysis.Analysis

Analysis class for RMS feature.

plot(interactive=True, time_format=None)

Generate a basic plot on RMS.

Parameters
  • interactive (bool) – True: show plot, False: save plot

  • time_format (str, optional) – strftime format specifier for tick_x_lables. If not given only dates are shown. To show dates and time use %y%m%d-%H:%M:%S

Returns

plot file name – name of plot file (or emtpy string in case of interactive plot)

Return type

str

summary()

Print summary information on RMS.

Returns

summary table

Return type

dataFrame