Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. let errorHistorgram = await Errors
  2. .raw(`SELECT period AS daily, coalesce(count,0) AS count
  3. FROM generate_series(date '${startTS}', date '${today}', interval '1d') AS period
  4. LEFT JOIN (
  5. SELECT time_bucket('1d',timestamp)::date AS date, count(timestamp)
  6. FROM my_error_table
  7. WHERE severity = 'HIGH'
  8. AND timestamp >= '${startTS}' AND timestamp < '${today}'
  9. AND device_id = ${deviceId}
  10. GROUP BY date
  11. ) t ON t.date = period;`)
  12. .debug();
  13.  
  14. let errorHistorgram = await Errors
  15. .query()
  16. .select(raw(`time_bucket('1 day', timestamp) AS daily, count(timestamp)`))
  17. .where('device_id', deviceId)
  18. .andWhere('timestamp', '>', startTS)
  19. .andWhere('severity', 'HIGH')
  20. .leftJoin(`generate_series(date ${startTS}, date ${today}, interval 1d) AS series`, 'series.date', 'my_error_table.timestamp')
  21. .debug();
  22.  
  23. select time_bucket('1 day', timestamp) AS daily, count(timestamp)
  24. from my_error_table
  25. left join "generate_series(date 2018-11-08T15:35:33"."050Z, date 2018-11-15T15:35:33"."133Z, interval 1d)" as "series"
  26. on "series"."date" = my_error_table."timestamp"
  27. where "device_id" = ? and "timestamp" > ? and "severity" = ?'
  28.  
  29. let errorHistorgram = await Errors
  30. .query()
  31. .select(raw(`time_bucket('1 day', timestamp) AS daily, count(timestamp)`))
  32. .where('device_id', deviceId)
  33. .andWhere('timestamp', '>', startTS)
  34. .andWhere('severity', 'HIGH')
  35. .groupBy('timestamp')
  36. .rightJoin(raw(`generate_series(date '${startTS}', date '${today}', interval '1d') AS series`), 'series.date', 'my_error_table.timestamp')
  37. .debug();
  38.  
  39. select time_bucket('1 day', timestamp) AS daily, count(timestamp)
  40. from my_errors_table
  41. right join generate_series(date '2018-11-08', date '2018-11-15', interval '1d') AS series
  42. on series = my_errors_table.timestamp
  43. where device_id = ? and timestamp > ? and severity = ?
  44. group by timestamp
  45.  
  46. import { raw } from 'objection';
  47.  
  48. const errors = await Errors
  49. .query()
  50. .select(
  51. raw("time_bucket_gapfill(?, timestamp, ?, ?) AS bucket", [bucketWidth, startTS, endTS]),
  52. raw('COALESCE(count(timestamp), 0) AS count'),
  53. ).where('device_id', deviceId)
  54. .andWhere('timestamp', '>=', startTS)
  55. .andWhere('timestamp', '<=', endTS)
  56. .groupBy('bucket')
  57. .orderBy('bucket');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement