WRSC / tracking

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

Error generating coordinates JSON view #31

Closed takluyver closed 5 years ago

takluyver commented 5 years ago

Accessing e.g. http://167.99.205.49/missions/2/latest_coordinates?limit=10

The error in the logs is:

ArgumentError (invalid strptime format - `%Y%m%d%H%M%S%z'):
  app/models/coordinate.rb:24:in `datetime_as_time'
  app/controllers/coordinates_controller.rb:88:in `block (2 levels) in latest_by_mission'
  app/controllers/coordinates_controller.rb:86:in `map'
  app/controllers/coordinates_controller.rb:86:in `block in latest_by_mission'
  app/controllers/coordinates_controller.rb:85:in `latest_by_mission'

Relevant line seems to be here: https://github.com/WRSC/tracking/blob/2458d2a75c126f4f1fc646726fb8f9faa2a5c8d8/MYR_rails/app/models/coordinate.rb#L24

I'm not sure what's invalid about that format.

takluyver commented 5 years ago

My suspicion is that we're storing the datetimes as floats, so "#{datetime}UTC" is expanded to something like "20180501104904.0UTC" (note the decimal point).

In the coordinate table view, the code to parse the datetimes looks like this:

Time.strptime(((coordinate.datetime.to_f).round).to_s+"UTC", "%Y%m%d%H%M%S%z")

I guess that .round will convert the float to an integer. The simple fix would be to copy this for the other datetime parsing code.

Longer term we should presumably store datetimes as datetimes.

saerdnaer commented 5 years ago

fixed on master and deployed, right now.

takluyver commented 5 years ago

:+1: thanks!