Skip to content

Instantly share code, notes, and snippets.

@nvkv
Last active August 29, 2015 14:24
Show Gist options
  • Save nvkv/84d01e9c3e086a487572 to your computer and use it in GitHub Desktop.
Save nvkv/84d01e9c3e086a487572 to your computer and use it in GitHub Desktop.
kanboard-metrics.scala
#!/usr/bin/env scalas
/***
scalacOptions += "-deprecation"
libraryDependencies ++= Seq(
"com.github.tototoshi" %% "scala-csv" % "1.2.1"
)
*/
import com.github.tototoshi.csv._
import java.io.{ UnsupportedEncodingException, FileReader, File, StringReader }
case class Transition(from: String, to: String, timeSpent: Double)
case class Result(column: String, averageTime: Double)
object Calculator {
def parseTransitions(file: String): List[Transition] = {
val reader = CSVReader.open(new File(file))
reader.all().toList.tail.map { item =>
item match {
case _ :: _ :: from :: to :: _ :: _ :: timeSpent :: _ => Some(Transition(from, to, timeSpent.toDouble))
case _ => None
}
}.flatMap { t => t }
}
def calculateAverage(transitions: List[Transition]): List[Result] = {
transitions.groupBy(_.from).map { case (column, ts) =>
val average = ts.foldLeft(0.0) { (acc, transition) =>
acc + transition.timeSpent
} / ts.length
Result(column, average)
}.toList
}
}
if (args.length == 0) {
println("scalas metrics.scala filename.csv")
sys.exit(0)
}
val results = Calculator.calculateAverage(Calculator.parseTransitions(args(0)))
results.foreach { result =>
println(f"Average time spent in column ${result.column}: ${result.averageTime}%.1f h.")
}
val leadTime = results.foldLeft(0.0) { (acc, result) => acc + result.averageTime }
println(f"Lead Time: $leadTime%.1f h.")
val cycleTime = results.filter{ r =>
(r.column != "Бэклог") && (r.column != "Аналитика") && (r.column != "Готово к деплою") && (r.column != "Победа")
}.foldLeft(0.0) { (acc, result) => acc + result.averageTime }
println(f"Cycle Time: $cycleTime%.1f h.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment