ok stop
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Game, type Score } from './interfaces';
|
import { Game, type GameRatingData, type Score } from './interfaces';
|
||||||
import { storedGames } from './store';
|
import { storedGames } from './store';
|
||||||
export const ssr = false;
|
export const ssr = false;
|
||||||
let gameEditing = '';
|
let gameEditing = '';
|
||||||
@@ -9,9 +9,21 @@
|
|||||||
$storedGames[$storedGames.length - 1];
|
$storedGames[$storedGames.length - 1];
|
||||||
$: currentScoreEditing = scoreEditing > -1 ? currentGameEditing.scores[scoreEditing] : null;
|
$: currentScoreEditing = scoreEditing > -1 ? currentGameEditing.scores[scoreEditing] : null;
|
||||||
$: gamesComplete = $storedGames.filter((g) => g.isComplete);
|
$: gamesComplete = $storedGames.filter((g) => g.isComplete);
|
||||||
|
$: gamesCompletedWithRating = calculateRatingForGames(gamesComplete);
|
||||||
$: completedStats = calculateTotalGameStats(gamesComplete);
|
$: completedStats = calculateTotalGameStats(gamesComplete);
|
||||||
$: disableEditing = currentGameEditing.isComplete && scoreEditing === -1;
|
$: disableEditing = currentGameEditing.isComplete && scoreEditing === -1;
|
||||||
$: storedGames;
|
$: storedGames;
|
||||||
|
function calculateRatingForGames(games: Game[]): GameRatingData[] {
|
||||||
|
return games.map((g, index) => {
|
||||||
|
const allGamesFromThisPointBack = games.slice(0, index + 1);
|
||||||
|
const totalRating = calculateRating(allGamesFromThisPointBack);
|
||||||
|
return {
|
||||||
|
game: g,
|
||||||
|
rating: calculateRating([g]),
|
||||||
|
totalRating: totalRating ? Math.round(totalRating * 10000) / 10000 : 0
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
function isKill(score: Score | undefined | null) {
|
function isKill(score: Score | undefined | null) {
|
||||||
return score === 'killHit6' || score === 'killHit8' || score === 'killMiss';
|
return score === 'killHit6' || score === 'killHit8' || score === 'killMiss';
|
||||||
}
|
}
|
||||||
@@ -57,6 +69,20 @@
|
|||||||
const totalScore = gamesToCalculate.reduce((acc, g) => acc + g.totalScore, 0);
|
const totalScore = gamesToCalculate.reduce((acc, g) => acc + g.totalScore, 0);
|
||||||
return totalScore / gamesToCalculate.length;
|
return totalScore / gamesToCalculate.length;
|
||||||
}
|
}
|
||||||
|
function checkDiff(games: GameRatingData[], targetGameIndex: number): '👆' | '👇' | '-' {
|
||||||
|
const targetGame = games[targetGameIndex];
|
||||||
|
const previousGame = games[targetGameIndex - 1];
|
||||||
|
if (!previousGame) {
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
if (targetGame.totalRating > previousGame.totalRating) {
|
||||||
|
return '👆';
|
||||||
|
}
|
||||||
|
if (targetGame.totalRating < previousGame.totalRating) {
|
||||||
|
return '👇';
|
||||||
|
}
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
function calculateRating(gamesToCalculate: Game[]): number {
|
function calculateRating(gamesToCalculate: Game[]): number {
|
||||||
const totalGames = gamesToCalculate.length;
|
const totalGames = gamesToCalculate.length;
|
||||||
|
|
||||||
@@ -121,10 +147,15 @@
|
|||||||
totalScore: number;
|
totalScore: number;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
const rating = calculateRating(gamesToCalc);
|
||||||
return {
|
return {
|
||||||
...stats,
|
...stats,
|
||||||
average: stats.totalScore && gamesToCalc.length ? stats.totalScore / gamesToCalc.length : 0,
|
average:
|
||||||
rating: calculateRating(gamesToCalc)
|
stats.totalScore && gamesToCalc.length
|
||||||
|
? Math.round((stats.totalScore / gamesToCalc.length) * 10000) / 10000
|
||||||
|
: 0,
|
||||||
|
rating: rating ? Math.round(rating * 100) / 100 : 0,
|
||||||
|
totalGames: gamesToCalc.length
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
function getLabelForScore(score: Score) {
|
function getLabelForScore(score: Score) {
|
||||||
@@ -279,6 +310,7 @@
|
|||||||
<button on:click={deleteAllGames}>Delete All</button><br /><br />
|
<button on:click={deleteAllGames}>Delete All</button><br /><br />
|
||||||
<p>
|
<p>
|
||||||
Rating: {completedStats.rating} <br />
|
Rating: {completedStats.rating} <br />
|
||||||
|
Games: {completedStats.totalGames} <br />
|
||||||
Average: {completedStats.average} <br />
|
Average: {completedStats.average} <br />
|
||||||
Kills: {completedStats.kills} <br />
|
Kills: {completedStats.kills} <br />
|
||||||
Bulls: {completedStats.bulls} <br />
|
Bulls: {completedStats.bulls} <br />
|
||||||
@@ -294,12 +326,14 @@
|
|||||||
<th>Kills 8</th>
|
<th>Kills 8</th>
|
||||||
<th>Kills 6</th>
|
<th>Kills 6</th>
|
||||||
<th>Drops</th>
|
<th>Drops</th>
|
||||||
|
<th>Rating</th>
|
||||||
|
<th>Total Rating</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each $storedGames as game, gameIndex}
|
{#each gamesCompletedWithRating as { game, rating, totalRating }, gameIndex}
|
||||||
{#if game.isComplete || (!game.isComplete && currentGameEditing !== game)}
|
{#if game.isComplete || (!game.isComplete && currentGameEditing !== game)}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="tdSmall">{gameIndex + 1}</td>
|
<td class="tdSmall">{gameIndex + 1}</td>
|
||||||
@@ -308,6 +342,10 @@
|
|||||||
<td class="tdSmall">{game.stats.totalEightKills}</td>
|
<td class="tdSmall">{game.stats.totalEightKills}</td>
|
||||||
<td class="tdSmall">{game.stats.totalSixKills}</td>
|
<td class="tdSmall">{game.stats.totalSixKills}</td>
|
||||||
<td class="tdSmall">{game.stats.drops}</td>
|
<td class="tdSmall">{game.stats.drops}</td>
|
||||||
|
<td class="tdSmall">{rating}</td>
|
||||||
|
<td class="tdSmall"
|
||||||
|
>{checkDiff(gamesCompletedWithRating, gameIndex)} {totalRating}</td
|
||||||
|
>
|
||||||
<td
|
<td
|
||||||
><button
|
><button
|
||||||
disabled={game === currentGameEditing}
|
disabled={game === currentGameEditing}
|
||||||
@@ -343,17 +381,19 @@
|
|||||||
.stats {
|
.stats {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
margin-bottom: 2rem;
|
||||||
}
|
}
|
||||||
.center {
|
.center {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
.flexrow {
|
.flexrow {
|
||||||
display: flex;
|
display: grid;
|
||||||
flex-direction: row;
|
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
|
||||||
gap: 0.5rem;
|
row-gap: 0.5rem;
|
||||||
|
column-gap: 0.75rem;
|
||||||
min-height: 7rem;
|
min-height: 7rem;
|
||||||
flex-wrap: wrap;
|
width: fit-content;
|
||||||
}
|
}
|
||||||
.flexrowButton {
|
.flexrowButton {
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ export interface GameStats {
|
|||||||
drops: number;
|
drops: number;
|
||||||
bulls: number;
|
bulls: number;
|
||||||
}
|
}
|
||||||
|
export interface GameRatingData {
|
||||||
|
game: Game;
|
||||||
|
rating: number;
|
||||||
|
totalRating: number;
|
||||||
|
}
|
||||||
export interface IStoredGame {
|
export interface IStoredGame {
|
||||||
scores: Score[];
|
scores: Score[];
|
||||||
stats: GameStats;
|
stats: GameStats;
|
||||||
|
|||||||
Reference in New Issue
Block a user