mobile_insight.analyzer.kpi.kpi_analyzer module

kpi_analyzer.py An abstraction for KPI analyzer

Author: Yuanjie Li

class mobile_insight.analyzer.kpi.kpi_analyzer.KpiAnalyzer

Bases: mobile_insight.analyzer.analyzer.Analyzer

An abstraction for KPI analyzer. It offers three functions

  1. Helpers to simplify the development of KPI tracking

  2. Automation of the KPI local storage management

  3. Automation of the KPI uploading to KPI map (cloud).

__create_db()

Create a local database for the KPI. The database is stored at /sdcard/mobileinsight/kpi/

Returns

True if the database is successfully created (or already exists), False otherwise

__create_table(kpi_name, attributes)

Create SQL tables for the kpi

Parameters
  • kpi_name (string) – name of the kpi

  • attributes (None or a list of attributes) –

__db_query(sql_cmd)

Return query result of a sql_cmd

__get_current_gps()
__get_operator_info()
__get_phone_model()
__log_kpi(kpi_name, timestamp, cell_id, kpi_value)
Parameters

kpi_name (string) – The KPI to be queried

:param timestamp :type timestamp: datetime :param cell_id: updated kpi cell id :type cell_id: string

__upload_kpi_async(kpi_name, kpi_value, cur_location)

Upload the KPI value to the cloud

Parameters
  • kpi_name (string) – The KPI to be queried

  • kpi_value (string) – The value of KPI

__upload_kpi_thread(e)

Internal thread to upload the KPI

enable_local_storage(enable_storage)

Set if the local KPI should be stored

Parameters

enable_storage (boolean) – Whether to locally store the kpi. False by default

list_kpis()

Return a list of available KPIs

Returns

a list of string, each of which is a KPI name

local_query_kpi(kpi_name, cell_id=None, timestamp=None)

Query the phone’s locally observed KPI

Parameters
  • kpi_name (string) – The KPI to be queried

  • cell_id (string) – cell global id

  • timestamp (datetime) – The timestamp of the KPI. If None, this function returns the latest KPI

Returns

The KPI value, or None if the KPI is not available

pending_upload_task = deque([])
register_kpi(kpi_type, kpi_name, callback, attributes=None)

Declare a KPI to be supported

Parameters
  • kpi_type (string) – The type of the KPI (accessibility, retainability, mobility, availability, …)

  • kpi_name (Python method) – The name of the KPI

  • callback – The callbacks to update the KPI

  • attributes (None or a list of attributes) –

Returns

True if the registeration succeeds, False otherwise (e.g., KPI already exists)

remote_query_kpi(kpi_name, phone_model, operator, gps, timestamp)

Query the remote cloud for the KPI

Parameters
  • kpi_name (string) – The KPI to be queried

  • phone_model (string) – The the phone model

  • operator (string) – The network operator

  • gps (string) – The GPS coordinate

  • timestamp (datetime) – The timestamp of the KPI.

Returns

The KPI value, or None if the KPI is not available

set_cell(kpi_showname, cell)

Set periodicity of the analyzer

Parameters
  • kpi_showname (string) – The KPI to be queried, this is the showname

  • cell (string) – cell (s,m,h,d repsents scale of seconds, minutes, hours, days)

set_operator(operator)

Set operator :param operator: string :return:

set_periodicity(kpi_showname, periodicity)

Set periodicity of the analyzer

Parameters
  • kpi_showname (string) – The KPI to be queried, this is the showname

  • periodicity (string) – periodicity (s,m,h,d repsents scale of seconds, minutes, hours, days)

set_phone_model(phone_model)

Set phone model :param phone_model: string :return:

store_kpi(kpi_name, kpi_value, timestamp, cur_location=None)

Store the KPIs to the local database

Parameters
  • kpi_name (string) – The KPI to be queried

  • kpi_value (string) – The value of KPI or a dict {attribute <type: str>: value <type: str>}

:param timestamp :type timestamp: datetime

upload_kpi(kpi_name, kpi_value)

Upload the KPI value to the cloud

Parameters
  • kpi_name (string) – The KPI to be queried

  • kpi_value (string) – The value of KPI

upload_thread = None