aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/com/drivergrp/core/stats.scala
diff options
context:
space:
mode:
authorvlad <vlad@drivergrp.com>2016-07-15 19:41:26 -0400
committervlad <vlad@drivergrp.com>2016-07-15 19:41:26 -0400
commitc0d574dc6134e4f406875ea5a1301ba46602a6ec (patch)
tree606a56d184bd8c4d67f98b5aa3fafa3640a8190f /src/main/scala/com/drivergrp/core/stats.scala
downloaddriver-core-c0d574dc6134e4f406875ea5a1301ba46602a6ec.tar.gz
driver-core-c0d574dc6134e4f406875ea5a1301ba46602a6ec.tar.bz2
driver-core-c0d574dc6134e4f406875ea5a1301ba46602a6ec.zip
Initial commit with standard lib, might be used a example of cake
Diffstat (limited to 'src/main/scala/com/drivergrp/core/stats.scala')
-rw-r--r--src/main/scala/com/drivergrp/core/stats.scala50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/main/scala/com/drivergrp/core/stats.scala b/src/main/scala/com/drivergrp/core/stats.scala
new file mode 100644
index 0000000..2a173df
--- /dev/null
+++ b/src/main/scala/com/drivergrp/core/stats.scala
@@ -0,0 +1,50 @@
+package com.drivergrp.core
+
+import com.drivergrp.core.logging.LoggerModule
+import com.drivergrp.core.time.{Time, TimeRange}
+
+object stats {
+
+ type StatsKey = String
+ type StatsKeys = Seq[StatsKey]
+
+
+ trait StatsModule {
+
+ def stats: Stats
+ }
+
+ trait Stats {
+
+ def recordStats(keys: StatsKeys, interval: TimeRange, value: BigDecimal): Unit
+
+ def recordStats(keys: StatsKeys, interval: TimeRange, value: Int): Unit =
+ recordStats(keys, interval, BigDecimal(value))
+
+ def recordStats(key: StatsKey, interval: TimeRange, value: BigDecimal): Unit =
+ recordStats(Vector(key), interval, value)
+
+ def recordStats(key: StatsKey, interval: TimeRange, value: Int): Unit =
+ recordStats(Vector(key), interval, BigDecimal(value))
+
+ def recordStats(keys: StatsKeys, time: Time, value: BigDecimal): Unit =
+ recordStats(keys, TimeRange(time, time), value)
+
+ def recordStats(keys: StatsKeys, time: Time, value: Int): Unit =
+ recordStats(keys, TimeRange(time, time), BigDecimal(value))
+
+ def recordStats(key: StatsKey, time: Time, value: BigDecimal): Unit =
+ recordStats(Vector(key), TimeRange(time, time), value)
+
+ def recordStats(key: StatsKey, time: Time, value: Int): Unit =
+ recordStats(Vector(key), TimeRange(time, time), BigDecimal(value))
+ }
+
+ trait LogStats extends Stats {
+ this: LoggerModule =>
+
+ def recordStats(keys: StatsKeys, interval: TimeRange, value: BigDecimal): Unit = {
+ log.audit(s"${keys.mkString(".")}(${interval.start.millis}-${interval.end.millis})=${value.toString}")
+ }
+ }
+}