popufare-avls 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2020 Clementine Computing LLC.
  4. #
  5. # This file is part of PopuFare.
  6. #
  7. # PopuFare is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # PopuFare is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. # A simple script ot query the AVLS data and format it out nicely.
  21. # This is a rough draft and should be considered experimental
  22. #
  23. # NOTE: this assumes the existence of a 'db-config' file that holds database
  24. # credential information. For example:
  25. #
  26. # $ cat db-config
  27. # [client]
  28. # database=popufare
  29. # user=u
  30. # password=p
  31. #
  32. # usage:
  33. #
  34. # ./popufave-avls '2020-11-05 00:00:00'
  35. #
  36. #
  37. querytd="$1"
  38. if [[ "$1" == "" ]] ; then
  39. querytd=`date --date '-10 min' +'%Y-%m-%d %H:%M:%S'`
  40. fi
  41. cat <<EOF | mysql --defaults-file=db-config | tr ',' '_' | tr '\t' ','
  42. set @ts = "$querytd";
  43. select
  44. a.equip_num as vehicle_id,
  45. floor(a.latitude/100.0) + ((a.latitude - (100.0*floor(a.latitude/100.0)))/60.0) as vehicle_lat,
  46. floor(a.longitude/100.0) + ((a.longitude - (100.0*floor(a.longitude/100.0)))/60.0) as vehicle_lon,
  47. -- a.latitude as vehicle_lat,
  48. -- a.longitude as vehicle_lon,
  49. a.heading as vehicle_bearing,
  50. a.chirp_time as vehicle_timestamp,
  51. a.velocity as vehicle_velocity,
  52. a.route as route_id,
  53. concat(convert(a.route, char), '_', convert(a.trip, char)) trip_id,
  54. floor(s.latitude/100.0) + ((s.latitude - (100.0*floor(s.latitude/100.0)))/60.0) as stop_lat,
  55. floor(s.longitude/100.0) + ((s.longitude - (100.0*floor(s.longitude/100.0)))/60.0) as stop_lon,
  56. -- s.latitude as stop_lat,
  57. -- s.longitude as stop_lon,
  58. s.name as stop_name
  59. from
  60. avls_data a,
  61. stops s,
  62. paddles p
  63. where
  64. a.paddle = p.id
  65. and a.route = p.route
  66. and a.trip = p.trip
  67. and ( (a.stop = 0 and p.stop is null) or
  68. (a.stop = p.stop) )
  69. and p.stopid = s.id
  70. and a.chirp_time >= @ts
  71. order by chirp_time desc ;
  72. EOF