Created
December 10, 2015 20:35
-
-
Save joefutrelle/d1d55a4460f598ed6246 to your computer and use it in GitHub Desktop.
Fix timestamps of IFCB dashboard
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
| from oii.ifcb2.session import session | |
| from oii.ifcb2.identifiers import parse_pid, get_timestamp | |
| from oii.ifcb2.orm import Bin, TimeSeries | |
| page_size = 5000 | |
| tses = session.query(TimeSeries).all() | |
| for ts in tses: | |
| ts_label = ts.label | |
| not_done = True | |
| n = 0 | |
| print 'Working on %s' % ts_label | |
| while not_done: | |
| dirty = False | |
| not_done = False | |
| for b in session.query(Bin).filter(Bin.ts_label==ts_label).\ | |
| order_by(Bin.lid).\ | |
| offset(n*page_size).limit(page_size): | |
| not_done = True | |
| lid = b.lid | |
| lid_ts = get_timestamp(parse_pid(lid)) | |
| db_ts = b.sample_time | |
| if lid_ts != db_ts: | |
| dirty = True | |
| b.sample_time = lid_ts | |
| print ts_label, lid, db_ts, '->', lid_ts, 'FIXED' | |
| if dirty: | |
| session.commit() | |
| n = n + 1 | |
| print '... still working on %s' % ts_label | |
| session.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment