Pretty up models.
Pretty up import file.
This commit is contained in:
parent
b817aecd1e
commit
e5eb602ec8
@ -50,23 +50,25 @@ class Command(BaseCommand):
|
||||
"Haven't run across one that has multiple segments. "
|
||||
"Contribute a patch if you have.")
|
||||
elif isinstance(segments, dict):
|
||||
# TODO: IF multiple import!
|
||||
track = Track.objects.create(user=self.user,
|
||||
start=start_time,
|
||||
name=name)
|
||||
points = segments['trkpt']
|
||||
segment = Segment(track=track, time=points[0]['time'])
|
||||
segment.save()
|
||||
print len(points)
|
||||
for pt in points:
|
||||
Point.objects.create(segment=segment,
|
||||
time=pt['time'],
|
||||
elevation=pt['ele'],
|
||||
latitude=pt['@lat'],
|
||||
longitude=pt['@lon'])
|
||||
print "created Track <{0}> start: {1}, stop: {2}".format(
|
||||
track.name,
|
||||
track.start,
|
||||
track.finish
|
||||
)
|
||||
print "created Track <{0}> start: {1}, stop: {2}".format(
|
||||
track.name,
|
||||
track.start,
|
||||
track.finish
|
||||
)
|
||||
|
||||
|
||||
def etree_to_dict(t):
|
||||
|
24
tracking/migrations/0006_auto_20150901_0054.py
Normal file
24
tracking/migrations/0006_auto_20150901_0054.py
Normal file
@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('tracking', '0005_segment_time'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='point',
|
||||
name='latitude',
|
||||
field=models.DecimalField(max_digits=10, decimal_places=6),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='point',
|
||||
name='longitude',
|
||||
field=models.DecimalField(max_digits=10, decimal_places=6),
|
||||
),
|
||||
]
|
@ -13,6 +13,13 @@ class Track(models.Model):
|
||||
def finish(self):
|
||||
return self.segment_set.order_by("-time")[0].finish
|
||||
|
||||
def __str__(self):
|
||||
return "[{user}] '{name}' from {start} to {finish}".format(
|
||||
user=self.user.username,
|
||||
name=self.name,
|
||||
start=self.start,
|
||||
finish=self.finish)
|
||||
|
||||
|
||||
class Segment(models.Model):
|
||||
track = models.ForeignKey(Track)
|
||||
@ -23,10 +30,24 @@ class Segment(models.Model):
|
||||
def finish(self):
|
||||
return self.point_set.order_by("-time")[0].time
|
||||
|
||||
def __str__(self):
|
||||
return "'{name}' Segment #{number} at {tme}".format(
|
||||
name=self.track.name,
|
||||
number=self.number,
|
||||
tme=self.time)
|
||||
|
||||
|
||||
class Point(models.Model):
|
||||
time = models.DateTimeField()
|
||||
latitude = models.DecimalField(max_digits=13, decimal_places=10)
|
||||
longitude = models.DecimalField(max_digits=12, decimal_places=10)
|
||||
latitude = models.DecimalField(max_digits=10, decimal_places=6)
|
||||
longitude = models.DecimalField(max_digits=10, decimal_places=6)
|
||||
elevation = models.DecimalField(max_digits=20, decimal_places=2)
|
||||
segment = models.ForeignKey(Segment)
|
||||
|
||||
def __str__(self):
|
||||
return "'{name}' ({lat},{lon}) -> {alt} on {time}".format(
|
||||
lat=self.latitude,
|
||||
lon=self.longitude,
|
||||
alt=self.elevation,
|
||||
time=self.time,
|
||||
name=self.segment.track.name)
|
||||
|
Loading…
Reference in New Issue
Block a user