|
1 |
| -(function(countlyTotalUsers, $, undefined) { |
| 1 | +/* global countlyCommon, countlyGlobal, countlyDevice, _ */ |
| 2 | +(function(countlyTotalUsers, $) { |
2 | 3 |
|
3 | 4 | //Private Properties
|
4 | 5 | var _activeAppId = 0,
|
|
97 | 98 | return countlyCommon.periodObj.periodContainsToday;
|
98 | 99 | };
|
99 | 100 |
|
100 |
| - /* |
101 |
| - Sets init status for forMetric in below format |
102 |
| - { "APP_KEY": { "countries": { "60days": true } } } |
103 |
| - We don't directly use _totalUserObjects for init check because it is init after AJAX and might take time |
| 101 | + /**Sets init status for forMetric in below format |
| 102 | + * { "APP_KEY": { "countries": { "60days": true } } } |
| 103 | + * We don't directly use _totalUserObjects for init check because it is init after AJAX and might take time |
| 104 | + * @param {string} forMetric - metric for which set init status |
104 | 105 | */
|
105 | 106 | function setInit(forMetric) {
|
106 | 107 | if (!_initialized[_activeAppId]) {
|
|
114 | 115 | _initialized[_activeAppId][forMetric][_period] = true;
|
115 | 116 | }
|
116 | 117 |
|
| 118 | + /** function checks if metric is initialized |
| 119 | + * @param {string} forMetric - metric name to check |
| 120 | + * @returns {boolean} if initialized |
| 121 | + */ |
117 | 122 | function isInitialized(forMetric) {
|
118 | 123 | return _initialized[_activeAppId] &&
|
119 | 124 | _initialized[_activeAppId][forMetric] &&
|
120 | 125 | _initialized[_activeAppId][forMetric][_period];
|
121 | 126 | }
|
122 | 127 |
|
123 |
| - /* |
124 |
| - Adds data for forMetric to _totalUserObjects object in below format |
125 |
| - { "APP_KEY": { "countries": { "60days": {"TR": 1, "UK": 5} } } } |
| 128 | + /** Adds data for forMetric to _totalUserObjects object in below format |
| 129 | + * { "APP_KEY": { "countries": { "60days": {"TR": 1, "UK": 5} } } } |
| 130 | + * @param {string} forMetric - metric name |
| 131 | + * @param {object} data - data to set |
126 | 132 | */
|
127 | 133 | function setCalculatedObj(forMetric, data) {
|
128 | 134 | if (!_totalUserObjects[_activeAppId]) {
|
|
136 | 142 | _totalUserObjects[_activeAppId][forMetric][_period] = formatCalculatedObj(data, forMetric);
|
137 | 143 | }
|
138 | 144 |
|
| 145 | + /** sets refresh obj for metric |
| 146 | + * { "APP_KEY": { "countries": { "60days": {"TR": 1, "UK": 5} } } } |
| 147 | + * @param {string} forMetric - metric name |
| 148 | + * @param {object} data - data to set |
| 149 | + */ |
139 | 150 | function setRefreshObj(forMetric, data) {
|
140 | 151 | if (!_totalUserObjects[_activeAppId]) {
|
141 | 152 | _totalUserObjects[_activeAppId] = {};
|
|
148 | 159 | _totalUserObjects[_activeAppId][forMetric][_period + "_refresh"] = formatCalculatedObj(data, forMetric);
|
149 | 160 | }
|
150 | 161 |
|
151 |
| - /* |
152 |
| - Response from the API is in [{"_id":"TR","u":1},{"_id":"UK","u":5}] format |
153 |
| - We convert it to {"TR": 1, "UK": 5} format in this function |
154 |
| - processingFunction is used for cases where keys are converted before being processed (e.g. device names) |
| 162 | + /** Response from the API is in [{"_id":"TR","u":1},{"_id":"UK","u":5}] format |
| 163 | + * We convert it to {"TR": 1, "UK": 5} format in this function |
| 164 | + * processingFunction is used for cases where keys are converted before being processed (e.g. device names) |
| 165 | + * @param {object} obj - data object |
| 166 | + * @param {string} forMetric - metric name |
| 167 | + * @returns {object} converted object |
155 | 168 | */
|
156 | 169 | function formatCalculatedObj(obj, forMetric) {
|
157 | 170 | var tmpObj = {},
|
|
172 | 185 | return tmpObj;
|
173 | 186 | }
|
174 | 187 |
|
175 |
| - /* |
176 |
| - Refreshes data based the diff between current "refresh" and the new one retrieved from the API |
177 |
| - { "APP_KEY": { "countries": { "30days_refresh": {"TR": 1, "UK": 5} } } } |
| 188 | + /** Refreshes data based the diff between current "refresh" and the new one retrieved from the API |
| 189 | + * { "APP_KEY": { "countries": { "30days_refresh": {"TR": 1, "UK": 5} } } } |
| 190 | + * @param {string} forMetric - metric name |
| 191 | + * @param {object} todaysJson - data |
178 | 192 | */
|
179 | 193 | function refreshData(forMetric, todaysJson) {
|
180 | 194 | if (_totalUserObjects[_activeAppId] &&
|
|
186 | 200 | currRefreshObj = _totalUserObjects[_activeAppId][forMetric][_period + "_refresh"],
|
187 | 201 | newRefreshObj = formatCalculatedObj(todaysJson, forMetric);
|
188 | 202 |
|
189 |
| - _.each(newRefreshObj, function(value, key, list) { |
| 203 | + _.each(newRefreshObj, function(value, key) { |
190 | 204 | if (currRefreshObj[key]) {
|
191 | 205 | // If existing refresh object contains the key we refresh the value
|
192 | 206 | // in total user object to curr value + new refresh value - curr refresh value
|
|
0 commit comments