def testGetLastPlace(self):
        self.testSavePlace()
    
        # The place saved in the previous step has no exit_ts set, so it is the
        # last place
        new_place = esdp.get_last_place(self.testUserId)
        new_place.exit_ts = 6
        esdp.save_place(new_place)

        # Now that I have set the exit_ts and saved it, there is no last place
        new_place = esdp.get_last_place(self.testUserId)
        self.assertIsNone(new_place)
Beispiel #2
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)