Created
December 19, 2017 22:26
-
-
Save hohonuuli/199905a7ecb181915b791a9ce3bd0923 to your computer and use it in GitHub Desktop.
Scala class for medium article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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