Created
August 4, 2017 19:21
-
-
Save camillef/b9349a2e4d8696f8bdce9ebe8919c630 to your computer and use it in GitHub Desktop.
TENT-2432: TADC Metatron vs xISBN review
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conn = new Mongo(); | |
db = conn.getDB("dev_system"); | |
timestampArray = [{"timestamp": {"$lte": ISODate("2017-06-13")}}, {"timestamp": {"$gte": ISODate("2017-06-22"), "$lte": ISODate("2017-07-24")}}, {"timestamp": {"$gte": ISODate("2017-08-04")}}]; | |
total = db.work_source_responses.count({"$or": timestampArray}); | |
print('Total = ' + total); | |
metatronMatch = db.work_source_responses.count({"responses.Metatron.0": {$exists: true}, "$or": timestampArray}); | |
print('Metatron match = ' + metatronMatch + ' / ' + total + ' = ' + metatronMatch/total*100 + '%'); | |
xISBNMatch = db.work_source_responses.count({"responses.xISBN.0": {$exists: true}, "$or": timestampArray}); | |
print('xISBN match = ' + xISBNMatch + ' / ' + total + ' = ' + xISBNMatch/total*100 + '%'); | |
bothMatch = db.work_source_responses.count({"responses.Metatron.0": {$exists: true}, "responses.xISBN.0": {$exists: true}, "$or": timestampArray}); | |
print('Both match = ' + bothMatch + ' / ' + total + ' = ' + bothMatch/total*100 + '%'); | |
metatronMatchNoXISBNMatch = db.work_source_responses.count({"responses.Metatron.0": {$exists: true}, "responses.xISBN.0": {$exists: false}, "$or": timestampArray}); | |
print('Metatron match, no xISBN match = ' + metatronMatchNoXISBNMatch + ' / ' + total + ' = ' + metatronMatchNoXISBNMatch/total*100 + '%'); | |
xISBNMatchNoMetatronMatch = db.work_source_responses.count({"responses.Metatron.0": {$exists: false}, "responses.xISBN.0": {$exists: true}, "$or": timestampArray}); | |
print('xISBN match, no Metatron match = ' + xISBNMatchNoMetatronMatch + ' / ' + total + ' = ' + xISBNMatchNoMetatronMatch/total*100 + '%'); | |
neitherMatch = db.work_source_responses.count({"responses.Metatron.0": {$exists: false}, "responses.xISBN.0": {$exists: false}, "$or": timestampArray}); | |
print('Neither match = ' + neitherMatch + ' / ' + total + ' = ' + neitherMatch/total*100 + '%'); | |
compareEditionsCursor = db.work_source_responses.aggregate([ | |
{$match: {"$or": timestampArray}}, | |
{$unwind: "$responses.xISBN"}, | |
{$unwind: "$responses.Metatron"}, | |
{$group: { | |
"_id": {id: "$_id", isbn: "$isbn", tenant_code: "$tenant_code"}, | |
"xISBNFrom": {$min: "$responses.xISBN.date"}, | |
"xISBNUntil": {$max: "$responses.xISBN.date"}, | |
"MetatronFrom": {$min: "$responses.Metatron.date"}, | |
"MetatronUntil": {$max: "$responses.Metatron.date"}, | |
}}, | |
{$project: { | |
xISBNFrom: 1, | |
xISBNUntil: 1, | |
MetatronFrom: 1, | |
MetatronUntil: 1, | |
xISBNEarliest: {$cmp: ["$MetatronFrom", "$xISBNFrom"]}, | |
xISBNLatest: {$cmp: ["$xISBNUntil", "$MetatronUntil"]}, | |
MetatronEarliest: {$cmp: ["$xISBNFrom", "$MetatronFrom"]}, | |
MetatronLatest: {$cmp: ["$MetatronUntil", "$xISBNUntil"]}, | |
}}, | |
{$group: { | |
_id : {xISBNEarliest: "$xISBNEarliest", MetatronLatest: "$MetatronLatest"}, | |
count: {$sum : 1} | |
}} | |
]); | |
result = compareEditionsCursor.toArray(); | |
totalEd = 0; | |
MetatronLaterEd = 0; | |
xISBNEarlierEd = 0; | |
for (i = 0; i < result.length; ++i) { | |
if (result[i]._id.MetatronLatest === 1) { | |
MetatronLaterEd += result[i].count; | |
} | |
if (result[i]._id.xISBNEarliest === 1) { | |
xISBNEarlierEd += result[i].count; | |
} | |
totalEd += result[i].count; | |
} | |
print('Metatron had later edition = ' + MetatronLaterEd + ' / ' + totalEd + ' = ' + MetatronLaterEd/totalEd*100 + '%'); | |
print('xISBN had earlier edition = ' + xISBNEarlierEd + ' / ' + totalEd + ' = ' + xISBNEarlierEd/totalEd*100 + '%'); | |
printjson(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment