Skip to content

Commit

Permalink
Merge branch 'next' into changelog_24.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtursKadikis authored Oct 8, 2024
2 parents dc4d4b2 + 73c1257 commit 1a9f67b
Show file tree
Hide file tree
Showing 16 changed files with 3,128 additions and 190 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Enterprise Features:
- [users] UI improvements
- [views] Added a quick transition to drill

## Version 24.05.15
Enterprise fixes:
- [nps] Fixed UI issues in the widget editor related to the "user consent" section
- [ratings] Fixed rendering issue for escaped values

## Version 24.05.14
Fixes:
- [code] Added better handling for countly servers while deployed using subdirectory
Expand Down
262 changes: 262 additions & 0 deletions bin/scripts/data-reports/compare_drill_aggregated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
/*
* Script compares aggregated data from events collection with drill data for given period.
* Place script ins
* {countly}/bin/scripts/data-reports/compare_drill_aggregated.js
*
* Usage:
* node compare_drill_aggregated.js
*/
var period = "7days"; //Chose any of formats: "Xdays" ("7days","100days") or ["1-1-2024", "1-10-2024"],
var app_list = []; //List with apps
//Example var eventMap = {"6075f94b7e5e0d392902520c":["Logout","Login"],"6075f94b7e5e0d392902520d":["Logout","Login","Buy"]};
var eventMap = {}; //If left empty will run for all alls/events.
var verbose = false; //true to show more output


const Promise = require("bluebird");
const crypto = require("crypto");
var pluginManager = require("../../../plugins/pluginManager");
var fetch = require("../../../api/parts/data/fetch.js");
var countlyCommon = require("../../../api/lib/countly.common.js");
var common = require("../../../api/utils/common.js");
var moment = require("moment");

var endReport = {};

console.log("Script compares numbers in aggregated data with drill data for given period.");
Promise.all([pluginManager.dbConnection("countly"), pluginManager.dbConnection("countly_drill")]).then(async function([countlyDb, drillDb]) {
common.db = countlyDb;
console.log("Connected to databases...");
getAppList({db: countlyDb}, function(err, apps) {
if (!apps || !apps.length) {
console.log("No apps found");
return close();
}
else {
console.log("Apps found:", apps.length);
Promise.each(apps, function(app) {
return new Promise(function(resolve, reject) {
console.log("Processing app: ", app.name);
countlyDb.collection("events").findOne({_id: app._id}, {'list': 1}, function(err, events) {
if (err) {
console.log("Error getting events: ", err);
reject();
}
else {
events = events || {};
events.list = events.list || [];
events.list = events.list.filter(function(ee) {
if (ee.indexOf("[CLY]_") === 0) {
return false;
}
else {
return true;
}
});

if (eventMap && eventMap[app._id + ""]) {
var listBF = events.list.length;
events.list = events.list.filter(function(ee) {
if (eventMap && eventMap[app._id + ""]) {
return eventMap[app._id + ""].indexOf(ee) > -1;
}
else {
return false;
}
});
if (events.list.length != listBF) {
console.log(" Filtered events based on eventMap: ", events.list.length, " from ", listBF);
}

}
if (events && events.list && events.list.length) {
endReport[app._id] = {"name": app.name, "total": events.list.length, "bad": 0};
Promise.each(events.list, function(event) {
return new Promise(function(resolve2, reject2) {
console.log(" Processing event: ", event);
var params = {
app_id: app._id + "",
appTimezone: app.timezone,
qstring: { period: period},
time: common.initTimeObj(app.timezone, Date.now().valueOf())
};

//fetch drill data
var periodObject = countlyCommon.getPeriodObj({"appTimezone": app.timezone, "qstring": {"period": period}});
getDataFromDrill({event: event, app_id: app._id + "", timezone: app.timezone, drillDb: drillDb, periodObj: periodObject}, function(err, drillData) {
if (err) {
console.log(" Error getting drill data: ", err);
reject2();
}
else {
if (verbose) {
console.log(" Drill data loaded");
console.log(JSON.stringify(drillData));
}
//fetch aggregated data
var collectionName = "events" + crypto.createHash('sha1').update(event + app._id).digest('hex');

fetch.getTimeObjForEvents(collectionName, params, null, function(data) {
var mergedData = {};
var totals = {"c": 0, "s": 0, "dur": 0};
for (var z0 = 0; z0 < periodObject.currentPeriodArr.length; z0++) {
var date = periodObject.currentPeriodArr[z0].split(".");
if (data && data[date[0]] && data[date[0]][date[1]] && data[date[0]][date[1]][date[2]]) {
mergedData[periodObject.currentPeriodArr[z0]] = {};
mergedData[periodObject.currentPeriodArr[z0]].c = data[date[0]][date[1]][date[2]].c || 0;
mergedData[periodObject.currentPeriodArr[z0]].s = data[date[0]][date[1]][date[2]].s || 0;
mergedData[periodObject.currentPeriodArr[z0]].dur = data[date[0]][date[1]][date[2]].dur || 0;
totals.c += data[date[0]][date[1]][date[2]].c || 0;
totals.s += data[date[0]][date[1]][date[2]].s || 0;
totals.dur += data[date[0]][date[1]][date[2]].dur || 0;
}
}
if (verbose) {
console.log(" Aggregated data loaded");
console.log(JSON.stringify(mergedData));
}
var report = {"totals": {}, "data": {}};
var haveAnything = false;
for (var key in totals) {
if (totals[key] != drillData.totals[key]) {
report.totals[key] = (totals[key] || 0) - (drillData.totals[key] || 0);
haveAnything = true;
}
}
for (var z = 0; z < periodObject.currentPeriodArr.length; z++) {
if (drillData.data[periodObject.currentPeriodArr[z]]) {
if (mergedData[periodObject.currentPeriodArr[z]]) {
var diff = {};
for (var key0 in mergedData[periodObject.currentPeriodArr[z]]) {
diff[key0] = (mergedData[periodObject.currentPeriodArr[z]][key0] || 0) - (drillData.data[periodObject.currentPeriodArr[z]][key0] || 0);
}
if (diff.c || diff.s || diff.dur) {
report.data[periodObject.currentPeriodArr[z]] = diff;
haveAnything = true;
}
}
else {
report.data[periodObject.currentPeriodArr[z]] = {};
report.data[periodObject.currentPeriodArr[z]].c = -1 * drillData.data[periodObject.currentPeriodArr[z]].c;
report.data[periodObject.currentPeriodArr[z]].s = -1 * drillData.data[periodObject.currentPeriodArr[z]].s;
report.data[periodObject.currentPeriodArr[z]].dur = -1 * drillData.data[periodObject.currentPeriodArr[z]].dur;
haveAnything;
}
}
else {
if (mergedData[periodObject.currentPeriodArr[z]]) {
report.data[periodObject.currentPeriodArr[z]] = mergedData[periodObject.currentPeriodArr[z]];
haveAnything = true;
}
}
}
if (haveAnything) {
console.log(" " + JSON.stringify(report));
endReport[app._id]["bad"]++;
endReport[app._id]["events"] = endReport[app._id]["events"] || {};
endReport[app._id]["events"][event] = {"e": event, report: report};
}
resolve2();
});
}
});
});
}).then(function() {
console.log("Finished processing app: ", app.name);
resolve();
}).catch(function(eee) {
console.log("Error processing app: ", app.name);
console.log(eee);
reject();
});
}
else {
resolve();
}
}

});
});

}).then(function() {
console.log("Finished");
console.log(JSON.stringify(endReport));
close();
}).catch(function(eee) {
console.log("Error while fetching data");
console.log(eee);
console.log("EXITING...");
console.log(JSON.stringify(endReport));
close();
});
}
});

function getDataFromDrill(options, callback) {
var tmpArr = options.periodObj.currentPeriodArr[0].split(".");
var startDate = moment(new Date(Date.UTC(parseInt(tmpArr[0]), parseInt(tmpArr[1]) - 1, parseInt(tmpArr[2]))));
if (options.timezone) {
startDate.tz(options.timezone);
}
startDate = startDate.valueOf() - startDate.utcOffset() * 60000;

tmpArr = options.periodObj.currentPeriodArr[options.periodObj.currentPeriodArr.length - 1].split(".");
var endDate = moment(new Date(Date.UTC(parseInt(tmpArr[0]), parseInt(tmpArr[1]) - 1, parseInt(tmpArr[2])))).add(1, 'days');
if (options.timezone) {
endDate.tz(options.timezone);
}
endDate = endDate.valueOf() - endDate.utcOffset() * 60000;

let collection = "drill_events" + crypto.createHash('sha1').update(options.event + options.app_id).digest('hex');
var query = {"ts": {"$gte": startDate, "$lt": endDate}};
var pipeline = [
{"$match": query},
];

pipeline.push({"$group": {"_id": "$d", "c": {"$sum": "$c"}, "s": {"$sum": "$s"}, "dur": {"$sum": "$dur"}}});
options.drillDb.collection(collection).aggregate(pipeline, {"allowDiskUse": true}).toArray(function(err, data) {
if (err) {
console.log(err);
}
var result = {"data": {}, "totals": {"c": 0, "s": 0, "dur": 0}};
if (data && data.length > 0) {
for (var z = 0; z < data.length; z++) {
var iid = data[z]._id.split(":").join(".");
if (options.periodObj.currentPeriodArr.indexOf(iid) !== -1) {
result.data[iid] = data[z];
result.totals.c += data[z].c || 0;
result.totals.s += data[z].s || 0;
result.totals.dur += data[z].dur || 0;
}
}
}
callback(err, result);
});

}

function close() {
countlyDb.close();
drillDb.close();
console.log("Done.");
}

function getAppList(options, calllback) {
var query = {};
if (app_list && app_list.length > 0) {
var listed = [];
for (var z = 0; z < app_list.length; z++) {
listed.push(options.db.ObjectID(app_list[z]));
}
query = {_id: {$in: listed}};
}
options.db.collection("apps").find(query, {"name": 1, "timezone": 1}).toArray(function(err, apps) {
if (err) {
console.log("Error getting apps: ", err);
}
calllback(err, apps);
});


}
});
4 changes: 3 additions & 1 deletion bin/scripts/device_list/amazon.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"KFSNWI":"Fire Max 11 (2023, 13th Gen)",
"KFRAWI (2GB)":"Fire HD 8 (2022, 2GB)",
"KFRAPWI (3GB)":"Fire HD 8 (2022, 3GB)",
"KFRAPWI (4GB)":"Fire HD 8 (2024, 4GB)",
"KFQUWI": "Fire 7 (2022)",
"KFTRWI (3GB)":"Fire HD 10 (2021, 3GB)",
"KFTRPWI (4GB)":"Fire HD 10 (2021, 4GB)",
Expand Down Expand Up @@ -52,8 +53,9 @@
"AFTTIFF55":"Onida HD/FHD - Fire TV (2020)",
"AFTSHN02":"TCL 32 FHD, 40 FHD Fire TV (2023)",
"AFTMD002":"TCL Class S3 1080p LED Smart TV with Fire TV (2023)",
"AFTMD001":"Fire TV - TCL Q6 4K QLED HDR (2023)",
"AFTMA475B1":"TCL 4K Smart Fire TV (2024)",
"AFTMD001":"Fire TV - TCL S4 Series 4K UHD HDR LED (2023)",
"AFTDEC012E":"Fire TV - TCL S4/S5/Q5/Q6 Series 4K UHD HDR LED (2024)",
"AFTKA002":"Fire TV 2-Series (2023)",
"AFTKAUK002":"Fire TV 2-Series (2023)",
"AFTHA004":"Toshiba 4K UHD - Fire TV (2022)",
Expand Down
4 changes: 4 additions & 0 deletions bin/scripts/device_list/apple.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
"iPhone15,5":"iPhone 15 Plus",
"iPhone16,1":"iPhone 15 Pro",
"iPhone16,2":"iPhone 15 Pro Max",
"iPhone17,1":"iPhone 16 Pro",
"iPhone17,2":"iPhone 16 Pro Max",
"iPhone17,3":"iPhone 16",
"iPhone17,4":"iPhone 16 Plus",
"iPod1,1":"iPod touch 1G",
"iPod2,1":"iPod touch 2G",
"iPod3,1":"iPod touch 3G",
Expand Down
17 changes: 16 additions & 1 deletion bin/scripts/device_list/generate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// run as
// node generate.js > countly.device.list.js
// resulting file should be copied to "/frontend/express/public/javascripts/countly"

//https://www.theiphonewiki.com/wiki/Models
//https://gist.github.com/adamawolf/3048717
Expand All @@ -15,11 +16,17 @@ var amazon = require("./amazon.json");
for (var i in amazon) {
devices[i] = amazon[i];
}

// Informative messages are writer to stderr so they don't interfere with the stdout piping to a file
// When downloading the CSV file it will be UTF-16 LE. It needs to be transformed to UTF-8 (non BOM version)
// converting with notepad++ or vscode might not work on a windows device. Try on a mac device
process.stderr.write("Starting CSV parsing\n");
var csv = require('csvtojson');
csv()
//from https://support.google.com/googleplay/answer/1727131?hl=en-GB
.fromFile("./supported_devices.csv")
.on('json', (jsonObj)=>{
//process.stderr.write("Parsed data/json line: " + jsonObj);
var d = jsonObj["Marketing Name"] + "";
var i = jsonObj["Model"] + "";
if (i != d && d.trim().length) {
Expand All @@ -33,6 +40,14 @@ csv()
}
}
})
// .on('data', (data)=>{
// //process.stderr.write("Parsed data line: " + data);
// })
// .on('error', (err)=>{
// process.stderr.write("Error while parsing: " + err);
// })
.on('done', ()=>{
process.stderr.write("CSV parsing 'done' trigger\n");
process.stdout.write("/**\n * Object with device models as keys and pretty/marketing device names as values\n * @name countlyDeviceList\n * @global\n * @namespace countlyDeviceList\n */\nvar countlyDeviceList = " + JSON.stringify(devices, null, 4) + ";\n/*global module*/\nif (typeof module !== 'undefined' && module.exports) {\n module.exports = countlyDeviceList;\n}");
});
});
process.stderr.write("Ending CSV parsing\n");
Loading

0 comments on commit 1a9f67b

Please sign in to comment.