当前位置: 首页>>代码示例>>Python>>正文


Python interchange.ActivityStatistic类代码示例

本文整理汇总了Python中tapiriik.services.interchange.ActivityStatistic的典型用法代码示例。如果您正苦于以下问题:Python ActivityStatistic类的具体用法?Python ActivityStatistic怎么用?Python ActivityStatistic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ActivityStatistic类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_stat_coalesce_multi

 def test_stat_coalesce_multi(self):
     stat1 = ActivityStatistic(ActivityStatisticUnit.Meters, value=1)
     stat2 = ActivityStatistic(ActivityStatisticUnit.Meters, value=2)
     stat3 = ActivityStatistic(ActivityStatisticUnit.Meters, value=3)
     stat4 = ActivityStatistic(ActivityStatisticUnit.Meters, value=4)
     stat5 = ActivityStatistic(ActivityStatisticUnit.Meters, value=5)
     stat1.coalesceWith(stat2)
     stat1.coalesceWith(stat3)
     stat1.coalesceWith(stat4)
     stat1.coalesceWith(stat5)
     self.assertEqual(stat1.Value, 3)
开发者ID:StanAccy,项目名称:tapiriik,代码行数:11,代码来源:statistics.py

示例2: test_unitconv_temp

    def test_unitconv_temp(self):
        stat = ActivityStatistic(ActivityStatisticUnit.DegreesCelcius, value=0)
        self.assertEqual(stat.asUnits(ActivityStatisticUnit.DegreesFahrenheit).Value, 32)

        stat = ActivityStatistic(ActivityStatisticUnit.DegreesCelcius, value=-40)
        self.assertEqual(stat.asUnits(ActivityStatisticUnit.DegreesFahrenheit).Value, -40)

        stat = ActivityStatistic(ActivityStatisticUnit.DegreesFahrenheit, value=-40)
        self.assertEqual(stat.asUnits(ActivityStatisticUnit.DegreesCelcius).Value, -40)

        stat = ActivityStatistic(ActivityStatisticUnit.DegreesFahrenheit, value=32)
        self.assertEqual(stat.asUnits(ActivityStatisticUnit.DegreesCelcius).Value, 0)
开发者ID:StanAccy,项目名称:tapiriik,代码行数:12,代码来源:statistics.py

示例3: test_unitconv_distance_cross

    def test_unitconv_distance_cross(self):
        stat = ActivityStatistic(ActivityStatisticUnit.Kilometers, value=1)
        self.assertAlmostEqual(stat.asUnits(ActivityStatisticUnit.Miles).Value, 0.6214, places=4)

        stat = ActivityStatistic(ActivityStatisticUnit.Miles, value=1)
        self.assertAlmostEqual(stat.asUnits(ActivityStatisticUnit.Kilometers).Value, 1.609, places=3)

        stat = ActivityStatistic(ActivityStatisticUnit.Miles, value=1)
        self.assertAlmostEqual(stat.asUnits(ActivityStatisticUnit.Meters).Value, 1609, places=0)
开发者ID:StanAccy,项目名称:tapiriik,代码行数:9,代码来源:statistics.py

示例4: test_stat_coalesce_missing

    def test_stat_coalesce_missing(self):
        stat1 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None)
        stat2 = ActivityStatistic(ActivityStatisticUnit.Meters, value=2)
        stat1.coalesceWith(stat2)
        self.assertEqual(stat1.Value, 2)

        stat1 = ActivityStatistic(ActivityStatisticUnit.Meters, value=1)
        stat2 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None)
        stat1.coalesceWith(stat2)
        self.assertEqual(stat1.Value, 1)
开发者ID:StanAccy,项目名称:tapiriik,代码行数:10,代码来源:statistics.py

示例5: DownloadActivity

    def DownloadActivity(self, serviceRecord, activity):
        # First, download the summary stats and lap stats
        self._downloadActivitySummary(serviceRecord, activity)

        if len(activity.Laps) == 1:
            activity.Stats = activity.Laps[0].Stats # They must be identical to pass the verification

        if activity.Stationary:
            # Nothing else to download
            return activity

        # https://connect.garmin.com/proxy/activity-service-1.3/json/activityDetails/####
        activityID = activity.ServiceData["ActivityID"]
        session = self._get_session(record=serviceRecord)
        self._rate_limit()
        res = session.get("http://connect.garmin.com/proxy/activity-service-1.3/json/activityDetails/" + str(activityID) + "?maxSize=999999999")
        try:
            raw_data = res.json()["com.garmin.activity.details.json.ActivityDetails"]
        except ValueError:
            raise APIException("Activity data parse error for %s: %s" % (res.status_code, res.text))

        if "measurements" not in raw_data:
            activity.Stationary = True # We were wrong, oh well
            return activity

        attrs_map = {}
        def _map_attr(gc_key, wp_key, units, in_location=False, is_timestamp=False):
            attrs_map[gc_key] = {
                "key": wp_key,
                "to_units": units,
                "in_location": in_location, # Blegh
                "is_timestamp": is_timestamp # See above
            }

        _map_attr("directSpeed", "Speed", ActivityStatisticUnit.MetersPerSecond)
        _map_attr("sumDistance", "Distance", ActivityStatisticUnit.Meters)
        _map_attr("directHeartRate", "HR", ActivityStatisticUnit.BeatsPerMinute)
        _map_attr("directBikeCadence", "Cadence", ActivityStatisticUnit.RevolutionsPerMinute)
        _map_attr("directDoubleCadence", "RunCadence", ActivityStatisticUnit.StepsPerMinute) # 2*x mystery solved
        _map_attr("directAirTemperature", "Temp", ActivityStatisticUnit.DegreesCelcius)
        _map_attr("directPower", "Power", ActivityStatisticUnit.Watts)
        _map_attr("directElevation", "Altitude", ActivityStatisticUnit.Meters, in_location=True)
        _map_attr("directLatitude", "Latitude", None, in_location=True)
        _map_attr("directLongitude", "Longitude", None, in_location=True)
        _map_attr("directTimestamp", "Timestamp", None, is_timestamp=True)

        # Figure out which metrics we'll be seeing in this activity
        attrs_indexed = {}
        attr_count = len(raw_data["measurements"])
        for measurement in raw_data["measurements"]:
            key = measurement["key"]
            if key in attrs_map:
                if attrs_map[key]["to_units"]:
                    attrs_map[key]["from_units"] = self._unitMap[measurement["unit"]]
                    if attrs_map[key]["to_units"] == attrs_map[key]["from_units"]:
                        attrs_map[key]["to_units"] = attrs_map[key]["from_units"] = None
                attrs_indexed[measurement["metricsIndex"]] = attrs_map[key]

        # Process the data frames
        frame_idx = 0
        active_lap_idx = 0
        for frame in raw_data["metrics"]:
            wp = Waypoint()
            for idx, attr in attrs_indexed.items():
                value = frame["metrics"][idx]
                target_obj = wp
                if attr["in_location"]:
                    if not wp.Location:
                        wp.Location = Location()
                    target_obj = wp.Location

                # Handle units
                if attr["is_timestamp"]:
                    value = pytz.utc.localize(datetime.utcfromtimestamp(value / 1000))
                elif attr["to_units"]:
                    value = ActivityStatistic.convertValue(value, attr["from_units"], attr["to_units"])

                # Write the value (can't use __dict__ because __slots__)
                setattr(target_obj, attr["key"], value)

            # Fix up lat/lng being zero (which appear to represent missing coords)
            if wp.Location and wp.Location.Latitude == 0 and wp.Location.Longitude == 0:
                wp.Location.Latitude = None
                wp.Location.Longitude = None
            # Bump the active lap if required
            while (active_lap_idx < len(activity.Laps) - 1 and # Not the last lap
                   activity.Laps[active_lap_idx + 1].StartTime <= wp.Timestamp):
                active_lap_idx += 1
            activity.Laps[active_lap_idx].Waypoints.append(wp)
            frame_idx += 1

        return activity
开发者ID:7e7,项目名称:tapiriik,代码行数:92,代码来源:garminconnect.py

示例6: test_unitconv_noop

 def test_unitconv_noop(self):
     stat = ActivityStatistic(ActivityStatisticUnit.KilometersPerHour, value=100)
     self.assertEqual(stat.asUnits(ActivityStatisticUnit.KilometersPerHour).Value, 100)
开发者ID:StanAccy,项目名称:tapiriik,代码行数:3,代码来源:statistics.py

示例7: test_unitconv_velocity_cross

    def test_unitconv_velocity_cross(self):
        stat = ActivityStatistic(ActivityStatisticUnit.KilometersPerHour, value=100)
        self.assertAlmostEqual(stat.asUnits(ActivityStatisticUnit.MilesPerHour).Value, 62, places=0)

        stat = ActivityStatistic(ActivityStatisticUnit.MilesPerHour, value=60)
        self.assertAlmostEqual(stat.asUnits(ActivityStatisticUnit.KilometersPerHour).Value, 96.5, places=0)
开发者ID:StanAccy,项目名称:tapiriik,代码行数:6,代码来源:statistics.py

示例8: test_unitconv_velocity_metric

    def test_unitconv_velocity_metric(self):
        stat = ActivityStatistic(ActivityStatisticUnit.MetersPerSecond, value=100)
        self.assertEqual(stat.asUnits(ActivityStatisticUnit.KilometersPerHour).Value, 360)

        stat = ActivityStatistic(ActivityStatisticUnit.KilometersPerHour, value=50)
        self.assertAlmostEqual(stat.asUnits(ActivityStatisticUnit.MetersPerSecond).Value, 13.89, places=2)
