Refactor of hit distribution chart to fix incorrect data representation and fix of crash when no slider end timings or keypress timings were present in the score
This commit is contained in:
parent
01bd4e4948
commit
4f49a375d0
@ -32,20 +32,20 @@ class ScoreService(
|
||||
}
|
||||
|
||||
fun getCharts(db: Record): List<ReplayDataChart> {
|
||||
// We only return additional charts if the user is an admin.
|
||||
if (!authService.isAdmin()) {
|
||||
if (!authService.isAdmin())
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
// Slider end chart
|
||||
val sliderEndData = db.get(SCORES.SLIDEREND_RELEASE_TIMES)!!
|
||||
val charts = mutableListOf<ReplayDataChart>()
|
||||
|
||||
val sliderEndReleaseTimes = db.get(SCORES.SLIDEREND_RELEASE_TIMES)
|
||||
if(sliderEndReleaseTimes != null) {
|
||||
val sliderEndData = sliderEndReleaseTimes
|
||||
.filterNotNull()
|
||||
val sliderFrequencyData: List<Pair<Double, Double>> = sliderEndData
|
||||
.groupingBy { it }
|
||||
.eachCount()
|
||||
.map { (value, count) -> Pair(value, count / sliderEndData.size.toDouble() * 100) }
|
||||
|
||||
// Slider end table
|
||||
val sliderEndTable = mutableListOf<Triple<String, String, String>>()
|
||||
|
||||
sliderEndTable.add(Triple(
|
||||
@ -65,18 +65,18 @@ class ScoreService(
|
||||
table = sliderEndTable,
|
||||
data = sliderFrequencyData
|
||||
)
|
||||
charts.add(sliderEndChart)
|
||||
}
|
||||
|
||||
// --------------------
|
||||
|
||||
// Slider end chart
|
||||
val keypressData = db.get(SCORES.KEYPRESSES_TIMES)!!
|
||||
val keypressTimes = db.get(SCORES.KEYPRESSES_TIMES)
|
||||
if(keypressTimes != null) {
|
||||
val keypressData = keypressTimes
|
||||
.filterNotNull()
|
||||
val keypressFrequencyData: List<Pair<Double, Double>> = keypressData
|
||||
.groupingBy { it }
|
||||
.eachCount()
|
||||
.map { (value, count) -> Pair(value, count / keypressData.size.toDouble() * 100) }
|
||||
|
||||
// Slider end table
|
||||
val keypressTable = mutableListOf<Triple<String, String, String>>()
|
||||
|
||||
keypressTable.add(Triple(
|
||||
@ -96,8 +96,10 @@ class ScoreService(
|
||||
table = keypressTable,
|
||||
data = keypressFrequencyData
|
||||
)
|
||||
charts.add(keypressChart)
|
||||
}
|
||||
|
||||
return listOf(sliderEndChart, keypressChart)
|
||||
return charts
|
||||
}
|
||||
|
||||
fun getReplayData(replayId: Long): ReplayData? {
|
||||
|
||||
@ -155,28 +155,27 @@ export class ViewScoreComponent implements OnInit {
|
||||
|
||||
private getChartRange(entries: [string, DistributionEntry][]): [number, number] {
|
||||
const keys = entries.map(([key, _]) => parseInt(key));
|
||||
|
||||
const minKey = Math.min(...keys);
|
||||
const maxKey = Math.max(...keys);
|
||||
|
||||
const absoluteMax = Math.max(Math.abs(minKey), Math.abs(maxKey));
|
||||
return [absoluteMax * -1, absoluteMax];
|
||||
return [minKey, maxKey];
|
||||
}
|
||||
|
||||
private generateLabelsFromEntries(entries: [string, DistributionEntry][]): string[] {
|
||||
const range = this.getChartRange(entries);
|
||||
|
||||
const entriesMap = new Map(entries.map(([key, value]) => [parseInt(key), value]));
|
||||
|
||||
const filledEntries = [];
|
||||
for (let key = range[0]; key <= range[1]; key++) {
|
||||
filledEntries.push([key.toString(), entriesMap.get(key) || 0]);
|
||||
const labelEntries = [];
|
||||
for (let key = range[0]; key <= range[1]; key += 2) {
|
||||
const endKey = key + 2;
|
||||
labelEntries.push(`${key}ms to ${endKey}ms`);
|
||||
}
|
||||
|
||||
return filledEntries.map(([key, _]) => {
|
||||
const start = parseInt(String(key));
|
||||
const end = start + 2;
|
||||
return `${start}ms to ${end}ms`;
|
||||
});
|
||||
if (range[1] % 2 !== range[0] % 2) {
|
||||
labelEntries.push(`${range[1]}ms to ${range[1] + 1}ms`);
|
||||
}
|
||||
|
||||
return labelEntries;
|
||||
}
|
||||
|
||||
private generateChartDataFromEntries(entries: [string, DistributionEntry][], i: number): number[] {
|
||||
@ -191,21 +190,36 @@ export class ViewScoreComponent implements OnInit {
|
||||
|
||||
const entriesMap = new Map<number, DistributionEntry>(entries.map(([key, value]) => [parseInt(key), value]));
|
||||
|
||||
const filledEntries: [number, DistributionEntry][] = [];
|
||||
for (let key = range[0]; key <= range[1]; key++) {
|
||||
filledEntries.push([key, entriesMap.get(key) || { ...defaultPercentageValues }]);
|
||||
const chartData = [];
|
||||
for (let key = range[0]; key <= range[1]; key += 2) {
|
||||
const currentEntry = entriesMap.get(key) || { ...defaultPercentageValues };
|
||||
const nextEntry = entriesMap.get(key + 1) || { ...defaultPercentageValues };
|
||||
|
||||
const sumEntry: DistributionEntry = {
|
||||
percentageMiss: currentEntry.percentageMiss + nextEntry.percentageMiss,
|
||||
percentage50: currentEntry.percentage50 + nextEntry.percentage50,
|
||||
percentage100: currentEntry.percentage100 + nextEntry.percentage100,
|
||||
percentage300: currentEntry.percentage300 + nextEntry.percentage300,
|
||||
};
|
||||
|
||||
chartData.push(sumEntry);
|
||||
}
|
||||
|
||||
// Handle the case where the last key is not included because of an odd number of total keys
|
||||
if (range[1] % 2 !== range[0] % 2) {
|
||||
const lastEntry = entriesMap.get(range[1]) || { ...defaultPercentageValues };
|
||||
chartData.push(lastEntry);
|
||||
}
|
||||
|
||||
const propertyMap = ['percentageMiss', 'percentage50', 'percentage100', 'percentage300'];
|
||||
|
||||
if (i >= 0 && i < propertyMap.length) {
|
||||
return filledEntries.map(([, value]) => value[propertyMap[i] as keyof DistributionEntry]);
|
||||
return chartData.map(entry => entry[propertyMap[i] as keyof DistributionEntry]);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
protected readonly Object = Object;
|
||||
|
||||
protected readonly calculateAccuracy = calculateAccuracy;
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user