What data structure or algorithm do I need?

So I have had a long term project goal for over 5 years that has driven my desire to master programming.

But maybe I am overthinking this and would like some feedback about what type of data-structure to house my problem & solution in.

What I want to do is input parameters related to fitness, and output a “smart” training plan.

Eventually I would like this to be AI driven but first I need to either create / design inputs with expert knowledge, or collect real data after the project starts to collect it from people.

So example inputs might be:
years training
goal event (distance)
goal date
best 5k time
best 10k time
best half marathon time

Normally I would use my “intuition” and experiene and plot this out on a spreadsheet. I have a flow that I use to do this, but I’ve been doing it so long I think I am having trouble abstracting my knowledge.

The other issue that maybe i"m overthinking is that I want to avoid strict algebraic projections of those inputs to fill out the schedule.

Ie training for a marathon 16 weeks away, experienced runner, currently running 40mph, no injuries, best 5k time is 19:00.

This initial data collection would let me start plottign out a schedule but i’m not really sure what it is I am doing in my head.

So how do I represent all of these elements & the schedule structure in javascript?

I appreciate any input. Thank you!

It is funny you say that. I have already started such a project. I am a runner and have created a few web apps for certain calculations that I just could not find in other apps.

Oh yeah? what kind of tools? Any suggestions for me on structures?

You would need to have already created a model that “predicts” possible performance on various metrics (actual race times, age, weight, height, etc…). The model would probably be based on some regression analysis. You will need lots of actual date to accomplish something like this. Several sites have already done this analysis (i.e. https://runsmartproject.com/calculator/) and determined the actual training paces for various distances.

My thinking has been instead of me trying to determine the training paces (which people with more data and experience than me have already done), I will use their calculated paces and my own experience with various training programs over the years to create my own training plans with specific workouts that I “know” work for me and others. The training plan is just a template of sorts that gets populated with specific workouts that target the training paces.

The template can be stored in something as simple a JSON structure as an array of objects with each object representing a day in the training program. For my marathon training, I use a 16 week program for those new to marathons and a 12 week program for those who have more experience and already have a specific base mileage. So in my situation, I would have two different JSON files (one for each training type for the marathon).

For the application, I can select a race date and training type (beginner or advanced or other if you want other levels) and the application iterates through the array of objects containing the workout for each day into a calendar (basically a table) with the race date as the last array item being the race and the first date on the calendar being the first element in the array.

I have pacing models that I successfully use based on writing by Peter Reigel. I thought you’d interpret my question as asking for advice on what to model, but i’m very comfortable with that. I have a lot of spreadsheets i’ve developed that can take a p ace and model a variety of workouts (similar to McMillan calculator).

However there’s a lot more to it as you know, such as when to choose what intensity based on a training plan model, and that model can change based on a lot of factors as well, right? I’m not struggling with how to plan the sessions, but how to model the plan if that makes sense, and how to do it programatically.

I think part of what stumps me is when I look at a calendar layout, there are repeating weeks and the week is a basic unit of my planning with progressions week to week, similar workouts on same day of the week, and training cycles are built up of 3-6 week blocks. When i LOOK at a calendar layout, I can do all of this intuitively.

The idea of iteration as part of the algorithm makes total sense.

Maybe I iterate once over a collection of weeks that represent training cycles, then iterate within those weeks to plan the days.

When I do it, there is also shuffling of blocks, long sessions, training days to get things to “fit” into easy to plan routines as well, and because the look of the plan can change once I get it all built out, I may reconsider.

So what I do isn’t black and white and its never the same even though there is a pattern and a flow.

Am I making any sense ?

I totally understand. I think the best you can do at this point is have the app create a “general” training plan. You also have to consider things like what happens if the trainee over does it and is too soar or fatigued to perform the scheduled workout. You will have to be able to “adjust” the plan by maybe being able to throw in a REST day and then have the app “recalibrate” the training based on some general best practices (i.e which major workouts would need to be scrapped all together over the next so many days and/or what workouts like “easy” days could be substituted in.

I can not tell you how many times I have had to “tweak” my training plan 3-4 weeks into a training cycle for something like I describe above and/or some work-related or family stuff that causes a workout to be skipped. Your app will need to be able to re-calibrate for such things. There are a lot of moving parts.

1 Like

Yes I completely agree. Some plans I change on a daily basis, but there is some underlying pattern Im tracking when I do so, even if I don’t write it down.

THe number of moving parts makes me think this is a cadidate for some type of machine learning solutions as well, but no idea how to implement that right now, aside from having done basic tutorials

Thanks for helping me think through this.

I can’t begin to contribute to the physical training discussion here (Gym class tanked my GPA), but taking it back to the technical problem as I understand it…
You will probably want to do your calculations (projections? suggestions? plan? whatever) on the fly, rather than storing it. There may be certain constant values that you will store under a user’s profile rather than recalculate because their inputs do not change (like if you always used age/number of legs in your plan calculations or whatever), but generally you would just build the schedule client side every time new data changes. Functionally, this is actually very much the same as what you do in excel if you apply a function to a row that uses earlier rows as input.

Structurally, you might do something like create a base “racePlan” class, with “marathonPlan” (etc) which extend that base class. If you can identify what, mathematically, differs between a 5k plan and a marathon plan, and write a shared function which can take that difference as a parameter.

1 Like

thanks that’s helpful as well.

programmatically, working with React and now react hooks have me a little confuzzeled. how do classes vs functions differ ? it used to be in react you needed to have a class (with methods) to use state…but now you can create and use state in a function with hooks.

If you can think of any simple examples of what you describe I would appreciate that.

THinking of the “What is different” between 2 types of plans is a good approach to organization as well.

Thank you

I don’t program in React, so I can’t speak to that. In JavaScript, class is really just syntactic sugar that makes JS’s prototypical inheritance look and feel more like classical inheritance.

1 Like

In the context of React, you can effectively get the same result with either option.

If you have a OOP background or preference, the class syntactic sugar may feel more comfortable. If you have some Functional Programming leanings, functional components may feel more comfortable. I prefer hooks, but YMMV.

Either way, a class is just one specific way to create and model objects - it’s not the only way. I tend to think of the modeling step the same way regardless of the inheritance model. One is more architecture, the other an implementation detail (in my mind. Perhaps others will enlighten me!).


I"m glad to read this. I forgot all about object constructors and so reviewed the FCC lessons on it last night.

I think it’s better to learn React without hooks first. Learn the difference between when you just need a function vs a class instance. Functions, generally, for less sophisticated things, when you just need to return some DOM node/s based on a prop, i.e. a text field. Classes for more sophisticated things like a container for some dynamically filtered or fetched data, or a fancy button that can do many different things. Hooks bring in some new ways to add sophistication to functional components and new ways to structure your component tree, but hard to understand the purpose of those things until you’ve found something hard to do or change in your program without using them.

Hey I really appreciate your input. I’ve done a score of little projects including 4 out of the 5 front end projects with react using both classes & functions and feel fine with it. But now I’m trying to learn hooks and it’s just confusing me more. useState for example…it seems like a shortcut to using local state (maybe that’s exactly what it is?)

So I’m trying to put in into context with what I already know. I can do everything I’m currently doing without hooks, the hook syntax is making local state really easy but so far that’s as far as I have gotton.