<commit_before>package im.mange.driveby.tracking.report

import im.mange.driveby.tracking._

case class ApplicationRun(applicationId: Long, events: Seq[Event]) {
  import im.mange.driveby.tracking.Format._

  private def startRequested = events.filter(_.isInstanceOf[ApplicationStartRequested]).headOption
  private def started = events.filter(_.isInstanceOf[ApplicationStarted]).headOption
  private def didStart = started.isDefined
  private def stopRequested = events.filter(_.isInstanceOf[ApplicationStopRequested]).headOption
  private def stopped = events.filter(_.isInstanceOf[ApplicationStopped]).headOption
  private def didStop = stopped.isDefined
  private def lastExampleFinished = events.filter(_.isInstanceOf[ApplicationWritten]).reverse.headOption

  private def idleMillis = for { r <- stopRequested; l <- lastExampleFinished } yield r.at - l.at
  private def startingMillis = for { s <- started; r <- startRequested } yield s.at - r.at
  private def stoppingMillis = for { s <- stopped; r <- stopRequested } yield s.at - r.at
  //TODO: find a less shonky way to do this
  private def name = if (startRequested.isDefined) startRequested.get.asInstanceOf[ApplicationStartRequested].applicationType else "???"
  private def exampleCount = events.filter(_.isInstanceOf[ApplicationTaken]).size

  //TODO: should be N/A for idle and examples if did not start and stop
  def report = "- " + applicationId +
    " (" + name + ")" +
    " start: " + (if (didStart) millis(startingMillis) else "Failed") +
    ", stop: " + (if (didStop) millis(stoppingMillis) else "Failed") +
    ", idle: " + millis(idleMillis) +<commit_msg>fix yet more suggestions<commit_after>package im.mange.driveby.tracking.report

import im.mange.driveby.tracking._

case class ApplicationRun(applicationId: Long, events: Seq[Event]) {
  import im.mange.driveby.tracking.Format._

  private def startRequested = events.find(_.isInstanceOf[ApplicationStartRequested])
  private def started = events.find(_.isInstanceOf[ApplicationStarted])
  private def didStart = started.isDefined
  private def stopRequested = events.find(_.isInstanceOf[ApplicationStopRequested])
  private def stopped = events.find(_.isInstanceOf[ApplicationStopped])
  private def didStop = stopped.isDefined
  private def lastExampleFinished = events.filter(_.isInstanceOf[ApplicationWritten]).reverse.headOption

  private def idleMillis = for { r <- stopRequested; l <- lastExampleFinished } yield r.at - l.at
  private def startingMillis = for { s <- started; r <- startRequested } yield s.at - r.at
  private def stoppingMillis = for { s <- stopped; r <- stopRequested } yield s.at - r.at
  //TODO: find a less shonky way to do this
  private def name = if (startRequested.isDefined) startRequested.get.asInstanceOf[ApplicationStartRequested].applicationType else "???"
  private def exampleCount = events.count(_.isInstanceOf[ApplicationTaken])

  //TODO: should be N/A for idle and examples if did not start and stop
  def report = "- " + applicationId +
    " (" + name + ")" +
    " start: " + (if (didStart) millis(startingMillis) else "Failed") +
    ", stop: " + (if (didStop) millis(stoppingMillis) else "Failed") +
    ", idle: " + millis(idleMillis) +
{'fraction_non_alphanumeric': 0.11090400745573159, 'fraction_numerical': 0.0, 'mean_word_length': 4.6, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6036323', 'n_tokens_mistral': 963, 'n_tokens_neox': 948, 'n_words': 253}