-
Notifications
You must be signed in to change notification settings - Fork 0
/
times_track.py
59 lines (53 loc) · 2.29 KB
/
times_track.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import datetime
import pandas as pd
import numpy as np
import pathlib
import logging
_log = logging.getLogger(__name__)
def update_proc_time(glider, mission, file_type):
if file_type == "complete":
path_base = pathlib.Path(f"/data/complete_mission/SEA{glider}/M{mission}/timeseries")
else:
path_base = pathlib.Path(f"/data/nrt/SEA{glider}/M{mission}/timeseries")
ncs = list(path_base.glob("*.nc"))
ncs.sort()
path = ncs[0]
mtime = datetime.datetime.fromtimestamp(path.lstat().st_mtime)
fn = f"/data/log/{file_type}.csv"
df = pd.read_csv(fn, parse_dates=["proc_time", "erddap_time"])
glider_mission_check = np.logical_and(df.glider == glider, df.mission == mission)
a = [glider_mission_check]
if glider_mission_check.any():
ind = df.index[tuple(a)].values[0]
df.at[ind, "proc_time"] = mtime
else:
new_row = pd.DataFrame({"glider": glider, "mission": mission,
"proc_time": mtime, "erddap_time": datetime.datetime(1970, 1, 1)}, index=[len(df)])
df = pd.concat((df, new_row))
df.sort_values("proc_time", inplace=True)
df.to_csv(fn, index=False)
def update_erddap_time(glider, mission, file_type):
fn = f"/data/log/{file_type}.csv"
df = pd.read_csv(fn, parse_dates=["proc_time", "erddap_time"])
glider_mission_check = np.logical_and(df.glider == glider, df.mission == mission)
a = [glider_mission_check]
if glider_mission_check.any():
ind = df.index[tuple(a)].values[0]
df.at[ind, "erddap_time"] = datetime.datetime.now()
else:
new_row = pd.DataFrame({"glider": glider, "mission": mission,
"erddap_time": datetime.datetime.now()}, index=[len(df)])
df = pd.concat((df, new_row))
df.sort_values("proc_time", inplace=True)
df.to_csv(fn, index=False)
def erddap_needs_update(glider, mission, file_type):
fn = f"/data/log/{file_type}.csv"
df = pd.read_csv(fn, parse_dates=["proc_time", "erddap_time"])
glider_mission_check = np.logical_and(df.glider == glider, df.mission == mission)
a = [glider_mission_check]
if glider_mission_check.any():
ind = df.index[tuple(a)].values[0]
row = df.loc[ind]
if row.proc_time > row.erddap_time:
return True
return False