Example #1
0
 def get_events_by_area (area=None, timestamp=None, event_repo=EventRepo()):
   criteria = {'area': area}
   is_now = timestamp == 'now'
   if timestamp is not None:
     if timestamp == 'now':
       timestamp = current_date()
     else:
       timestamp = datetime_from_str(timestamp)
       timestamp = datetime_floor_hour(timestamp)
     criteria['timestamp'] = str(timestamp)
   events = event_repo.find_by_criteria(criteria)
   if len(events) == 0 and is_now:
     print '[event-service] events not found for %s, now mine data from waze' %(str(criteria))
     LOCATIONS = read_json('data/locations.json')
     EventService.mine_events(LOCATIONS[area], area=area)
     events = event_repo.find_by_criteria(criteria)
   return events
Example #2
0
 def testBasic(self):
   raw = read_json('tests/fixtures/itb-bec.route.json')
   route = Route(raw['routes'][0])
   self.assertTrue(route.total_distance == 4568)
   self.assertTrue(route.total_duration == 835)
Example #3
0
 def testJamPerLeg(self):
     route = read_json('tests/fixtures/ss-rsmelinda.route.json')
     events = read_json('tests/fixtures/bandung-2200.event.json')
     leg = route['routes'][0]['legs'][0]
     res = RouteService.jam_per_leg(leg, events)
     self.assertEqual(res, 14)
Example #4
0
    res = EventService.insert_events(events, event_repo=event_repo)
    return len(events)

  @staticmethod
  def get_events_by_area (area=None, timestamp=None, event_repo=EventRepo()):
    criteria = {'area': area}
    is_now = timestamp == 'now'
    if timestamp is not None:
      if timestamp == 'now':
        timestamp = current_date()
      else:
        timestamp = datetime_from_str(timestamp)
        timestamp = datetime_floor_hour(timestamp)
      criteria['timestamp'] = str(timestamp)
    events = event_repo.find_by_criteria(criteria)
    if len(events) == 0 and is_now:
      print '[event-service] events not found for %s, now mine data from waze' %(str(criteria))
      LOCATIONS = read_json('data/locations.json')
      EventService.mine_events(LOCATIONS[area], area=area)
      events = event_repo.find_by_criteria(criteria)
    return events

if __name__ == '__main__':
  LOCATIONS = read_json('data/locations.json')
  while True:
    print ''
    len_events = EventService.mine_events(LOCATIONS['jakarta2'], area='jakarta2')
    print '%s event(s) added' % (str(len_events))
    time.sleep(Config.TIMEOUT)

Example #5
0
 def testJamPerStep(self):
     route = read_json('tests/fixtures/ss-rsmelinda.route.json')
     events = read_json('tests/fixtures/bandung-2200.event.json')
     step = route['routes'][0]['legs'][0]['steps'][1]
     res = RouteService.jam_per_step(step, events)
     self.assertEqual(res, 5)