Exemple #1
0
    def _random_points(cls, count=100, root=None):
        """Get some random points.

        Distance between two points will never exceed 200m.

        Returns:
            A list with count points

        """

        start_time = cls._random_datetime()
        if root is None:
            root = GPXTrackPoint(latitude=random.uniform(-90.0, 90.0),
                                 longitude=random.uniform(-180.0, 180.0),
                                 elevation=0,
                                 time=start_time)
        result = [root]

        angle = 50
        for _ in range(1, count):
            angle = angle + random.uniform(-20, 20)
            delta = LocationDelta(distance=random.randrange(200), angle=angle)
            point = GPXTrackPoint(latitude=result[-1].latitude,
                                  longitude=result[-1].longitude)
            point.move(delta)
            point.elevation = _
            point.time = start_time + datetime.timedelta(seconds=10 * _)
            result.append(point)
        return result
Exemple #2
0
    def create_test_activity(cls,
                             count: int = 1,
                             idx: int = 0,
                             what: str = None,
                             status: bool = False):
        """creates an :class:`~gpxity.Activity`. It starts off with **test.gpx** and appends a
        last track point, it also changes the time stamp of the last point.
        This is done using **count** and **idx**: The last point is set such that
        looking at the tracks, they all go in a different direction clockwise, with an angle
        in degrees of :literal:`360 * idx / count`.

        Args:
            count: See above. Using 1 as default if not given.
            idx: See above. Using 0 as default if not given.
            what: The wanted value for the activity.
                Default: if count == len(:attr:`Activity.legal_what <gpxity.Activity.legal_what>`),
                the default value will be legal_what[idx].
                Otherwise a random value will be applied.
            status: Public?

        Returns:
            (~gpxity.Activity): A new activity not bound to a backend
        """
        if BasicTest.all_backend_classes is None:
            BasicTest.all_backend_classes = BasicTest._find_backend_classes()
        gpx = cls._get_gpx_from_test_file('test')
        movement = gpxpy.geo.LocationDelta(distance=100000,
                                           angle=360 * idx / count)
        last_points = gpx.tracks[-1].segments[-1].points
        new_point = GPXTrackPoint(latitude=last_points[-1].latitude,
                                  longitude=last_points[-1].longitude + 0.001,
                                  time=last_points[-1].time +
                                  datetime.timedelta(hours=10, seconds=idx))
        new_point.move(movement)
        gpx.tracks[-1].segments[-1].points.append(new_point)

        # now set all times such that they are in order with this activity and do not overlap
        # with other test activities
        duration = new_point.time - gpx.tracks[0].segments[0].points[
            0].time + datetime.timedelta(seconds=10)
        for point in gpx.walk(only_points=True):
            point.time += duration * idx

        result = Activity(gpx=gpx)
        result.title = 'Random GPX # {}'.format(idx)
        result.description = 'Description to {}'.format(gpx.name)
        if what:
            result.what = what
        elif count == len(Activity.legal_what):
            result.what = Activity.legal_what[idx]
        else:
            result.what = random.choice(Activity.legal_what)
        result.public = status
        return result
Exemple #3
0
    def create_test_track(cls,
                          backend_class=None,
                          count: int = 1,
                          idx: int = 0,
                          category: str = None,
                          public: bool = False,
                          start_time=None,
                          end_time=None):
        """create a :class:`~gpxity.gpxfile.GpxFile`.

        It starts off with **test.gpx** and appends a
        last gpxfile point, it also changes the time stamp of the last point.
        This is done using **count** and **idx**: The last point is set such that
        looking at the gpxfiles, they all go in a different direction clockwise, with an angle
        in degrees of :literal:`360 * idx / count`.

        Args:
            backend_class: If given, use it as source for a random category
            count: See above. Using 1 as default if not given.
            idx: See above. Using 0 as default if not given.
            category: The wanted value for the gpxfile.
                Default: if count == len(:attr:`GpxFile.categories <gpxity.gpxfile.GpxFile.categories>`),
                the default value will be backend_class.supported_categories[idx].
                Otherwise a random value from backend_class.supported_categories will be applied.
            public: should the gpxfiles be public or private?
            start_time: If given, assign it to the first point and adjust all following times
            end_time: explicit time for the last point. If None: See above.

        Returns:
            (~gpxity.gpxfile.GpxFile): A new gpxfile not bound to a backend

        """
        # pylint: disable=too-many-locals
        result = cls._get_track_from_test_file('test')
        if start_time is not None:
            if not start_time.tzinfo:
                start_time = start_time.replace(tzinfo=datetime.timezone.utc)
            result.adjust_time(start_time - result.first_time)
        last_point = result.last_point()
        if end_time is None:
            end_time = last_point.time + datetime.timedelta(hours=10,
                                                            seconds=idx)
        if not end_time.tzinfo:
            end_time = end_time.replace(tzinfo=datetime.timezone.utc)
        new_point = GPXTrackPoint(latitude=last_point.latitude,
                                  longitude=last_point.longitude + 0.001,
                                  time=end_time)
        _ = gpxpy.geo.LocationDelta(distance=1000, angle=360 * idx / count)
        new_point.move(_)
        result.add_points([new_point])

        # now set all times such that they are in order with this gpxfile and do not overlap
        # with other test gpxfiles
        _ = result.first_time
        duration = new_point.time - _ + datetime.timedelta(seconds=10)
        for point in result.gpx.walk(only_points=True):
            point.time += duration * idx

        result.title = 'Random GPX # {}'.format(idx)
        result.description = 'Description to {}'.format(result.title)
        if backend_class is None:
            cat_source = GpxFile.categories
        else:
            cat_source = backend_class.supported_categories
            cat_source = [backend_class.decode_category(x) for x in cat_source]
        if category:
            result.category = category
        elif count == len(GpxFile.categories):
            result.category = cat_source[idx]
        else:
            result.category = random.choice(cat_source)
        result.public = public
        return result