Skip to content

Commit 528e40d

Browse files
authored
Merge pull request #83 from Quafadas/stats
Stats
2 parents c2f487b + 52ace52 commit 528e40d

File tree

15 files changed

+2268
-90
lines changed

15 files changed

+2268
-90
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ jobs:
2727
fetch-depth: 0
2828
fetch-tags: true
2929
- uses: coursier/cache-action@v6.4
30-
- name: Compile
30+
- name: Compile JS
31+
run: ./mill scautable.js.compile
32+
- name: Compile JVM
33+
run: ./mill scautable.jvm.compile
34+
- name: Compile All
3135
run: ./mill __.compile
32-
- name: test
36+
- name: test All
3337
run: ./mill scautable.test._
3438
- name: Publish artifacts
3539
run: ./mill -i __.publishArtifacts

build.mill

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait Common extends ScalaModule:
3030
Config.oslib,
3131
Config.fansi
3232
)
33-
override def scalacOptions: T[Seq[String]] = super.scalacOptions() ++ Seq("-Xmax-inlines", "128")
33+
override def scalacOptions = super.scalacOptions() ++ Seq("-Xmax-inlines", "128")
3434
end Common
3535

3636
trait CommonJS extends Common with ScalaJSModule:

scautable/package.mill

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ object `package` extends Module:
1515
object jvm extends SharedModule with ScalaModule with build.PublishModule:
1616
override def mvnDeps = super.mvnDeps() ++ Seq(
1717
mvn"org.apache.poi:poi:5.4.1",
18-
mvn"org.apache.poi:poi-ooxml:5.4.1"
18+
mvn"org.apache.poi:poi-ooxml:5.4.1",
19+
mvn"com.tdunning:t-digest:3.3"
1920
)
2021
end jvm
2122

scautable/src-js/stats.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.github.quafadas.scautable
2+
3+
/**
4+
* Api compatibility object.
5+
*/
6+
object Stats:
7+
8+
end Stats

scautable/src-jvm/stats.scala

Lines changed: 559 additions & 0 deletions
Large diffs are not rendered by default.

scautable/src/columnExtensions.scala

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,60 +24,6 @@ object NamedTupleIteratorExtensions:
2424

2525
extension [K <: Tuple, V <: Tuple](itr: Iterator[NamedTuple[K, V]])
2626

27-
inline def numericTypeTest: (List[ConversionAcc], Long) =
28-
val headers = constValueTuple[K].toList.map(_.toString())
29-
val headerAcc = headers.map(_ => ConversionAcc(0, 0, 0))
30-
31-
itr.foldLeft[List[ConversionAcc] *: Long *: EmptyTuple]((headerAcc, 0L)) { case (acc: (List[ConversionAcc], Long), elem: NamedTuple[K, V]) =>
32-
val list = elem.toList
33-
.asInstanceOf[List[String]]
34-
.zip(acc._1)
35-
.map { case (str, acc) =>
36-
(
37-
ConversionAcc(
38-
acc.validInts + str.toIntOption.fold(0)(_ => 1),
39-
acc.validDoubles + str.toDoubleOption.fold(0)(_ => 1),
40-
acc.validLongs + str.toLongOption.fold(0)(_ => 1)
41-
)
42-
)
43-
}
44-
45-
(list, acc._2 + 1L)
46-
47-
}
48-
end numericTypeTest
49-
50-
inline def formatTypeTest: String =
51-
val headers = constValueTuple[K].toList.map(_.toString())
52-
val (asList, n) = numericTypeTest
53-
val intReport = (
54-
"int" *: listToTuple(
55-
for (acc <- asList) yield (acc.validInts / n.toDouble).formatAsPercentage
56-
)
57-
)
58-
val doubleReported = "doubles" *: listToTuple(
59-
for (acc <- asList) yield (acc.validDoubles / n.toDouble).formatAsPercentage
60-
)
61-
val longReported = "long" *: listToTuple(
62-
for (acc <- asList) yield (acc.validLongs / n.toDouble).formatAsPercentage
63-
)
64-
val recommendation = "recommendation" *: listToTuple(
65-
for (acc <- asList) yield recommendConversion(List(acc), n)
66-
)
67-
68-
val ntList = Seq(
69-
intReport,
70-
doubleReported,
71-
longReported,
72-
recommendation
73-
)
74-
75-
ConsoleFormat.consoleFormat_(headers = "conversion % to" +: headers, fancy = true, table = ntList)
76-
end formatTypeTest
77-
78-
inline def showTypeTest: Unit =
79-
println(formatTypeTest)
80-
8127
inline def sample(frac: Double, inline deterministic: Boolean = false): Iterator[NamedTuple[K, V]] =
8228
if deterministic then itr.zipWithIndex.filter { case (_, idx) => idx % (1 / frac) == 0 }.map(_._1)
8329
else itr.filter(_ => rand.nextDouble() < frac)

scautable/src/package.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object table:
1111
export io.github.quafadas.scautable.NamedTupleIteratorExtensions.*
1212
export io.github.quafadas.scautable.CSVWriterExtensions.*
1313
export io.github.quafadas.scautable.HeaderOptions.*
14-
14+
export io.github.quafadas.scautable.Stats.*
1515

1616
/**
1717
* Enumeration of strategies for inferring column types when reading CSV files.

0 commit comments

Comments
 (0)