Fix duplications of data, sort query list, visual improvements
This commit is contained in:
@@ -22,10 +22,11 @@ class DBService(log: Logger[IO]) {
|
|||||||
private val dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmm")
|
private val dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmm")
|
||||||
private val dataPath = "./data"
|
private val dataPath = "./data"
|
||||||
|
|
||||||
private def readFile(fileName: String): IO[List[String]] = {
|
// takes only first 34 lines of data as rest after 'Zosēni' is duplicated
|
||||||
|
def readFile(fileName: String): IO[List[String]] = {
|
||||||
val file = new File(dataPath, fileName)
|
val file = new File(dataPath, fileName)
|
||||||
val sourceResource = Resource.fromAutoCloseable(IO(Source.fromFile(file)))
|
val sourceResource = Resource.fromAutoCloseable(IO(Source.fromFile(file)))
|
||||||
sourceResource.use(source => IO(source.getLines().toList)).handleErrorWith(_ => IO.pure(List.empty))
|
sourceResource.use(source => IO(source.getLines().take(34).toList)).handleErrorWith(_ => IO.pure(List.empty))
|
||||||
}
|
}
|
||||||
|
|
||||||
private def readFileNames(path: String): IO[List[String]] =
|
private def readFileNames(path: String): IO[List[String]] =
|
||||||
@@ -82,12 +83,4 @@ class DBService(log: Logger[IO]) {
|
|||||||
val dateStr: String = date.format(formatter)
|
val dateStr: String = date.format(formatter)
|
||||||
readFileNames(dataPath).map(_.filter(_.startsWith(dateStr)).sorted)
|
readFileNames(dataPath).map(_.filter(_.startsWith(dateStr)).sorted)
|
||||||
}
|
}
|
||||||
|
|
||||||
def getFileContent(fileName: String): IO[String] = {
|
|
||||||
val file = new File(dataPath, fileName)
|
|
||||||
val sourceResource = Resource.fromAutoCloseable(IO(Source.fromFile(file)))
|
|
||||||
sourceResource.use(source => IO(source.getLines().mkString("<br/>\n"))).handleErrorWith { error =>
|
|
||||||
IO(println(s"Failed to read file: $error")) *> IO.pure("")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ object Aggregate {
|
|||||||
case AggregateKey.Max => flatValues.maximumOption.map(DoubleValue)
|
case AggregateKey.Max => flatValues.maximumOption.map(DoubleValue)
|
||||||
case AggregateKey.Avg => flatValues.reduceOption(_ + _).map(sum => DoubleValue(sum / flatValues.length))
|
case AggregateKey.Avg => flatValues.reduceOption(_ + _).map(sum => DoubleValue(sum / flatValues.length))
|
||||||
case AggregateKey.Sum => flatValues.sum.some.map(DoubleValue)
|
case AggregateKey.Sum => flatValues.sum.some.map(DoubleValue)
|
||||||
case AggregateKey.List => TimeDoubleList(timestamps.zip(values)).some
|
case AggregateKey.List => TimeDoubleList(timestamps.zip(values).sorted).some
|
||||||
case AggregateKey.Distinct => None
|
case AggregateKey.Distinct => None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ object Main {
|
|||||||
println("================ start parser")
|
println("================ start parser")
|
||||||
|
|
||||||
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmm")
|
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmm")
|
||||||
val from = LocalDateTime.parse("20230512_2200", formatter)
|
val from = LocalDateTime.parse("20230515_0905", formatter)
|
||||||
val to = LocalDateTime.parse("20230514_1230", formatter)
|
val to = LocalDateTime.parse("20230516_0942", formatter)
|
||||||
val userQuery = UserQuery(List("Rīga"), "tempAvg", AggregateKey.List)
|
val userQuery = UserQuery(List("Bauska", "Dagda", "Daugavgrīva", "Rīga"), "precipitation", AggregateKey.Sum)
|
||||||
|
// val userQuery = UserQuery(List("Daugavgrīva"), "precipitation", AggregateKey.List)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
dbService <- DBService.of
|
dbService <- DBService.of
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ object WeatherData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//val cityList: List[String] = List("Ainaži", "Alūksne", "Bauska", "Dagda", "Daugavgrīva", "Daugavpils", "Dobele", "Gulbene", "Jelgava", "Kalnciems", "Kolka", "Kuldīga", "Lielpēči", "Liepāja", "Madona", "Mērsrags", "Pāvilosta", "Piedruja", "Priekuļi", "Rēzekne", "Rīga", "Rucava", "Rūjiena", "Saldus", "Sigulda", "Sīļi", "Skrīveri", "Skulte", "Stende", "Ventspils", "Vičaki", "Zīlāni", "Zosēni", "Ainaži", "Alūksne", "Bauska", "Dagda", "Daugavgrīva", "Daugavpils", "Dobele", "Gulbene", "Jelgava", "Kalnciems", "Kolka", "Kuldīga", "Lielpēči", "Liepāja", "Madona", "Mērsrags", "Pāvilosta", "Piedruja", "Priekuļi", "Rēzekne", "Rīga", "Rucava", "Rūjiena", "Saldus", "Sigulda", "Sīļi", "Skrīveri", "Skulte", "Stende", "Ventspils", "Vičaki", "Zīlāni", "Zosēni")
|
//val cityList: List[String] = List("Ainaži", "Alūksne", "Bauska", "Dagda", "Daugavgrīva", "Daugavpils", "Dobele", "Gulbene", "Jelgava", "Kalnciems", "Kolka", "Kuldīga", "Lielpēči", "Liepāja", "Madona", "Mērsrags", "Pāvilosta", "Piedruja", "Priekuļi", "Rēzekne", "Rīga", "Rucava", "Rūjiena", "Saldus", "Sigulda", "Sīļi", "Skrīveri", "Skulte", "Stende", "Ventspils", "Vičaki", "Zīlāni", "Zosēni")
|
||||||
|
|
||||||
|
|
||||||
//Map(
|
//Map(
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import org.http4s.ember.server.EmberServerBuilder
|
|||||||
import io.circe.syntax._
|
import io.circe.syntax._
|
||||||
import parse.Aggregate.AggregateValueImplicits.aggregateValueEncoder
|
import parse.Aggregate.AggregateValueImplicits.aggregateValueEncoder
|
||||||
import parse.Aggregate.{AggregateKey, UserQuery}
|
import parse.Aggregate.{AggregateKey, UserQuery}
|
||||||
import fs2.Stream
|
import org.http4s.circe.jsonEncoder
|
||||||
|
|
||||||
import scala.concurrent.duration.DurationInt
|
import scala.concurrent.duration.DurationInt
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ object Server {
|
|||||||
|
|
||||||
// http://0.0.0.0:8080/api/show/file/20230423_12:30.csv
|
// http://0.0.0.0:8080/api/show/file/20230423_12:30.csv
|
||||||
case GET -> Root / "show" / "file" / (fileName: String) =>
|
case GET -> Root / "show" / "file" / (fileName: String) =>
|
||||||
DBService.of.flatMap(_.getFileContent(fileName).flatMap(Ok(_)))
|
DBService.of.flatMap(_.readFile(fileName).flatMap(content => Ok(content.asJson)))
|
||||||
|
|
||||||
// http://0.0.0.0:8080/api/help
|
// http://0.0.0.0:8080/api/help
|
||||||
case GET -> Root / "help" => {
|
case GET -> Root / "help" => {
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ console.log("api host:", import.meta.env.VITE_API_HOST);
|
|||||||
type Section = "aggregator" | "fileManager";
|
type Section = "aggregator" | "fileManager";
|
||||||
|
|
||||||
const App: Component = () => {
|
const App: Component = () => {
|
||||||
const [getSection, setSection] = createSignal<Section>("aggregator");
|
const [getSection, setSection] = createSignal<Section>("fileManager");
|
||||||
|
|
||||||
const section = () => getSection() === "aggregator" ? <Aggregator /> : <FileManager />;
|
const section = () => getSection() === "aggregator" ? <Aggregator /> : <FileManager />;
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
export const apiHost = import.meta.env.VITE_API_HOST;
|
export const apiHost = import.meta.env.VITE_API_HOST;
|
||||||
|
|
||||||
export const cityList = ["Ainaži", "Alūksne", "Bauska", "Dagda", "Daugavgrīva", "Daugavpils", "Dobele", "Gulbene", "Jelgava", "Kalnciems", "Kolka", "Kuldīga", "Lielpēči", "Liepāja", "Madona", "Mērsrags", "Pāvilosta", "Piedruja", "Priekuļi", "Rēzekne", "Rīga", "Rucava", "Rūjiena", "Saldus", "Sigulda", "Sīļi", "Skrīveri", "Skulte", "Stende", "Ventspils", "Vičaki", "Zīlāni", "Zosēni", "Ainaži", "Alūksne", "Bauska", "Dagda", "Daugavgrīva", "Daugavpils", "Dobele", "Gulbene", "Jelgava", "Kalnciems", "Kolka", "Kuldīga", "Lielpēči", "Liepāja", "Madona", "Mērsrags", "Pāvilosta", "Piedruja", "Priekuļi", "Rēzekne", "Rīga", "Rucava", "Rūjiena", "Saldus", "Sigulda", "Sīļi", "Skrīveri", "Skulte", "Stende", "Ventspils", "Vičaki", "Zīlāni", "Zosēni"];
|
export const cityList = ["Ainaži", "Alūksne", "Bauska", "Dagda", "Daugavgrīva", "Daugavpils", "Dobele", "Gulbene", "Jelgava", "Kalnciems", "Kolka", "Kuldīga", "Lielpēči", "Liepāja", "Madona", "Mērsrags", "Pāvilosta", "Piedruja", "Priekuļi", "Rēzekne", "Rīga", "Rucava", "Rūjiena", "Saldus", "Sigulda", "Sīļi", "Skrīveri", "Skulte", "Stende", "Ventspils", "Vičaki", "Zīlāni", "Zosēni"];
|
||||||
|
|
||||||
export const weatherField = ["tempMax", "tempMin", "tempAvg", "precipitation", "windAvg", "windMax", "visibilityMin", "visibilityAvg", "snowAvg", "atmPressire", "dewPoint", "humidity", "sunDuration", "phenomena"];
|
export const weatherField = ["tempMax", "tempMin", "tempAvg", "precipitation", "windAvg", "windMax", "visibilityMin", "visibilityAvg", "snowAvg", "atmPressire", "dewPoint", "humidity", "sunDuration", "phenomena"];
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ export const FileContent: Component<{getFileName: Accessor<string>}> = (props) =
|
|||||||
if (fileName === "") return;
|
if (fileName === "") return;
|
||||||
await new Promise(resolve => setTimeout(resolve, 500))
|
await new Promise(resolve => setTimeout(resolve, 500))
|
||||||
const response = await fetch(`${apiHost}/api/show/file/${fileName}`);
|
const response = await fetch(`${apiHost}/api/show/file/${fileName}`);
|
||||||
const text = await response.text();
|
const text = await response.json();
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [contentResource] = createResource(props.getFileName, fetchFileContent);
|
const [contentResource] = createResource(props.getFileName, fetchFileContent);
|
||||||
const lines = () => contentResource()?.split("<br/>") ?? ["empty..."];
|
const lines = () => contentResource();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in New Issue
Block a user