def test_empty_list(self): # print(len(self.tripA.segments[0].points)) def expected(track): # print(len(track.segments[0].points)) self.assertTrue(True) learn_trip.learn_trip(self.tripA, [], expected, self.fail)
def test_matching_track(self): def expected(track): self.assertTrue(True) learn_trip.learn_trip(self.tripA, [self.tripB], self.fail, expected)
def annotate_to_next(self, track, life): """ Stores the track and dequeues another track to be processed. Moves the current GPX file from the input path to the backup path, creates a LIFE file in the life path and creates a trip entry in the database. Finally the trip is exported as a GPX file to the output path. Args: track (:obj:tracktotrip.Track`) changes (:obj:`list` of :obj:`dict`): Details of, user made, changes """ if not track.name or len(track.name) == 0: track.name = track.generate_name(self.config['trip_name_format']) # Export trip to GPX if self.config['output_path']: save_to_file(join(expanduser(self.config['output_path']), track.name), track.to_gpx()) # if not self.is_bulk_processing: # apply_transportation_mode_to(track, life, set(self.clf.labels.classes_)) # learn_transportation_mode(track, self.clf) # with open(self.config['transportation']['classifier_path'], 'w') as classifier_file: # self.clf.save_to_file(classifier_file) # To LIFE if self.config['life_path']: name = '.'.join(track.name.split('.')[:-1]) save_to_file(join(expanduser(self.config['life_path']), name), life) if self.config['life_all']: life_all_file = expanduser(self.config['life_all']) else: life_all_file = join(expanduser(self.config['life_path']), 'all.life') save_to_file(life_all_file, "\n\n%s" % life, mode='a+') conn, cur = self.db_connect() if conn and cur: db.load_from_segments_annotated( cur, self.current_track(), life, self.config['location']['max_distance'], self.config['location']['min_samples'] ) def insert_can_trip(can_trip, mother_trip_id): """ Insert a cannonical trip into the database See `db.insert_canonical_trip` Args: can_trip (:obj:`tracktotrip.Segment`): Canonical trip mother_trip_id (int): Id of the trip that originated the canonical representation Returns: int: Canonical trip id """ return db.insert_canonical_trip(cur, can_trip, mother_trip_id) def update_can_trip(can_id, trip, mother_trip_id): """ Updates a cannonical trip on the database See `db.update_canonical_trip` Args: can_id (int): Canonical trip id trip (:obj:`tracktotrip.Segment`): Canonical trip mother_trip_id (int): Id of the trip that originated the canonical representation """ db.update_canonical_trip(cur, can_id, trip, mother_trip_id) trips_ids = [] for trip in track.segments: # To database trip_id = db.insert_segment( cur, trip, self.config['location']['max_distance'], self.config['location']['min_samples'] ) trips_ids.append(trip_id) d_latlon = estimate_meters_to_deg(self.config['location']['max_distance']) # Build/learn canonical trip canonical_trips = db.match_canonical_trip(cur, trip, d_latlon) print "canonical_trips # = %d" % len(canonical_trips) learn_trip( trip, trip_id, canonical_trips, insert_can_trip, update_can_trip, self.config['simplification']['eps'], d_latlon ) # db.insertStays(cur, trip, trips_ids, life) db.dispose(conn, cur) # Backup if self.config['backup_path']: for gpx in self.queue[self.current_day]: from_path = gpx['path'] to_path = join(expanduser(self.config['backup_path']), gpx['name']) rename(from_path, to_path) self.next_day() self.current_step = Step.preview return self.current_track()