-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcompute-summaries.py
36 lines (29 loc) · 1.11 KB
/
compute-summaries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from pymongo import MongoClient
import datetime, json, copy, re
client = MongoClient('mongodb://database/argo')
db = client.argo
def get_timestamp_range(db, collection_name):
collection = db['timeseriesMeta']
filter = {"_id":collection_name}
metadoc = collection.find_one(filter)
earliest_timestamp = metadoc['timeseries'][0]
latest_timestamp = metadoc['timeseries'][-1]
# Convert timestamps to ISO 8601 format
try:
earliest_iso = earliest_timestamp.isoformat() + "Z"
latest_iso = latest_timestamp.isoformat() + "Z"
return earliest_iso, latest_iso
except:
return None, None
startDate, endDate = get_timestamp_range(db, 'noaasst')
entry = {"metagroups": ["id"], "startDate": startDate, "endDate": endDate}
rldoc = db.summaries.find_one({"_id": 'ratelimiter'})
if rldoc:
rldoc['metadata']['noaasst'] = entry
else:
rldoc = {"_id": "ratelimiter", "metadata": {"noaasst": entry}}
try:
db.summaries.replace_one({"_id": 'ratelimiter'}, rldoc, upsert=True)
except BaseException as err:
print('error: db write failure')
print(err)