Skip to content

Commit

Permalink
Adapt the generator in order to require a single evaluation when a si…
Browse files Browse the repository at this point in the history
…ngle date is submitted to the service.
  • Loading branch information
mgoeminne committed Dec 6, 2016
1 parent ac249c4 commit 2086dfb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name := "ts-generator-ws"
version := "1.0"
version := "1.1"
scalaVersion := "2.11.8"

libraryDependencies ++= Seq(
Expand All @@ -15,7 +15,7 @@ libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.0" % "test"
)

libraryDependencies += "be.cetic" %% "rts-gen" % "0.1.6"
libraryDependencies += "be.cetic" %% "rts-gen" % "0.1.10"

// Create a package with sbt package
mainClass in Compile := Some("be.cetic.rtsgen.genservice.GeneratorWebServer")
Expand Down
23 changes: 8 additions & 15 deletions src/main/scala/be/cetic/rtsgen/genservice/GeneratorWebServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import akka.http.scaladsl.server.PathMatchers
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Source
import akka.util.ByteString
import be.cetic.rtsgen.Main
import be.cetic.rtsgen.Utils

import scala.io.StdIn
import be.cetic.rtsgen.config.{Configuration}
Expand Down Expand Up @@ -59,7 +59,7 @@ object GeneratorWebServer {

val config = Configuration(document.parseJson)

val results = Main.generate(Main.config2Results(config))
val results = Utils.generate(Utils.config2Results(config))

val answer = Source(results.map(x => dtf.print(x._1) + ";" + x._2 + ";" + x._3))

Expand All @@ -85,29 +85,22 @@ object GeneratorWebServer {
{ document =>

val config = Configuration(document.parseJson)
val results = Main.generate(Main.config2Results(config))

val answer = segments match {

case List(limit) => {
// We are looking for the values corresponding to a date before or equal to limit
// We are looking for the values corresponding to a particular date
val reference = LocalDateTime.parse(limit, dtf)
val last = scala.collection.mutable.Map[String, (LocalDateTime, String)]()
val results = Utils.eval(config, reference)

results .takeWhile(entry => entry._1 <= reference)
.foreach(entry =>
{
val date = entry._1
val data = entry._2
val value = entry._3.toString

last.put(data, (date, value))
})

Source(last.toMap.map(entry => dtf.print(entry._2._1) + ";" + entry._1 + ";" + entry._2._2))
Source(results.map(entry => dtf.print(reference) + ";" + entry._1 + ";" + entry._2.getOrElse("NA").toString))
}

case List(start, stop) => {

val results = Utils.generate(Utils.config2Results(config))

val startDate = LocalDateTime.parse(start, dtf)
val endDate = LocalDateTime.parse(stop, dtf)

Expand Down

0 comments on commit 2086dfb

Please sign in to comment.