2023-04-25 20:11:49 +03:00
|
|
|
package server
|
|
|
|
|
|
2023-05-03 00:02:59 +03:00
|
|
|
import parse.Aggregate.AggregateKey
|
2023-04-25 20:11:49 +03:00
|
|
|
|
|
|
|
|
import java.time.{LocalDate, LocalDateTime}
|
|
|
|
|
import java.time.format.DateTimeFormatter
|
2023-07-03 23:17:43 +03:00
|
|
|
import java.time.temporal.ChronoUnit
|
2023-04-25 20:11:49 +03:00
|
|
|
import scala.util.Try
|
|
|
|
|
|
|
|
|
|
object ValidateRoutes {
|
|
|
|
|
object DateTimeRange {
|
|
|
|
|
def unapply(str: String): Option[(LocalDateTime, LocalDateTime)] = {
|
|
|
|
|
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmm")
|
|
|
|
|
str.split("-")
|
|
|
|
|
.toList
|
|
|
|
|
.map(str => Try(LocalDateTime.parse(str, formatter)).toOption) match {
|
|
|
|
|
case List(Some(from), Some(to)) => Some(from, to)
|
|
|
|
|
case _ => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object ValidDate {
|
|
|
|
|
def unapply(str: String): Option[LocalDate] = {
|
|
|
|
|
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd")
|
|
|
|
|
Try(LocalDate.parse(str, formatter)).toOption
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
object CityList {
|
|
|
|
|
def unapply(str: String): Option[List[String]] = {
|
|
|
|
|
str.split(",").toList match {
|
|
|
|
|
case Nil => None
|
2023-05-22 22:31:28 +03:00
|
|
|
case list => Some(list)
|
2023-04-25 20:11:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-03 00:02:59 +03:00
|
|
|
object AggKey {
|
2023-04-26 16:37:11 +03:00
|
|
|
def unapply(str: String): Option[AggregateKey] = {
|
2023-05-03 00:02:59 +03:00
|
|
|
AggregateKey.fromString(str)
|
2023-04-25 20:11:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
2023-07-03 23:17:43 +03:00
|
|
|
|
|
|
|
|
object Granularity {
|
|
|
|
|
def unapply(str: String): Option[ChronoUnit] = {
|
|
|
|
|
str match {
|
|
|
|
|
case "hour" => Some(ChronoUnit.HOURS)
|
|
|
|
|
case "day" => Some(ChronoUnit.DAYS)
|
|
|
|
|
case "month" => Some(ChronoUnit.MONTHS)
|
|
|
|
|
case "year" => Some(ChronoUnit.YEARS)
|
|
|
|
|
case _ => None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-25 20:11:49 +03:00
|
|
|
}
|