api/parts/data/fetch

This module is meant from fetching data from db and processing and outputting

Source:

Methods

(static) alljobs(metric, params)

Source:

Get all jobs grouped by job name for jobs api

Parameters:
Name Type Description
metric string

name of the collection where to get data from

params params

params object with app_id and date

(static) fetchAllApps(params)

Source:

Get data for old all apps api and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchCollection(collection, params)

Source:

Get collection data for specific app and output to browser

Parameters:
Name Type Description
collection string

collection name

params params

params object

(static) fetchCountries(params)

Source:

Get data for countries api and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchDashboard(params)

Source:

Get data for dashboard api and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchDataEventsOverview(params)

Source:

Get events overview data for overview api and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchDataTopEvents(params)

Source:

Get top events data

Parameters:
Name Type Description
params params

params object

(static) fetchDurations(params)

Source:

Get durations ranges data and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchEventData(collection, params)

Source:

Fetch specific event data and output to browser

Parameters:
Name Type Description
collection string

event key

params params

params object

(static) fetchEventGroupById(params)

Source:

The return the event groups data by _id.

Parameters:
Name Type Description
params Object

params object

Properties
Name Type Description
_id string

The id of the event group id.

(static) fetchEventGroups(params)

Source:

The return the event groups data by app_id.

Parameters:
Name Type Description
params Object

params object

Properties
Name Type Description
app_id string

The id of the event group of application id.

(static) fetchEvents(params) → {void}

Source:

Get events data for events pi output to browser

Parameters:
Name Type Description
params params

params object

Returns:

void

Type
void

(static) fetchFrequency(params)

Source:

Get frequency ranges data and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchJobs(metric, params)

Source:

Get data for jobs listing for jobs api

Parameters:
Name Type Description
metric string

name of the collection where to get data from

params params

params object with app_id and date

(static) fetchLoyalty(params)

Source:

Get loyalty ranges data and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchMergedEventData(params)

Source:

Get merged data from multiple events in standard data model and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchMergedEventGroups(params)

Source:

The return the merged event data for event groups.

Parameters:
Name Type Description
params Object

params object

(static) fetchMetric(params)

Source:

Get metric data for metric api and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchSessions(params)

Source:

Get session data and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchTimeData(collection, params)

Source:

Get time data for specific metric by collection and output to browser

Parameters:
Name Type Description
collection string

collection name

params params

params object

(static) fetchTimeObj(collection, params, isCustomEvent, optionsopt)

Source:

Get Countly standard data model from database for segments or single level data as users, merging year and month and splitted docments together and output to browser

Parameters:
Name Type Attributes Description
collection string

name of the collection where to get data from

params params

params object with app_id and date

isCustomEvent boolean

if value we are fetching for custom event or standard metric

options object <optional>

additional optional settings

Properties
Name Type Attributes Description
db object <optional>

database connection to use, by default will try to use common.db

unique string <optional>

name of the metric to treat as unique, default "u" from common.dbMap.unique

id string <optional>

id to use as prefix from documents, by default will use params.app_id

levels object <optional>

describes which metrics to expect on which levels

Properties
Name Type Attributes Description
daily array <optional>

which metrics to expect on daily level, default ["t", "n", "c", "s", "dur"]

monthly array <optional>

which metrics to expect on monthly level, default ["t", "n", "d", "e", "c", "s", "dur"]

(static) fetchTop(params)

Source:

Get data for tops api and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchTops(params)

Source:

Get data for tops api and output to browser

Parameters:
Name Type Description
params params

params object

(static) fetchTotalUsersObj(metric, params)

Source:

Get data for estimating total users count if period contains today and output to browser

Parameters:
Name Type Description
metric string

name of the collection where to get data from

params params

params object with app_id and date

(static) formatTotalUsersObj(obj, forMetric, prev) → {object}

Source:

Format total users object based on propeties it has (converting short metric values to long proper ones, etc)

Parameters:
Name Type Description
obj object

total users object

forMetric string

for which metric to format result

prev boolean

get data for previous period, if available

Returns:

total users object with formated values

Type
object

(static) getMergedEventData(params, events, optionsopt, callback)

Source:

Get merged data from multiple events in standard data model

Parameters:
Name Type Attributes Description
params params

params object with app_id and date

events array

array with event keys

options object <optional>

additional optional settings

Properties
Name Type Attributes Description
db object <optional>

database connection to use, by default will try to use common.db

unique string <optional>

name of the metric to treat as unique, default "u" from common.dbMap.unique

id string <optional>

id to use as prefix from documents, by default will use params.app_id

levels object <optional>

describes which metrics to expect on which levels

Properties
Name Type Attributes Description
daily array <optional>

