onadata.libs.data package

Subpackages

Submodules

onadata.libs.data.query module

Query data utility functions.

onadata.libs.data.query.flatten(lst)

Flattens a list of lists.

onadata.libs.data.query.get_date_fields(xform)

List of date field names for specified xform

onadata.libs.data.query.get_field_records(field, xform)

Queries and returns all records of the given field.

onadata.libs.data.query.get_form_submissions_aggregated_by_select_one(xform, field, name=None, group_by=None, data_view=None)

Number of submissions grouped and aggregated by select_one field

onadata.libs.data.query.get_form_submissions_grouped_by_field(xform, field, name=None, data_view=None)

Number of submissions grouped by field

onadata.libs.data.query.get_form_submissions_grouped_by_select_one(xform, field, group_by, name=None, data_view=None)

Number of submissions disaggregated by select_one field

onadata.libs.data.query.get_numeric_fields(xform)

List of numeric field names for specified xform

onadata.libs.data.query.is_date_field(xform, field)

Returns True if an XForm field is a date field.

onadata.libs.data.query.using_postgres()

Returns True if django.db.backends.postgresql is the DB engine in use

onadata.libs.data.statistics module

Statistics utility functions.

onadata.libs.data.statistics.get_all_stats(xform, field=None)

Get’s mean, median, mode, min, max, range of values in numeric fields.

Returns a dict with the fields as key and the mean, median, mode, min, max, range as a value.

onadata.libs.data.statistics.get_mean(values)

Returns numpy.mean() of values.

onadata.libs.data.statistics.get_mean_for_field(field, xform)

Returns numpy.mean() of values in the given field.

onadata.libs.data.statistics.get_mean_for_numeric_fields_in_form(xform, field)

Get’s numpy.mean() of values in numeric fields.

Returns a dict with the fields as key and the mean as a value.

onadata.libs.data.statistics.get_median(values, axis=None)

Returns numpy.median() of values for the given axis

onadata.libs.data.statistics.get_median_for_field(field, xform)

Returns numpy.median() of values in the given field.

onadata.libs.data.statistics.get_median_for_numeric_fields_in_form(xform, field=None)

Get’s numpy.median() of values in numeric fields.

Returns a dict with the fields as key and the median as a value.

onadata.libs.data.statistics.get_min_max_range(xform, field=None)

Get’s min, max, range of values in numeric fields.

Returns a dict with the fields as key and the min, max, range as a value.

onadata.libs.data.statistics.get_min_max_range_for_field(field, xform)

Returns min, max, range of values in the given field.

onadata.libs.data.statistics.get_mode(values, axis=0)

Adapted from https://github.com/scipy/scipy/blob/master/scipy/stats/stats.py#L568

onadata.libs.data.statistics.get_mode_for_field(field, xform)

Returns mode of values in the given field.

onadata.libs.data.statistics.get_mode_for_numeric_fields_in_form(xform, field=None)

Get’s mode of values in numeric fields.

Returns a dict with the fields as key and the mode as a value.

Module contents

Data utility functions.

onadata.libs.data.parse_int(num)

Parse integer from a string.

onadata.libs.data.strtobool(val)

Convert a string representation of truth to true (1) or false (0).

True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’. Raises ValueError if ‘val’ is anything else.