Collecting Uncertain Data the Reactive Way
-
Upload
jeff-smith -
Category
Data & Analytics
-
view
23.118 -
download
0
Transcript of Collecting Uncertain Data the Reactive Way
Certain Data Model
case class ZebraReading(sensorId: Int, locationId: Int, timestamp: Long, count: Int)
Uncertain Data Model
case class PreyReading(sensorId: Int, locationId: Int, timestamp: Long, animalsLowerBound: Double, animalsUpperBound: Double, percentZebras: Double)
Mutable State
case class Region(id: Int)
import collection.mutable.HashMap var densities = new HashMap[Region, Double]()
densities.put(Region(4), 52.4)
Out of Order Updates
densities.put(Region(6), 73.6) densities.put(Region(6), 0.5) densities.get(Region(6)).get
Out of Order Updates
densities.put(Region(6), 73.6) densities.put(Region(6), 0.5) densities.get(Region(6)).get
densities.put(Region(6), 0.5) densities.put(Region(6), 73.6) densities.get(Region(6)).get
Concurrent Collections
import collection.mutable._
var synchronizedDensities = new LinkedHashMap[Region, Double]() with SynchronizedMap[Region, Double]
Immutable Factscase class PreyReading(sensorId: Int, locationId: Int, timestamp: Long, animalsLowerBound: Double, animalsUpperBound: Double, percentZebras: Double)
implicit val preyReadingFormatter = Json.format[PreyReading]
Immutable Factsval reading = PreyReading(36, 12, currentTimeMillis(), 12.0, 18.0, 0.60)
val setDoc = bucket.set[PreyReading](readingId(reading), reading)
Querying Complete Data
(bucket.searchValues[PreyReading]("prey", "by_sensor_id") (new Query().setIncludeDocs(true))) .enumerate.apply(Iteratee.foreach { doc => println(s"Prey Reading: $doc")})
Querying Incomplete Data
(bucket.searchValues[PreyReading]("prey", "by_sensor_id") (new Query().setIncludeDocs(true))) .enumerate.apply(Iteratee.foreach { doc => println(s"Prey Reading: $doc")})
x.ai @xdotai [email protected] New York, New York