-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
205 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
ambient7-analysis/src/main/scala/ru/maizy/ambient7/analysis/notifications/data/Co2Data.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package ru.maizy.ambient7.analysis.notifications.data | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2017 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
import java.time.temporal.ChronoUnit | ||
import java.time.{ ZoneId, ZonedDateTime } | ||
import scala.concurrent.{ ExecutionContext, Future } | ||
import scala.concurrent.duration.Duration | ||
import scala.concurrent.duration.DurationInt | ||
import ru.maizy.ambient7.analysis.service.InfluxDbCo2Service | ||
import ru.maizy.ambient7.core.data.Co2Agent | ||
import ru.maizy.influxdbclient.InfluxDbClient | ||
|
||
class Co2Data( | ||
val agent: Co2Agent, | ||
influxDbClient: InfluxDbClient, | ||
val refreshRate: Duration, | ||
val storeDuration: Duration) extends Data | ||
{ | ||
|
||
private val limit = Co2Data.computeLimit(storeDuration, refreshRate) | ||
val co2 = new DataPoints[Option[Int]](limit) | ||
val temp = new DataPoints[Option[Float]](limit) | ||
val availability = new DataPoints[Boolean](limit) | ||
|
||
def update(): Future[Unit] = { | ||
implicit val ec = ExecutionContext.Implicits.global | ||
|
||
// FIXME tmp | ||
val now = ZonedDateTime.of(2017, 2, 12, 12, 0, 0, 0, ZoneId.systemDefault()) | ||
val from = now.minus(storeDuration.toMillis, ChronoUnit.MILLIS) | ||
|
||
InfluxDbCo2Service.getValuesForTimePeriod( | ||
influxDbClient, | ||
agent, | ||
from, | ||
now, | ||
segment = 5.seconds min refreshRate | ||
) map { res => | ||
res.foreach { level => | ||
co2.appendPoint(level.from, level.ppm) | ||
} | ||
() | ||
} | ||
|
||
// TODO: temp | ||
// TODO: availability | ||
|
||
} | ||
} | ||
|
||
object Co2Data { | ||
|
||
def computeLimit(refreshRate: Duration, storeDuration: Duration): Int = | ||
(storeDuration.toSeconds.toDouble / refreshRate.toSeconds).floor.toInt + 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
ambient7-analysis/src/main/scala/ru/maizy/ambient7/analysis/service/AggregateType.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package ru.maizy.ambient7.analysis.service | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2017 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
sealed trait AggregateType { | ||
def code: String | ||
def apply(value: String): String | ||
} | ||
|
||
object MAX extends AggregateType { | ||
override def code: String = "max" | ||
override def apply(value: String): String = s"max($value)" | ||
} | ||
|
||
object MIN extends AggregateType { | ||
override def code: String = "min" | ||
override def apply(value: String): String = s"min($value)" | ||
} | ||
|
||
object MEAN extends AggregateType { | ||
override def code: String = "mean" | ||
override def apply(value: String): String = s"mean($value)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters