Build fixed Faktiska production workflow

This commit is contained in:
b0txec
2026-08-19 17:11:58 +03:00
parent d9a788376b
commit e726291bdb
6 changed files with 140 additions and 47 deletions
+12
View File
@@ -28,6 +28,18 @@ object PostgresService {
}
class PostgresService(transactor: Transactor[IO], log: Logger[IO]) {
def queryLatestTemperatures(cities: NonEmptyList[String]): IO[List[(String, LocalDateTime, Option[Double])]] = {
val query =
fr"SELECT DISTINCT ON (city) city, dateTime, tempAvg" ++
fr" FROM weather" ++
fr" WHERE " ++ Fragments.in(fr"city", cities) ++
fr" ORDER BY city, dateTime DESC"
query.query[(String, LocalDateTime, Option[Double])]
.to[List]
.transact(transactor)
}
def save(fileName: String, content: String): IO[String] = {
val YearPattern: Regex = """(\d{4})\d{4}_\d{4}\.csv""".r
+7
View File
@@ -49,6 +49,7 @@ class Server(postgresService: PostgresService, dataService: DataService, fetch:
}
private case class ResponseWrapper(result: Map[String, Option[Aggregate.AggregateValue]], query: UserQuery)
private case class LatestTemperature(city: String, observedAt: String, value: Option[Double])
private val apiRoutes = HttpRoutes.of[IO] {
// http://0.0.0.0:8080/api/show/lvgmc-forecast/Latvija_LTV_pilsetas_tekosa_dn.csv
@@ -127,6 +128,12 @@ class Server(postgresService: PostgresService, dataService: DataService, fetch:
.map(result => ResponseWrapper(result, userQuery))
.flatMap(responseWrapper => Ok(responseWrapper.asJson.pretty))
// Latest observation-time temperatures for a fixed production station set.
case GET -> Root / "query" / "latest-temperatures" / CityList(cities) =>
postgresService.queryLatestTemperatures(cities)
.map(_.map { case (city, observedAt, value) => LatestTemperature(city, observedAt.toString, value) })
.flatMap(result => Ok(result.asJson.pretty))
// http://0.0.0.0:8080/api/query/city/Kolka/20230414_2200-20230501_1230/allFields
case GET -> Root / "query" / "city" / (city: String) / DateTimeRange(from, to) / "allFields" =>
postgresService.queryCityAllFields(city, from, to).flatMap(result => Ok(result.asJson))