Skip to content

Commit

Permalink
#9 updated comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyweston committed Oct 8, 2017
1 parent 1752cb0 commit 7c19d92
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import scala.collection.concurrent.TrieMap
object IgnoreTemperatureSpikes {
type SensorName = String

private val thirtyPercent = 30
private val spikePercentage = 30

// negative numbers would be a decrease, which we'll ignore (use Math.abs if we change our mind later)
def percentageIncrease(oldValue: Double, newValue: Double): Double = (newValue - oldValue) / oldValue * 100
}

/**
* This isn't atomic in terms of the `get` and `update` calls against the cached values.
* This isn't atomic in terms of the `get` and `update` calls against the cached values. An value could be retrieved,
* the `spikeBetween` check made whilst the cache contains an updated value.
*
* However, the cache structure is thread safe, so at worst, you may get out of date data.
*
Expand All @@ -38,7 +39,7 @@ class IgnoreTemperatureSpikes(delegate: TemperatureWriter) extends TemperatureWr
}

private def spikeBetween(reading: SensorReading, previous: Temperature) = {
percentageIncrease(previous.celsius, reading.temperature.celsius) >= thirtyPercent
percentageIncrease(previous.celsius, reading.temperature.celsius) >= spikePercentage
}

}

0 comments on commit 7c19d92

Please sign in to comment.