generated from carpentries-incubator/astronaut-data-analysis-not-so-fair
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my code v2.py
62 lines (46 loc) · 1.38 KB
/
my code v2.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
60
61
62
#https://data.nasa.gov/resource/eva.json
data_f = open('/home/sarah/Projects/ssi-ukrn-fair-course/eva-data.json', 'r')
fieldnames = ("EVA #", "Country", "Crew ", "Vehicle", "Date", "Duration", "Purpose")
data=[]
import json
data_t = open('/home/sarah/Projects/ssi-ukrn-fair-course/data.csv', 'w')
dt = []
for i in range(374):
line=data_f.readline()
print(line)
data.append(json.loads(line[1:-1]))
#data.pop(0)
## Comment out this bit if you don't want the spreadsheet
import csv
w=csv.writer(data_t)
import datetime as dt
time = []
date =[]
j=0
for i in data:
print(data[j])
# and this bit
w.writerow(data[j].values())
if 'duration' in data[j].keys():
tt=data[j]['duration']
if tt == '':
pass
else:
t=dt.datetime.strptime(tt,'%H:%M')
ttt = dt.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second).total_seconds()/(60*60)
print(t,ttt)
time.append(ttt)
if 'date' in data[j].keys():
date.append(dt.datetime.strptime(data[j]['date'][0:10], '%Y-%m-%d'))
#date.append(data[j]['date'][0:10])
else:
time.pop(0)
j+=1
t=[0]
for i in time:
t.append(t[-1]+i)
date,time = zip(*sorted(zip(date, time)))
import matplotlib.pyplot as myplot
myplot.plot(date,t[1:],'-')
myplot.plot(date,t[1:],'ko')
myplot.show()