Commit 96b8c277 authored by sylvie fiat's avatar sylvie fiat
Browse files

create script - to be tested with real data

parent a96f578d
# where_argos
Projet python qui télécharge les données des balises argos et les transforme pour envoi aux partenaires
import httplib
import re
import csv
import math
import datetime
import xml.dom.minidom
import xml.etree.ElementTree as ET
ARGOS_HOST = "ws-argos.clsamerica.com"
#http://ws-argos.cls.fr/argosDws/services/DixService?wsdl
ARGOS_HOST = "ws-argos.cls.fr"
def argosRequest(request):
conn = httplib.HTTPConnection(ARGOS_HOST)
......@@ -13,7 +15,7 @@ def argosRequest(request):
response = conn.getresponse()
#print response.status, response.reason, response.msg
data = response.read()
#print data
print data
conn.close()
return data
......@@ -24,6 +26,7 @@ def cleanupXml(data):
body = re.sub("&lt;", "<", body)
body = re.sub("&gt;", ">", body)
body = re.sub("&amp;", "&", body)
body = re.sub("&lt;", "<", body)
ugly_xml = xml.dom.minidom.parseString(body)
ugly_xml = ugly_xml.toprettyxml(indent=' ')
text_re = re.compile('>\n\s+([^<>\s].*?)\n\s+</', re.DOTALL)
......@@ -142,6 +145,21 @@ def getXml(username, password, id, type="platform", nbPassByPtt=10, nbDaysFromNo
data = cleanupXml(data)
return data
def getXsd():
request = (
'<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:typ="http://service.dataxmldistribution.argos.cls.fr/types">\n'
'<soap:Header/>\n'
'<soap:Body>\n'
'<typ:xsdRequest/>\n'
'</soap:Body>\n'
'</soap:Envelope>'
) % ()
#print request
data = argosRequest(request)
data = cleanupXml(data)
return data
def getLocations(argos_xml):
......@@ -168,7 +186,51 @@ def get_current_location(username, password, platform_id):
current_loc = sorted(locations).pop()
return current_loc
# new stuff
def calcul_speed(latitude1,longitude1, date1, latitude2, longitude2, date2):
lon1=float(longitude1.replace(',','.'))
lon2=float(longitude2.replace(',','.'))
lat1=float(latitude1.replace(',','.'))
lat2=float(latitude2.replace(',','.'))
d1=datetime.datetime.strptime(date1, '%Y/%m/%d %H:%M:%S')
d2=datetime.datetime.strptime(date2, '%Y/%m/%d %H:%M:%S')
distance = math.acos(math.sin(math.radians(lon1))*math.sin(math.radians(lon2))+math.cos(math.radians(lon1))*math.cos(math.radians(lon2))*math.cos(math.radians(lat1-lat2)))*6371
elapsedTime = d2 - d1
temps = elapsedTime.days * 24 + elapsedTime.seconds / 3600.0
vitesse = 0 if temps==0 else distance / temps
return distance,temps,vitesse
def convertCSV_for_DTSI():
with open('/media/sfiat/data2/workspace_python/where_argos/examples/ArgosData_2016_09_23-25.csv', 'rb') as f:
fieldnames = ['N\xc2\xb0 ID','Date de loc.','Latitude (degr\xc3\xa9 d\xc3\xa9cimal)','Longitude (degr\xc3\xa9 d\xc3\xa9cimal)','Chronologie']
writer = csv.DictWriter(open('/media/sfiat/data2/workspace_python/where_argos/examples/argos_where_"+datetime.datetime.today().strftime('%Y-%m-%d')+".csv', 'w'), fieldnames=fieldnames,delimiter=';')
writer.writeheader()
reader = csv.DictReader(f,delimiter=';')
nid = 0
for row in reader:
if(row[fieldnames[0]]!=nid):
latitude1 = 0
longitude1 = 0
date1 = 0
n = 1
nid=row[fieldnames[0]]
elif not((latitude1==row[fieldnames[3]] and longitude1==row[fieldnames[2]] and date1==row[fieldnames[1]]) or row[fieldnames[1]]==''):
if (latitude1==0 and longitude1==0 and date1==0):
distance,temps,vitesse=0,0,0
else:
distance,temps,vitesse=calcul_speed(latitude1,longitude1, date1, row[fieldnames[3]], row[fieldnames[2]], row[fieldnames[1]])
if(vitesse<12):
writer.writerow({fieldnames[0]: row[fieldnames[0]], fieldnames[1]: row[fieldnames[1]], fieldnames[2]: row[fieldnames[2]], fieldnames[3]: row[fieldnames[3]],fieldnames[7]: n})
nid1=row[fieldnames[0]]
latitude1=row[fieldnames[3]]
longitude1=row[fieldnames[2]]
date1=row[fieldnames[1]]
n = n+1
return ""
if __name__ == '__main__':
argos_csv=getCsv('GARRIGUE','BOSSE_2016',IDPROGRAM,'program',10, 20, "true", "false")
convertCSV_for_DTSI();
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment