Skip to content

Commit

Permalink
Merge pull request #263 from moeyashi/feature/261
Browse files Browse the repository at this point in the history
feat(stats): 結果の四捨五入とログ
  • Loading branch information
moeyashi authored Dec 16, 2024
2 parents 395c2c2 + 6a6c89e commit 1ebd7d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
13 changes: 13 additions & 0 deletions src/infra/repository/nita.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const postgresNitaRepository = () => {
}));
},
async selectStats(trackCode, wrMilliseconds) {
console.info(trackCode, wrMilliseconds);
const results = await sql`
SELECT
count(*) as total,
Expand All @@ -139,6 +140,18 @@ export const postgresNitaRepository = () => {
FROM nita
WHERE track_code = ${trackCode}
`;
console.info(`
SELECT
count(*) as total,
SUM(CASE WHEN milliseconds < ${wrMilliseconds + 1000} THEN 1 ELSE 0 END) as rank1,
SUM(CASE WHEN milliseconds >= ${wrMilliseconds + 1000} AND milliseconds < ${wrMilliseconds + 2000} THEN 1 ELSE 0 END) as rank2,
SUM(CASE WHEN milliseconds >= ${wrMilliseconds + 2000} AND milliseconds < ${wrMilliseconds + 3000} THEN 1 ELSE 0 END) as rank3,
SUM(CASE WHEN milliseconds >= ${wrMilliseconds + 3000} AND milliseconds < ${wrMilliseconds + 4000} THEN 1 ELSE 0 END) as rank4,
SUM(CASE WHEN milliseconds >= ${wrMilliseconds + 4000} AND milliseconds < ${wrMilliseconds + 5000} THEN 1 ELSE 0 END) as rank5,
SUM(CASE WHEN milliseconds >= ${wrMilliseconds + 5000} THEN 1 ELSE 0 END) as over
FROM nita
WHERE track_code = ${trackCode}
`);
return {
total: Number(results[0].total),
rank1: Number(results[0].rank1),
Expand Down
13 changes: 7 additions & 6 deletions src/slash-command/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default {
}

const stats = await nitaRepository.selectStats(track.code, toMilliseconds(track.nitaVSWRMilliseconds));
console.info(stats);

await interaction.reply({
embeds: [
Expand All @@ -30,27 +31,27 @@ export default {
fields: [
{
name: '1落ち',
value: `${(stats.rank1 / stats.total) * 100}%`,
value: `${Math.round((stats.rank1 / stats.total) * 100 * 10) / 10}%`,
},
{
name: '2落ち',
value: `${(stats.rank2 / stats.total) * 100}%`,
value: `${Math.round((stats.rank2 / stats.total) * 100 * 10) / 10}%`,
},
{
name: '3落ち',
value: `${(stats.rank3 / stats.total) * 100}%`,
value: `${Math.round((stats.rank3 / stats.total) * 100 * 10) / 10}%`,
},
{
name: '4落ち',
value: `${(stats.rank4 / stats.total) * 100}%`,
value: `${Math.round((stats.rank4 / stats.total) * 100 * 10) / 10}%`,
},
{
name: '5落ち',
value: `${(stats.rank5 / stats.total) * 100}%`,
value: `${Math.round((stats.rank5 / stats.total) * 100 * 10) / 10}%`,
},
{
name: '6落以上',
value: `${(stats.over / stats.total) * 100}%`,
value: `${Math.round((stats.over / stats.total) * 100 * 10) / 10}%`,
},
],
},
Expand Down

0 comments on commit 1ebd7d7

Please sign in to comment.