Skip to content
Daniel edited this page Oct 25, 2015 · 49 revisions

Vehicles

Read Vehicle

In order to read a vehicle, you use read, specifying the vehicle model and its id. The reponse stores the requested vehicle in the value field, here is how to read the vehicle from a socket

var vehicle;

socket.onmessage = function(msg){
    var resp = msg.data;
    vehicle = resp.model.value;
};

var msg = {
  "read":{
    "model":"Vehicle",
    "id":4
  }
};
socket.send(Json.stringify(msg));

Request

For the request, you specify the Vehicle type and provide the id of the desired Vehicle

{
   "read": {
     "model":"Vehicle",
     "id":4,
    }
}

Response

The response has a model object that contains the vehicle as the value

{
    "model":{
      "model":"Vehicle",
      "value":{
        "id":4,
        "longitude":2,
        "latitude":7,
        "capacity":6
      }
    }
}

Create Vehicle

Request

A new vehicle requires a latitude, longitude, capacity, and clusterId

{
  "create":{
    "model":"Vehicle",
    "value":{
      "latitude":0.123,
      "longitude":0.456,
      "capacity":4,
      "clusterId":3
    }
  }
}

Response

The response is an object with created which has the vehicle as the value

{
   "created":{
     "model":"Vehicle",
     "value":{
        "id":20,
        "latitude":0.123,
        "longitude":0.456,
        "capacitor":4
     }
   }
}

Update Vehicle

Request

An update is similar to a create except you need so specify the id of the row that you are updating, for an update, no fields are required for a vehicle.

{
   "update":{
     "model":"Vehicle",
     "id":6,
     "value":{
       "latitude":1.2,
       "longitude":66
     }
   }
}

Response

{
   "updated":{
     "model":"Vehicle",
     "value":{
       "id":6,
       "latitude":0.123,
       "longitude":0.456,
       "capacitor":4
     }
  }
}

Delete Vehicle

Request

{
   "delete":{
     "model":"Vehicle",
     "id":4
   }
}

Response

{
   "deleted":{
     "model":"Vehicle",
     "value":{
       "id":4,
       "latitude":40,
       "longitude":30,
       "capacity": 10
     }
   }
}

Commodities

Read Commodities

Reading Commodities is similar to reading vehicles, you just use Commodity instead of Vehicle for the type field

Request

{
   "read": {
     "model":"Commodity",
     "id":4
    }
}

Response

The response has a model object that contains the commodity

{
    "model":{
      "model":"Commodity",
      "value":{
        "id":4,
        "longitude":2,
        "latitude":7,
        "capacity":6
      }
    }
}

Create Commodity

Request

A new commodity requires a startLatitude, startLongitude, endLatitude, endLongitude, a param, and a clusterId

{
  "create":{
    "model":"Commodity",
    "value":{
      "startLatitude":0.123,
      "startLongitude":0.456,
      "endLatitude":0.789,
      "endLongitude":0.101
      "param":4,
      "clusterId":5
    }
  }
}

Response

The response is an object with created which has the Commodity

{
   "created":{
     "model":"Commodity",
     "value":{
       "id":20,
       "startLatitude":0.123,
       "startLongitude":0.456,
       "endLatitude":0.789,
       "endLongitude":0.101
       "param":4
     }
   }
}

Update Commodity

Request

An update is similar to a create except you need so specify the id of the row that you are updating, for an update, no fields are required for a commodity.

{
   "update":{
     "model":"Commodity",
     "id":6,
     "value":{
       "endLatitude":1.2,
       "endLongitude":66
     }
   }
}

Response

{
   "updated":{
     "model":"Vehicle",
     "value":{
      "id":6
      "startLatitude":0.123,
      "startLongitude":0.456,
       "endLatitude":1.2,
       "endLongitude":66
      "param":4
     }
  }
}

Deleting a Commodity

Like a vehicle, you delete the commodity by specifying its id

Request

{
   "delete":{
     "model":"Commodity",
     "id":4
   }
}

Response

{
   "deleted":{
     "model":"Commodity",
     "value":{
       "id":6,
       "startLatitude":0.123,
       "startLongitude":0.456,
       "endLatitude":1.2,
       "endLongitude":66,
       "param":4
     }
   }
}

Clusters

Clusters can read, created and deleted

Reading a cluster

Request

{
   "read":{
     "model":"Cluster",
     "id":8
   }
}

Response

{
   "model":{
      "model":"Cluster",
      "value":{
        "id": 10,
        "parent":8,
        "vehicles":[
            { "id": 1, "latitude":19, "longitude":77, "capacity":3 },
            { "id": 2, "latitude":10, "longitude":22, "capacity":4 },
            { "id": 3, "latitude":21, "longitude":31, "capacity":2 }
        ],
        "commodities":[
            { "id":6,                "param":4,
              "startLatitude":0.123, "startLongitude":0.456,
              "endLatitude":1.2,     "endLongitude":66 },
            { "id":8,              "param":3,
              "startLatitude":923, "startLongitude":5.756,
              "endLatitude":77,    "endLongitude":606 }
        ]
     }
  }
}

Creating a cluster

clusters can be created from an empty object

Request

{
  "create": {
    "model":"Cluster",
    "value":{ }
  }
}

Response

{
   "created": {
     "model":"Cluster"
     "value":{
       "id":10,
       "commodities":[],
       "vehicles":[]
     }
  }
}

deleting a cluster

Deleting a cluster is similar to deleting a commodity or a vehicle

Request

{
  "delete":{
    "model":"Cluster",
    "id":10
  }
}

Response

{
   "deleted":{
      "model":"Cluster",
      "value":{
        "id": 10,
        "parent":8,
        "vehicles":[
            { "id": 1, "latitude":19, "longitude":77, "capacity":3 },
            { "id": 2, "latitude":10, "longitude":22, "capacity":4 },
            { "id": 3, "latitude":21, "longitude":31, "capacity":2 }
        ],
        "commodities":[
            { "id":6,                "param":4,
              "startLatitude":0.123, "startLongitude":0.456,
              "endLatitude":1.2,     "endLongitude":66 },
            { "id":8,              "param":3,
              "startLatitude":923, "startLongitude":5.756,
              "endLatitude":77,    "endLongitude":606 }
        ]
     }
  }
}

Routes

The user can obtain a route for any vehicle or commodity

Get a vehicle's route

The route request requires the vehicle id

Request

{
  "route":{
    "model":"Vehicle"
    "id":78
  }
}

Response

The route contains an array of actions which each have a position and a commodity id

{
  "routed":{
    "model":"Vehicle"
    "value":{
      "Vehicle":{"id":78, "latitude":100, "longitude":-150, "capacity":3},
      "actions":[
        { "action":"start","latitude":100,"longitude":-150 },
        { "action":"pickup","latitude":20,"longitude":5,
          "commodity":{ "id":20, "startLatitude":20, "startLongitude":5, "endLatitude":5, "endLongitude":12, "param":3},
        { "action":"pickup","latitude":12,"longitude":20,"commodity":{ "id":21, \\ other commodity fields } },
        { "action":"dropoff","latitude":2,"longitude":30,"commodityId":{ "id":21, \\ other commodity fields }  },
        { "action":"dropoff","latitude":5,"longitude":12,"commodityId":{ "id":20, \\ other commodity fields } }
      ]
    }
  }
}
Clone this wiki locally