Cleaning up data in file manager

This commit is contained in:
Guntis Smaukstelis
2023-12-12 16:15:36 +02:00
parent eaf2788031
commit e89b526a88
+10 -5
View File
@@ -65,8 +65,9 @@ class PostgresService(transactor: Transactor[IO], log: Logger[IO]) extends DataS
def getDates: IO[List[LocalDate]] = ??? def getDates: IO[List[LocalDate]] = ???
def getDateTimeEntries(dateTime: LocalDateTime): IO[List[String]] = { def getDateTimeEntries(dateTime: LocalDateTime): IO[List[String]] = {
fr""" val columnNames = List("City; TempMax; TempMin; TempAvg; Precipitation; WindAvg; WindMax; VisibilityMin; VisibilityAvg; SnowAvg; AtmPressure; DewPoint; Humidity; SunDuration; Phenomena")
SELECT datetime || ';' || city || ';' || COALESCE(tempmax::text, '' ) || ';' || COALESCE(tempmin::text, '' ) || ';' || COALESCE(tempavg::text, '' ) || ';' || COALESCE(precipitation::text, '' ) || ';' || COALESCE(windavg::text, '' ) || ';' || COALESCE(windmax::text, '' ) || ';' || COALESCE(tempmax::text, '' ) || ';' || COALESCE(visibilitymin::text, '' ) || ';' || COALESCE(visibilityavg::text, '' ) || ';' || COALESCE(snowavg::text, '' ) || ';' || COALESCE(atmpressure::text, '' ) || ';' || COALESCE(dewpoint::text, '' ) || ';' || COALESCE(humidity::text, '' ) || ';' || COALESCE(sunduration::text, '' ) || ';' || COALESCE(phenomena::text, '' ) val result = fr"""
SELECT city || ';' || COALESCE(tempmax::text, '' ) || ';' || COALESCE(tempmin::text, '' ) || ';' || COALESCE(tempavg::text, '' ) || ';' || COALESCE(precipitation::text, '' ) || ';' || COALESCE(windavg::text, '' ) || ';' || COALESCE(windmax::text, '' ) || ';' || COALESCE(tempmax::text, '' ) || ';' || COALESCE(visibilitymin::text, '' ) || ';' || COALESCE(visibilityavg::text, '' ) || ';' || COALESCE(snowavg::text, '' ) || ';' || COALESCE(atmpressure::text, '' ) || ';' || COALESCE(dewpoint::text, '' ) || ';' || COALESCE(humidity::text, '' ) || ';' || COALESCE(sunduration::text, '' ) || ';' || array_to_string(phenomena, ', ')
FROM weather FROM weather
WHERE dateTime = $dateTime WHERE dateTime = $dateTime
ORDER BY city ORDER BY city
@@ -74,6 +75,8 @@ class PostgresService(transactor: Transactor[IO], log: Logger[IO]) extends DataS
.query[String] .query[String]
.to[List] .to[List]
.transact(transactor) .transact(transactor)
result.map(columnNames ++ _)
} }
def getDateFileNames(date: LocalDate): IO[List[String]] = { def getDateFileNames(date: LocalDate): IO[List[String]] = {
@@ -93,11 +96,13 @@ class PostgresService(transactor: Transactor[IO], log: Logger[IO]) extends DataS
.query[OffsetDateTime] .query[OffsetDateTime]
.to[List] .to[List]
.transact(transactor) .transact(transactor)
.map { dateTimes => { .map { dateTimes =>
dateTimes.map(_.format(formatter)) dateTimes.map(dateTime =>
} dateTime.atZoneSameInstant(rigaZone).format(formatter)
)
} }
} }
def getResourceContent(path: String): IO[String] = { def getResourceContent(path: String): IO[String] = {
val streamResource = Resource.make(IO(getClass.getResourceAsStream(path))) { stream => val streamResource = Resource.make(IO(getClass.getResourceAsStream(path))) { stream =>
IO(stream.close()).handleErrorWith(_ => IO.unit) IO(stream.close()).handleErrorWith(_ => IO.unit)