Skip to content
8 changes: 4 additions & 4 deletions api/ingestor/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var usage = {},

/**
* Get location either from coordinate to populate country and city, or from country and city to get coordinates
* @param {params} params - params object
* @param {Params} params - params object
* @param {object} loc - location object
* @param {number} loc.lat - lattitude
* @param {number} loc.lon - longitude
Expand Down Expand Up @@ -92,7 +92,7 @@ function locFromGeoip(loc, ip_address) {

/**
* Set Location information in params but donot update it in users document
* @param {params} params - params object
* @param {Params} params - params object
* @returns {Promise} promise which resolves upon completeing processing
*/
usage.setLocation = function(params) {
Expand Down Expand Up @@ -152,7 +152,7 @@ usage.setLocation = function(params) {

/**
* Set user location in params
* @param {params} params - params object
* @param {Params} params - params object
* @param {object} loc - location info
*/
usage.setUserLocation = function(params, loc) {
Expand Down Expand Up @@ -274,7 +274,7 @@ usage;

/**
* Process all metrics and return
* @param {params} params - params object
* @param {Params} params - params object
* @returns {object} params
*/
usage.returnRequestMetrics = function(params) {
Expand Down
106 changes: 68 additions & 38 deletions api/lib/countly.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,24 @@

/**
* @typedef {import('moment-timezone').Moment} MomentTimezone
* @typedef {import('../../types/countly.common').PeriodObject} PeriodObject
* @typedef {import('../../types/countly.common').CountlyCommon} CountlyCommonType
* @typedef {import('../../types/countly.common').PercentChange} PercentChange
* @typedef {import('../../types/countly.common').DashboardData} DashboardData
* @typedef {import('../../types/countly.common').DataProperty} DataProperty
* @typedef {import('../../types/countly.common').ChartDataPoint} ChartDataPoint
* @typedef {import('../../types/countly.common').ExtractedChartData} ExtractedChartData
* @typedef {import('../../types/countly.common').ExtractedTwoLevelData} ExtractedTwoLevelData
* @typedef {import('../../types/countly.common').BarDataItem} BarDataItem
* @typedef {import('../../types/countly.common').PeriodRangeQuery} PeriodRangeQuery
* @typedef {import('../../types/countly.common').TimestampRangeQuery} TimestampRangeQuery
* @typedef {import('../../types/countly.common').ClearFunction} ClearFunction
* @typedef {import('../../types/countly.common').FixBarSegmentDataFunction} FixBarSegmentDataFunction
* @typedef {import('../../types/countly.common').FetchFunction} FetchFunction
* @typedef {import('../../types/requestProcessor').Params} Params
*/

/** @type {CountlyCommonType} */
/** @lends module:api/lib/countly.common */
var countlyCommon = {},
/**
Expand All @@ -24,8 +40,8 @@ var _period = "hour",

/**
* Calculates unique values from a hierarchical map structure
* @param {Object} dbObj - Database object containing hierarchical data (years, months, weeks, days)
* @param {Object} uniqueMap - Map with hierarchical structure (years, months, weeks, days) used to calculate unique values
* @param {Record<String, any>} dbObj - Database object containing hierarchical data (years, months, weeks, days)
* @param {Record<String, any>} uniqueMap - Map with hierarchical structure (years, months, weeks, days) used to calculate unique values
* @returns {number} - Count of unique items
*/
countlyCommon.calculateUniqueFromMap = function(dbObj, uniqueMap) {
Expand Down Expand Up @@ -316,12 +332,13 @@ function fixTimestampToMilliseconds(ts) {

/**
* Returns a period object used by all time related data calculation functions
* @param {string|any} prmPeriod period to be calculated (optional) todo:figure this type out
* @param {string} bucket - daily or monthly. If bucket is set, period will be modified to fit full months or days
* @returns {timeObject} time object
* @param {string|Array<number>|Record<string, any>} [prmPeriod] - period to be calculated (optional)
* @param {string} [bucket] - daily or monthly. If bucket is set, period will be modified to fit full months or days
* @returns {PeriodObject} period object
**/
function getPeriodObject(prmPeriod, bucket) {
var startTimestamp, endTimestamp, periodObject, cycleDuration;
/** @type {PeriodObject} */
periodObject = {
start: 0,
end: 0,
Expand Down Expand Up @@ -856,7 +873,7 @@ countlyCommon.getTimezone = function(params) {
* @param {object} period - common period in Countly
* @param {string} timezone - app timezone (optional. Pass if not using offset)
* @param {number} offset - offset in minutes
* @returns {object} - describes period range
* @returns {PeriodRangeQuery} - describes period range
*/
countlyCommon.getPeriodRange = function(period, timezone, offset) {
//Gets start and end points of period for querying in drill
Expand Down Expand Up @@ -1157,10 +1174,10 @@ countlyCommon.extractRangeData = function(db, propertyName, rangeArray, explainR
/**
* Extract single level data without metrics/segments, like total user data from users collection
* @param {object} db - countly standard metric data object
* @param {function} clearFunction - function to prefill all expected properties as u, t, n, etc with 0, so you would not have null in the result which won't work when drawing graphs
* @param {object} chartData - prefill chart data with labels, colors, etc
* @param {object} dataProperties - describing which properties and how to extract
* @returns {object} object to use in timeline graph with {"chartDP":chartData, "chartData":_.compact(tableData), "keyEvents":keyEvents}
* @param {ClearFunction} clearFunction - function to prefill all expected properties as u, t, n, etc with 0, so you would not have null in the result which won't work when drawing graphs
* @param {Array<ChartDataPoint>} chartData - prefill chart data with labels, colors, etc
* @param {Array<DataProperty>} dataProperties - describing which properties and how to extract
* @returns {ExtractedChartData} object to use in timeline graph with {"chartDP":chartData, "chartData":_.compact(tableData), "keyEvents":keyEvents}
* @example <caption>Extracting total users data from users collection</caption>
* countlyCommon.extractChartData(_sessionDb, countlySession.clearObject, [
* { data:[], label:"Total Users" }
Expand Down Expand Up @@ -1532,8 +1549,8 @@ countlyCommon.extractStackedBarData = function(db, clearFunction, chartData, dat
* @param {object} data - countly metric model data
* @param {object} props - object where key is output property name and value could be string as key from data object or function to create new value based on existing ones
* @param {function} clearObject - function to prefill all expected properties as u, t, n, etc with 0, so you would not have null in the result which won't work when drawing graphs
* @param {object} periodObject - period object override
* @returns {object} object with sparkleline data for each property
* @param {PeriodObject} periodObject - period object override
* @returns {Object<string, string>} object with sparkleline data for each property
* @example
* var sparkLines = countlyCommon.getSparklineData(countlySession.getDb(), {
* "total-sessions": "t",
Expand Down Expand Up @@ -1605,12 +1622,12 @@ countlyCommon.getSparklineData = function(data, props, clearObject, periodObject
/**
* Extract two level data with metrics/segments, like total user data from carriers collection
* @param {object} db - countly standard metric data object
* @param {object} rangeArray - array of all metrics/segments to extract (usually what is contained in meta)
* @param {function} clearFunction - function to prefill all expected properties as u, t, n, etc with 0, so you would not have null in the result which won't work when drawing graphs
* @param {object} dataProperties - describing which properties and how to extract
* @param {Array<string>} rangeArray - array of all metrics/segments to extract (usually what is contained in meta)
* @param {ClearFunction} clearFunction - function to prefill all expected properties as u, t, n, etc with 0, so you would not have null in the result which won't work when drawing graphs
* @param {Array<DataProperty>} dataProperties - describing which properties and how to extract
* @param {object=} totalUserOverrideObj - data from total users api request to correct unique user values
* @param {string=} period - period to override
* @returns {object} object to use in bar and pie charts with {"chartData":_.compact(tableData)}
* @param {PeriodObject=} period - period to override
* @returns {ExtractedTwoLevelData} object to use in bar and pie charts with {"chartData":_.compact(tableData)}
* @example <caption>Extracting carriers data from carriers collection</caption>
* var chartData = countlyCommon.extractTwoLevelData(_carrierDb, ["At&t", "Verizon"], countlyCarrier.clearObject, [
* {
Expand Down Expand Up @@ -1703,6 +1720,7 @@ countlyCommon.extractTwoLevelData = function(db, rangeArray, clearFunction, data

for (let j = 0; j < rangeArray.length; j++) {

/** @type {{[key: string]: any}} */
let tmpPropertyObj = {},
tmp_x = {};

Expand Down Expand Up @@ -1832,15 +1850,15 @@ countlyCommon.extractTwoLevelData = function(db, rangeArray, clearFunction, data
/**
* Extracts top three items (from rangeArray) that have the biggest total session counts from the db object.
* @param {object} db - countly standard metric data object
* @param {object} rangeArray - array of all metrics/segments to extract (usually what is contained in meta)
* @param {function} clearFunction - function to prefill all expected properties as u, t, n, etc with 0, so you would not have null in the result which won't work when drawing graphs
* @param {function} fetchFunction - function to fetch property, default used is function (rangeArr, dataObj) {return rangeArr;}
* @param {Array<string>} rangeArray - array of all metrics/segments to extract (usually what is contained in meta)
* @param {ClearFunction} clearFunction - function to prefill all expected properties as u, t, n, etc with 0, so you would not have null in the result which won't work when drawing graphs
* @param {FetchFunction} fetchFunction - function to fetch property, default used is function (rangeArr, dataObj) {return rangeArr;}
* @param {number} maxItems - amount of items to return, default 3, if -1 return all
* @param {string=} metric - metric to output and use in sorting, default "t"
* @param {object=} totalUserOverrideObj - data from total users api request to correct unique user values
* @param {function} fixBarSegmentData - function to make any adjustments to the extracted data based on segment
* @param {string} period - period to extract data from
* @returns {array} array with top 3 values
* @param {FixBarSegmentDataFunction} fixBarSegmentData - function to make any adjustments to the extracted data based on segment
* @param {PeriodObject} period - period to extract data from
* @returns {Array<BarDataItem>} array with top 3 values
* @example <caption>Return data</caption>
* [
* {"name":"iOS","percent":35},
Expand Down Expand Up @@ -2220,8 +2238,9 @@ countlyCommon.extractMetric = function(db, rangeArray, clearFunction, dataProper

for (let j = 0; j < rangeArray.length; j++) {

let tmpPropertyObj = {},
tmp_x = {};
/** @type {{[key: string]: any}} */
let tmpPropertyObj = {};
let tmp_x = {};

for (let i = periodMin; i < periodMax; i++) {
dataObj = countlyCommon.getDescendantProp(db, countlyCommon.periodObj.currentPeriodArr[i] + "." + rangeArray[j]);
Expand Down Expand Up @@ -2379,12 +2398,12 @@ countlyCommon.timeString = function(timespent) {
/**
* Get calculated totals for each property, usualy used as main dashboard data timeline data without metric segments
* @param {object} data - countly metric model data
* @param {array} properties - array of all properties to extract
* @param {array} unique - array of all properties that are unique from properties array. We need to apply estimation to them
* @param {Array<string>} properties - array of all properties to extract
* @param {Array<string>} unique - array of all properties that are unique from properties array. We need to apply estimation to them
* @param {object} totalUserOverrideObj - using unique property as key and total_users estimation property as value for all unique metrics that we want to have total user estimation overridden
* @param {object} prevTotalUserOverrideObj - using unique property as key and total_users estimation property as value for all unique metrics that we want to have total user estimation overridden for previous period
* @param {object} periodObject period object override for calculation
* @returns {object} dashboard data object
* @param {PeriodObject} periodObject period object override for calculation
* @returns {DashboardData} dashboard data object
* @example
* countlyCommon.getDashboardData(countlySession.getDb(), ["t", "n", "u", "d", "e", "p", "m"], ["u", "p", "m"], {u:"users"});
* //outputs
Expand Down Expand Up @@ -2422,16 +2441,27 @@ countlyCommon.getDashboardData = function(data, properties, unique, totalUserOve
return obj;
}

/** @type {{[key: string]: any}} */
var _periodObj = periodObject || countlyCommon.periodObj,
/** @type {{[key: string]: any}} */
dataArr = {},
/** @type {{[key: string]: any}} */
tmp_x,
/** @type {{[key: string]: any}} */
tmp_y,
/** @type {{[key: string]: any}} */
tmpUniqObj,
/** @type {{[key: string]: any}} */
tmpPrevUniqObj,
/** @type {{[key: string]: any}} */
current = {},
/** @type {{[key: string]: any}} */
previous = {},
/** @type {{[key: string]: any}} */
currentCheck = {},
/** @type {{[key: string]: any}} */
previousCheck = {},
/** @type {{[key: string]: any}} */
change = {},
isEstimate = false;

Expand Down Expand Up @@ -2581,9 +2611,9 @@ countlyCommon.getDashboardData = function(data, properties, unique, totalUserOve

/**
* Get timestamp query range based on request data using period and app's timezone
* @param {params} params - params object
* @param {Params} params - params object
* @param {boolean} inSeconds - if true will output result in seconds, else in miliseconds
* @returns {object} mongodb query object with preset ts field to be queried
* @returns {TimestampRangeQuery} mongodb query object with preset ts field to be queried
* @example
* countlyCommon.getTimestampRangeQuery(params, true)
* //outputs
Expand Down Expand Up @@ -2703,9 +2733,9 @@ countlyCommon.mergeMetricsByName = function(chartData, metric) {

/**
* Joined 2 arrays into one removing all duplicated values
* @param {array} x - first array
* @param {array} y - second array
* @returns {array} new array with only unique values from x and y
* @param {Array<any>} x - first array
* @param {Array<any>} y - second array
* @returns {Array<any>} new array with only unique values from x and y
* @example
* //outputs [1,2,3]
* countlyCommon.union([1,2],[2,3]);
Expand Down Expand Up @@ -2758,9 +2788,9 @@ countlyCommon.decode = function(str) {
* Get period object in atomic way from params,
* getting params.qstring.period for period
* and params.appTimezone for timezone
* @param {params} params - params object with app timezone and period
* @param {Params} params - params object with app timezone and period
* @param {(string|string[]|number[])} defaultPeriod - default period value in case it's not supplied in the params
* @returns {module:api/lib/countly.common.periodObj} period object
* @returns {PeriodObject} period object
*/
countlyCommon.getPeriodObj = function(params, defaultPeriod = "30days") {
let appTimezone = params.appTimezone || (params.app && params.app.timezone);
Expand Down Expand Up @@ -2821,9 +2851,9 @@ countlyCommon.round = function(num, digits) {

/**
* Function to fix percentage difference
* @param {Array} items - All items
* @param {Array<any>} items - All items
* @param {Number} totalPercent - Total percentage so far
* @returns {Array} items
* @returns {Array<any>} items
*/
countlyCommon.fixPercentageDelta = function(items, totalPercent) {
if (!items.length) {
Expand Down
4 changes: 2 additions & 2 deletions api/parts/data/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var countlyEvents = {},

/**
* Process JSON decoded events data from request
* @param {params} params - params object
* @param {Params} params - params object
* @returns {Promise} resolved when procesing finished
**/
countlyEvents.processEvents = function(params) {
Expand Down Expand Up @@ -201,7 +201,7 @@ countlyEvents.processEvents = function(params) {
* @param {array} appEvents - aray with existing event keys
* @param {object} appSegments - object with event key as key, and segments as array value
* @param {object} appSgValues - object in format [collection][document_id][segment] and array of values as value for inserting in database
* @param {params} params - params object
* @param {Params} params - params object
* @param {array} omitted_segments - array of segments to omit
* @param {array} whitelisted_segments - array of segments to keep
* @param {function} done - callback function to call when done processing
Expand Down
10 changes: 5 additions & 5 deletions api/parts/data/exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ exports.getType = function(key) {
};
/**
* Output data as response
* @param {params} params - params object
* @param {Params} params - params object
* @param {string} data - data to output
* @param {string} filename - name of the file to output to browser
* @param {string} type - type to be used in content type
Expand Down Expand Up @@ -331,7 +331,7 @@ function getValues(values, valuesMap, paramList, doc, options) {
}
/**
* Stream data as response
* @param {params} params - params object
* @param {Params} params - params object
* @param {Stream} stream - cursor object. Need to call stream on it.
* @param {string} options - options object
options.filename - name of the file to output to browser
Expand Down Expand Up @@ -470,7 +470,7 @@ function isObjectId(id) {
* Export data from database
* @param {object} options - options for the export
* @param {object} options.db - database connection
* @param {params} options.params - params object
* @param {Params} options.params - params object
* @param {string} options.collection - name of the collection to export
* @param {object} [options.query={}] - database query which data to filter
* @param {object} [options.projection={}] - database projections which fields to return
Expand Down Expand Up @@ -568,7 +568,7 @@ exports.fromDatabase = function(options) {
/**
* Export data from response of request
* @param {object} options - options for the export
* @param {params} options.params - params object
* @param {Params} options.params - params object
* @param {object} options.path - path for api endpoint
* @param {object} options.data - json data to use as post or query string
* @param {object} options.prop - which property to export, tries to export whole response if not provided
Expand Down Expand Up @@ -734,7 +734,7 @@ exports.fromRequestQuery = function(options) {
* Create export from provided data
* @param {string|array} data - data to format
* @param {object} options - options for the export
* @param {params} options.params - params object
* @param {Params} options.params - params object
* @param {string} [options.type=json] - type of data to output
* @param {string} [options.filename] - name of the file to output, by default auto generated
* @param {function} options.output - callback function where to pass data, by default outputs as file based on type
Expand Down
Loading
Loading