10-16-2017 06:07 - edited 10-16-2017 08:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-16-2017 06:07 - edited 10-16-2017 08:35
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
I programmed my first watch face that carries tide data. Now I am thinking of developing an app for sprint activities while already running or swmming, and I need some feedback.
I am not a programmer, even though I had some coding experience. I am refreshing everything and thinking of going through FreeCodeCamp to set my javascript skills.
My app would count repetitions when a certain condition works (speed is more than X and distance is > Y). It will then calculate the distance for the sprint effort, and the max speed during it.
I am considering writing something that has this logic of if and while statements.
IF statement speed > X
set initial time, location
WHILE speed > X
get max speed
get time
// out of the while loop now (as speed < X)
// but I should still be within the if statement, correct?
calculate time elapsed
calculate distance
IF distance > Y
rep count = +1
// end of if statements 1 and 2
Can any of you more experienced developer let me know if this structure is sound, or whether I should consider alternative routes?
10-16-2017 08:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


10-16-2017 08:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-16-2017 08:42
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Could you share what it is you are looking to achieve? The structure looks sound, but there are many values that you don't appear to use in any way (eg: max speed).
It's also worth noting that humans are not pure function generators, so single element logic gates like (while speed > x) will often cause unforeseen problems when a person is approaching speed == x because they can very easily fluctuate around that number, causing conditions where they are continually falling in and out of the condition resulting in potentially hundreds of microsecond intervals, rather than a few several seconds to minutes long intervals (as I am assuming you are expecting).

10-16-2017 08:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-16-2017 08:51
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Thanks for the feedback @JonFitbit and @BayssMekanique.
Speed in the function would be the minimum speed for which an event becomes something to count.
I am trying to create a logic that would help me develop an app that I could use for counting waves as I surf, but potentially I could apply to other sports (run with sprints, mountain bike sprints, and so on). Basically the idea is to create a couple of minimum parameter to be met (acceleration or speed, distance, time) and track the event between the start of the parameter and the end.
For example to be considered a sprint (and counted as so), I would have to go at a speed over 10mph for at least 30yards or 5 seconds.
10-16-2017 09:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

10-16-2017 09:01
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You are on the right track then. You'll want to constantly be looking at the last few seconds of data and running logic over it to determine when an event has occurred. I would recommend doing a map().reduce() or some similar function on a fixed array which you are constantly pop()'ing and push()'ing on, so that you'll maintain fairly steady memory usage, rather than using a large array and indexes where you'll potentially run into issues with O(n) memory growth.
Looks good so far. Feel free to post a link to a bin when you need more help!

