---
# System prepended metadata

title: Hackathon

---

---
title: 'Hackathon'
disqus: hackmd
---

Hackaton
===


# Idées

## Préférences

- Classement des moyens de transport par preference
- ...

## Recommandations

Recommandation d'un itinéraire ou moyen de transport (ou "contre-indication") en fonction de la météo et de la qualité de l'air.

## Badges

En fonction des itinéraires et moyens de transport utilisés, un profil et établi et un badge est associé (et affiché).

## Calories

Afficher lors des itinéraires "physiques" (vélo ou à pieds) le nombre de calories potentiellement brulées.

# Endpoints (Back for Front)

### /UpdatePreferences

- Request

``` json
{
    "transport": [
        "bike": 0,
        "walk": 1,
        "subway": 2,
        "car": 3
    ]
}
```

### /GetMission

Returns the mission we got via MQTT with the different positions to go to.
``` json
{
    "mission": "Votre mission, si vous l'acceptez, consiste à passer par l'ensemble des points ci dessous.",
    "positions": [
        {
            "x": 0.0,
            "y": 0.0
        },
        ...
    ]
}
```

### /ListItineraries

ListItineraries returns the list of the itineraries (path, associated distance and time), ordered depending on the user's account preferences and the time of each itinerary.

``` json
{
    "itineraries": [
    {
        "steps": [
            {
                "vehicle_type": "walk",
                "time": 3.233
            },
            {
                "vehicle_type": "subway",
                "time": 10.97777
            },
            ...
        ],
        ...
    }
    ]
}
```
__Implementation__:
- Fetch shortest path for all 4 transport types
- Create the itinerary associated to each one, which is not trivial because multiple transportations might have to be used. To take the metro for example, the user might have to walk a bit beforehand.
We must therefore build the itineraries with the different steps (see structure above)
- Order the list of the created itineraries using:
    - `time` of the itinerary
    - `preferences` registered for the user
    In order to so, we can compute a score based on those values, i.e: $score = (rank + 1) * time$
    The lower the score, the highest it will be in the list of itineraries.
    
### /ChooseItinerary
Sends the chosen itinerary to the server to allow all the processing to take place
ex: 
```
POST {"id": 0}
```

__Implementation__:
Two solutions:
- Store the list of itineraries when we create it, and associate each itinerary to an ID. The request of `ChooseItinerary` contains the ID of the itinerary. Once we receive it, we fetch the itinerary associated to the given ID, and send the MQTT topic accordingly
- Have the request hold the itinerary, so that we don't have to store them and can process it directly, and publish the correct MQTT topic.

Either way, we need to save the choice (for the badges).
i.e: if shortest (time wise) path has been chosen, increment counter of `shortest_path_selection`, if longest (time wise) path has been chosen, increment counter of `longest_path_selection`, same with polution (most and least poluting itineraries chosen), and with preference accurate choices (if choices are accurate according to chosen preferences). __Open to suggestions?__

### /ListRecommendations
Returns the recommendations according to the weather and the air quality
``` json
{
    "recommendations": [
        {
            "type": "weather",
            "value": "It's raining, you should avoid walking and bike riding or you'll get soaked!"
        },
        {
            "type": "air_quality",
            "value": "The air is quite polluted, avoid using cars if you love your planet"
        }
    ]
}
```

__Implementation__:
Use the API to fetch the weather, build the object with a pre-defined text for each case (rainny, sunny, etc...)
Same with air quality - fetch it with appropriate method and build recommendation.

### /ListBadges
Returns all of the badges the user acquired

__Implementation__:
We need to set a minimum value for each counter, and if criterias are met (at least the minimum value of each counter) for each badge, add badge to list to return

### /Stop
Stops the character and recomputes the itineraries for all transportations from the point the user stopped at

__Implementation__:
- Stop the user by publishing the appropriate MQTT topic
- Same logic as `ListItineraries`

# Data structures

# TODO

### - API Client
Client for the Renault API to fetch the useful info
### - Server & Endpoints
Implement endpoints listed above
### - Front