Example #1
0
 def speed_received(self, speed):
     with app.app_context():
         current_time = time.time()
         if self.last_time_received is not None:
             distance = speed / 3600.0 * (current_time - self.last_time_received)
             self.total_distance += distance
             res = mongo.db.sessions.update({"_id": self.session_id}, {"$set": {self.bike_id: self.total_distance}})
         self.last_speed_received = speed
         self.last_time_received = current_time
Example #2
0
def start_new_session():
    with app.app_context():
        session_id = mongo.db.sessions.insert({"timestamp": time.time()})
        app.bikes[0].start_new_session(session_id)
        app.bikes[1].start_new_session(session_id)
        app.current_session_id = session_id