which metrics to expect on daily level, default ["t", "n", "c", "s", "dur"]

monthly array <optional>

which metrics to expect on monthly level, default ["t", "n", "d", "e", "c", "s", "dur"]

callback function

callback to retrieve the data, receiving only one param which is output

(static) getMergedEventGroups(params, event, optionsopt, callback)

Source:

The return the merged event data for event groups.

Parameters:
Name Type Attributes Description
params params

params object with app_id and date

event string

id of event group

options object <optional>

additional optional settings

Properties
Name Type Attributes Description
db object <optional>

database connection to use, by default will try to use common.db

unique string <optional>

name of the metric to treat as unique, default "u" from common.dbMap.unique

id string <optional>

id to use as prefix from documents, by default will use params.app_id

levels object <optional>

describes which metrics to expect on which levels

Properties
Name Type Attributes Description
daily array <optional>

which metrics to expect on daily level, default ["t", "n", "c", "s", "dur"]

monthly array <optional>

which metrics to expect on monthly level, default ["t", "n", "d", "e", "c", "s", "dur"]

callback function

callback to retrieve the data, receiving only one param which is output

(static) getMetric(params, metric, totalUsersMetric, callback)

Source:

Get metric segment data from database, merging year and month and splitted docments together and breaking down data by segment

Example

Retrieved data

[
   {"_id":"Cricket Communications","t":37,"n":21,"u":34},
   {"_id":"Tele2","t":32,"n":19,"u":31},
   {"_id":"\tAt&amp;t","t":32,"n":20,"u":31},
   {"_id":"O2","t":26,"n":19,"u":26},
   {"_id":"Metro Pcs","t":28,"n":13,"u":26},
   {"_id":"Turkcell","t":23,"n":11,"u":23},
   {"_id":"Telus","t":22,"n":15,"u":22},
   {"_id":"Rogers Wireless","t":21,"n":13,"u":21},
   {"_id":"Verizon","t":21,"n":11,"u":21},
   {"_id":"Sprint","t":21,"n":11,"u":20},
   {"_id":"Vodafone","t":22,"n":12,"u":19},
   {"_id":"Orange","t":18,"n":12,"u":18},
   {"_id":"T-mobile","t":17,"n":9,"u":17},
   {"_id":"Bell Canada","t":12,"n":6,"u":12}
]
Parameters:
Name Type Description
params params

params object with app_id and date

metric string

name of the collection where to get data from

totalUsersMetric object

data from total users api request to correct unique user values

callback function

callback to retrieve the data, receiving only one param which is output

(static) getMetricWithOptions(params, metric, totalUsersMetric, fetchTimeOptionsopt, callback)

Source:

Get metric segment data from database with options, merging year and month and splitted docments together and breaking down data by segment

Example

Retrieved data

[
   {"_id":"Cricket Communications","t":37,"n":21,"u":34},
   {"_id":"Tele2","t":32,"n":19,"u":31},
   {"_id":"\tAt&amp;t","t":32,"n":20,"u":31},
   {"_id":"O2","t":26,"n":19,"u":26},
   {"_id":"Metro Pcs","t":28,"n":13,"u":26},
   {"_id":"Turkcell","t":23,"n":11,"u":23},
   {"_id":"Telus","t":22,"n":15,"u":22},
   {"_id":"Rogers Wireless","t":21,"n":13,"u":21},
   {"_id":"Verizon","t":21,"n":11,"u":21},
   {"_id":"Sprint","t":21,"n":11,"u":20},
   {"_id":"Vodafone","t":22,"n":12,"u":19},
   {"_id":"Orange","t":18,"n":12,"u":18},
   {"_id":"T-mobile","t":17,"n":9,"u":17},
   {"_id":"Bell Canada","t":12,"n":6,"u":12}
]
Parameters:
Name Type Attributes Description
params params

params object with app_id and date

metric string

name of the collection where to get data from

totalUsersMetric object

data from total users api request to correct unique user values

fetchTimeOptions object <optional>

additional optional settings

Properties
Name Type Attributes Description
db object <optional>

database connection to use, by default will try to use common.db

unique string <optional>

name of the metric to treat as unique, default "u" from common.dbMap.unique

id string <optional>

id to use as prefix from documents, by default will use params.app_id

levels object <optional>

describes which metrics to expect on which levels

Properties
Name Type Attributes Description
daily array <optional>

which metrics to expect on daily level, default ["t", "n", "c", "s", "dur"]

monthly array <optional>

which metrics to expect on monthly level, default ["t", "n", "d", "e", "c", "s", "dur"]

callback function

callback to retrieve the data, receiving only one param which is output

