Skip to content

Commit

Permalink
writeCSV (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
avi-stripe authored and avibryant committed Mar 5, 2019
1 parent 5c1b39c commit 6751d8e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions rainier-core/src/main/scala/com/stripe/rainier/repl/package.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.rainier

import com.stripe.rainier.sampler._
import java.io._

package object repl {
def plot1D[N](seq: Seq[N])(implicit num: Numeric[N]): Unit = {
Expand All @@ -15,5 +16,20 @@ package object repl {
.mkString("\n"))
}

def writeCSV(path: String, seq: Seq[Map[String, Double]]): Unit = {
val fieldNames = seq.map(_.keys.toSet).reduce(_ ++ _).toList
val pw = new PrintWriter(new File(path))
pw.write(fieldNames.mkString(","))
seq.foreach { row =>
pw.write("\n")
fieldNames.tail.foreach { f =>
pw.write(row.get(f).map(_.toString).getOrElse(""))
pw.write(",")
}
pw.write(row.get(fieldNames.head).map(_.toString).getOrElse(""))
}
pw.close
}

implicit val rng: RNG = RNG.default
}

0 comments on commit 6751d8e

Please sign in to comment.