Skip to content

YourOpenDAta/ml_bike_barcelona

Repository files navigation

YODA - ML bike Barcelona

Initial tasks

  • Copy the template.env file into .env and configure it.
  • Create ckan_yoda network
docker network create ckan_yoda

Training

  • Clone this project

  • If the model already exists (prediction-job/model) just build de project packages

docker compose -f docker-compose.build.packages.yml up -d --build
  • If the model does not exist: Build the packages and train the model
docker compose -f docker-compose.train.yml up -d --build

Testing (Development)

  • Run the whole scenario in dev
docker compose -f docker-compose.dev.yml up -d
  • Initialize the nifi recollection (Nifi will recollect data every 30 minutes and will store only the last 24 hours of historical data):

    • Enter in the nifi interface: https://localhost:9090/nifi

    • Log in with the following credentials:

      • username: root
      • password: pass1234567890
    • Upload the template stored in ./nifi/Barcelona_template.xml

    • Run every component deployed by the template

  • Create the prediction entities and the subscriptions:

    • Enter in the orion container

    • Create the predictionEntities and the subscriptions like in the entities folder

Test the solution

  1. Validate that the subscription and entities exist (inside the orion container):
curl --location --request GET 'http://localhost:1026/ngsi-ld/v1/subscriptions/'
curl --location --request GET 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:ReqBarcelonaBikePrediction1'
curl --location --request GET 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:ResBarcelonaBikePrediction1'
  1. Update the ReqBarcelonaBikePrediction1
curl --location --request PATCH 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:ReqBarcelonaBikePrediction1/attrs' \
--header 'Content-Type: application/json' \
--data-raw '{
   "idStation": {
      "type":"Property",
      "value": [VALUE from 1 to 505]
   },
   "weekday":{
      "type":"Property",
      "value": [VALUE from 0 to 6]
   },
   "hour":{
      "type":"Property",
      "value": [VALUE from 0 to 23]
   },
   "predictionId":{
      "type":"Property",
      "value":"p-1662768034900"
   },
   "socketId":{
      "type":"Property",
      "value":"Fn0kKHEF-dOcr311AAAF"
   }
}'
  1. See if the ResBarcelonaBikePrediction1 changes
curl --location --request GET 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:ResBarcelonaBikePrediction1'

Being:

  • idStation: station id
  • month: [1, 2, 3, ..., 12]
  • weekday: [1, ..., 7] (1 ->Sunday 7->Saturday)
  • time: : [0, ... , 23]
  • predictionId: String to identify the prediction in the consuming application
  • socketId: String to identify the socket with the client in the consuming application

Response:

{
   "@context":"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld",
   "id":"urn:ngsi-ld:BarcelonaBikePrediction1",
   "type":"ResSantanderBikePrediction",
   "socketId":{
      "type":"Property",
      "value":"Fn0kKHEF-dOcr311AAAF"
   },
   "predictionId":{
      "type":"Property",
      "value":"p-1662768034900"
   },
   "predictionValue":{
      "type":"Property",
      "value": [PREDICTED VALUE]
   },
   "idStation":{
      "type":"Property",
      "value": [VALUE set at the request]
   },
   "weekday":{
      "type":"Property",
      "value": [VALUE set at the request]
   },
   "hour":{
      "type":"Property",
      "value": [VALUE set at the request]
   }

Production (YODA)

  • Run the whole scenario in prod within YODA (only spark). You need to create the predictionEntities and the subscriptions like in the entities folder. They are required the creation of entities and the subscription of spark. In the consuming application there are two possibilities:
    • The application receives a notification when the prediction is made and receives the urn:ngsi-ld:ResSantanderBikePrediction1
    • The application asks periodically to orion (urn:ngsi-ld:ResSantanderBikePrediction1) and see if the prediction was made
docker compose up -d
  • Example of petition made to ask for a prediction:
curl --location --request PATCH 'http://138.4.22.130/ngsi-ld/v1/entities/urn:ngsi-ld:ReqBarcelonaBikePrediction1/attrs' \
--header 'Content-Type: application/json' \
--data-raw '{...}'

Testing everything worked

  1. Validate that the subscription and entities exist:
curl --location --request GET 'http://138.4.22.130/ngsi-ld/v1/subscriptions/'
curl --location --request GET 'http://138.4.22.130/ngsi-ld/v1/entities/urn:ngsi-ld:ReqBarcelonaBikePrediction1'
curl --location --request GET 'http://138.4.22.130/ngsi-ld/v1/entities/urn:ngsi-ld:ResBarcelonaBikePrediction1'
  1. Update the ReqBarcelonaBikePrediction1
curl --location --request PATCH 'http://138.4.22.130/ngsi-ld/v1/entities/urn:ngsi-ld:ReqBarcelonaBikePrediction1/attrs' \
--header 'Content-Type: application/json' \
--data-raw '{...}'
  1. See if the ResBarcelonaBikePrediction1 changes
curl --location --request GET 'http://138.4.22.130/ngsi-ld/v1/entities/urn:ngsi-ld:ResBarcelonaBikePrediction1'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published