Skip to content
Snippets Groups Projects
Commit 00f2eade authored by Megan Henning's avatar Megan Henning
Browse files

check-session-length

parent 1532a587
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,8 @@ from api.jobs.gears import get_gear_by_name
# Methods should return true if all integrity checks passed
INTEGRITY_CHECKS = {
"rule_alg": "Confirm alg keys in rules table can be resolved to gear in gear table"
"rule_alg" : "Confirm alg keys in rules table can be resolved to gear in gear table",
"session_length" : "Confirm there are no sessions whose acquisition timestamps span more than 3 hours"
}
......@@ -33,6 +34,25 @@ def rule_alg():
return not errors
def session_length():
errors = False
pipeline = [
{'$match': {'timestamp': {'$ne': None}}},
{'$group': {'_id': '$session', 'min_timestamp': { '$min': '$timestamp' }, 'max_timestamp': { '$max': '$timestamp' }}},
{'$project': {'_id': '$_id', 'diff': { '$subtract': ['$max_timestamp', '$min_timestamp']}}},
{'$match': {'diff': {'$gt': 10800000}}}
]
results = config.db.command('aggregate', 'acquisitions', pipeline=pipeline)['result']
if len(results) > 0:
errors = True
logging.warning('There are {} sessions that span 3 hours.'.format(len(results)))
for r in results:
logging.warning('Session {} spans {} minutes'.format(r['_id'], r['diff']/60000))
return not errors
if __name__ == '__main__':
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment