cancel
Showing results for 
Search instead for 
Did you mean: 

Web Application

Raymond7
Shkhara

Hi, 

I have been working on a simple web application to track running performance. Currently I am using the MySQL database. I have a form taking in Time of run as a string. I was running into issues trying to store the run time as a time via MySQL. I joined Strava hoping I could inspect the HTML with hopes of helping me with my issue.

First, I observed that information is being stored as JSON objects. I also observed that the inputs of the form we're taking in the time for a run as a number. I was hoping to engage in a conversation with a developer to assist me as I try to solve my issue and continue building my application. 

My questions are can I accomplish my goal with MySQL as my database or will I need to convert to a NoSQL database? Does my information need to be input as a JSON object? What steps should I take to accomplish storing "duration" of a run in my Web Application?

5 REPLIES 5

Lovro
Shkhara

I have a few questions:

1. do you already have a working app that has a form for manually entering time of runs, or what is the purpose of this form you were describing?

2. When you say that "information is being stored as JSON objects" what information are you talking about? Did you connect your app with Strava API and is this information activity information?

3. what are you actually trying to do? Do you want to just see how much time you ran, or which days you were running or something else?

Hey Lovro,

Thanks for your response!

1. I do have a working app that has a form for manually entering time of runs. However, becasue I was struggling to figure out how to store the data, the work around I did was storing the "Run time" as a String.

2. So in exploring the Strava site to try to find a fix for my web application, I explored the "API Playground" on the site. In searching the HTTP methods I looked at the GET "/activities" route. In the route it gave examples of the information in the API. I noticed they were JSON objects that held information like "activity_type", "run_type", etc. My application is currently not utilizing an API. It is a simple Web Application with CRUD functionality that is manually operated by the users. 

3. So the simple of it all is, like I mentioned in Answer 1, my Web App is currently storing the Run Time as a String and I would like to store it properly and more efficiently as a means of "Time."

Full disclosure, I'm sort of a beginner at all of this. I was working on my Web App for class. I was working under a time crunch, so that's the reason for storing my Run Time as a String. Going back to work on my Web App now I just would like to have it so my form is storing the Run Time like other applications do and not a string. I sort of came here for help as a shot in the dark. 

Thanks for your time and help Lovro. I appreciate it.

Ok so you just want a simple app to manually add runs via form.
In what format do you save the run time? Like "75min", "1h 15m", "1 hour 15 minutes"... anything else? The first suggestion would be to save your time as seconds (integers) in your database and you display the time in "human readable format" in html.

What do you use for backend? PHP?

That is correct. This is a very simple low level web app to manually add runs via form. 

Currently I am saving the run as a String. In my form input i have a placeholder for hours, minutes, seconds that looks like this: "hh:mm:ss". Because it is a String this does call for the user to follow that format, however you can see my issue if a different key is pressed.

On my backend I'm coding in Python and using Flask to build my web app.

So as I said my suggestion would be to save your time in seconds which are integers. This will also enable you to easily get sums of different runs.

So when you receive the form request from html to Python, you convert the string into a `datetime` object and calculate that to seconds. Example:

from datetime import datetime

def time_string_to_seconds(time_string):
    # Parse the time string into a datetime object
    time_obj = datetime.strptime(time_string, "%H:%M:%S")
    
    # Calculate the total number of seconds using the time object
    total_seconds = time_obj.hour * 3600 + time_obj.minute * 60 + time_obj.second
    
    return total_seconds

# Example usage:
time_string = "01:15:30" # this "time_string" is what you get from your form
seconds = time_string_to_seconds(time_string)
print(seconds)  # Output: 4530

And when you retrieve time from database (integers) you convert the seconds to the same format (or any other) to then display it in html form. Example:

def seconds_to_time_string(total_seconds):
    hours = total_seconds // 3600
    minutes = (total_seconds % 3600) // 60
    seconds = total_seconds % 60
    
    # Format the time as "hh:mm:ss"
    time_string = "{:02d}:{:02d}:{:02d}".format(hours, minutes, seconds)
    
    return time_string

# Example usage:
total_seconds = 4530
time_string = seconds_to_time_string(total_seconds)
print(time_string)  # Output: "01:15:30"

DISCLAIMER: I am not familiar with Python, I know PHP. ChatGPT helped me with the above examples 🙂

Ready, Get Set, Go!

Welcome to the Community - here is your guide to help you get started!


Know how to use Community


Understand Community Settings