def testSegmentationWrapperWithManualTrip(self):
        test_trip = esdt.create_new_trip(self.testUUID)
        test_trip.start_ts = 1440695152.989
        test_trip.start_fmt_time = "2015-08-27 10:05:52.989000-07:00"
        test_trip.start_loc = {
                "type": "Point",
                "coordinates": [
                    -122.4029569,
                    37.6162024
                ]
            }

        test_trip.end_ts = 1440699266.669
        test_trip.end_fmt_time = "2015-08-27 11:14:26.669000-07:00"
        test_trip.end_loc = {
                "type": "Point",
                "coordinates": [
                    -122.2603947,
                    37.875023
                ]
            }
        esdt.save_trip(test_trip)
        eaiss.segment_trip_into_sections(self.testUUID, test_trip.get_id(), "DwellSegmentationTimeFilter")

        created_stops = esdt.get_stops_for_trip(self.testUUID, test_trip.get_id())
        created_sections = esdt.get_sections_for_trip(self.testUUID, test_trip.get_id())

        tq_stop = enua.UserCache.TimeQuery("enter_ts", 1440658800, 1440745200)
        queried_stops = esdst.get_stops(self.testUUID, tq_stop)

        tq_section = enua.UserCache.TimeQuery("start_ts", 1440658800, 1440745200)
        queried_sections = esds.get_sections(self.testUUID, tq_section)

        for i, stop in enumerate(created_stops):
            logging.info("Retrieved stop %s: %s -> %s" % (i, stop.enter_fmt_time, stop.exit_fmt_time))
        for i, section in enumerate(created_sections):
            logging.info("Retrieved section %s: %s -> %s" % (i, section.start_fmt_time, section.end_fmt_time))

        self.assertEqual(len(created_stops), 1)
        self.assertEqual(created_stops[0].enter_ts, 1440698066.704)
        self.assertEqual(created_stops[0].exit_ts, 1440698306.892)
        self.assertEqual(created_stops[0].exit_loc, created_sections[1].start_loc)
        self.assertEqual(created_stops[0].ending_section, created_sections[0].get_id())
        self.assertEqual(created_stops[0].starting_section, created_sections[1].get_id())

        self.assertEqual(len(created_sections), 2)
        logging.info("Checking fields for section %s" % created_sections[0])
        self.assertEqual(created_sections[0].start_ts, 1440695152.989)
        self.assertEqual(created_sections[0].end_ts, 1440698066.704)
        self.assertIsNone(created_sections[0].start_stop)
        self.assertEqual(created_sections[0].end_stop, created_stops[0].get_id())

        logging.info("Checking fields for section %s" % created_sections[1])
        self.assertEqual(created_sections[1].start_ts, 1440698306.892)
        self.assertEqual(created_sections[1].end_ts, 1440699266.669)
        self.assertEqual(created_sections[1].start_stop, created_stops[0].get_id())
        self.assertIsNone(created_sections[1].end_stop)

        self.assertEqual(created_sections, queried_sections)
        self.assertEqual(created_stops, queried_stops)
Esempio n. 2
0
    def turn_into_new_trip(self, user_id):
        print "new trip"
        trip = ecsdtq.create_new_trip(user_id)
        sections = []
        our_json = self.get_json()
        mode_list = set ( )


        if "plan" not in our_json:
            print("While querying alternatives from %s to %s" % (self.start_point, self.end_point))
            print("query URL is %s" % self.make_url())
            print("Response %s does not have a plan " % our_json)
            raise PathNotFoundException(our_json['debugOutput'])

        trip.start_loc = gj.Point( (float(our_json["plan"]["from"]["lat"]), float(our_json["plan"]["from"]["lon"])) ) 
        trip.end_loc = gj.Point( (float(our_json["plan"]["to"]["lat"]), float(our_json["plan"]["to"]["lon"])) ) 
        trip.start_local_dt = otp_time_to_ours(our_json['plan']['itineraries'][0]["startTime"])
        trip.end_local_dt = otp_time_to_ours(our_json['plan']['itineraries'][0]["endTime"])
        ecsdtq.save_trip(trip)

        for leg in our_json["plan"]["itineraries"][0]['legs']:
            section = ecsdsq.create_new_section(user_id, trip["_id"])
            section.start_local_dt = otp_time_to_ours(leg["startTime"])
            section.end_local_dt = otp_time_to_ours(leg["endTime"])
            section.distance = float(leg["distance"])
            section.start_loc = gj.Point( (float(leg["from"]["lat"]), float(leg["from"]["lon"])) )
            section.end_loc = gj.Point( (float(leg["to"]["lat"]), float(leg["to"]["lon"])) )
            ecsdsq.save_section(section)
