Skip to content

Commit e86af8d

Browse files
authored
Merge pull request #956 from scitran/check-session-length
Add integrity check for sessions that span longer than 3 hours
2 parents 8954b48 + 00f2ead commit e86af8d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

bin/integrity_check.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
# Methods should return true if all integrity checks passed
1212
INTEGRITY_CHECKS = {
13-
"rule_alg": "Confirm alg keys in rules table can be resolved to gear in gear table"
13+
"rule_alg" : "Confirm alg keys in rules table can be resolved to gear in gear table",
14+
"session_length" : "Confirm there are no sessions whose acquisition timestamps span more than 3 hours"
1415
}
1516

1617

@@ -33,6 +34,25 @@ def rule_alg():
3334

3435
return not errors
3536

37+
def session_length():
38+
errors = False
39+
40+
pipeline = [
41+
{'$match': {'timestamp': {'$ne': None}}},
42+
{'$group': {'_id': '$session', 'min_timestamp': { '$min': '$timestamp' }, 'max_timestamp': { '$max': '$timestamp' }}},
43+
{'$project': {'_id': '$_id', 'diff': { '$subtract': ['$max_timestamp', '$min_timestamp']}}},
44+
{'$match': {'diff': {'$gt': 10800000}}}
45+
]
46+
47+
results = config.db.command('aggregate', 'acquisitions', pipeline=pipeline)['result']
48+
if len(results) > 0:
49+
errors = True
50+
logging.warning('There are {} sessions that span 3 hours.'.format(len(results)))
51+
for r in results:
52+
logging.warning('Session {} spans {} minutes'.format(r['_id'], r['diff']/60000))
53+
54+
return not errors
55+
3656

3757
if __name__ == '__main__':
3858
try:

0 commit comments

Comments
 (0)