Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #936: Way to calculate proportion of points with same coordinate #940

Merged
merged 7 commits into from
Nov 22, 2023
Next Next commit
Add SUMPROP and SUMPCT variables to the AbstractCountStat.
  • Loading branch information
ASmirnov-HORIS committed Nov 22, 2023
commit 7ba2cb9bd1ea20b92c0a905d2b7781ffcbba1e97
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,19 @@ abstract class AbstractCountStat(
// compute total location weights on the whole data
val summary = groupAndSum(locations, weights)
val totalWeights = locations.map { summary[it]!! }
val totalWeightsSum = summary.values.sum()

val prop = weights.zip(totalWeights).map { (groupWeight, totalWeight) -> groupWeight / totalWeight }
val propPercent = prop.map { it * 100 }
val sumProp = totalWeights.map { it / totalWeightsSum }
val sumPropPercent = sumProp.map { it * 100 }

val statDf = dataAfterStat.builder()
statDf.putNumeric(Stats.SUM, totalWeights)
statDf.putNumeric(Stats.PROP, prop)
statDf.putNumeric(Stats.PROPPCT, propPercent)
statDf.putNumeric(Stats.SUMPROP, sumProp)
statDf.putNumeric(Stats.SUMPCT, sumPropPercent)
return statDf.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ object Stats {
val SUM = DataFrame.Variable("..sum..", STAT, "sum")
val PROP = DataFrame.Variable("..prop..", STAT, "prop")
val PROPPCT = DataFrame.Variable("..proppct..", STAT, "proppct")
val SUMPROP = DataFrame.Variable("..sumprop..", STAT, "sumprop")
val SUMPCT = DataFrame.Variable("..sumpct..", STAT, "sumpct")

val SCALED = DataFrame.Variable("..scaled..", STAT, "scaled")

Expand Down Expand Up @@ -66,6 +68,8 @@ object Stats {
SUM,
PROP,
PROPPCT,
SUMPROP,
SUMPCT,
SCALED,
GROUP,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ internal object TooltipFormatting {

fun createFormatter(variable: DataFrame.Variable): (Any) -> String {
return when (variable) {
Stats.PROP -> StringFormat.forOneArg(".2f", formatFor = variable.name)::format
Stats.PROPPCT -> StringFormat.forOneArg("{.1f} %", formatFor = variable.name)::format
Stats.PROP,
Stats.SUMPROP -> StringFormat.forOneArg(".2f", formatFor = variable.name)::format
Stats.PROPPCT,
Stats.SUMPCT -> StringFormat.forOneArg("{.1f} %", formatFor = variable.name)::format
else -> { value -> value.toString() }
}
}
Expand Down