开发者ID:StanAccy,项目名称:tapiriik,代码行数:6,代码来源:statistics.py

示例9: test_unitconv_distance_metric

    def test_unitconv_distance_metric(self):
        stat = ActivityStatistic(ActivityStatisticUnit.Kilometers, value=1)
        self.assertEqual(stat.asUnits(ActivityStatisticUnit.Meters).Value, 1000)

        stat = ActivityStatistic(ActivityStatisticUnit.Meters, value=250)
        self.assertEqual(stat.asUnits(ActivityStatisticUnit.Kilometers).Value, 0.25)
开发者ID:StanAccy,项目名称:tapiriik,代码行数:6,代码来源:statistics.py

示例10: test_unitconv_distance_nonmetric

    def test_unitconv_distance_nonmetric(self):
        stat = ActivityStatistic(ActivityStatisticUnit.Miles, value=1)
        self.assertEqual(stat.asUnits(ActivityStatisticUnit.Feet).Value, 5280)

        stat = ActivityStatistic(ActivityStatisticUnit.Feet, value=5280/2)
        self.assertEqual(stat.asUnits(ActivityStatisticUnit.Miles).Value, 0.5)
开发者ID:StanAccy,项目名称:tapiriik,代码行数:6,代码来源:statistics.py

示例11: test_stat_coalesce_multi_missingmixed_multivalued

    def test_stat_coalesce_multi_missingmixed_multivalued(self):
        stat1 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None, min=None)
        stat2 = ActivityStatistic(ActivityStatisticUnit.Meters, value=2, max=2)
        stat3 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None, gain=3)
        stat4 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None, loss=4)
        stat5 = ActivityStatistic(ActivityStatisticUnit.Meters, value=5, min=3)
        stat5.coalesceWith(stat2)
        stat3.coalesceWith(stat5)
        stat4.coalesceWith(stat3)
        stat1.coalesceWith(stat4)

        self.assertAlmostEqual(stat1.Value, 7/2)
        self.assertEqual(stat1.Min, 3)
        self.assertEqual(stat1.Max, 2)
        self.assertEqual(stat1.Gain, 3)
        self.assertEqual(stat1.Loss, 4)
开发者ID:StanAccy,项目名称:tapiriik,代码行数:16,代码来源:statistics.py

示例12: test_stat_coalesce_multi_missingmixed

    def test_stat_coalesce_multi_missingmixed(self):
        stat1 = ActivityStatistic(ActivityStatisticUnit.Meters, value=1)
        stat2 = ActivityStatistic(ActivityStatisticUnit.Meters, value=2)
        stat3 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None)
        stat4 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None)
        stat5 = ActivityStatistic(ActivityStatisticUnit.Meters, value=5)
        stat5.coalesceWith(stat2)
        stat3.coalesceWith(stat5)
        stat4.coalesceWith(stat3)
        stat1.coalesceWith(stat4)

        self.assertAlmostEqual(stat1.Value, 8/3)
开发者ID:StanAccy,项目名称:tapiriik,代码行数:12,代码来源:statistics.py

示例13: test_stat_update

    def test_stat_update(self):
        stat1 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None, min=None)
        stat2 = ActivityStatistic(ActivityStatisticUnit.Meters, value=2, max=2)
        stat3 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None, gain=3)
        stat4 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None, gain=4)
        stat5 = ActivityStatistic(ActivityStatisticUnit.Meters, value=5, max=3)
        stat5.update(stat2)
        stat3.update(stat5)
        stat4.update(stat3)
        stat1.update(stat4)

        self.assertEqual(stat1.Value, 2)
        self.assertEqual(stat1.Max, 2)
        self.assertEqual(stat1.Gain, 3)
开发者ID:OkanEsen,项目名称:tapiriik,代码行数:14,代码来源:statistics.py

示例14: test_stat_sum

    def test_stat_sum(self):
        stat1 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None, min=None)
        stat2 = ActivityStatistic(ActivityStatisticUnit.Meters, value=2, max=2)
        stat3 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None, gain=3)
        stat4 = ActivityStatistic(ActivityStatisticUnit.Meters, value=None, gain=4)
        stat5 = ActivityStatistic(ActivityStatisticUnit.Meters, value=5, max=3)
        stat5.sumWith(stat2)
        stat3.sumWith(stat5)
        stat4.sumWith(stat3)
        stat1.sumWith(stat4)

        self.assertEqual(stat1.Value, 7)
        self.assertEqual(stat1.Max, 3)
        self.assertEqual(stat1.Gain, 7)
开发者ID:OkanEsen,项目名称:tapiriik,代码行数:14,代码来源:statistics.py


注:本文中的tapiriik.services.interchange.ActivityStatistic类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。