-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.py
59 lines (41 loc) · 1.49 KB
/
common.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
from datetime import datetime
import csv
def cToF(c):
return round((c * 9/5) + 32, 2)
def parseWebToolOutput(args, dataType):
station = None
years = {}
# parse input file
with open(args.input_file) as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if not station:
station = row['STATION']
date = datetime.strptime(row['DATE'], '%Y-%m-%d')
if row[dataType] == '':
continue
if date.year not in years:
years[date.year] = []
years[date.year].append(row[dataType])
return station, years
def parseFtpOutput(args, dataType):
station = None
years = {}
input = []
def sortFunc(r):
return r['date']
with open(args.input_file) as csvfile:
reader = csv.DictReader(csvfile, ['station', 'date', 'type', 'value'])
for row in reader:
if not station:
station = row['station']
if row['type'] == dataType:
input.append(row)
input.sort(key=sortFunc)
for row in input:
if row['value'] != '':
date = datetime.strptime(row['date'], '%Y%m%d')
if date.year not in years:
years[date.year] = []
years[date.year].append(cToF(int(row['value']) / 10))
return station, years