<commit_before>package models.jbehave

import java.io.File
import play.api.libs.json.{Json, JsValue}
import scala.io.Source
import scala.xml.XML

class JBehaveReporter {

  val FINISHED = "finished"

  def listJson(reportsPath: String, id: String): Option[JsValue] = {
    val realReportsPath = {
      if (new File(s"$reportsPath/$id").exists()) {
        reportsPath
      } else {
        s"target/$reportsPath"
      }
    }
    println(realReportsPath)
    println(new File(realReportsPath).getAbsolutePath)
    val reports = list(realReportsPath, id)
    if (reports.isEmpty) None
    else {
      val data = Map(
        "status" -> Json.toJson(status(realReportsPath, id)),
        "reports" -> Json.toJson(reportsMap(realReportsPath, id, reports.get))
      )
      Some(Json.toJson(data))
    }
  }

  def reportContent(reportsPath: String, id: String, report: String): Option[String] = {
    val file = new File(s"$reportsPath/$id/$report")
    if (!file.exists()) None
    else Some(Source.fromFile(file).mkString)
  }

  private[jbehave] def list(reportsPath: String, id: String): Option[List[String]] = {
//    val path = new File(s"$reportsPath/$id").getAbsoluteFile
    val dir = new File(s"$reportsPath/$id").getAbsoluteFile
    println(dir + " " + dir.exists())
    if (!dir.exists()) None
    else Some(dir.listFiles()
      .filter(_.getName.endsWith(".html"))
      .sortWith(_.lastModified() < _.lastModified())
      .map(file => file.getName)
      .toList
    )
  }

  private[jbehave] def steps(reportPath: String, reportsPath: String, id: String) = {
    if (status(reportsPath, id).equals(FINISHED)) {
      val xml = XML.loadFile(new File(reportPath))
      Some((xml \ "scenario" \ "step").map(node => Map(
        "text" -> node.text,
        "status" -> (node \ "@outcome").text
      )))
    } else {
      None<commit_msg>Fixed single story runner timeout<commit_after>package models.jbehave

import java.io.File
import play.api.libs.json.{Json, JsValue}
import scala.io.Source
import scala.xml.XML

class JBehaveReporter {

  val FINISHED = "finished"

  def listJson(reportsPath: String, id: String): Option[JsValue] = {
    val realReportsPath = {
      if (new File(s"$reportsPath/$id").exists()) {
        reportsPath
      } else {
        new File(s"target/$reportsPath").getAbsolutePath
      }
    }
    println(realReportsPath)
    println(new File(realReportsPath).getAbsolutePath)
    val reports = list(realReportsPath, id)
    if (reports.isEmpty) None
    else {
      val data = Map(
        "status" -> Json.toJson(status(realReportsPath, id)),
        "reports" -> Json.toJson(reportsMap(realReportsPath, id, reports.get))
      )
      Some(Json.toJson(data))
    }
  }

  def reportContent(reportsPath: String, id: String, report: String): Option[String] = {
    val file = new File(s"$reportsPath/$id/$report")
    if (!file.exists()) None
    else Some(Source.fromFile(file).mkString)
  }

  private[jbehave] def list(reportsPath: String, id: String): Option[List[String]] = {
    val dir = new File(s"$reportsPath/$id")
    println(dir + " " + dir.exists())
    if (!dir.exists()) None
    else Some(dir.listFiles()
      .filter(_.getName.endsWith(".html"))
      .sortWith(_.lastModified() < _.lastModified())
      .map(file => file.getName)
      .toList
    )
  }

  private[jbehave] def steps(reportPath: String, reportsPath: String, id: String) = {
    if (status(reportsPath, id).equals(FINISHED)) {
      val xml = XML.loadFile(new File(reportPath))
      Some((xml \ "scenario" \ "step").map(node => Map(
        "text" -> node.text,
        "status" -> (node \ "@outcome").text
      )))
    } else {
      None
{'fraction_non_alphanumeric': 0.15031258494156022, 'fraction_numerical': 0.0, 'mean_word_length': 3.057331863285557, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '4612999', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1195, 'n_words': 246}