Last active
March 1, 2019 04:20
-
-
Save weisk/cf533044d18850e184081ce475101fee to your computer and use it in GitHub Desktop.
mongo stuff, aggregation framework
This file contains hidden or 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
db.auth('admin', '9b2EpmkFtasdfas--wrxo-NVwZp'); | |
const SERIAL = '3e84e930-b6af-11e8-a512-9d2b3d7cbb08'; | |
const DESCRIPTION = 'PLC_1'; | |
const NTAGS = 22; | |
const MAX_ROWS = 100; | |
const pipelineBefore = [ | |
{ $match: { serial: SERIAL, description: DESCRIPTION } }, | |
{ $group: { _id: "$date", name: { $first: "$name" }, count: { $sum: 1 }} }, | |
]; | |
const pipelineWrong = [ { $match: { "count": { $ne: NTAGS } } } ]; | |
const pipelineGood = [ { $match: { "count": { $eq: NTAGS }} } ]; | |
const pipelineAfter = [ { $sort: { _id: -1 } } ]; | |
const allTags = db.tagData.aggregate([ | |
{ $match: { serial: SERIAL, description: DESCRIPTION } }, | |
{ $group: { _id: "$name", count: { $sum: 1} } }, | |
{ $project: { _id: 0, tag: "$_id" } } | |
]).toArray().map((e) => e.tag).sort(); | |
uniqTags = [ ...new Set(allTags)]; | |
const wrongLectures = db.tagData.aggregate([...pipelineBefore, ...pipelineWrong, ...pipelineAfter]); | |
const goodLectures = db.tagData.aggregate([...pipelineBefore, ...pipelineGood, ...pipelineAfter]); | |
print(`Number of Wrong lectures length: ${wrongLectures.toArray().length}`); | |
print(`Number of Good lectures length: ${goodLectures.toArray().length}`); | |
const wrongLectures = db.tagData.aggregate([...pipelineBefore, ...pipelineWrong, ...pipelineAfter]) | |
const wrongArray = wrongLectures.toArray().slice(0, MAX_ROWS); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment