import numpy as np from pytz import timezone import pytz import time #strptime for e-mail alarms from datetime import datetime from geopy.distance import geodesic import pandas as pd #for reading master spreadsheet xls file import json #for loading json file manually import wgFunctions as wg #----------------------------# #added to make sure logging works -JF print("start at: " + time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime())) #User inputs vehicles = ['wgHansen','wgTiny','wgTest'] #vehicles = ['wgHansen'] #vehicles = ['wgTiny'] #vehicles = ['wgTest'] desiredYear = 2025 #----------------------------# for veh in vehicles: currentDist = 0 currentDay = 0 totalDist = 0 totalDay = 0 #define data directories #myDirWG = 'C:/Users/tmasek/Dropbox/Projects/MBARI/WaveGliderDisplay/WaveGlider/' myDirWG = '//atlas.shore.mbari.org/WaveGlider/' #myDirWeb = 'C:/Users/tmasek/Dropbox/Projects/MBARI/WaveGliderDisplay/WaveGlider/' + veh +'/data/' myDirWeb = '//atlas.shore.mbari.org/oasis_users/web/extern/bog/waveglider/' + veh +'/data/' #see if there is a active run and all calib lines are added #get cal/config info off master spreadsheet xlInfo = pd.read_excel(myDirWG +'WG_cal_config.xlsx', engine='openpyxl', sheet_name='Info', na_values=['NaN','N/A'], keep_default_na=False, engine_kwargs={'read_only': True}) xlCCU = pd.read_excel(myDirWG +'WG_cal_config.xlsx', engine='openpyxl', sheet_name='CCU', na_values=['NaN','N/A'], keep_default_na=False, engine_kwargs={'read_only': True}) xlDeps = xlInfo['Deployment'] xlRowStart = xlDeps[xlDeps == veh].index[0] for index, row in xlInfo[xlRowStart + 1:int(xlInfo.shape[0])].iterrows(): #xlRowInd = xlDeps[xlDeps == int(dep)].index[0] if row['Deployment'] == '': break xlRowInd = index fmt = '%Y-%m-%dT%H:%M:%SZ' if(str(xlInfo.loc[xlRowInd,'tBeg']) != ''): tBeg = datetime.strptime(xlInfo.loc[xlRowInd,'tBeg'], fmt).replace(tzinfo=pytz.utc) if tBeg.year == desiredYear: if(str(xlInfo.loc[xlRowInd,'tEnd']) != ''): tEnd = datetime.strptime(xlInfo.loc[xlRowInd,'tEnd'], fmt).replace(tzinfo=pytz.utc) else: tEnd = datetime.now(timezone('UTC')) print("New Mission: " + veh + " " + str(tBeg) + " " + str(tEnd)) # CCU vids CCUname = xlCCU.loc[xlRowInd,'CCU'] CCUnum = str(int(xlCCU.loc[xlRowInd,'VID'])) #----------------------------# # Initialize var's WGtime, WGlon, WGlat, WGdist, WGwaypoint, WGHead, WGDesHead, WGCOG = wg.getTelemRecord(CCUnum,tBeg,tEnd) print('Telemetry:' + str(len(WGtime)) + " records") #clean-up LR distance ind1 = np.where(np.array(WGdist)<0)[0] ind2 = np.where(np.array(WGdist)>10000)[0] for i in range(0,len(ind1)): WGdist[ind1[i]] = 0 for i in range(0,len(ind2)): WGdist[ind2[i]] = 0 #other way of calc'ing dist using gps WGdist_v2 = list() WGdist_v2.append(0) for i in range(0,len(WGlon)-1): WGdist_v2.append( int( geodesic( (WGlat[i], WGlon[i]), (WGlat[i+1],WGlon[i+1]) ).meters ) ) #clean-up gps distance ind3 = np.where(np.array(WGdist_v2)<0)[0] ind4 = np.where(np.array(WGdist_v2)>10000)[0] for i in range(0,len(ind3)): WGdist_v2[ind3[i]] = 0 for i in range(0,len(ind4)): WGdist_v2[ind4[i]] = 0 currentDist = np.nansum(WGdist_v2) / 1000 days = (tEnd - tBeg).days days = days + (tEnd - tBeg).seconds / 60 /60 / 24 currentDay = days totalDist = totalDist + currentDist totalDay = totalDay + currentDay print("Dur: " + f"{currentDay:.1f}" + " Dist: " + f"{currentDist:.1f}" ) print("Dist Calc: " + str(np.nansum(WGdist) / 1000) + " Dist Calc V2: " + str(np.nansum(WGdist_v2) / 1000) ) #Update dataTable.json with open(myDirWeb +'../json/dataTable_preDepl.json', newline='\r\n') as data_file: contents = json.load(data_file) contentsNew = contents[:] #will overwrite below if datetime.now(timezone('UTC')).year == desiredYear: #enter current mission stats preDeplDay = totalDay-currentDay preDeplDist = totalDist-currentDist else: preDeplDay = totalDay preDeplDist = totalDist for j in range(0, len(contents) ): if contents[j]['yr'] == str(desiredYear): #contentsNew[j]['durDay'] = float('{0:.1f}'.format( b + contents[j]['durDay'] ) ) contentsNew[j]['durDay'] = round(preDeplDay,1) contentsNew[j]['dist'] = round(preDeplDist,1) #write new table with open(myDirWeb +'../json/dataTable_preDepl.json', 'w', newline='\r\n') as outfile: json.dump(contentsNew, outfile) for j in range(0, len(contents) ): if contents[j]['yr'] == str(desiredYear): #contentsNew[j]['durDay'] = float('{0:.1f}'.format( b + contents[j]['durDay'] ) ) contentsNew[j]['durDay'] = round(totalDay,1) contentsNew[j]['dist'] = round(totalDist,1) #write new table with open(myDirWeb +'../json/dataTable.json', 'w', newline='\r\n') as outfile: json.dump(contentsNew, outfile) # smtpObj.quit() print("ended at: " + time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime())) print("Total Dur: " + f"{totalDay:.1f}" + " Total Dist: " + f"{totalDist:.1f}" )