-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework PP to use Phoenix score, rework all calculations, rework Ranking
- Loading branch information
Showing
30 changed files
with
1,291 additions
and
452 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export const mix = 26; // XX | ||
export const mix = 27; // phoenix | ||
export const minMixToGetPp = 25; // prime2, xx, phoenix + |
75 changes: 75 additions & 0 deletions
75
packages/api/src/controllers/charts/difficultyInterpolation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { db } from 'db'; | ||
import type { Response, Request, NextFunction } from 'express'; | ||
import _ from 'lodash/fp'; | ||
import { | ||
getInterpolatedDifficultyPerChartInstance, | ||
updateChartsDifficulty, | ||
} from 'services/charts/chartDifficultyInterpolation'; | ||
|
||
export const difficultyInterpolationController = async ( | ||
request: Request, | ||
response: Response, | ||
next: NextFunction | ||
) => { | ||
try { | ||
const interpolatedDiffs = await getInterpolatedDifficultyPerChartInstance(); | ||
|
||
const chartLevels = ( | ||
await db | ||
.selectFrom('chart_instances') | ||
.leftJoin('tracks', 'chart_instances.track', 'tracks.id') | ||
.select([ | ||
'chart_instances.id as chart_instance_id', | ||
'chart_instances.shared_chart as shared_chart_id', | ||
'chart_instances.level', | ||
'chart_instances.mix', | ||
'tracks.full_name', | ||
'chart_instances.label', | ||
]) | ||
.where('mix', '>=', 25) | ||
.where('chart_instances.level', 'is not', null) | ||
.execute() | ||
) | ||
.map((chart) => { | ||
return { | ||
...chart, | ||
interpolated: interpolatedDiffs[chart.chart_instance_id]?.difficulty, | ||
}; | ||
}) | ||
.filter((ch) => ch.interpolated && ch.level) | ||
.sort((a, b) => { | ||
return Math.abs(b.level! - b.interpolated) - Math.abs(a.level! - a.interpolated); | ||
}); | ||
|
||
const bySharedChart = _.flow( | ||
_.groupBy((ch: (typeof chartLevels)[number]) => ch.shared_chart_id), | ||
(z) => _.toPairs(z), | ||
_.map(([, charts]) => ({ | ||
charts, | ||
amplitude: Math.max( | ||
Math.max(...charts.map((c) => c.interpolated)) - | ||
Math.min(...charts.map((c) => c.interpolated)), | ||
Math.max(...charts.map((c) => (c.level ? Math.abs(c.level - c.interpolated) : 0))) | ||
), | ||
})), | ||
_.orderBy('amplitude', 'desc') | ||
)(chartLevels); | ||
|
||
response.json(bySharedChart); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; | ||
|
||
export const updateChartsDifficultyController = async ( | ||
request: Request, | ||
response: Response, | ||
next: NextFunction | ||
) => { | ||
try { | ||
await updateChartsDifficulty(); | ||
response.json({ success: true }); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Response, Request, NextFunction } from 'express'; | ||
import _ from 'lodash/fp'; | ||
import { calculateResultsPp } from 'services/results/resultsPp'; | ||
|
||
export const sharedChartPpController = async ( | ||
request: Request, | ||
response: Response, | ||
next: NextFunction | ||
) => { | ||
try { | ||
const resultPpMap = await calculateResultsPp({ | ||
sharedChartId: Number(request.params.sharedChartId), | ||
}); | ||
response.json(Object.fromEntries(resultPpMap.entries())); | ||
} catch (error) { | ||
next(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/api/src/jobs/chartDifficulty/chartDifficultyJob.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import createDebug from 'debug'; | ||
import cron from 'node-cron'; | ||
import { updateChartsDifficulty } from 'services/charts/chartDifficultyInterpolation'; | ||
|
||
const debug = createDebug('backend-ts:jobs:chart-difficulty'); | ||
|
||
// Every day at 4 AM | ||
cron.schedule('0 4 * * *', async () => { | ||
debug('Starting job: Recalculate chart difficulty and all pp'); | ||
await updateChartsDifficulty(); | ||
debug('Job finished: Recalculate chart difficulty and all pp'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './chartDifficulty/chartDifficultyJob'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,48 @@ | ||
import { Router } from 'express'; | ||
|
||
import { | ||
difficultyInterpolationController, | ||
updateChartsDifficultyController, | ||
} from 'controllers/charts/difficultyInterpolation'; | ||
import { searchChartsController } from 'controllers/charts/search'; | ||
import { sharedChartPpController } from 'controllers/charts/sharedChartPp'; | ||
import { Router } from 'express'; | ||
import { validate } from 'utils'; | ||
|
||
const router = Router(); | ||
|
||
/** | ||
* GET /charts/search | ||
* GET /charts/interpolated-difficulty | ||
* @summary Search charts with filters | ||
* @tags charts | ||
* @return {array<object>} 200 - success response - application/json | ||
*/ | ||
router.get('/interpolated-difficulty', difficultyInterpolationController); | ||
|
||
/** | ||
* GET /charts/refresh-difficulty | ||
* @summary Update charts difficulty and update all scores | ||
* @tags charts | ||
* @return {array<object>} 200 - success response - application/json | ||
*/ | ||
router.get('/refresh-difficulty', updateChartsDifficultyController); | ||
|
||
/** | ||
* GET /charts/recalc-diff | ||
* @summary Recalculate difficulty | ||
* @tags charts | ||
* @return {array<object>} 200 - success response - application/json | ||
*/ | ||
router.get('/search', searchChartsController); | ||
|
||
/** | ||
* GET /charts/:sharedChartId/pp | ||
* @summary Recalculate pp for chart | ||
* @tags charts pp | ||
* @return {array<object>} 200 - success response - application/json | ||
*/ | ||
router.get( | ||
'/:sharedChartId/pp', | ||
validate({ params: { sharedChartId: 'required|integer' } }), | ||
sharedChartPpController | ||
); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.