Desarrolladores

Ya sea que esté utilizando Trafficweb como centro de datos en su aplicación ITS o simplemente desee incluir una descripción general de la situación del tráfico en el sitio web de su ciudad, puede obtener los datos de la API de Trafficweb. Con soporte para datos en tiempo real vehículo por vehículo y métricas de medición agregadas, debería encontrar lo que necesita aquí.


Cartas credenciales

Para acceder a la API de Trafficweb, primero necesita una cuenta. Las credenciales de su cuenta consisten en un nombre de usuario y una contraseña y le dicen a Trafficweb de qué grupos es miembro y, por lo tanto, a qué datos tiene acceso. Si aún no tiene una cuenta, puede obtener una completando el formulario en la página de inicio.


Inicio rápido

La API Trafficweb es un servicio RESTful al que se accede a través de HTTPS en trafficweb.io/api. Los objetos se devuelven en formato JSON. Aquí hay un código de ejemplo para que pueda empezar a trabajar.

require "net/https"
require "uri"

# set path and SSL mode
uri = URI.parse("https://trafficweb.io/api/locations")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

# create request with basic auth
request = Net::HTTP::Get.new(uri.request_uri)
request.basic_auth('USERNAME', 'PASSWORD')

# make request and print results
response = http.request(request)
puts response.body
from http.client import HTTPSConnection
from base64 import b64encode

# set up the HTTPS connection
c = HTTPSConnection("trafficweb.io")

# base64 encode credentials as it's stored as byte string by Python
credentials = b64encode(b"USERNAME:PASSWORD").decode("ascii")
headers = {'Authorization': 'Basic %s' % credentials}

# make the request and read response
c.request('GET', '/api/locations', headers=headers)
res = c.getresponse()
print(res.read())
curl -u USERNAME:PASSWORD https://trafficweb.io/api/locations

API referencia

Locations


A location represents a point on a map. It contains a name for the point, possible identifiers for the road and coordinates. Meta information such as speed limit and number of lanes on the road can also be included.

Get locations


GET /locations
Parameters
Name Type Required Description
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
Example response
Status: 200 OK
[
  {
    "id":123,
    "name":"Test location 1",
    "road_identifier":"Test road 66",
    "number_of_lanes":2,
    "longitude":"13.124721",
    "latitude":"55.484982",
    "group_id":1,
    "speed_limit":70
  },
  {
    "id":124,
    "name":"Test location 2",
    "road_identifier":"Test road 66",
    "number_of_lanes":2,
    "longitude":"17.934496",
    "latitude":"59.438881",
    "group_id":1,
    "speed_limit":70
  }
]

Get specific location


GET /locations/{id}
Example response
Status: 200 OK

  {
    "id":123,
    "name":"Test location 1",
    "road_identifier":"Test road 66",
    "number_of_lanes":2,
    "longitude":"13.124721",
    "latitude":"55.484982",
    "group_id":1,
    "speed_limit":70
  }

Installations


An installation represents the physical location of a detector at a given time by connecting detectors with locations and a time interval. The interval can be open, meaning the detector is currently installed at the location. The installation also contains information about the configuration of the detector at the time, such as classification scheme used.

Get installations


GET /installations
Parameters
Name Type Required Description
location_idintegernoReturns installations at given location
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
Example response
Status: 200 OK
[
  {
    "id":321,
    "detector_id":1,
    "location_id":123,
    "installed":"2015-05-04T12:00:00.000+02:00",
    "removed":"2015-05-12T13:00:00.000+02:00",
    "lane_number":1,
    "bearing":"north",
    "classification_scheme":"Euro 6",
    "group_id":1
  },
  {
    "id":322,
    "detector_id":2,
    "location_id":124,
    "installed":"2015-05-19T12:05:13.000+02:00",
    "removed":"2015-05-27T11:19:01.000+02:00",
    "lane_number":2,
    "bearing":"southwest",
    "classification_scheme":"NorSIKT 4",
    "group_id":1
  }
]

Get specific installation


GET /installation/{id}
Example response
Status: 200 OK

  {
    "id":321,
    "detector_id":1,
    "location_id":123,
    "installed":"2015-05-04T12:00:00.000+02:00",
    "removed":"2015-05-12T13:00:00.000+02:00",
    "lane_number":1,
    "bearing":"north",
    "classification_scheme":"Euro 6",
    "group_id":1
  }

Measurement periods


A measurement period contains information on when measurements have been conducted for a given installation. Note that some detectors stream data continously rather than in predetermined intervals and thus lack measurement periods.

Get measurement periods


GET /measurement_periods
Parameters
Name Type Required Description
installation_idintegernoReturns mesaurement periods for given installation
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
Example response
Status: 200 OK
[
  {
    "id":432,
    "start":"2015-05-05T12:00:00.000+02:00",
    "stop":"2015-05-07T12:00:00.000+02:00",
    "status":"completed",
    "group_id":1,
    "installation_id":321
  },
  {
    "id":433,
    "start":"2015-05-08T12:00:00.000+02:00",
    "stop":"2015-05-10T12:00:00.000+02:00",
    "status":"completed",
    "group_id":1,
    "installation_id":321
  }
]

Get specific measurement period


GET /measurement_period/{id}
Example response
Status: 200 OK

   {
    "id":432,
    "start":"2015-05-05T12:00:00.000+02:00",
    "stop":"2015-05-07T12:00:00.000+02:00",
    "status":"completed",
    "group_id":1,
    "installation_id":321
  }

Detections


A detection represents a detected vehicle, cyclist or pedestrian by a detector. It contains informaion on the type, speed and bearing of the vehicle.

Get detections


GET /detections
Parameters
Name Type Required Description
installation_idintegeryesSpecifies installation for which detections is desired
fromstringyesDate and time representing start of desired interval on ISO8601 format
tostringyesDate and time representing end of desired interval on ISO8601 format
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
Example response
Status: 200 OK
[
  {
    "id":123321,
    "detector_id":2,
    "detection_time":"2016-08-22T22:00:00.000+02:00",
    "flagged":false,
    "velocity":"72.12",
    "installation_id":123,
    "length":5.2,
    "count":1,
    "lane_number":1,
    "bearing":"south",
    "vehicle_type":"Car"
  },
  {
    "id":123321,
    "detector_id":2,
    "detection_time":"2016-08-22T22:00:00.000+02:00",
    "flagged":false,
    "velocity":"82.84",
    "installation_id":123,
    "length":12.2,
    "count":1,
    "lane_number":1,
    "bearing":"south",
    "vehicle_type":"Truck"
  }
]

Detectors


A detector contains information about a physical measurement equipment such as technology, brand and model.

Get detectors


GET /detectors
Parameters
Name Type Required Description
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
Example response
Status: 200 OK
[
  {
    "id":1,
    "short_name":"SS125_U100006476",
    "group_id":1,
    "model":"SS125",
    "technology":"Radar",
    "manufacturer":"Wavetronix"
  },
  {
    "id":2,
    "short_name":"METOR_LOOP_1415",
    "group_id":1,
    "model":"2000",
    "technology":"Inductive Loop",
    "manufacturer":"TDP"
  }
]

Get specific detector


GET /detectors/{id}
Example response
Status: 200 OK

  {
    "id":1,
    "short_name":"SS125_U100006476",
    "group_id":1,
    "model":"SS125",
    "technology":"Radar",
    "manufacturer":"Wavetronix"
  }

Data losses


A data loss contains information on where data is corrupt or missing from a measurement. By specifying an interval as well as type of data loss, currupt data can be excluded from calculations.

Get data losses


GET /data_losses
Parameters
Name Type Required Description
installation_idintegeryesSpecifies installation for which data losses to be retrieved
fromstringyesDate and time representing start of desired interval on ISO8601 format
tostringyesDate and time representing end of desired interval on ISO8601 format
limitintegernoLimits the number of objects returned (max and default is 1000)
offsetintegernoSpecifies the number of objects to skip
Example response
Status: 200 OK
[
  {
    "id":1,
    "detector_id":1,
    "start":"2012-02-04T08:00:00.000+02:00",
    "stop":"2012-02-04T20:00:00.000+02:00",
    "data_type":"detections",
    "comment":"Power outage"
  },
  {
    "id":2,
    "detector_id":2,
    "start":"2013-02-05T21:00:00.000+02:00",
    "stop":"2013-02-06T09:00:00.000+02:00",
    "data_type":"velocity",
    "comment":"Tube broken, count ok"
  }
]

Get specific data loss


GET /data_losses/{id}
Example response
Status: 200 OK

  {
    "id":1,
    "detector_id":1,
    "start":"2012-02-04T08:00:00.000+02:00",
    "stop":"2012-02-04T20:00:00.000+02:00",
    "data_type":"detections",
    "comment":"Power outage"
  }

Groups


All access to data is controlled by the users memberships in groups. The group data structure contains id and the name of a group.

Get groups


GET /groups
Example response
Status: 200 OK
[
  {
    "id":1,
    "name":"Test group one"
  },
  {
    "id":2,
    "name":"Test group two"
  }
]

Get specific group


GET /groups/{id}
Example response
Status: 200 OK

  {
    "id":1,
    "name":"Test group one"
  }
 

Legacy API (not recommended for new designs)


Location metrics


Location metrics contains aggregated traffic data for a location, such as average daily traffic, average speeds and percentage heavy traffic.

Get location metrics


GET /location_metrics
Parameters
Name Type Required Description
locations_per_pageintegernoSpecifies the maximum number of objects to be returned
pageintegernoSpecifies the offset in locations_per_page counts
Example response
Status: 200 OK
[
  {
    "location": {
      "id": 123,
      "name": "Test location 1",
      "longitude":"13.124721",
      "latitude":"55.484982",
      "speed_limit": 70,
      "diff_speed_limit": null,
      "diff_speed_limit_descr": null,
      "owner": "Test city 1"
    },
    "measurement": {
      "start": "2021-03-24T05:00:00.000Z",
      "stop": "2021-03-24T16:00:00.000Z",
      "daily_traffic": 1203,
      "workday_daily_traffic": 1345,
      "weekend_daily_traffic": 1002,
      "average_speed": 54.8,
      "speed_percentile_50": 54.0,
      "speed_percentile_85": 63.0,
      "type": "motor_vehicles",
      "sensors": ["Magnetometer (Sensebit FLEX)"],
      "link": "https://trafficweb.io/..."
    }
  }, 
  {
    "location": {
      "id": 124,
      "name": "Test location 2",
      "longitude":"17.934496",
      "latitude":"59.438881",
      "speed_limit": 70,
      "diff_speed_limit": null,
      "diff_speed_limit_descr": null,
      "owner": "Test city 1"
    },
    "measurement": {
      "start": "2021-03-23T23:00:00.000Z",
      "stop": "2021-03-24T23:00:00.000Z",
      "daily_traffic": 1589,
      "workday_daily_traffic": 1589,
      "weekend_daily_traffic": null,
      "average_speed": 49.1,
      "speed_percentile_50": 47.0,
      "speed_percentile_85": 59.0,
      "type": "motor_vehicles",
      "sensors": ["Magnetometer (Sensebit WD-300)"],
      "link": "https://trafficweb.io/..."
    }
  }
]