-
Notifications
You must be signed in to change notification settings - Fork 2
/
report_missing.py
executable file
·50 lines (40 loc) · 1.1 KB
/
report_missing.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
#! /usr/bin/env python3
#
# report_missing.py -- Copyright (C) 2016-2017 Stephen Makonin
#
import os, sys
def int32(lsw, msw):
return msw * 0x10000 + lsw
if len(sys.argv) != 4:
print()
print('USAGE: %s [house #] [house] [date, e.g., 2016-02-07] [sub-meters]' % (sys.argv[0]))
print()
exit(1)
house = int(sys.argv[1])
date = sys.argv[2]
submeter_count = int(sys.argv[3])
raw_dir = './raw/house%d' % (house)
subs_file = '%s/SUB_%s.csv' % (raw_dir, date)
if not os.path.isfile(subs_file):
print('\t ERROR:', subs_file, 'file does not exist!')
exit(1)
f_subs = open(subs_file, 'r')
subs_raw = list(f_subs)
f_subs.close()
subs_step1 = []
for l in subs_raw:
l = l.strip()
l = l.split(',')
for i in range(len(l)):
if i != 1:
l[i] = int(l[i])
subs_step1.append(l)
meter_count = 8
circuit_count = meter_count * 3
prev_ts = 0
for subs_i in range(0, len(subs_step1), meter_count):
ts = subs_step1[subs_i][0]
ts_diff = ts - prev_ts - 1
if prev_ts > 0 and ts_diff != 0:
print('\t ERROR:', ts_diff, 'missing readings after ts ', ts)
prev_ts = ts