Skip to content

Commit

Permalink
Merge pull request #956 from scitran/check-session-length
Browse files Browse the repository at this point in the history
Add integrity check for sessions that span longer than 3 hours
  • Loading branch information
nagem authored Oct 11, 2017
2 parents 8954b48 + 00f2ead commit e86af8d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion bin/integrity_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

# 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"
}


Expand All @@ -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:
Expand Down

0 comments on commit e86af8d

Please sign in to comment.