in slomonitor/src/main/scala/com.gu.notifications.slos/SloMonitor.scala [88:143]
def generateQueryString(notificationId: String, sentTime: LocalDateTime): String = {
val partitionDate = if (sentTime.toLocalTime.isAfter(LocalTime.of(23, 57)))
s"(partition_date = '${sentTime.toLocalDate}' OR partition_date = '${sentTime.toLocalDate.plusDays(1)}')"
else
s"partition_date = '${sentTime.toLocalDate}'"
s"""
|SELECT
| platform,
| SUM(CASE
| WHEN DATE_DIFF('second', from_iso8601_timestamp('$sentTime'), received_timestamp) < 30 THEN 1
| ELSE 0
| END) AS less_than_30,
| SUM(CASE
| WHEN DATE_DIFF('second', from_iso8601_timestamp('$sentTime'), received_timestamp) < 60 THEN 1
| ELSE 0
| END) AS less_than_60,
| SUM(CASE
| WHEN DATE_DIFF('second', from_iso8601_timestamp('$sentTime'), received_timestamp) < 90 THEN 1
| ELSE 0
| END) AS less_than_90,
| SUM(CASE
| WHEN DATE_DIFF('second', from_iso8601_timestamp('$sentTime'), received_timestamp) < 120 THEN 1
| ELSE 0
| END) AS less_than_120,
| SUM(CASE
| WHEN DATE_DIFF('second', from_iso8601_timestamp('$sentTime'), received_timestamp) < 150 THEN 1
| ELSE 0
| END) AS less_than_150,
| SUM(CASE
| WHEN DATE_DIFF('second', from_iso8601_timestamp('$sentTime'), received_timestamp) < 180 THEN 1
| ELSE 0
| END) AS less_than_180,
| SUM(CASE
| WHEN DATE_DIFF('second', from_iso8601_timestamp('$sentTime'), received_timestamp) < 210 THEN 1
| ELSE 0
| END) AS less_than_210,
| SUM(CASE
| WHEN DATE_DIFF('second', from_iso8601_timestamp('$sentTime'), received_timestamp) < 240 THEN 1
| ELSE 0
| END) AS less_than_240,
| SUM(CASE
| WHEN DATE_DIFF('second', from_iso8601_timestamp('$sentTime'), received_timestamp) < 270 THEN 1
| ELSE 0
| END) AS less_than_270,
| SUM(CASE
| WHEN DATE_DIFF('second', from_iso8601_timestamp('$sentTime'), received_timestamp) < 300 THEN 1
| ELSE 0
| END) AS less_than_300,
| COUNT(*) AS total_deliveries
|FROM notification_received_${stage.toLowerCase()}
|WHERE notificationid = '$notificationId'
|AND $partitionDate
|GROUP BY platform
""".stripMargin
}