mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
sort output alphabetically by item name; improve readable data so it is actually readable
This commit is contained in:
@@ -7,31 +7,31 @@ var authorUuid = 'd904bd62-da08-416b-a816-ba797c9ee265'; //... own data is done
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var thingsOfInterest = {
|
var thingsOfInterest = {
|
||||||
'Unconventional Armor ownership': {
|
'Unconventional Armor ownership': {
|
||||||
'data_path': 'items.gear.owned',
|
'data_path': 'items.gear.owned',
|
||||||
'identifyOwnershipWith': 'exists',
|
'identifyOwnershipWith': 'exists',
|
||||||
'items': [
|
'items': [
|
||||||
'headAccessory_special_wondercon_red',
|
'headAccessory_special_wondercon_red',
|
||||||
'headAccessory_special_wondercon_black',
|
'headAccessory_special_wondercon_black',
|
||||||
'back_special_wondercon_black',
|
'back_special_wondercon_black',
|
||||||
'back_special_wondercon_red',
|
'back_special_wondercon_red',
|
||||||
'body_special_wondercon_red',
|
'body_special_wondercon_red',
|
||||||
'body_special_wondercon_black',
|
'body_special_wondercon_black',
|
||||||
'body_special_wondercon_gold'
|
'body_special_wondercon_gold'
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
'Spooky Skins purchases': {
|
'Spooky Skins purchases': {
|
||||||
'data_path': 'purchased.skin',
|
'data_path': 'purchased.skin',
|
||||||
'identifyOwnershipWith': 'true',
|
'identifyOwnershipWith': 'true',
|
||||||
'items': [
|
'items': [
|
||||||
'monster',
|
'monster',
|
||||||
'pumpkin',
|
'pumpkin',
|
||||||
'skeleton',
|
'skeleton',
|
||||||
'zombie',
|
'zombie',
|
||||||
'ghost',
|
'ghost',
|
||||||
'shadow'
|
'shadow'
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var mongo = require('mongoskin');
|
var mongo = require('mongoskin');
|
||||||
@@ -63,21 +63,21 @@ dbUsers.findEach(query, fields, {batchSize:250}, function(err, user) {
|
|||||||
count++;
|
count++;
|
||||||
|
|
||||||
_.each(thingsOfInterest,function(obj,label){
|
_.each(thingsOfInterest,function(obj,label){
|
||||||
var data_path = obj['data_path'];
|
var data_path = obj['data_path'];
|
||||||
var items = obj['items'];
|
var items = obj['items'];
|
||||||
var identifyOwnershipWith = obj['identifyOwnershipWith'];
|
var identifyOwnershipWith = obj['identifyOwnershipWith'];
|
||||||
var userOwns = path(user, data_path);
|
var userOwns = path(user, data_path);
|
||||||
|
|
||||||
_.each(items,function(item){
|
_.each(items,function(item){
|
||||||
if ( (identifyOwnershipWith == 'exists' && item in userOwns) ||
|
if ( (identifyOwnershipWith == 'exists' && item in userOwns) ||
|
||||||
(identifyOwnershipWith == 'true' && userOwns[item])
|
(identifyOwnershipWith == 'true' && userOwns[item])
|
||||||
) {
|
) {
|
||||||
if (! thingsFound[label]) { thingsFound[label] = {}; }
|
if (! thingsFound[label]) { thingsFound[label] = {}; }
|
||||||
thingsFound[label][item] = (thingsFound[label][item] || 0) + 1;
|
thingsFound[label][item] = (thingsFound[label][item] || 0) + 1;
|
||||||
// console.warn(user.auth.local.username + ": " + label + ": " + item); // good for testing, bad for privacy
|
// console.warn(user.auth.local.username + ": " + label + ": " + item); // good for testing, bad for privacy
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (count%progressCount == 0) console.warn(count + ' ' + user._id);
|
if (count%progressCount == 0) console.warn(count + ' ' + user._id);
|
||||||
if (user._id == authorUuid) console.warn(authorName + ' processed');
|
if (user._id == authorUuid) console.warn(authorName + ' processed');
|
||||||
@@ -86,28 +86,31 @@ dbUsers.findEach(query, fields, {batchSize:250}, function(err, user) {
|
|||||||
|
|
||||||
|
|
||||||
function displayData() {
|
function displayData() {
|
||||||
var today = yyyymmdd(new Date());
|
var today = yyyymmdd(new Date());
|
||||||
var report = '';
|
var csvReport = '';
|
||||||
_.each(thingsFound,function(obj,label){
|
var textReport = today + '\n';
|
||||||
report += '"' + label + '"' + '\n';
|
|
||||||
var header = '"date"'; // heading row in CSV data
|
|
||||||
var data = '"' + today + '"'; // data row in CSV data
|
|
||||||
_.each(obj,function(value,key){
|
|
||||||
header += ',"' + key + '"';
|
|
||||||
data += ',"' + (value || 0) + '"';
|
|
||||||
});
|
|
||||||
report += header + '\n' + data + '\n\n';
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('\nCSV DATA:\n\n' +
|
_.each(thingsFound,function(obj,label){
|
||||||
report +
|
csvReport += '\n"' + label + '"' + '\n';
|
||||||
'\nREADABLE DATA:\n\n' +
|
textReport += '\n' + label + ':\n';
|
||||||
today + '\n' +
|
var csvHeader = '"date"'; // heading row in CSV data
|
||||||
JSON.stringify(thingsFound, null, ' ') +
|
var csvData = '"' + today + '"'; // data row in CSV data
|
||||||
'\n');
|
|
||||||
|
|
||||||
console.warn('\n' + count + ' users searched (should be >400k)\n');
|
var sortedKeys = _.sortBy(_.keys(obj), function(key){ return key; });
|
||||||
// NB: "should be" assumes that no query filter was applied to findEach
|
_.each(sortedKeys,function(key){
|
||||||
|
var value = obj[key];
|
||||||
|
csvHeader += ',"' + key + '"';
|
||||||
|
csvData += ',"' + (value || 0) + '"';
|
||||||
|
textReport += '\t' + key + ': ' + value + '\n';
|
||||||
|
});
|
||||||
|
csvReport += csvHeader + '\n' + csvData + '\n';
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('\nCSV DATA:\n' + csvReport + '\n\n' +
|
||||||
|
'READABLE DATA:\n\n' + textReport + '\n\n');
|
||||||
|
|
||||||
|
console.warn(count + ' users searched (should be >400k)\n');
|
||||||
|
// NB: "should be" assumes that no query filter was applied to findEach
|
||||||
|
|
||||||
return exiting(0);
|
return exiting(0);
|
||||||
}
|
}
|
||||||
@@ -123,12 +126,12 @@ function path(obj, path, def) {
|
|||||||
* http://stackoverflow.com/a/16190716
|
* http://stackoverflow.com/a/16190716
|
||||||
* Usage: console.log(path(someObject, pathname));
|
* Usage: console.log(path(someObject, pathname));
|
||||||
*/
|
*/
|
||||||
for(var i = 0,path = path.split('.'),len = path.length; i < len; i++){
|
for(var i = 0,path = path.split('.'),len = path.length; i < len; i++){
|
||||||
if(!obj || typeof obj !== 'object') return def;
|
if(!obj || typeof obj !== 'object') return def;
|
||||||
obj = obj[path[i]];
|
obj = obj[path[i]];
|
||||||
}
|
}
|
||||||
if(obj === 'undefined') return def;
|
if(obj === 'undefined') return def;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -162,36 +165,35 @@ All users found.
|
|||||||
CSV DATA:
|
CSV DATA:
|
||||||
|
|
||||||
"Unconventional Armor ownership"
|
"Unconventional Armor ownership"
|
||||||
"date","headAccessory_special_wondercon_red","headAccessory_special_wondercon_black","back_special_wondercon_black","back_special_wondercon_red","body_special_wondercon_red","body_special_wondercon_black","body_special_wondercon_gold"
|
"date","back_special_wondercon_black","back_special_wondercon_red","body_special_wondercon_black","body_special_wondercon_gold","body_special_wondercon_red","headAccessory_special_wondercon_black","headAccessory_special_wondercon_red"
|
||||||
"2014-09-01","9","7","7","7","7","7","7"
|
"2014-09-01","7","7","7","7","7","7","9"
|
||||||
|
|
||||||
"Spooky Skins purchases"
|
"Spooky Skins purchases"
|
||||||
"date","monster","pumpkin","skeleton","zombie","ghost","shadow"
|
"date","ghost","monster","pumpkin","shadow","skeleton","zombie"
|
||||||
"2014-09-01","3","3","4","3","2","6"
|
"2014-09-01","2","3","3","6","4","3"
|
||||||
|
|
||||||
|
|
||||||
READABLE DATA:
|
READABLE DATA:
|
||||||
|
|
||||||
2014-09-01
|
2014-09-01
|
||||||
{
|
|
||||||
"Unconventional Armor ownership": {
|
Unconventional Armor ownership:
|
||||||
"headAccessory_special_wondercon_red": 9,
|
back_special_wondercon_black: 7
|
||||||
"headAccessory_special_wondercon_black": 7,
|
back_special_wondercon_red: 7
|
||||||
"back_special_wondercon_black": 7,
|
body_special_wondercon_black: 7
|
||||||
"back_special_wondercon_red": 7,
|
body_special_wondercon_gold: 7
|
||||||
"body_special_wondercon_red": 7,
|
body_special_wondercon_red: 7
|
||||||
"body_special_wondercon_black": 7,
|
headAccessory_special_wondercon_black: 7
|
||||||
"body_special_wondercon_gold": 7
|
headAccessory_special_wondercon_red: 9
|
||||||
},
|
|
||||||
"Spooky Skins purchases": {
|
Spooky Skins purchases:
|
||||||
"monster": 3,
|
ghost: 2
|
||||||
"pumpkin": 3,
|
monster: 3
|
||||||
"skeleton": 4,
|
pumpkin: 3
|
||||||
"zombie": 3,
|
shadow: 6
|
||||||
"ghost": 2,
|
skeleton: 4
|
||||||
"shadow": 6
|
zombie: 3
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
400100 users searched (should be >400k)
|
400100 users searched (should be >400k)
|
||||||
|
|||||||
Reference in New Issue
Block a user