Skip to content

Instantly share code, notes, and snippets.

@niektemme
Created July 31, 2015 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niektemme/adc9e9dd402fcee22f04 to your computer and use it in GitHub Desktop.
Save niektemme/adc9e9dd402fcee22f04 to your computer and use it in GitHub Desktop.
Smart Thermostat AWS Spark - part Spark cluster select best scenario
//select best scenario for each temperature cluster
val RDDtotalClustered = valRowsOnOff.map(result => ( (result._1, clusters.predict(Vectors.dense(result._2._1,result._2._2)) ), (result._2._3, 1L) )
).reduceByKey((x, y) => (x._1 + y._1, x._2 + y._2)
).map(result => (result._1._2, ( result._2._1/result._2._2, result._1._1 ) )
).reduceByKey((x, y) => if (x._1 < y._1) {(x._1, x._2)} else {(y._1, y._2)}
).mapValues(result => (math.round(result._1), result._2 ))
RDDtotalClustered.cache()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment