Example #1
0
 def wpt(self):
     if self.wp is None:
         self.wp = Waypoint(parent=self.interval)
         self.wp.seqnr = self.seqnr
         self.wp.interval = self.interval
         self.seqnr += 1
         self.interval.num_waypoints = self.seqnr
         if self.ts is not None:
             self.wp.timestamp = self.ts
             self.wp.seconds = Util.time_to_seconds(self.ts)
     return self.wp
Example #2
0
 def wpt(self):
     if self.wp is None:
         self.wp = Waypoint(parent=self.interval)
         self.wp.seqnr = self.seqnr
         self.wp.interval = self.interval
         self.seqnr += 1
         self.interval.num_waypoints = self.seqnr
         if self.ts is not None:
             self.wp.timestamp = self.ts
             self.wp.seconds = Util.time_to_seconds(self.ts)
     return self.wp
Example #3
0
class IntervalContainer():
    def __init__(self, interval, parent = None):
        self.parent = parent
        self.waypoints = []
        self.interval = interval
        self.min_lat = 200
        self.max_lat = -200
        self.min_lon = 100
        self.max_lon = -100
        self.cur_altitude = None
        self.policy = Policy(Policy.UPDATE_ABSOLUTE, Policy.UPDATE_ABSOLUTE)
        self.distance_offset = 0
        self.start_time = None
        self.ftp = 0
        if parent is None:
            self.seqnr = 0
            self.root = self
            self.session = self.interval.parent()
        else:
            self.seqnr = self.parent.seqnr
            self.type = parent.type
            self.root = parent.root
            self.session = parent.session
        self.wp = None
        self.current = None

    def get_ftp(self):
        if self.ftp:
            return self.ftp
        elif self.parent:
            return self.parent.get_ftp()
        else:
            self.ftp = self.session.get_athlete().get_ftp(self.session.session_start)
            return self.ftp

    def close(self):
        if self.wp is not None:
            self.wp.put()
        if self.interval is not None:
            self.interval.put()
            a = Analysis(container = self)
            a.analyze()
            a.persist()
        if self.parent is not None:
            self.parent.current = None
            self.parent.seqnr = self.seqnr
        return self.parent

    def timestamp(self, value):
        self.ts = value
        if self.policy.duration == Policy.DONT_UPDATE:
            pass
        elif self.policy.duration == Policy.UPDATE_WITH_OFFSET:
            self.interval.duration = Util.time_after_offset(value, self.start_time)
        elif self.policy.duration == Policy.UPDATE_ABSOLUTE:
            self.interval.duration = value
        if self.parent:
            self.parent.timestamp(value)

    def distance(self, value):
        v = int(round(float(value)))
        if self.policy.distance == Policy.DONT_UPDATE:
            pass
        elif self.policy.distance == Policy.UPDATE_WITH_OFFSET:
            self.interval.distance = self.distance_offset + v
        elif self.policy.distance == Policy.UPDATE_ABSOLUTE:
            self.interval.distance = v
        if not self.current:
            self.wpt().distance = self.interval.distance
        if self.parent:
            self.parent.distance(value)

    def work(self, value):
        self.interval.work = int(round(float(value)))

    def speed(self, value):
        self.wpt().speed = float(value)

    def power(self, value):
        self.wpt().power = int(round(float(value)))

    def torque(self, v):
        self.wpt().torque = float(v)

    def heartrate(self, v):
        self.wpt().heartrate = int(round(float(v)))

    def cadence(self, v):
        self.wpt().cadence = int(round(float(v)))

    def elevation(self, value):
        self.wpt().elevation = int(round(float(value)))

    def location(self, latval, lonval):
        lat = float(latval)
        lon = float(lonval)
        if lat != 0.0 and lon != 0.0:
            self.wpt().location = GeoPt(lat, lon)

    def new_wp(self):
        if self.wp is not None:
            self.wp.put()
        self.wp = None

    def wpt(self):
        if self.wp is None:
            self.wp = Waypoint(parent=self.interval)
            self.wp.seqnr = self.seqnr
            self.wp.interval = self.interval
            self.seqnr += 1
            self.interval.num_waypoints = self.seqnr
            if self.ts is not None:
                self.wp.timestamp = self.ts
                self.wp.seconds = Util.time_to_seconds(self.ts)
        return self.wp

    def close_wp(self):
        if self.wp is not None:
            self.wp.put()
            self.wp = None
Example #4
0
class IntervalContainer():
    def __init__(self, interval, parent = None):
        self.parent = parent
        self.waypoints = []
        self.interval = interval
        self.min_lat = 200
        self.max_lat = -200
        self.min_lon = 100
        self.max_lon = -100
        self.cur_altitude = None
        self.policy = Policy(Policy.UPDATE_ABSOLUTE, Policy.UPDATE_ABSOLUTE)
        self.distance_offset = 0
        self.start_time = None
        self.ftp = 0
        if parent is None:
            self.seqnr = 0
            self.root = self
            self.session = self.interval.parent()
        else:
            self.seqnr = self.parent.seqnr
            self.type = parent.type
            self.root = parent.root
            self.session = parent.session
        self.wp = None
        self.current = None

    def get_ftp(self):
        if self.ftp:
            return self.ftp
        elif self.parent:
            return self.parent.get_ftp()
        else:
            self.ftp = self.session.get_athlete().get_ftp(self.session.session_start)
            return self.ftp

    def close(self):
        if self.wp is not None:
            self.wp.put()
        if self.interval is not None:
            self.interval.put()
            a = Analysis(container = self)
            a.analyze()
            a.persist()
        if self.parent is not None:
            self.parent.current = None
            self.parent.seqnr = self.seqnr
        return self.parent

    def timestamp(self, value):
        self.ts = value
        if self.policy.duration == Policy.DONT_UPDATE:
            pass
        elif self.policy.duration == Policy.UPDATE_WITH_OFFSET:
            self.interval.duration = Util.time_after_offset(value, self.start_time)
        elif self.policy.duration == Policy.UPDATE_ABSOLUTE:
            self.interval.duration = value
        if self.parent:
            self.parent.timestamp(value)

    def distance(self, value):
        v = int(round(float(value)))
        if self.policy.distance == Policy.DONT_UPDATE:
            pass
        elif self.policy.distance == Policy.UPDATE_WITH_OFFSET:
            self.interval.distance = self.distance_offset + v
        elif self.policy.distance == Policy.UPDATE_ABSOLUTE:
            self.interval.distance = v
        if not self.current:
            self.wpt().distance = self.interval.distance
        if self.parent:
            self.parent.distance(value)

    def work(self, value):
        self.interval.work = int(round(float(value)))

    def speed(self, value):
        self.wpt().speed = float(value)

    def power(self, value):
        self.wpt().power = int(round(float(value)))

    def torque(self, v):
        self.wpt().torque = float(v)

    def heartrate(self, v):
        self.wpt().heartrate = int(round(float(v)))

    def cadence(self, v):
        self.wpt().cadence = int(round(float(v)))

    def elevation(self, value):
        self.wpt().elevation = int(round(float(value)))

    def location(self, latval, lonval):
        lat = float(latval)
        lon = float(lonval)
        if lat != 0.0 and lon != 0.0:
            self.wpt().location = GeoPt(lat, lon)

    def new_wp(self):
        if self.wp is not None:
            self.wp.put()
        self.wp = None

    def wpt(self):
        if self.wp is None:
            self.wp = Waypoint(parent=self.interval)
            self.wp.seqnr = self.seqnr
            self.wp.interval = self.interval
            self.seqnr += 1
            self.interval.num_waypoints = self.seqnr
            if self.ts is not None:
                self.wp.timestamp = self.ts
                self.wp.seconds = Util.time_to_seconds(self.ts)
        return self.wp

    def close_wp(self):
        if self.wp is not None:
            self.wp.put()
            self.wp = None