Esempio n. 3
0
def create_places_and_trips(user_id, segmentation_points,
                            segmentation_method_name):
    # new segments, need to deal with them
    # First, retrieve the last place so that we can stitch it to the newly created trip.
    # Again, there are easy and hard. In the easy case, the trip was
    # continuous, was stopped when the trip end was detected, and there is
    # no gap between the start of the trip and the last place. But there
    # can be other issues caused by gaps in tracking. A more detailed
    # description of dealing with gaps in tracking can be found in the wiki.
    # Let us first deal with the easy case.
    # restart_events_df = get_restart_events(ts, time_query)
    last_place = esdp.get_last_place(user_id)
    if last_place is None:
        last_place = start_new_chain(user_id)
        last_place.source = segmentation_method_name

    # if is_easy_case(restart_events_df):
    # Theoretically, we can do some sanity checks here to make sure
    # that we are fairly close to the last point. Maybe mark some kind
    # of confidence level based on that?
    logging.debug("segmentation_point_list has length %s" %
                  len(segmentation_points))
    for (start_loc_doc, end_loc_doc) in segmentation_points:
        logging.debug("start_loc_doc = %s, end_loc_doc = %s" %
                      (start_loc_doc, end_loc_doc))
        start_loc = ecwl.Location(start_loc_doc)
        end_loc = ecwl.Location(end_loc_doc)
        logging.debug("start_loc = %s, end_loc = %s" % (start_loc, end_loc))

        # Stitch together the last place and the current trip
        curr_trip = esdt.create_new_trip(user_id)
        curr_trip.source = segmentation_method_name
        new_place = esdp.create_new_place(user_id)
        new_place.source = segmentation_method_name

        stitch_together_start(last_place, curr_trip, start_loc)
        stitch_together_end(new_place, curr_trip, end_loc)

        esdp.save_place(last_place)
        esdt.save_trip(curr_trip)

        last_place = new_place

    # The last last_place hasn't been stitched together yet, but we
    # need to save it so that it can be the last_place for the next run
    esdp.save_place(last_place)
def create_places_and_trips(user_id, segmentation_points, segmentation_method_name):
    # new segments, need to deal with them
    # First, retrieve the last place so that we can stitch it to the newly created trip.
    # Again, there are easy and hard. In the easy case, the trip was
    # continuous, was stopped when the trip end was detected, and there is
    # no gap between the start of the trip and the last place. But there
    # can be other issues caused by gaps in tracking. A more detailed
    # description of dealing with gaps in tracking can be found in the wiki.
    # Let us first deal with the easy case.
    # restart_events_df = get_restart_events(ts, time_query)
    last_place = esdp.get_last_place(user_id)
    if last_place is None:
        last_place = start_new_chain(user_id)
        last_place.source = segmentation_method_name

    # if is_easy_case(restart_events_df):
    # Theoretically, we can do some sanity checks here to make sure
    # that we are fairly close to the last point. Maybe mark some kind
    # of confidence level based on that?
    logging.debug("segmentation_point_list has length %s" % len(segmentation_points))
    for (start_loc_doc, end_loc_doc) in segmentation_points:
        logging.debug("start_loc_doc = %s, end_loc_doc = %s" % (start_loc_doc, end_loc_doc))
        start_loc = ecwl.Location(start_loc_doc)
        end_loc = ecwl.Location(end_loc_doc)
        logging.debug("start_loc = %s, end_loc = %s" % (start_loc, end_loc))

        # Stitch together the last place and the current trip
        curr_trip = esdt.create_new_trip(user_id)
        curr_trip.source = segmentation_method_name
        new_place = esdp.create_new_place(user_id)
        new_place.source = segmentation_method_name

        stitch_together_start(last_place, curr_trip, start_loc)
        stitch_together_end(new_place, curr_trip, end_loc)

        esdp.save_place(last_place)
        esdt.save_trip(curr_trip)

        last_place = new_place

    # The last last_place hasn't been stitched together yet, but we
    # need to save it so that it can be the last_place for the next run
    esdp.save_place(last_place)
 def create_fake_trip(self):
     new_trip = esdt.create_new_trip(self.testUserId)
     new_trip.start_ts = 5
     new_trip.end_ts = 6
     esdt.save_trip(new_trip)
     return new_trip
Esempio n. 6
0
    def testSegmentationWrapperWithManualTrip(self):
        test_trip = esdt.create_new_trip(self.testUUID)
        test_trip.start_ts = 1440695152.989
        test_trip.start_fmt_time = "2015-08-27 10:05:52.989000-07:00"
        test_trip.start_loc = {
            "type": "Point",
            "coordinates": [-122.4029569, 37.6162024]
        }

        test_trip.end_ts = 1440699266.669
        test_trip.end_fmt_time = "2015-08-27 11:14:26.669000-07:00"
        test_trip.end_loc = {
            "type": "Point",
            "coordinates": [-122.2603947, 37.875023]
        }
        esdt.save_trip(test_trip)
        eaiss.segment_trip_into_sections(self.testUUID, test_trip.get_id(),
                                         "DwellSegmentationTimeFilter")

        created_stops = esdt.get_stops_for_trip(self.testUUID,
                                                test_trip.get_id())
        created_sections = esdt.get_sections_for_trip(self.testUUID,
                                                      test_trip.get_id())

        tq_stop = enua.UserCache.TimeQuery("enter_ts", 1440658800, 1440745200)
        queried_stops = esdst.get_stops(self.testUUID, tq_stop)

        tq_section = enua.UserCache.TimeQuery("start_ts", 1440658800,
                                              1440745200)
        queried_sections = esds.get_sections(self.testUUID, tq_section)

        for i, stop in enumerate(created_stops):
            logging.info("Retrieved stop %s: %s -> %s" %
                         (i, stop.enter_fmt_time, stop.exit_fmt_time))
        for i, section in enumerate(created_sections):
            logging.info("Retrieved section %s: %s -> %s" %
                         (i, section.start_fmt_time, section.end_fmt_time))

        self.assertEqual(len(created_stops), 1)
        self.assertEqual(created_stops[0].enter_ts, 1440698066.704)
        self.assertEqual(created_stops[0].exit_ts, 1440698306.892)
        self.assertEqual(created_stops[0].exit_loc,
                         created_sections[1].start_loc)
        self.assertEqual(created_stops[0].ending_section,
                         created_sections[0].get_id())
        self.assertEqual(created_stops[0].starting_section,
                         created_sections[1].get_id())

        self.assertEqual(len(created_sections), 2)
        logging.info("Checking fields for section %s" % created_sections[0])
        self.assertEqual(created_sections[0].start_ts, 1440695152.989)
        self.assertEqual(created_sections[0].end_ts, 1440698066.704)
        self.assertIsNone(created_sections[0].start_stop)
        self.assertEqual(created_sections[0].end_stop,
                         created_stops[0].get_id())

        logging.info("Checking fields for section %s" % created_sections[1])
        self.assertEqual(created_sections[1].start_ts, 1440698306.892)
        self.assertEqual(created_sections[1].end_ts, 1440699266.669)
        self.assertEqual(created_sections[1].start_stop,
                         created_stops[0].get_id())
        self.assertIsNone(created_sections[1].end_stop)

        self.assertEqual(created_sections, queried_sections)
        self.assertEqual(created_stops, queried_stops)