(static) getPeriodObj(coll, params)

Source:

Get period and out it to browser

Parameters:
Name Type Description
coll string

collection, this is not used, but more for compliance with validation functions

params params

params object

(static) getTimeObj(collection, params, optionsopt, callback)

Source:

Get Countly standard data model from database for segments or single level data as users, merging year and month and splitted docments together

Parameters:
Name Type Attributes Description
collection string

name of the collection where to get data from

params params

params object with app_id and date

options object <optional>

additional optional settings

Properties
Name Type Attributes Description
db object <optional>

database connection to use, by default will try to use common.db

unique string <optional>

name of the metric to treat as unique, default "u" from common.dbMap.unique

id string <optional>

id to use as prefix from documents, by default will use params.app_id

levels object <optional>

describes which metrics to expect on which levels

Properties
Name Type Attributes Description
daily array <optional>

which metrics to expect on daily level, default ["t", "n", "c", "s", "dur"]

monthly array <optional>

which metrics to expect on monthly level, default ["t", "n", "d", "e", "c", "s", "dur"]

callback function

callback to retrieve the data, receiving only one param which is output

(static) getTimeObjForEvents(collection, params, optionsopt, callback)

Source:

Get Countly standard data model from database for events, merging year and month and splitted docments together

Parameters:
Name Type Attributes Description
collection string

name of the collection where to get data from

params params

params object with app_id and date

options object <optional>

additional optional settings

Properties
Name Type Attributes Description
db object <optional>

database connection to use, by default will try to use common.db

unique string <optional>

name of the metric to treat as unique, default "u" from common.dbMap.unique

id string <optional>

id to use as prefix from documents, by default will use params.app_id

levels object <optional>

describes which metrics to expect on which levels

Properties
Name Type Attributes Description
daily array <optional>

which metrics to expect on daily level, default ["t", "n", "c", "s", "dur"]

monthly array <optional>

which metrics to expect on monthly level, default ["t", "n", "d", "e", "c", "s", "dur"]

callback function

callback to retrieve the data, receiving only one param which is output

(static) getTotalUsersObj(metric, params, callback)

Source:

Get data for estimating total users count if period contains today

Parameters:
Name Type Description
metric string

name of the collection where to get data from

params params

params object with app_id and date

callback function

callback to retrieve the data, receiving only one param which is output

(static) getTotalUsersObjWithOptions(metric, params, optionsopt, callback) → {void}

Source:

Get data for estimating total users count allowing plugins to add their own data

Parameters:
Name Type Attributes Description
metric string

name of the collection where to get data from

params params

params object with app_id and date

options object <optional>

additional optional settings

Properties
Name Type Attributes Description
db object <optional>

database connection to use, by default will try to use common.db

callback function

callback to retrieve the data, receiving only one param which is output

Returns:

void

Type
void

(static) jobDetails(metric, params)

Source:

Get all documents for a given job name

Parameters:
Name Type Description
metric string

name of the collection where to get data from

params params

params object with app_id and date

(static) metricToCollection(metric) → {Array}

Source:

Get collection and metric name from metric string

Parameters:
Name Type Description
metric string

metric/segment name

Returns:

array with collection, metric, model object

Type
Array

(static) prefetchEventData(collection, params)

Source:

Prefetch event data, either by provided key or first event in the list and output result to browser

Parameters:
Name Type Description
collection string

event key

params params

params object

(inner) fetchTimeObj(collection, params, isCustomEvent, optionsopt, callback)

Source:

Fetch db data in standard format

Parameters:
Name Type Attributes Description
collection string

from which collection to fetch

params params

params object

isCustomEvent boolean

if we are fetching custom event or not

options object <optional>

additional optional settings

Properties
Name Type Attributes Description
db object <optional>

database connection to use, by default will try to use common.db

unique string <optional>

name of the metric to treat as unique, default "u" from common.dbMap.unique

id string <optional>

id to use as prefix from documents, by default will use params.app_id

levels object <optional>

describes which metrics to expect on which levels

Properties
Name Type Attributes Description
daily array <optional>

which metrics to expect on daily level, default ["t", "n", "c", "s", "dur"]

monthly array <optional>

which metrics to expect on monthly level, default ["t", "n", "d", "e", "c", "s", "dur"]

callback function

to call when fetch done

(inner) getTopThree(params, collection, callback)

Source:

Calls aggregation query to calculate top three values based on 't' in given collection

Parameters:
Name Type Description
params params

params object

collection string

collection name

callback function

callback function

(inner) union(x, y) → {array}

Source:

Returns the union of two arrays

Parameters:
Name Type Description
x array

array 1

y array

array 2

Returns:

merged array

Type
array