def setTrack(self, track):
        if track is None:  # create a default, empty track if none provided
            track = TrackMap()

        raceTrackView = self.ids.track
        raceTrackView.loadTrack(track)

        name = track.name
        configuration = '' if len(
            track.configuration) == 0 else ' ({})'.format(track.configuration)
        self.ids.name.text = name + configuration

        self.ids.length.text = '' if track.length == 0 else '{} mi.'.format(
            track.length)

        flag_image = self.ids.flag
        cc = track.country_code
        if cc:
            cc = cc.lower()
            try:
                flagImagePath = 'resource/flags/' + str(
                    track.country_code.lower()) + '.png'
                flag_image.source = flagImagePath
            except Exception as detail:
                Logger.warn(
                    'Error loading flag for country code: {}'.format(detail))
        else:
            flag_image.source = 'resource/flags/blank.png'
        self.track = track
Beispiel #2
0
 def test_create_trackmap(self):
     tm = TrackMap.create_new()
     self.assertEqual(tm.name, TrackMap.DEFAULT_TRACK_NAME)
     self.assertEqual(tm.configuration, TrackMap.DEFAULT_CONFIGURATION)
     self.assertEqual(len(tm.track_id), 32)
     epoch_time = time_to_epoch(tm.created)
     self.assertTrue(epoch_time > 0)
     self.assertTrue(len(tm.map_points) == 0)
     self.assertTrue(len(tm.sector_points) == 0)
 def test_create_trackmap(self):
     tm = TrackMap.create_new()
     self.assertEqual(tm.name, TrackMap.DEFAULT_TRACK_NAME)
     self.assertEqual(tm.configuration, TrackMap.DEFAULT_CONFIGURATION)
     self.assertEqual(len(tm.track_id), 32)
     epoch_time = time_to_epoch(tm.created)
     self.assertTrue(epoch_time > 0)
     self.assertTrue(len(tm.map_points) == 0)
     self.assertTrue(len(tm.sector_points) == 0)
 def __init__(self, rc_api, databus, track_manager, current_point=None, prompt_track_creation=False, ** kwargs):
     super(TrackBuilderView, self).__init__(**kwargs)
     self.register_event_type('on_track_complete')
     self.register_event_type('on_title')
     self._rc_api = rc_api
     self._databus = databus
     self._prompt_track_creation = prompt_track_creation
     self._track_manager = track_manager
     self._current_point = current_point
     self._screens = []
     self._track = TrackMap.create_new()
     self._track.custom = True
