Skip to content

Instantly share code, notes, and snippets.

@hohonuuli
Created December 19, 2017 22:26
Show Gist options
  • Save hohonuuli/199905a7ecb181915b791a9ce3bd0923 to your computer and use it in GitHub Desktop.
Save hohonuuli/199905a7ecb181915b791a9ce3bd0923 to your computer and use it in GitHub Desktop.
Scala class for medium article
import java.time.{Duration, Instant}
object BudgetPlot extends App with scalax.chart.module.Charting {
val budget = CurrentBudget
val endDate = Instant.now.plus(Duration.ofDays(365))
def filter(s: Stream[Transaction]): Stream[Transaction] = s.takeWhile(i => i.date.isBefore(endDate))
val timeseries = new BudgetTimeSeries
budget.events
.map(_.stream)
.map(filter)
.map(_.toSeq)
.foreach(timeseries.addToSeries)
val data = timeseries.cumulative()
.map(v => v._1.toEpochMilli -> v._2)
.toSeq
val chart = XYLineChart(data)
chart.saveAsPNG("target/chart.png")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment