Skip to content

Commit

Permalink
Merge pull request #1028 from luechtdiode/feature/more-team-aggregate…
Browse files Browse the repository at this point in the history
…-functions

Feature/more team aggregate functions
  • Loading branch information
luechtdiode authored Jan 4, 2025
2 parents 36142e7 + fd3f07f commit d459243
Show file tree
Hide file tree
Showing 13 changed files with 2,550 additions and 949 deletions.
2,723 changes: 1,987 additions & 736 deletions newclient/resultcatcher/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions newclient/resultcatcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"rollup": ">=4.22.4",
"rxjs": "~7.8.1",
"tslib": "^2.3.0",
"vite": ">=5.4.6",
"vite": ">=6.0.6",
"webpack": ">=5.94.0",
"zone.js": "~0.15.0"
},
Expand All @@ -55,8 +55,8 @@
"@types/jasmine": "~5.1.5",
"@types/jasminewd2": "~2.0.13",
"@types/node": "^22.10.2",
"@typescript-eslint/eslint-plugin": "8.18.2",
"@typescript-eslint/parser": "8.18.2",
"@typescript-eslint/eslint-plugin": "8.19.0",
"@typescript-eslint/parser": "8.19.0",
"body-parser": ">=1.20.3",
"eslint": "^9.17.0",
"eslint-plugin-import": "2.31.0",
Expand All @@ -73,7 +73,7 @@
"rollup": ">=4.22.4",
"ts-node": "~10.9.2",
"typescript": "~5.6.3",
"vite": ">=5.4.6",
"vite": ">=6.0.6",
"webpack": ">=5.94.0"
},
"description": "Resultcatcher"
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ch.seidel</groupId>
<artifactId>KuTu</artifactId>
<version>2.3.15</version>
<version>2.3.16</version>

<inceptionYear>2014</inceptionYear>

Expand Down Expand Up @@ -330,7 +330,7 @@
<scalatest.version>3.3.0-SNAP4</scalatest.version>
<scala-maven-plugin.version>4.9.2</scala-maven-plugin.version>
<gatling.version>3.12.0</gatling.version>
<gatling-plugin.version>4.9.6</gatling-plugin.version>
<gatling-plugin.version>4.12.2</gatling-plugin.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -516,7 +516,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.17.0</version>
<version>2.18.2</version>
</dependency>


Expand Down Expand Up @@ -576,7 +576,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.12.0</version>
<version>1.13.0</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ object CompetitionCoordinatorClientActor extends JsonSupport with EnrichedJson {
wsSource
}.named(deviceId))

Flow.fromSinkAndSource(sink, source).log(name = deviceId)
Flow.fromSinkAndSourceCoupled(sink, source).log(name = deviceId)
}

// unauthenticted oneway/readonly streaming
Expand All @@ -730,7 +730,7 @@ object CompetitionCoordinatorClientActor extends JsonSupport with EnrichedJson {
wsSource
}.named(deviceId))

Flow.fromSinkAndSource(sink, source).log(name = deviceId)
Flow.fromSinkAndSourceCoupled(sink, source).log(name = deviceId)

}
}
73 changes: 42 additions & 31 deletions src/main/scala/ch/seidel/kutu/data/GroupSection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ object GroupSection {
}

def mapAvgRang(list: Iterable[(DataObject, Resultat, Resultat)]) = {
val rangD = list.toList.map(_._3.noteD).filter(_ > 0).sorted.reverse :+ 0
val rangE = list.toList.map(_._3.noteE).filter(_ > 0).sorted.reverse :+ 0
val rangEnd = list.toList.map(_._3.endnote).filter(_ > 0).sorted.reverse :+ 0
val rangD = list.toList.map(_._3.noteD).filter(_ != 0).sorted.reverse :+ 0
val rangE = list.toList.map(_._3.noteE).filter(_ != 0).sorted.reverse :+ 0
val rangEnd = list.toList.map(_._3.endnote).filter(_ != 0).sorted.reverse :+ 0
def rang(r: Resultat) = {
val rd = if (rangD.nonEmpty) rangD.indexOf(r.noteD) + 1 else 0
val re = if (rangE.nonEmpty) rangE.indexOf(r.noteE) + 1 else 0
Expand Down Expand Up @@ -57,17 +57,17 @@ sealed trait WKCol {
case class WKLeafCol[T](override val text: String, override val prefWidth: Int, colspan: Int = 1, override val styleClass: Seq[String], valueMapper: T => String) extends WKCol
case class WKGroupCol(override val text: String, override val prefWidth: Int, colspan: Int = 1, override val styleClass: Seq[String], cols: Seq[WKCol]) extends WKCol

case class GroupLeaf[GK <: DataObject](override val groupKey: GK, list: Iterable[WertungView], diszs: List[Disziplin] = List()) extends GroupSection {
case class GroupLeaf[GK <: DataObject](override val groupKey: GK, list: Iterable[WertungView], diszs: List[Disziplin] = List(), aggreateFun: TeamAggreateFun = Sum) extends GroupSection {
val isTeamGroup = groupKey.isInstanceOf[Team]
override val sum: Resultat = {
groupKey match {
case gk: Team => gk.sum
case _ => list.map(_.resultat).reduce(_+_)
//case gk: Team => gk.sum
case _ => aggreateFun(list.map(_.resultat)) //.reduce(_+_)
}
}
override val avg: Resultat = {
groupKey match {
case gk: Team => gk.avg
case gk: Team => gk.wertungen.map(_.resultat).reduce(_ + _) / gk.wertungen.size
case _ => sum / list.size
}
}
Expand Down Expand Up @@ -262,7 +262,7 @@ case class GroupLeaf[GK <: DataObject](override val groupKey: GK, list: Iterable
s"Total ø aus $eNoteLabel"
}
else {
s"ø Gerät"
"ø Gerät"
}
}
else if (!isDivided && withDNotes) {
Expand All @@ -272,16 +272,20 @@ case class GroupLeaf[GK <: DataObject](override val groupKey: GK, list: Iterable
"ø Gerät"
}
, prefWidth = 80, styleClass = Seq("hintdata"), valueMapper = gr => {
val div = Math.max(gr.divider, divider)
if (div < 2) {
if (gr.sum.noteE > 0
&& gr.rang.noteE.toInt == 1)
"*" + gr.sum.formattedE
else
"" + gr.sum.formattedE
}
else {
(gr.sum / div).formattedEnd
if (isTeamGroup && aggreateFun != Sum) {
gr.avg.formattedEnd
} else {
val div = Math.max(gr.divider, divider)
if (div < 2) {
if (gr.sum.noteE > 0
&& gr.rang.noteE.toInt == 1)
"*" + gr.sum.formattedE
else
"" + gr.sum.formattedE
}
else {
(gr.sum / div).formattedEnd
}
}
}
),
Expand All @@ -308,18 +312,18 @@ case class GroupLeaf[GK <: DataObject](override val groupKey: GK, list: Iterable

def mapToAvgRowSummary(athlWertungen: Iterable[WertungView] = list): (Resultat, Resultat, Iterable[(Disziplin, Long, Resultat, Resultat, Option[Int], Option[BigDecimal])], Iterable[(ProgrammView, Resultat, Resultat, Option[Int], Option[BigDecimal])], Resultat) = {
val wks = athlWertungen.filter(_.endnote.nonEmpty).groupBy { w => w.wettkampf }
val wksums = wks.map { wk => wk._2.map(w => w.resultat).reduce(_ + _) }.toList
val rsum = if (wksums.nonEmpty) wksums.reduce(_ + _) else Resultat(0, 0, 0)
val wksums = wks.map { wk => aggreateFun(wk._2.map(w => w.resultat)) }.toList
val rsum = aggreateFun(wksums)

val gwksums = wks.map { wk =>
val gwksums = wks.map { wk => aggreateFun(
wk._2.map { w =>
if (anzahWettkaempfe > 1)
w.resultat
else
(w.resultat * STANDARD_SCORE_FACTOR) + (w.resultat * gleichstandsregel.factorize(w, wk._2.map(w => w.resultat).toList))
}.reduce(_ + _)
}) * aggreateFun.sortFactor
}
val gsum = if (gwksums.nonEmpty) gwksums.reduce(_ + _) else Resultat(0, 0, 0)
val gsum = aggreateFun(gwksums) //if (gwksums.nonEmpty) gwksums.reduce(_ + _) else Resultat(0, 0, 0)
val avg = if (wksums.nonEmpty) rsum / wksums.size else Resultat(0, 0, 0)
val gavg = if (wksums.nonEmpty) gsum / wksums.size else Resultat(0, 0, 0)
val withAuszeichnung = anzahWettkaempfe == 1 && groups.size == 1 && wks.size == 1
Expand All @@ -332,11 +336,12 @@ case class GroupLeaf[GK <: DataObject](override val groupKey: GK, list: Iterable
yield {
val prog = dwertungen.head.wettkampf.programmId
val dsums = dwertungen.map { w => w.resultat }
val dsum = if (dsums.nonEmpty) dsums.reduce(_ + _) else Resultat(0, 0, 0)
val dsum = aggreateFun(dsums)// if (dsums.nonEmpty) dsums.reduce(_ + _) else Resultat(0, 0, 0)
((ord, disziplin, prog) -> dsum)
}).groupBy(_._1).map { x =>
val xsum = x._2.map(_._2).reduce(_ + _)
(x._1, xsum, xsum / x._2.size, auszeichnung, auszeichnungEndnote)
val xasum = aggreateFun(x._2.map(_._2))
(x._1, xasum, xsum / x._2.size, auszeichnung, auszeichnungEndnote)
}
.toList.sortBy(d => d._1._1)
.map(d => (d._1._2, d._1._3, d._2, d._3, d._4, d._5))
Expand All @@ -347,13 +352,14 @@ case class GroupLeaf[GK <: DataObject](override val groupKey: GK, list: Iterable
_.wettkampfdisziplin.programm.aggregatorSubHead
}
psums = pwertungen.map { w => w.resultat }
psum = if (psums.nonEmpty) psums.reduce(_ + _) else Resultat(0, 0, 0)
psum = aggreateFun(psums) //if (psums.nonEmpty) psums.reduce(_ + _) else Resultat(0, 0, 0)
}
yield {
(programm, psum)
}).groupBy(_._1).map { x =>
val xsum = x._2.map(_._2).reduce(_ + _)
(x._1, xsum, xsum / x._2.size, auszeichnung, auszeichnungEndnote)
val xasum = aggreateFun(x._2.map(_._2))
(x._1, xasum, xsum / x._2.size, auszeichnung, auszeichnungEndnote)
}
.toList.sortBy(d => d._1.ord)
(rsum, avg, perDisziplinAvgs, perProgrammAvgs, gavg)
Expand Down Expand Up @@ -497,7 +503,7 @@ object TeamSums {
val diszs = teams.flatMap(_.diszList).distinct
.groupBy(_._1).toList.sortBy(_._2.head._2).map(_._2.head._1)
val tms = teams.filter(team => team.wertungen.nonEmpty).map { team =>
GroupLeaf(team, team.wertungen, diszs)
GroupLeaf(team, team.wertungen, diszs, team.aggregateFun)
}
if (tms.isEmpty) None else Some(TeamSums(teamRows.groupKey.asInstanceOf[DataObject], tms))
}
Expand All @@ -508,8 +514,12 @@ object TeamSums {

}
case class TeamSums(override val groupKey: DataObject, teamRows: List[GroupLeaf[Team]]) extends GroupSection {
/**
* used to filter teams in scores, only if they've results. Therefore, the aggregateFn isn't relevant for that.
*/
override val sum: Resultat = teamRows.map(_.sum).reduce(_ + _)
override val avg: Resultat = sum / teamRows.size

def getTeam(gl: GroupLeaf[Team]) = gl.groupKey
def getTeamGroupLeaf(team: Team): GroupLeaf[Team] = teamRows.find(t => t.groupKey.equals(team)).get

Expand Down Expand Up @@ -544,7 +554,8 @@ case class TeamSums(override val groupKey: DataObject, teamRows: List[GroupLeaf[
(getTeam(x), x)
}.map { x =>
val (team, teamRow) = x
(team, teamRow.mapToAvgRowSummary(team.countingWertungen.flatMap(_._2)))
val teamwertungen = team.countingWertungen.flatMap(_._2)
(team, teamRow.mapToAvgRowSummary(teamwertungen))
}

(for (teamRuleGroup <- avgPerTeams.groupBy(_._1.rulename)) yield {
Expand All @@ -571,11 +582,11 @@ case class TeamSums(override val groupKey: DataObject, teamRows: List[GroupLeaf[
}

avgPerTeam.map { x =>
val (team, (sum, avg, wd, wp, gsum)) = x
val (team, (sum, teamTotalScore, wd, wp, gsum)) = x
val gsrang = rangMap(team)
val gs = mapToTeamSum(team, wd)

TeamRow(team, gs, avg, gsrang.rang,
TeamRow(team, gs, teamTotalScore, gsrang.rang,
gsrang.rang.endnote > 0 && gsrang.rang.endnote < 4
)

Expand Down
Loading

0 comments on commit d459243

Please sign in to comment.