Revisualizing Running Data on MongoDB

Bliss Wave IT LLC

Data Visualizer
Database Specialist
MongoDB
Python

New year, new start.

As we welcomed the new year, I embraced the opportunity for a fresh start, not just personally but also in terms of fitness and technological endeavors. Having Laika, my faithful companion, by my side for over a year, I revisited our running routine with a renewed sense of purpose. Initially, we started off gently in January, committing to consistency. This laid the groundwork for a more structured approach in February, as I adopted a 5k program tailored for both of us.

The journey took an interesting turn when I reconnected with a friend, an avid runner, whose passion reignited my own aspirations for marathon running. Despite previously completing two marathons, the challenge now was to balance my marathon training with Laika’s exercise regimen. Ingeniously, I devised a plan that accommodated both our needs. The shorter runs from the marathon schedule aligned perfectly with Laika’s 5k program, facilitating a seamless integration of our activities. As the marathon training intensified, it naturally complemented the conclusion of Laika’s program, marking a harmonious progression in our training journey.

Tracking activities alone and with my dog.



In tracking our activities, the distinction between solo and joint sessions with Laika became crucial. My solution was to utilize PostgreSQL, introducing a 'withDog' column in the database schema to categorize our runs accurately. This foresight was pivotal, especially as I entertained the possibility of long-distance running from the outset.



Relational Database or Nonrelational Database?

Despite the initial setup with PostgreSQL, I later transitioned to MongoDB, a decision driven by its flexibility and suitability for handling diverse profiles. MongoDB’s document-oriented structure allowed for a more nuanced representation of our activities, integrating details such as distance, time, and even shoe attributes directly within each activity document. This shift not only streamlined data management but also enhanced the analysis of our running activities, both with and without Laika.

{

"_id": "<activity_id>",

"type": "<activity_type>",

"withDog": true,

"distance": "<distance>",

"time": "<time>",

"date": "<date>",

"shoe": {

"shoeId": "<shoe_id>",

"brand": "<brand>",

"model": "<model>",

"color": "<color>",

"isRetired": false

}

},

{

"_id": "<activity_id>",

"type": "<another_activity_type>",

"withDog": false,

"distance": "<distance>",

"time": "<time>",

"date": "<date>",

"shoe": {

"shoeId": "<shoe_id>",

"brand": "<brand>",

"model": "<model>",

"color": "<color>",

"isRetired": false

}

}



The analytical power of MongoDB was further leveraged through the aggregation pipeline, enabling sophisticated queries that differentiated between solo runs and those undertaken with Laika. Additionally, it facilitated an efficient tracking system for the mileage of our shoes, a critical factor in ensuring our runs were supported by appropriate gear.

# Aggregation Pipeline for summing distance for each shoe

distance_pipeline = [

{

"$match": {

"type": "Run"

}

},

{

"$group": {

"_id": {

"shoeid": "$shoe.shoeid",

"withdog": "$withdog"

},

"totaldistance": {"$sum": "$distance"}

}

}

]

# Request payload for distance aggregation

distance_payload = {

"collection": "activities",

"database": "shoemiletracker",

"dataSource": "ClusterShoe",

"pipeline": distance_pipeline

}

# Make the request for distance aggregation

distance_response = requests.post(api_url, headers=headers, data=json.dumps(distance_payload))

# Process the response for distance aggregation

distance_response_data = distance_response.json()

# Check if the response contains data

if 'documents' in distance_response_data:

# Convert the results to a DataFrame

distance_df = pd.DataFrame(distance_response_data['documents'])

print("Distance Aggregation Results:")

print(distance_df)

else:

print("No data found or an error occurred in distance aggregation:", distance_response_data)

Have to see it to believe it.



Reflecting on the months of training with Laika and the marathon preparation, I realized the profound impact of integrating my passion for running with advanced database management. This experience not only strengthened our bond but also underscored the versatility of MongoDB in personal fitness tracking. Running with Laika, especially on longer distances, necessitated a thoughtful approach, where her well-being was paramount. The strategy of running together up to a certain distance before continuing solo proved effective, optimizing our exercise routine while catering to Laika’s needs.




Lessons learned

The lessons learned through this journey extend beyond the realms of fitness and technology. They speak to the value of adaptability, the importance of balancing personal goals with the well-being of our companions, and the power of data in enhancing our understanding of such endeavors.

I hope this recount of our experience offers valuable insights into the integration of fitness, pet companionship, and technology.



Partner With Bliss Wave IT
View Services

More Projects by Bliss Wave IT