简体   繁体   English

如果跑步者在健身追踪应用中保持同步,我如何跟踪?

[英]How can I keep track if runner is on pace in fitness tracking app?

I am going through the challenges in Apple's "App Development With Swift" iBook and have hit a roadblock in completing the fitness app in Lesson 2.2 - Functions. 我正在经历苹果公司的“使用Swift开发应用程序” iBook中遇到的挑战,并且在完成第2.2课-函数中完成健身应用程序遇到了障碍。 I can't think of a good formula to track if the user is on pace or not. 我想不出一个跟踪用户是否步调良好的公式。 I am still a noob and this is so far what I have come up with which obviously doesn't accurately keep track of the pace. 我仍然是一个菜鸟,到目前为止,这是我的想法,显然无法准确跟踪进度。

func pacing(currentDistance: Double, totalDistance: Double, currentTime: Double, goalTime: Double) {

        if (currentDistance < 0.50 * totalDistance && currentTime > 0.40 * goalTime)     {
            print("You've got to push it just a bit harder!")
    }
    else {
            print("Keep it up!")
    }
}
pacing(currentDistance: 1, totalDistance: 10, currentTime: 8, goalTime:60)

The challenge in the book tells you to do the following: Your fitness tracking app is going to help runners stay on pace to reach their goals. 书中的挑战告诉您要执行以下操作:您的健身跟踪应用程序将帮助跑步者保持步伐以实现自己的目标。 Write a function called pacing that takes four Double parameters called currentDistance, totalDistance, currentTime, and goalTime. 编写一个名为pacing的函数,该函数接受四个Double参数,分别称为currentDistance,totalDistance,currentTime和GoalTime。 Your function should calculate whether or not the user is on pace to hit or beat goalTime. 您的函数应计算用户是否在达到或击败目标时间上。 If yes, print "Keep it up!", otherwise print "You've got to push it just a bit harder!" 如果是,请打印“保持!”,否则请打印“您必须将其推得更紧一点!”

As we know that Distance = Speed * Time , so here you want to know that what is the current speed and based on that you would print the appropriate message So you can try something like this: 我们知道Distance = Speed * Time,所以在这里您想知道当前速度是多少,并在此基础上打印相应的消息,因此可以尝试如下操作:

func pacing(currentDistance: Double, totalDistance: Double, currentTime: Double, goalTime: Double) {

        let goalSpeed = totalDistance / goalTime
        let currentSpeed = currentDistance / currentTime

        if (currentSpeed < goalSpeed)     {
                print("You've got to push it just a bit harder!")
        }
        else {
                print("Keep it up!")
        }
}
pacing(currentDistance: 1, totalDistance: 10, currentTime: 8, goalTime:60)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不同时间段内跟踪数据(快速)-计数器/习惯跟踪应用程序 - How to keep track of data over various periods of time (Swift) - Counter/Habit Tracking App iOS-健身应用中的推送通知和距离跟踪 - iOS - Push notification and distance tracking in fitness app ARKIT - 它可以跟踪多少跟踪图像? - ARKIT - how many tracking images can it track? 如何跟踪UIImagePickerController创建/选择的媒体? - How can I keep track of media created/chosen by UIImagePickerController? 如何跟踪随日期变化的数据? - How can I keep track of data moving with dates? 如何检查 iOS 设备上是否启用了 Motion &amp; Fitness? - How can I check whether or not Motion & Fitness is enabled on an iOS device? 我可以从一个平台管理和跟踪我的应用程序发布吗 - Can i manage and keep track of my app release from one platform 如何跟踪“Moment”应用程序的iPhone使用情况? - How can I track iPhone usage like the 'Moment' app does? 如何跟踪我的应用可见的时间? - How can I track time my app is visible? 如何跟踪cocos2d中的精灵被触摸了多少次? - How can I keep track of how many times a sprite has been touched in cocos2d?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM