Skip to content

Commit f05cc60

Browse files
committed
[views] Remove old getHeatmap
1 parent 54de0eb commit f05cc60

1 file changed

Lines changed: 2 additions & 180 deletions

File tree

plugins/views/api/api.js

Lines changed: 2 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,185 +1349,7 @@ const escapedViewSegments = { "name": true, "segment": true, "height": true, "wi
13491349
* @param {Object} params - Default parameters object
13501350
* @returns {undefined} Returns nothing
13511351
*/
1352-
function getHeatmap(params) {
1353-
var result = {types: [], data: []};
1354-
1355-
var device = {};
1356-
try {
1357-
device = JSON.parse(params.qstring.device);
1358-
}
1359-
catch (SyntaxError) {
1360-
console.log('Parse device failed: ', params.qstring.device);
1361-
}
1362-
1363-
var actionType = params.qstring.actionType;
1364-
1365-
if (!(device.minWidth >= 0) || !(device.maxWidth >= 0)) {
1366-
common.returnMessage(params, 400, 'Bad request parameter: device');
1367-
return false;
1368-
}
1369-
var collectionName = "drill_events" + crypto.createHash('sha1').update("[CLY]_action" + params.qstring.app_id).digest('hex');
1370-
common.drillDb.collection(collectionName).findOne({"_id": "meta_v2"}, {_id: 0, "sg.type": 1, "sg.domain": 1}, function(err1, meta) {
1371-
if (meta && meta.sg && meta.sg.type) {
1372-
result.types = Object.keys(meta.sg.type.values);
1373-
}
1374-
else {
1375-
result.types = [];
1376-
}
1377-
if (meta && meta.sg && meta.sg.domain) {
1378-
result.domains = Object.keys(meta.sg.domain.values).map(function(item) {
1379-
return common.db.decode(item);
1380-
});
1381-
}
1382-
else {
1383-
result.domains = [];
1384-
}
1385-
common.drillDb.collection(collectionName).findOne({"_id": "meta"}, {_id: 0, "sg.type": 1, "sg.domain": 1}, function(err2, meta2) {
1386-
if (meta2 && meta2.sg && meta2.sg.type) {
1387-
common.arrayAddUniq(result.types, meta2.sg.type.values);
1388-
}
1389-
if (meta2 && meta2.sg && meta2.sg.domain) {
1390-
common.arrayAddUniq(result.domains, meta2.sg.domain.values);
1391-
}
1392-
var eventHash = crypto.createHash('sha1').update("[CLY]_action" + params.qstring.app_id).digest('hex');
1393-
var collectionMeta = "drill_meta" + params.qstring.app_id;
1394-
common.drillDb.collection(collectionMeta).findOne({"_id": "meta_" + eventHash}, {_id: 0, "sg.domain": 1}, function(err3, meta_event) {
1395-
if (meta_event && meta_event.sg && meta_event.sg.type) {
1396-
common.arrayAddUniq(result.types, Object.keys(meta_event.sg.type.values));
1397-
}
1398-
if (meta_event && meta_event.sg && meta_event.sg.domain) {
1399-
common.arrayAddUniq(result.domains, Object.keys(meta_event.sg.domain.values));
1400-
}
1401-
1402-
if (params.qstring.period) {
1403-
//check if period comes from datapicker
1404-
if (params.qstring.period.indexOf(",") !== -1) {
1405-
try {
1406-
params.qstring.period = JSON.parse(params.qstring.period);
1407-
}
1408-
catch (SyntaxError) {
1409-
log.d('Parsing custom period failed!');
1410-
common.returnMessage(params, 400, 'Bad request parameter: period');
1411-
return false;
1412-
}
1413-
}
1414-
else {
1415-
switch (params.qstring.period) {
1416-
case "month":
1417-
case "day":
1418-
case "yesterday":
1419-
case "hour":
1420-
break;
1421-
default:
1422-
if (!/([0-9]+)days/.test(params.qstring.period)) {
1423-
common.returnMessage(params, 400, 'Bad request parameter: period');
1424-
return false;
1425-
}
1426-
break;
1427-
}
1428-
}
1429-
}
1430-
else {
1431-
common.returnMessage(params, 400, 'Missing request parameter: period');
1432-
return false;
1433-
}
1434-
countlyCommon.setTimezone(params.appTimezone);
1435-
countlyCommon.setPeriod(params.qstring.period);
1436-
var periodObj = countlyCommon.periodObj,
1437-
queryObject = {},
1438-
now = params.time.now.toDate();
1439-
1440-
//create current period array if it does not exist
1441-
if (!periodObj.currentPeriodArr) {
1442-
periodObj.currentPeriodArr = [];
1443-
1444-
//create a period array that starts from the beginning of the current year until today
1445-
if (params.qstring.period === "month") {
1446-
for (let i = 0; i < (now.getMonth() + 1); i++) {
1447-
var moment1 = moment();
1448-
var daysInMonth = moment1.month(i).daysInMonth();
1449-
1450-
for (var j = 0; j < daysInMonth; j++) {
1451-
periodObj.currentPeriodArr.push(periodObj.activePeriod + "." + (i + 1) + "." + (j + 1));
1452-
1453-
// If current day of current month, just break
1454-
if ((i === now.getMonth()) && (j === (now.getDate() - 1))) {
1455-
break;
1456-
}
1457-
}
1458-
}
1459-
}
1460-
//create a period array that starts from the beginning of the current month until today
1461-
else if (params.qstring.period === "day") {
1462-
for (let i = 0; i < now.getDate(); i++) {
1463-
periodObj.currentPeriodArr.push(periodObj.activePeriod + "." + (i + 1));
1464-
}
1465-
}
1466-
//create one day period array
1467-
else {
1468-
periodObj.currentPeriodArr.push(periodObj.activePeriod);
1469-
}
1470-
}
1471-
1472-
//get timestamps of start of days (DD-MM-YYYY-00:00) with respect to apptimezone for both beginning and end of period arrays
1473-
var tmpArr;
1474-
var ts = {};
1475-
1476-
tmpArr = periodObj.currentPeriodArr[0].split(".");
1477-
ts.$gte = moment(new Date(Date.UTC(parseInt(tmpArr[0]), parseInt(tmpArr[1]) - 1, parseInt(tmpArr[2]))));
1478-
if (params.appTimezone) {
1479-
ts.$gte.tz(params.appTimezone);
1480-
}
1481-
ts.$gte = ts.$gte.valueOf() - ts.$gte.utcOffset() * 60000;
1482-
1483-
tmpArr = periodObj.currentPeriodArr[periodObj.currentPeriodArr.length - 1].split(".");
1484-
ts.$lt = moment(new Date(Date.UTC(parseInt(tmpArr[0]), parseInt(tmpArr[1]) - 1, parseInt(tmpArr[2])))).add(1, 'days');
1485-
if (params.appTimezone) {
1486-
ts.$lt.tz(params.appTimezone);
1487-
}
1488-
ts.$lt = ts.$lt.valueOf() - ts.$lt.utcOffset() * 60000;
1489-
1490-
queryObject.ts = ts;
1491-
queryObject["sg.width"] = {};
1492-
queryObject["sg.width"].$gt = device.minWidth;
1493-
queryObject["sg.width"].$lte = device.maxWidth;
1494-
queryObject["sg.type"] = actionType;
1495-
1496-
var projections = {
1497-
_id: 0,
1498-
c: 1,
1499-
"sg.type": 1,
1500-
"sg.width": 1,
1501-
"sg.height": 1
1502-
};
1503-
1504-
if (actionType === "scroll") {
1505-
projections["sg.y"] = 1;
1506-
queryObject["sg.view"] = params.qstring.view;
1507-
}
1508-
else {
1509-
projections["sg.x"] = 1;
1510-
projections["sg.y"] = 1;
1511-
queryObject["up.lv"] = params.qstring.view;
1512-
}
1513-
1514-
if (params.qstring.segment) {
1515-
queryObject["sg.segment"] = params.qstring.segment;
1516-
}
1517-
common.drillDb.collection(collectionName).find(queryObject, projections).toArray(function(err, data) {
1518-
result.data = data;
1519-
common.returnOutput(params, result, true, params.token_headers);
1520-
});
1521-
});
1522-
});
1523-
});
1524-
}
1525-
1526-
/**
1527-
* @param {Object} params - Default parameters object
1528-
* @returns {undefined} Returns nothing
1529-
*/
1530-
async function getHeatmapNeo(params) {
1352+
async function getHeatmap(params) {
15311353
const result = {types: [], data: [], domains: []};
15321354

15331355
let device = {};
@@ -1791,7 +1613,7 @@ const escapedViewSegments = { "name": true, "segment": true, "height": true, "wi
17911613
});
17921614
}
17931615
else {
1794-
validateRead(params, FEATURE_NAME, getHeatmapNeo);
1616+
validateRead(params, FEATURE_NAME, getHeatmap);
17951617
}
17961618
return true;
17971619
}

0 commit comments

Comments
 (0)