NameL3ss

alert-configuration-query-cd

Nov 2nd, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. response
  2. creacion de modelo events_configuration los cuales tienen un tiempo de frecuencia, dependiendo si es necesario:
  3. por ejemplo en tipos de eventos (speed, stopping, overheating)
  4. {
  5. "data":[
  6. {
  7. "id":"19",
  8. "type":"events_configuration",
  9. "attributes":{
  10. "id":19,
  11. "event_type":"speeding",
  12. "frequency_time":5,
  13. "event_attribute_value":120
  14. }
  15. },
  16. {
  17. "id":"20",
  18. "type":"events_configuration",
  19. "attributes":{
  20. "id":20,
  21. "event_type":"overheating",
  22. "frequency_time":5,
  23. "event_attribute_value":100
  24. }
  25. },
  26. {
  27. "id":"21",
  28. "type":"events_configuration",
  29. "attributes":{
  30. "id":21,
  31. "event_type":"stop",
  32. "frequency_time":5,
  33. "event_attribute_value":1
  34. }
  35. },
  36. {
  37. "id":"22",
  38. "type":"events_configuration",
  39. "attributes":{
  40. "id":22,
  41. "event_type":"inside_origin_warehouse",
  42. "frequency_time":5
  43. }
  44. }
  45. ],
  46. "meta":{
  47. "total_elements":4,
  48. "total_pages":1,
  49. "current_page":1,
  50. "objects_per_page":25
  51. },
  52. "links":{
  53. "first":"/api/v1/settings/configurations?page=1&per_page=25.0",
  54. "last":"/api/v1/settings/configurations?page=1&per_page=25.0",
  55. "self":"/api/v1/settings/configurations?page=1&per_page=25.0"
  56. }
  57. }
  58.  
  59. Poco factible por lado de backend realizar proceso de alertas, se rompe el algoritmo debido a que cada evento tiene un inicio y fin (abierto-cerrado) , si una configuracion por ejemplo tiene un margen de 5 minutos se tendria que estar consultando cada vez que se realiza el proceso de algoritmo (debido a los waypoints entrantes) si es que estos estan dentro del tiempo de frecuencia
  60.  
  61. 1-Solucion crear un modelo Alerta y Configuracion de Eventos por separado
  62. Complicaciones: Se debe consultar en cada proceso del algoritmo por los eventos abiertos y calcular si sus alertas corresponden al rango de tiempo predefinido en el modelo de alerta
  63. Un evento puede tener una alerta (sujeta a estar activa o inactiva, actualizandose) o varias alertas.
  64.  
  65. 2-Solución crear modelo de configuración planteado al inicio y entregar todos los eventos luego que el front se encarge de comparar el tiempo de frecuencia definido para los distintos tipos de eventos con los objetos de eventos y mostrarlos de modo de notificaciones.
  66.  
  67.  
  68. trucks_cd = current_account.expeditions.joins([trips: :destination_warehouse], :truck, :driver).where('warehouses.address ilike (?)', "%New Numbersfort%").where(trips: { started_at: Time.now.beginning_of_day..Time.now.end_of_day, status: "in_route", active: true}).map(&:truck_id)
  69.  
  70. waypoints_truck = Waypoint.where(waypointable_type: "Truck", waypointable_id: trucks_cd, sent_at: Time.now.beginning_of_day..Time.now.end_of_day).select('DISTINCT ON ("waypointable_id") *').order(:waypointable_id, sent_at: :desc, id: :desc)
  71.  
  72.  
  73. current_account.trucks.joins(:waypoints).where(id: trucks_cd, waypoints: { id: waypoints_truck.ids }).actived
  74.  
  75.  
  76.  
  77. truck_waypoints = Waypoint.where(waypointable_type: "Truck", waypointable_id: trucks_cd, sent_at: Time.now.beginning_of_day..Time.now.end_of_day).group(:waypointable_id).maximum(:sent_at)
  78.  
Advertisement
Add Comment
Please, Sign In to add comment