Server responses for grib list and grib structure
This commit is contained in:
@@ -2,6 +2,7 @@ package fetchDMI
|
||||
|
||||
import cats.effect._
|
||||
import cats.implicits.toTraverseOps
|
||||
import data.DataService
|
||||
import fs2.io.file.{CopyFlag, CopyFlags, Files, Path}
|
||||
import grib.GribParser
|
||||
import org.http4s._
|
||||
@@ -61,7 +62,7 @@ class FetchService(log: Logger[IO]) {
|
||||
urlWithParams = Uri.unsafeFromString(s"${base.toString}?${queryParams.toString}")
|
||||
request = Request[IO](Method.GET, urlWithParams)
|
||||
|
||||
tmpPath = Path("data/tmp.grib")
|
||||
tmpPath = Path(s"${DataService.FOLDER}/tmp.grib")
|
||||
_ <- client.stream(request)
|
||||
.flatMap(_.body)
|
||||
.through(Files[IO].writeAll(tmpPath))
|
||||
@@ -69,7 +70,7 @@ class FetchService(log: Logger[IO]) {
|
||||
.drain
|
||||
gribList <- GribParser.parseFile(tmpPath)
|
||||
gribTime = gribList.head.time
|
||||
fileName = Path(s"data/harmonie_${gribTime.referenceTime}_${gribTime.forecastTime}.grib".replace(":", ""))
|
||||
fileName = Path(s"${DataService.FOLDER}/harmonie_${gribTime.referenceTime}_${gribTime.forecastTime}.grib".replace(":", ""))
|
||||
_ <- Files[IO].move(tmpPath, fileName, CopyFlags.apply(CopyFlag.ReplaceExisting))
|
||||
_ <- log.info(fileName.toString)
|
||||
fileNameStr = fileName.toString
|
||||
|
||||
@@ -5,6 +5,7 @@ import fs2.io.file.Path
|
||||
import io.circe.generic.auto._
|
||||
import io.circe.syntax._
|
||||
import cats.effect.unsafe.implicits.global
|
||||
import data.DataService
|
||||
|
||||
object GribParserTest {
|
||||
def main(args: Array[String]): Unit = {
|
||||
@@ -12,7 +13,8 @@ object GribParserTest {
|
||||
println(gribTitle)
|
||||
|
||||
|
||||
val fileName = "data/HARMONIE_DINI_SF_2025-01-24T030000Z_2025-01-26T010000Z.grib"
|
||||
// val fileName = s"${DataService.FOLDER}/HARMONIE_DINI_SF_2025-01-24T030000Z_2025-01-26T010000Z.grib"
|
||||
val fileName = s"${DataService.FOLDER}/harmonie_2025-02-01T1500Z_2025-02-01T180000Z.grib"
|
||||
val path = Path(fileName)
|
||||
|
||||
val program = for {
|
||||
|
||||
@@ -3,9 +3,9 @@ package server
|
||||
import cats.effect._
|
||||
import cats.implicits.toTraverseOps
|
||||
import com.comcast.ip4s.IpLiteralSyntax
|
||||
import data.DataService
|
||||
import db.PostgresService
|
||||
import fetch.FetchService
|
||||
import grib.GribParser
|
||||
import parse.Aggregate
|
||||
import server.ValidateRoutes.{AggFieldList, AggKey, CityList, DateTimeRange, Granularity, ValidateDate, ValidateDateTime, ValidateMonths, ValidateZonedDateTime}
|
||||
import io.circe.{Json, Printer}
|
||||
@@ -51,15 +51,21 @@ class Server(postgresService: PostgresService, fetch: FetchService, log: Logger[
|
||||
private case class ResponseWrapper(result: Map[String, Option[Aggregate.AggregateValue]], query: UserQuery)
|
||||
|
||||
private val apiRoutes = HttpRoutes.of[IO] {
|
||||
// http://0.0.0.0:8080/api/show/grib/2025-01-24T03:00:00Z
|
||||
// case GET -> Root / "show" / "grib" / ValidateZonedDateTime(referenceTime) =>
|
||||
case GET -> Root / "show" / "grib" =>
|
||||
// TODO change from hardcoded value to reference time and forecast time
|
||||
val fileName = "data/HARMONIE_DINI_SF_2025-01-24T030000Z_2025-01-26T010000Z.grib"
|
||||
GribParser.parseFile(Path(fileName)).flatMap(response => Ok(response.asJson.pretty))
|
||||
// http://0.0.0.0:8080/api/show/grib-name/harmonie_2025-02-01T1500Z_2025-02-01T180000Z.grib
|
||||
case GET -> Root / "show" / "grib" / fileName =>
|
||||
// val fileName = "data/HARMONIE_DINI_SF_2025-01-24T030000Z_2025-01-26T010000Z.grib"
|
||||
DataService.getGribStucture(fileName).flatMap(response => Ok(response.asJson.pretty))
|
||||
|
||||
case GET -> Root / "show" / "gribName" => Ok("{\"fileName\":\"TODO replace this fake name\"}")
|
||||
|
||||
// http://0.0.0.0:8080/api/show/grib-list
|
||||
case GET -> Root / "show" / "grib-list" =>
|
||||
DataService.getFileList().flatMap(fileList => Ok(fileList.asJson))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// http://0.0.0.0:8080/api/query/city/Liepāja,Rēzekne/20230414_2200-20230501_1230/hour/tempMax/max
|
||||
case GET -> Root / "query" / "city" / CityList(cities) / DateTimeRange(from, to) / Granularity(granularity) / field / AggKey(key) =>
|
||||
val userQuery = UserQuery(cities, field, key, granularity, from, to)
|
||||
|
||||
Reference in New Issue
Block a user