<commit_before>package client.js

import autowire._
import org.scalajs.dom
import org.scalajs.dom.MessageEvent
import shared.MapApi
import shared.car.CarsUpdate
import upickle.Js
import upickle.default._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.scalajs.js
import scala.util.{Failure, Success}

object ClientApi extends Client[Js.Value, Reader, Writer] {
  def read[Result: Reader](p: Js.Value) = upickle.default.readJs[Result](p)

  def write[Result: Writer](r: Result) = upickle.default.writeJs(r)

  override def doCall(req: Request): Future[Js.Value] = {
    dom.ext.Ajax.get(
      url = "/api/" + req.path.mkString("/"),
      data = upickle.json.write(Js.Obj(req.args.toSeq: _*))
    ).map(_.responseText)
      .map(upickle.json.read)
  }
}

object ClientApp extends js.JSApp {
  def main(): Unit = {
    val mainView = new MainView()
    dom.document.body.appendChild(mainView.wholePage)

    ClientApi[MapApi].map().call().onComplete {
      case Success(mapFromServer) =>
        val mapViewer = new MapViewer(mainView.canvasContext, mapFromServer)

        val webSocket = new dom.WebSocket("ws://localhost:9000/sim")
        webSocket.onmessage = (e: MessageEvent) => {
          mapViewer.drawCars(read[CarsUpdate](e.data.toString))
        }
      case Failure(fail) => println(s"unable to fetch map: $fail")
    }
  }
}
<commit_msg>frontend statistics added<commit_after>package client.js

import autowire._
import client.js.model.Statistics
import org.scalajs.dom
import org.scalajs.dom.MessageEvent
import shared.MapApi
import shared.car.CarsUpdate
import upickle.Js
import upickle.default._

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import scala.scalajs.js
import scala.util.{Failure, Success}

object ClientApi extends Client[Js.Value, Reader, Writer] {
  def read[Result: Reader](p: Js.Value) = upickle.default.readJs[Result](p)

  def write[Result: Writer](r: Result) = upickle.default.writeJs(r)

  override def doCall(req: Request): Future[Js.Value] = {
    dom.ext.Ajax.get(
      url = "/api/" + req.path.mkString("/"),
      data = upickle.json.write(Js.Obj(req.args.toSeq: _*))
    ).map(_.responseText)
      .map(upickle.json.read)
  }
}

object ClientApp extends js.JSApp {
  def main(): Unit = {
    val mainView = new MainView()
    dom.document.body.appendChild(mainView.wholePage)

    ClientApi[MapApi].map().call().onComplete {
      case Success(mapFromServer) =>
        val mapViewer = new MapViewer(mainView.simulationMapContext, mapFromServer)
        val statisticsViewer = new StatisticsViewer(mainView.statisticsChartContext)

        var statistics = Statistics.empty

        val webSocket = new dom.WebSocket("ws://localhost:9000/sim")
        webSocket.onmessage = (e: MessageEvent) => {
          val update: CarsUpdate = read[CarsUpdate](e.data.toString)

          update.stats foreach {
            stat => statistics = statistics.withPoint(stat)
          }

          mapViewer.drawCars(update)
          statisticsViewer.drawStatistics(statistics)
        }
      case Failure(fail) => println(s"unable to fetch map: $fail")
    }
  }
}

{'fraction_non_alphanumeric': 0.12460961898813241, 'fraction_numerical': 0.0024984384759525295, 'mean_word_length': 3.5626780626780628, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '6979010', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1032, 'n_words': 199}