#!/usr/bin/env python
-try:
- import mapnik2 as mapnik
-except:
- import mapnik
+import mapnik
import sys, os
rule = mapnik.Rule()
line_symbolizer = mapnik.LineSymbolizer()
- line_symbolizer.stroke = mapnik.Color('rgb(125, 125, 0)')
- rule.symbols.append(line_symbolizer)
- point_symbolizer = mapnik.MarkersSymbolizer()
- point_symbolizer.allow_overlap = True
- point_symbolizer.opacity = 0.8 # semi-transparent
- rule.symbols.append(point_symbolizer)
+ line_symbolizer.stroke = mapnik.Color('rgb(0,0,127)')
+ line_symbolizer.stroke_width = 4.0
+ line_symbolizer.stroke_opacity = 0.5
+
+ rule.symbols.append(line_symbolizer)
style.rules.append(rule)
m.append_style('GPS_tracking_points', style)
layer = mapnik.Layer('GPS_tracking_points')
- layer.datasource = mapnik.Ogr(file=gpx_file, layer='track_points')
+ layer.datasource = mapnik.Ogr(file=gpx_file, layer='tracks')
layer.styles.append('GPS_tracking_points')
m.layers.append(layer)
from os.path import dirname
conn = sqlite3.connect(db)
+ conn.text_factory = str
cur = conn.cursor()
updcur = conn.cursor()
if options.mapfile:
mapfile = options.mapfile
else:
- mapfile = "/etc/mapnik-osm-carto-data/veloroad-transparent.xml"
+ mapfile = "/etc/mapnik-osm-carto-data/veloroad-imposm.xml"
if options.outfile:
map_uri = options.outfile
if options.x:
imgx = int(options.x)
else:
- imgx= 400
+ imgx= 640
if options.y:
imgy = int(options.y)
else:
- imgy= 400
+ imgy= 640
if options.db:
render_all(options.db,mapfile,imgx,imgy)
def check_db_for_training(db,sport,timestamp):
conn = sqlite3.connect(db)
+ conn.text_factory = str
cur = conn.cursor()
cur.execute ("select count(*) from tracks where sport=? and start_time=?" , (sport,timestamp))
def write_parsed_to_db(db,gpx,filename):
conn = sqlite3.connect(db)
+ conn.text_factory = str
cur = conn.cursor()
- cur.execute ("delete from tracks where filename=?" , (filename.decode('UTF-8'),))
+ if type(filename) is str:
+ filename=filename.decode('UTF-8')
+
+ cur.execute ("delete from tracks where filename=?" , (filename,))
tracks = gpx.tracks
try:
name = gpx.name
+ if type(name) is str:
+ name=name.decode('UTF-8')
except:
name = None
descent = track.elevation_loss()
((minlat,minlon),(maxlat,maxlon)) = track.bound_box()
params = (
- gpx.author,name,filename.decode('UTF-8'),
+ gpx.author,name,filename,
track.sport,start_time,full_duration,
distance,filtered_distance,ascent,descent,
start.lat,start.lon,
printable,
minlat,minlon,maxlat,maxlon
)
+ print(params)
cur.execute("""
insert into tracks(
author,name,filename,sport,
write_parsed_to_db(db,gpx,filename)
-
\ No newline at end of file
+def print_parsed_file(filename):
+
+ gpx = pygpx.GPX()
+ gpx.ReadFile(filename)
+
+ for track in gpx.tracks:
+
+ try:
+ author = gpx.author
+ except:
+ author = None
+
+ try:
+ name = gpx.name
+ except:
+ name = None
+
+ start = track.start()
+ if start:
+ printable = pygeocode.GeoName(start.lat,start.lon).printable
+ start_time = track.start_time()
+ full_duration = track.full_duration().total_seconds()
+ distance = track.distance()
+ filtered_distance = track.filtered_distance(max_speed=50)
+ ascent = track.elevation_gain()
+ descent = track.elevation_loss()
+ ((minlat,minlon),(maxlat,maxlon)) = track.bound_box()
+ params = (
+ gpx.author,name,filename.decode('UTF-8'),
+ track.sport,start_time,full_duration,
+ distance,filtered_distance,ascent,descent,
+ start.lat,start.lon,
+ printable,
+ minlat,minlon,maxlat,maxlon
+ )
+ print(params)
import math
import datetime
from dateutil.parser import parse
+from pprint import pprint
def deg2rad(deg):
# Преобразование из градусов в радианы.
i.write(trksegnode,"trkpt")
def _get_elevation(self):
+
+ elev_data = []
+ for pt in self.trkpts:
+ if pt.elevation:
+ elev_data.append(pt.elevation)
+
gain = 0.0
loss = 0.0
- last_pt = None
- for pt in self.trkpts:
- if last_pt is not None:
- last_elevation = last_pt.elevation
+ last_elevation = None
+
+ window_size = 5
+ i = 0
+ moving_averages = []
+
+ while i < len(elev_data) - window_size + 1:
+ this_window = elev_data[i : i + window_size]
+ window_average = sum(this_window) / window_size
+ moving_averages.append(window_average)
+ i += 1
+
+ if len(moving_averages)>2:
+ elev_data = moving_averages
+
+ for pt in elev_data:
+ if last_elevation is not None:
try:
- if pt.elevation > last_elevation:
- gain += pt.elevation -last_elevation
+ if pt > last_elevation:
+ gain += pt - last_elevation
else:
- loss += last_elevation - pt.elevation
+ loss += last_elevation - pt
except:
pass
- last_pt=pt
+ last_elevation=pt
+
self.elevation_gain = gain
self.elevation_loss = loss
return ((minlat,minlon),(maxlat,maxlon))
def FixNames(self,linkname):
- goodname = linkname.decode('UTF-8')
+ pprint(linkname)
+ pprint(type(linkname))
+ if type(linkname) is unicode:
+ goodname=linkname
+ else:
+ goodname = linkname.decode('UTF-8')
badname = goodname.encode('ascii','replace')
if self.name and self.name.startswith(badname):
self.name=self.name.replace(badname,goodname)
if current_seg is not None:
new_segs.append(current_seg)
# Обработали
+ for trs in new_segs:
+ trs._get_elevation()
tr.trksegs = new_segs
+
def XMLTree(self):
root = etree.Element("gpx", attrib ={"creator": "pygpx",
# coding: UTF-8
import requests
+
+from urllib3.exceptions import InsecureRequestWarning
+requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
#import sys
import os
trainings = []
- req = requests.get("http://www.gps-sport.net/services/getMonthlyTrainingDataHTML_V2.jsp?userName=%s&year=%s&month=%s&rnd=0.645673"% (uname,year,month), headers = {'User-agent': 'Mozilla/5.0'})
+ req = requests.get("http://www.gps-sport.net/services/getMonthlyTrainingDataHTML_V2.jsp?userName=%s&year=%s&month=%s&rnd=0.645673"% (uname,year,month), headers = {'User-agent': 'Mozilla/5.0'}, verify=False)
page = req.text.encode('utf-8')
dom = html.document_fromstring(page)
print "trid=",trid
- req = requests.get("http://www.gps-sport.net/services/trainingGPX.jsp?trainingID=%s&tz=-180" % (trid))
+ req = requests.get("http://www.gps-sport.net/services/trainingGPX.jsp?trainingID=%s&tz=-180" % (trid), verify=False)
xml = etree.fromstring(req.text.encode('utf-8'))
return xml
if entry.name == u'Приложения':
for entry_app in dbx.files_list_folder(entry.id).entries:
if entry_app.name == u'Run.GPS':
+ print "id="+entry_app.id
gpx_list_id=entry_app.id
break
break
if gpx_list_id:
for file in dbx.files_list_folder(gpx_list_id).entries:
-
+
filename,ext = os.path.splitext(file.name)
if ext == '.tcx':
try:
fyear = int(filename[0:4])
fmonth = int(filename[5:7])
if fyear == year and fmonth == month:
- sport = filename[18:]
- timestamp = datetime.strptime(filename[0:16],'%Y-%m-%d_%H%M%S')
+ sport = filename[41:]
+ timestamp = datetime.strptime(filename[0:19],'%Y-%m-%dT%H_%M_%S')
record={ 'id': file.id, 'timestamp': timestamp, 'sport': sport }
res.append(record)
except:
- None
-
+ try:
+ fyear = int(filename[0:4])
+ fmonth = int(filename[5:7])
+ if fyear == year and fmonth == month:
+ sport = filename[18:]
+ timestamp = datetime.strptime(filename[0:16],'%Y-%m-%d_%H%M%S')
+ record={ 'id': file.id, 'timestamp': timestamp, 'sport': sport }
+ res.append(record)
+ except:
+ None
+
return res
elif dbauth:
sync_db(dbx,pusername,current_year,current_month,outdir,options.verbose,options.force)
- generate_image.render_all(db,'/etc/mapnik-osm-carto-data/veloroad-transparent.xml',400,400)
+ generate_image.render_all(db,'/etc/mapnik-osm-carto-data/veloroad-imposm.xml',640,640)
if __name__ == "__main__":
def queue_render(db,filename,forced_max_zoom=None):
conn = sqlite3.connect(db)
+ conn.text_factory = str
cur = conn.cursor()
cur.execute("select minlat,minlon,maxlat,maxlon from tracks where filename=?" , (filename.decode('UTF-8'),))