WRSC / tracking

WRSC boat tracking system with web dashboard
Other
13 stars 7 forks source link

Input format for coordinates endpoint #10

Closed kirs closed 6 years ago

kirs commented 6 years ago

I was reviewing CoordinatesController#create and it looks like to submit multiple coordinates, clients should do the following POST request:

{
  coordinate: {
    tracker_id: 1,
    latitude: "38.00_39.00_40.00",
    longitude: "20.00_21.00_22.00"
    speed: "1_2_3",
    date: "201801010101_201802010101_201801030101",
    course: "1_1_1"
  }
}

It feels a bit weird that multiple values are passed in the same field separated by underscore. Why underscore?

@takluyver does this look the actual format for you? Can you confirm what format the clients are submitting to the server? This would help me to write tests.

takluyver commented 6 years ago

That looks like it could be what's coming from the trackers during the run. You can see the Lua code that the trackers run here:

https://github.com/WRSC/tracking/blob/master/trackers/autorun_ref.lua

I guess there's no JSON library available - these are pretty simple devices - so the underscores are a way to avoid building JSON arrays out of primitive string manipulations. I don't think there's any reason it's underscore rather than some other character; it needs to be an ASCII character that can't occur in any of the values it's separating.

There are other formats for the data that teams can supply from their own tracking systems - they have a choice of CSV of a binary format. There are details in the rules from 2017.

kirs commented 6 years ago

Thanks!

There is no JSON required if we want to send an array of values by POST. An example:

{ longitude: [1,2,3] }.to_query
=> "longitude%5B%5D=1&longitude%5B%5D=2&longitude%5B%5D=3"

Or in decoded way:

longitude[]=1&longitude[]=2&longitude[]=3

(see HTTP POST spec).

I guess at this point it's easier to preserve existing behaviour. I'll a test for CoordinatesController to check the input format of coordinates.