-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpTempO_Python.py
219 lines (177 loc) · 6.01 KB
/
UpTempO_Python.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!/usr/bin/python
import os
import sys
import time
import datetime
import BuoyTools_py3_toot as BT
import PlottingFuncs as PF
import numpy as np
import UpTempO_BuoyMaster as BM
import UpTempO_Downloads as upd
import ftplib
from ftplib import FTP
import pandas as pd
def StatsReport(lupdate):
print(lupdate)
# exit(-1)
curbuoys,deadbuoys,orderbuoys,newdead=BM.getBuoys()
oph=open('UPTEMPO/WebPlots/STATS-REPORT.txt','r')
have=oph.read()
oph.close()
have=have.split('\n')[0:-1]
haveinf={}
for h in have:
sh=h.split(',')
haveinf[sh[11]]=h # makes the buoy ID the key
if sh[11] == '300034013618650':
pass #print(haveinf)
for b in orderbuoys:
if (b in curbuoys) or (b in newdead):
print(b, 'line 32 in UpTempO_Python.py')
if b in haveinf:
statline=haveinf[b]
else: statline=''
binf=BM.BuoyMaster(b) # buoy info
try:
abbv,byear,depdate,source=curbuoys[b]
except:
abbv,byear,depdate,source=newdead[b]
df = pd.read_csv(f'UPTEMPO/Processed_Data/{b}.csv') # cols year/month/day/hour NOT date
# opf=open('UPTEMPO/Processed_Data/'+b+'.dat','r')
# data=opf.read()
# opf.close()
# data=data.split('\n')
# head=data[0]
# data=data[1:]
# data=[d for d in data if d]
if not statline:
fdeplat=df['Lat'].iloc[0]
fdeplon=df['Lon'].iloc[0]
# firstline=data[0]
# sfirst=firstline.split(' ')
# sfirst=[sf for sf in sfirst if sf]
# deplat=sfirst[4]
# deplon=sfirst[5]
#
# fdeplat=float(deplat)
# fdeplon=float(deplon)
if fdeplon < 0:
eorw='W'
fdeplon=-fdeplon
else: eorw='E'
sdeplon="%.2f" % fdeplon
sdeplat="%.2f" % fdeplat
if fdeplat < 0: nors='S '
else: nors='N '
depll=sdeplat+nors+sdeplon+eorw
statlist=[binf['name'][1],binf['vessel'],depdate,depll,'','','',abbv,'NA','0',binf['name'][0],b,'','1']
else:
statlist=statline.split(',')
print('line 82')
print(statlist)
print()
if b in newdead: statlist[-6]='1'
# lastline=data[-1]
# slast=lastline.split(' ')
# slast=[sl for sl in slast if sl]
# lastyr=slast[0]
# lastmo=slast[1]
# lastda=slast[2]
# lasthr=slast[3]
# lastlat=slast[4]
# lastlon=slast[5]
lastlat = df['Lat'].iloc[-1]
lastlon = df['Lon'].iloc[-1]
print(b)
print(df.iloc[-1])
lastdate=f"{df['Month'].iloc[-1]:02}/{df['Day'].iloc[-1]:02}/{df['Year'].iloc[-1]}"
print(binf['vessel'],lastdate)
print()
# flastlon=float(lastlon)
# flastlat=float(lastlat)
if lastlon < 0: slastlon="%.2f" % (-lastlon)
else: slastlon="%.2f" % (lastlon)
slastlat="%.2f" % lastlat
if lastlat < 0: nors='S '
else: nors='N '
if lastlon < 0: eorw='W'
else: eorw='E'
lastll=slastlat+nors+slastlon+eorw
if 'BATT' in df.columns:
lastbatt=str(df['BATT'].iloc[-1])
else:
lastbatt = 'NA'
depdate=depdate.split(' ')[0]
print('line 123 Python')
print(depdate)
print(binf)
amlistening=binf['listening']
statlist[4]=lastdate
statlist[5]=lastll
statlist[6]=lupdate
if 'BATT' in df.columns:
statlist[8]=lastbatt
if statlist[12] == 'NA' or not statlist[12]:
# wmo=BT.lookupWMO(b)
statlist[12]=binf['wmo']
statlist[14]=amlistening
print(b)
print('new statline')
print(statlist)
jout=','.join(statlist)
haveinf[b]=jout
opw=open('UPTEMPO/WebPlots/STATS-REPORT.txt','w')
for b in orderbuoys:
opw.write(haveinf[b]+'\n')
print(haveinf[b])
opw.close()
def UploadToPSC():
transrecs='UPTEMPO/transferRecord.dat'
opf=open(transrecs,'r')
tfiles=opf.read()
opf.close()
tfiles=tfiles.split('\n')
tfiles=[tf for tf in tfiles if tf]
datarecs='UPTEMPO/DataFilesToTransfer.dat'
opf=open(datarecs,'r')
tdata=opf.read()
opf.close()
tdata=tdata.split('\n')
tdata=[td for td in tdata if td]
ftp=FTP('psctestsite.org')
ftp.login('psctestsite.org','Ice+Melt3go')
ftp.cwd('UpTempO')
for f in tfiles:
tup=f.split(' ')
tofile=tup[1]
fromfile=tup[0]
try:
ftp.storbinary('STOR '+tofile,open(fromfile,'rb'))
print('TRANSFER SUCCESSFUL: '+tofile)
except ftplib.all_errors:
print('This data file did not go: '+tofile)
print('Transfering Data Files...')
for d in tdata:
tup=d.split(' ')
tofile=tup[1]
fromfile=tup[0]
try:
ftp.storbinary('STOR '+tofile,open(fromfile,'rb'))
print('DATA TRANSFER SUCCESSFUL: '+tofile)
except ftplib.all_errors:
print('This data file did not go: '+tofile)
ftp.quit()
def DownloadFromPSC(fname):
#fname = 'BuoyInfo.php' Individual buoy plots
#fname = 'Data.php' main Data & Graphics page
putpath='UPTEMPO/DownloadedFromPSC/'+fname
ftp=FTP('psctestsite.org')
ftp.login('psctestsite.org','Ice+Melt3go')
ftp.cwd('UpTempO')
with open(putpath,'wb') as fp:
ftp.retrbinary('RETR '+fname,fp.write)
ftp.quit()
def BatteryStats():
curbuoys,deadbuoys,orderbuoys,newdead=BM.getBuoys()
for o in orderbuoys:
dinf=loadUpTempO(o)