aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/com/drivergrp/core/stats.scala
blob: cd77f7a1166c455c1f60737d980125c7de781c78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.drivergrp.core

import com.drivergrp.core.logging.Logger
import com.drivergrp.core.time.{Time, TimeRange}

object stats {

  type StatsKey  = String
  type StatsKeys = Seq[StatsKey]

  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))
  }

  class LogStats(log: Logger) extends Stats {
    def recordStats(keys: StatsKeys, interval: TimeRange, value: BigDecimal): Unit = {
      val valueString = value.bigDecimal.toPlainString
      log.audit(s"${keys.mkString(".")}(${interval.start.millis}-${interval.end.millis})=$valueString")
    }
  }
}