Beispiel #5
0
 def __init__(self,
              rc_api,
              databus,
              track_manager,
              current_point=None,
              prompt_track_creation=False,
              **kwargs):
     super(TrackBuilderView, self).__init__(**kwargs)
     self.register_event_type('on_track_complete')
     self.register_event_type('on_title')
     self._rc_api = rc_api
     self._databus = databus
     self._prompt_track_creation = prompt_track_creation
     self._track_manager = track_manager
     self._current_point = current_point
     self._screens = []
     self._track = TrackMap.create_new()
     self._track.custom = True
    def _race_setup(self):
        """
        Logic tree for setting up a race event, including track map selection and
        automatic configuration
        """
        # skip if this screen is not active
        if self.manager is not None and self.manager.current_screen != self:
            return

        # skip if we're not connected
        if not self._rc_api.connected:
            return

        # skip if GPS data is not good
        if self._gps_sample.gps_qual <= GpsConfig.GPS_QUALITY_NO_FIX:
            return

        track_cfg = self._rc_config.trackConfig
        auto_detect = track_cfg.autoDetect

        # skip if we haven't enabled auto detection
        if not auto_detect:
            return

        # what track is currently configured?
        current_track = TrackMap.from_track_cfg(track_cfg.track)

        # is the currently configured track in the list of nearby tracks?
        # if so, just keep this one
        tracks = self._track_manager.find_nearby_tracks(
            self._gps_sample.geopoint)

        prefs = self._settings.userPrefs
        last_track_set_time = datetime.datetime.fromtimestamp(
            prefs.get_last_selected_track_timestamp())
        track_set_a_while_ago = datetime.datetime.now(
        ) > last_track_set_time + datetime.timedelta(
            days=DashboardView.AUTO_CONFIGURE_WAIT_PERIOD_DAYS)

        # is the currently configured track in the area?
        current_track_is_nearby = current_track.short_id in (t.short_id
                                                             for t in tracks)

        # no need to re-detect a nearby track that was recently set
        if current_track_is_nearby and not track_set_a_while_ago:
            Logger.info(
                'DashboardView: Nearby track was recently set, skipping auto configuration'
            )
            return

        # we found only one track nearby, so select it and be done.
        if len(tracks) == 1:
            new_track = tracks[0]
            Logger.info('DashboardView: auto selecting track {}({})'.format(
                new_track.name, new_track.short_id))
            track_cfg.track.import_trackmap(new_track)
            self._set_rc_track(track_cfg)
            return

        # ok. To prevent repeatedly pestering the user about asking to configure a track
        # check if the user last cancelled near the same location
        last_cancelled_location = GeoPoint.from_string(
            prefs.get_user_cancelled_location())
        radius = last_cancelled_location.metersToDegrees(
            TrackManager.TRACK_DEFAULT_SEARCH_RADIUS_METERS,
            TrackManager.TRACK_DEFAULT_SEARCH_BEARING_DEGREES)
        if last_cancelled_location.withinCircle(self._gps_sample.geopoint,
                                                radius):
            Logger.info(
                "DashboardView: Still near the same location where the user last cancelled track configuration. Not pestering again"
            )
            return

        # if we made it this far, we're going to ask the user to help select or create a track
        Clock.schedule_once(lambda dt: self._load_track_setup_view(track_cfg))
    def _race_setup(self):
        """
        Logic tree for setting up a race event, including track map selection and
        automatic configuration
        """
        # skip if this screen is not active
        if self.manager is not None and self.manager.current_screen != self:
            return

        # skip if we're not connected
        if not self._rc_api.connected:
            return

        # skip if GPS data is not good
        if self._gps_sample.gps_qual <= GpsConfig.GPS_QUALITY_NO_FIX:
            return

        track_cfg = self._rc_config.trackConfig
        auto_detect = track_cfg.autoDetect

        # skip if we haven't enabled auto detection
        if not auto_detect:
            return

        # what track is currently configured?
        current_track = TrackMap.from_track_cfg(track_cfg.track)

        # is the currently configured track in the list of nearby tracks?
        # if so, just keep this one
        tracks = self._track_manager.find_nearby_tracks(self._gps_sample.geopoint)

        prefs = self._settings.userPrefs
        last_track_set_time = datetime.datetime.fromtimestamp(prefs.get_last_selected_track_timestamp())
        track_set_a_while_ago = datetime.datetime.now() > last_track_set_time + datetime.timedelta(days=DashboardView.AUTO_CONFIGURE_WAIT_PERIOD_DAYS)

        # is the currently configured track in the area?
        current_track_is_nearby = current_track.short_id in (t.short_id for t in tracks)

        # no need to re-detect a nearby track that was recently set
        if current_track_is_nearby and not track_set_a_while_ago:
            Logger.info('DashboardView: Nearby track was recently set, skipping auto configuration')
            return

        # we found only one track nearby, so select it and be done.
        if len(tracks) == 1:
            new_track = tracks[0]
            Logger.info('DashboardView: auto selecting track {}({})'.format(new_track.name, new_track.short_id))
            track_cfg.track.import_trackmap(new_track)
            self._set_rc_track(track_cfg)
            return

        # ok. To prevent repeatedly pestering the user about asking to configure a track
        # check if the user last cancelled near the same location
        last_cancelled_location = GeoPoint.from_string(prefs.get_user_cancelled_location())
        radius = last_cancelled_location.metersToDegrees(TrackManager.TRACK_DEFAULT_SEARCH_RADIUS_METERS,
                                                         TrackManager.TRACK_DEFAULT_SEARCH_BEARING_DEGREES)
        if last_cancelled_location.withinCircle(self._gps_sample.geopoint, radius):
            Logger.info("DashboardView: Still near the same location where the user last cancelled track configuration. Not pestering again")
            return

        # if we made it this far, we're going to ask the user to help select or create a track
        Clock.schedule_once(lambda dt: self._load_track_setup_view(track_cfg))