Skip to content

Commit

Permalink
Change CSV parser (prepare for #51)
Browse files Browse the repository at this point in the history
  • Loading branch information
v6ak committed Oct 16, 2023
1 parent cf22447 commit 7dea748
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,17 @@ lazy val client = (project in file("client")).settings(
libraryDependencies ++= Seq(
"org.scala-js" %%% "scalajs-dom" % "2.7.0",
"com.lihaoyi" %%% "scalatags" % "0.12.0",
"com.nrinaudo" %%% "kantan.csv" % "0.7.0",
),
Compile / npmDependencies ++= Seq(
"comma-separated-values" -> "3.6.4",
"bootstrap" -> bootstrapVersion,
"moment" -> "2.10.6",
"moment-timezone" -> "0.4.0",
"chart.js" -> "4.4.0",
"chartjs-adapter-moment" -> "1.0.1",
),
stIgnore ++= List("moment", "moment-timezone", "bootstrap", "chart.js", "chartjs-adapter-moment"),
stIgnore ++= List("moment", "moment-timezone", "bootstrap", "chart.js", "chartjs-adapter-moment",
"comma-separated-values"),
).enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin, ScalablyTypedConverterPlugin)//.dependsOn(sharedJs)

/*lazy val shared = (crossProject.crossType(CrossType.Pure) in file("shared")).
Expand Down
15 changes: 15 additions & 0 deletions client/src/main/scala/com/v6ak/zbdb/CsvParser.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.v6ak.zbdb

import scala.scalajs.js
import scala.scalajs.js.annotation._

object CsvParser {

@JSImport("comma-separated-values", JSImport.Namespace)
@js.native
private val csvParser: js.Dynamic = js.native

def parse(s: String): IndexedSeq[IndexedSeq[String]] = csvParser.parse(s, js.Dynamic.literal(
cast = false
)).asInstanceOf[js.Array[js.Array[String]]].map(_.toIndexedSeq).toIndexedSeq
}
4 changes: 1 addition & 3 deletions client/src/main/scala/com/v6ak/zbdb/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ object Parser{
}

def parse(csvData: String, startTime: Moment, totalEndTime: Moment, maxHourDelta: Int, formatVersion: FormatVersion) = {
import kantan.csv._
import kantan.csv.ops._
val fullDataTable: IndexedSeq[IndexedSeq[String]] = csvData.trim.unsafeReadCsv[IndexedSeq, IndexedSeq[String]](rfc)
val fullDataTable: IndexedSeq[IndexedSeq[String]] = CsvParser.parse(csvData)
val Seq(header1, header2, header3, dataWithTail @ _*) = fullDataTable.drop(formatVersion.headSize)
val (dataTable, footer) = formatVersion.tail.split(dataWithTail.dropWhile(_.head == "").toIndexedSeq)
footer.foreach{fl =>
Expand Down

0 comments on commit 7dea748

Please sign in to comment.