physalia.models module

Models that require persistence.

class physalia.models.Measurement(timestamp, use_case, app_pkg, app_version, device_model, duration, energy_consumption, power_meter='NA')[source]

Bases: object

Energy measurement information.

Attributes:
timestamp When the execution started. use_case Key identifier of the use case. app_pkg Package of the app. app_version Version of the app. device_model Device where the measurements were performed. duration Time it takes to execute the use case. energy_consumption Mean of the measurements. power_meter Name of the power meter used.
COLUMN_APP_PKG = 2
COLUMN_USE_CASE = 1
classmethod clear_database()[source]

Clear database. Deletes CSV data file.

csv_storage = './db.csv'
classmethod describe(measurements)[source]

Descriptive statistics for a set of measurements.

Get descriptive statistics for time and energy consumption for a set of measurements.

Returns:
Tuple of Energy consumption mean, std, Duration mean, std.
classmethod describe_app_use_case(app, use_case)[source]

Descriptive statistics for a stored App use case.

Get descriptive statistics for time and energy consumption of an application use case.

Args:
app (string): Application package. use_case (string): Name of the use case
Returns:
Tuple of Energy consumption mean, std, Duration mean, std.
classmethod fancy_hypothesis_test(sample_a, sample_b, name_a, name_b, out=<open file '<stdout>', mode 'w'>)[source]

Perform and describe hypothesis testing of 2 samples.

Args:
sample_a (list of Measurement): measurements of sample a sample_b (list of Measurement): measurements of sample b sample_a (String): population name of sample a sample_b (String): population name of sample b out (file): data stream for output
classmethod get_all_entries_of_app(app, use_case)[source]

Get all entries that have a specific app and use case.

If the use_case is None, all use_cases are retrieved.

classmethod get_energy_ranking()[source]

Ranking of the energy consumption of all apps.

Get apps aggregated and sorted by mean energy consumption.

Returns:
OrderedDict with key=app_pkg and value=energy_consumption
classmethod get_position_in_ranking(measurements)[source]

Get the position in ranking of a given sample of measurements.

classmethod get_unique_apps()[source]

Get all unique apps existing in the database.

Returns:
List of unique apps.
classmethod get_unique_use_cases()[source]

Get all unique use cases.

Returns:
List of unique use cases.
classmethod hypothesis_test(sample_a, sample_b)[source]

Perform hypothesis test over two samples of measurements.

Uses Welch’s t-test to check whether energy consumption is different in the populations of samples a and b.

Args:
sample_a (list of Measurement): measurements of sample a sample_b (list of Measurement): measurements of sample b
Returns:
t (float): The calculated t-statistic prob (float): The two-tailed p-value
classmethod mean_energy_consumption(measurements)[source]

Get mean energy consumption from a set of measurements.

persist()[source]

Store measurement in the database.

save_to_csv(filename)[source]

Store measurements in a CSV file.