44*/
55
66/**
7- * @typedef {import('moment-timezone') } MomentTimezone
7+ * @typedef {import('moment-timezone').Moment } MomentTimezone
88 */
99
1010/** @lends module:api/lib/countly.common */
1111var countlyCommon = { } ,
1212 /**
1313 * Reference to momentjs
14- * @type {MomentTimezone } moment
1514 */
1615 moment = require ( 'moment-timezone' ) ,
1716 underscore = require ( 'underscore' ) ;
@@ -24,57 +23,11 @@ var _period = "hour",
2423// Private Methods
2524
2625/**
27- * Returns array with unique ticks for period
28- * @param {MomentTimezone } startTimestamp - start of period
29- * @param {MomentTimezone } endTimestamp - end of period
30- * @returns {array } unique array ticks for period
31- **/
32- /*function getTicksBetween(startTimestamp, endTimestamp) {
33- var dayIt = startTimestamp.clone(),
34- ticks = [];
35-
36- while (dayIt < endTimestamp) {
37- let daysLeft = Math.round(moment.duration(endTimestamp - dayIt).asDays());
38- if (daysLeft >= dayIt.daysInMonth() && dayIt.date() === 1) {
39- ticks.push(dayIt.format("YYYY.M"));
40- dayIt.add(1 + dayIt.daysInMonth() - dayIt.date(), "days");
41- }
42- else if (daysLeft >= (7 - dayIt.day()) && dayIt.day() === 1) {
43- ticks.push(dayIt.format("YYYY.[w]W"));
44- dayIt.add(8 - dayIt.day(), "days");
45- }
46- else {
47- ticks.push(dayIt.format("YYYY.M.D"));
48- dayIt.add(1, "day");
49- }
50- }
51-
52- return ticks;
53- }*/
54-
55- /**
56- * Returns array with more generalized unique ticks for period
57- * @param {MomentTimezone } startTimestamp - start of period
58- * @param {MomentTimezone } endTimestamp - end of period
59- * @returns {array } unique array ticks for period
60- **/
61- /*function getTicksCheckBetween(startTimestamp, endTimestamp) {
62- var dayIt = startTimestamp.clone(),
63- ticks = [];
64- while (dayIt < endTimestamp) {
65- let daysLeft = Math.round(moment.duration(endTimestamp - dayIt).asDays());
66- if (daysLeft >= (dayIt.daysInMonth() * 0.5 - dayIt.date())) {
67- ticks.push(dayIt.format("YYYY.M"));
68- dayIt.add(1 + dayIt.daysInMonth() - dayIt.date(), "days");
69- }
70- else {
71- ticks.push(dayIt.format("YYYY.[w]W"));
72- dayIt.add(8 - dayIt.day(), "days");
73- }
74- }
75- return ticks;
76- }*/
77-
26+ * Calculates unique values from a hierarchical map structure
27+ * @param {Object } dbObj - Database object containing hierarchical data (years, months, weeks, days)
28+ * @param {Object } uniqueMap - Map with hierarchical structure (years, months, weeks, days) used to calculate unique values
29+ * @returns {number } - Count of unique items
30+ */
7831countlyCommon . calculateUniqueFromMap = function ( dbObj , uniqueMap ) {
7932 var u = 0 ;
8033 for ( var year in uniqueMap ) {
@@ -113,13 +66,13 @@ countlyCommon.calculateUniqueFromMap = function(dbObj, uniqueMap) {
11366} ;
11467
11568/** returns unique period check array
116- * @param {array } weeksArray_pd - weeks array
117- * @param {array } weekCounts_pd - week counts
118- * @param {array } monthsArray_pd - months array
119- * @param {array } monthCounts_pd - months counts
120- * @param {array } periodArr_pd - period array
121- * @returns {array } periods
122- */
69+ * @param {Array<string> } weeksArray_pd - weeks array
70+ * @param {Array<string> } weekCounts_pd - week counts
71+ * @param {Array<string> } monthsArray_pd - months array
72+ * @param {Array<string> } monthCounts_pd - months counts
73+ * @param {Array<string> } periodArr_pd - period array
74+ * @returns {Array<string> } periods
75+ */
12376function getUniqArray ( weeksArray_pd , weekCounts_pd , monthsArray_pd , monthCounts_pd , periodArr_pd ) {
12477
12578 if ( _period === "month" || _period === "day" || _period === "yesterday" || _period === "hour" ) {
@@ -238,12 +191,12 @@ function getUniqArray(weeksArray_pd, weekCounts_pd, monthsArray_pd, monthCounts_
238191 return uniquePeriods ;
239192}
240193/** returns unique period check array
241- * @param {array } weeksArray_pd - weeks array
242- * @param {array } weekCounts_pd - week counts
243- * @param {array } monthsArray_pd - months array
244- * @param {array } monthCounts_pd - months counts
245- * @returns {array } periods
246- */
194+ * @param {Array<string> } weeksArray_pd - weeks array
195+ * @param {Array<string> } weekCounts_pd - week counts
196+ * @param {Array<string> } monthsArray_pd - months array
197+ * @param {Array<string> } monthCounts_pd - months counts
198+ * @returns {Array<string> } periods
199+ */
247200function getUniqCheckArray ( weeksArray_pd , weekCounts_pd , monthsArray_pd , monthCounts_pd ) {
248201
249202 if ( _period === "month" || _period === "day" || _period === "yesterday" || _period === "hour" ) {
@@ -314,9 +267,9 @@ function getUniqCheckArray(weeksArray_pd, weekCounts_pd, monthsArray_pd, monthCo
314267}
315268
316269/** Function to clone object
317- * @param {object } obj - object to clone
318- * @returns {object } cloned object
319- */
270+ * @param {object } obj - object to clone
271+ * @returns {object|undefined|string|Array<string>|Date } cloned object
272+ */
320273function clone ( obj ) {
321274 if ( null === obj || "object" !== typeof obj ) {
322275 return obj ;
@@ -350,8 +303,8 @@ function clone(obj) {
350303
351304/**
352305* Returns number for timestamp making sure it is 13 digits
353- * @param {integer } ts - number we need to se as timestamp
354- * @returns {integer } timestamp in ms
306+ * @param {number } ts - number we need to se as timestamp
307+ * @returns {number } timestamp in ms
355308**/
356309function fixTimestampToMilliseconds ( ts ) {
357310 if ( ( ts + "" ) . length > 13 ) {
@@ -363,7 +316,7 @@ function fixTimestampToMilliseconds(ts) {
363316
364317/**
365318* Returns a period object used by all time related data calculation functions
366- * @param {MomentTimezone } prmPeriod period to be calculated (optional)
319+ * @param {string|any } prmPeriod period to be calculated (optional) todo:figure this type out
367320* @param {string } bucket - daily or monthly. If bucket is set, period will be modified to fit full months or days
368321* @returns {timeObject } time object
369322**/
0 commit comments