▪️Activity Trackers

The Activity Tracker serves as a crucial element of the GrabWay platform, meticulously designed to accurately monitor and analyze user travel distances. This functionality directly impacts users' earnings, providing a transparent and engaging experience within the ecosystem.

1. Manual Control System

To promote user engagement and accountability, the Activity Tracker features a manual start and stop function for tracking sessions. Users can initiate and terminate their tracking as needed, ensuring precise distance recording.

  • Working Logic:

    Users activate tracking at the beginning of their journey and stop it upon arrival. This allows them to have complete control over what is counted toward their total distance.

class ActivityTracker:
    def __init__(self):
        self.total_distance = 0
        self.is_tracking = False

    def start_tracking(self):
        self.is_tracking = True
        print("Tracking started.")

    def stop_tracking(self):
        self.is_tracking = False
        print("Tracking stopped.")

    def add_distance(self, distance):
        if self.is_tracking:
            self.total_distance += distance
            print(f"Distance added: {distance} km")
        else:
            print("Tracking is not active.")

    def get_total_distance(self):
        return self.total_distance

2. Motion Sensors and GPS Integration

The Activity Tracker leverages advanced motion sensors alongside GPS technology to enable real-time monitoring of user movements. This integration ensures that distance data is collected with high precision, significantly reducing discrepancies in measurements.

  • Working Logic:

    GPS calculates the user's position over time, while motion sensors confirm movement. The combination ensures that distance tracking is accurate and reflective of the actual journey.

from math import radians, cos, sin, asin, sqrt

def haversine(lon1, lat1, lon2, lat2):
    # Convert decimal degrees to radians
    lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
    # Haversine formula
    dlon = lon2 - lon1 
    dlat = lat2 - lat1 
    a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
    c = 2 * asin(sqrt(a)) 
    return 6371 * c  # Returns distance in kilometers

3. Visual Distance Tracking

The system incorporates a dynamic visual interface that displays the total distance traveled during each session. This visual feedback empowers users to evaluate their travel patterns, enabling them to identify optimal routes for maximizing their earnings.

  • Working Logic:

    The user interface updates in real time, showing both the total distance covered and the estimated earnings based on that distance, enhancing user engagement and providing clear performance metrics.

4. Data Analytics and Reporting

The Activity Tracker features robust data analytics capabilities, which generate comprehensive reports analyzing user behavior and travel efficiency. Users receive insights into:

  • Average distance per trip

  • Peak earning times

  • Recommendations for optimizing travel routes based on historical data

  • Working Logic:

    By aggregating distance data over multiple sessions, the system can provide users with analytics that inform their travel decisions, encouraging smarter routes and better earnings.

def analyze_trips(trip_distances):
    average_distance = sum(trip_distances) / len(trip_distances) if trip_distances else 0
    peak_earning_time = max(trip_distances) if trip_distances else 0
    return average_distance, peak_earning_time

5. API Connectivity

The Activity Tracker is designed with API connectivity, facilitating seamless integration with other components of the GrabWay ecosystem. This architecture enhances user experience by allowing data sharing across functionalities, ensuring a cohesive platform.

  • Working Logic:

    APIs allow for real-time updates across the platform, meaning that distance tracked can be immediately reflected in user profiles, earnings calculations, and reward systems.

import requests

def update_distance_in_api(user_id, distance):
    url = "https://api.grabway.com/update_distance"
    payload = {"user_id": user_id, "distance": distance}
    response = requests.post(url, json=payload)
    return response.status_code, response.json()

Last updated