Skip to content

Commit

Permalink
Merge pull request #731 from elmadev/dev
Browse files Browse the repository at this point in the history
Live release 6 Jan 2025
  • Loading branch information
sunehs authored Jan 6, 2025
2 parents 0f88037 + ef1c09c commit 30774a4
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 39 deletions.
34 changes: 26 additions & 8 deletions src/api/allfinished.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,10 @@ const getLeaderHistoryForLevel = async (
BattleIndex,
from,
to,
UserId,
) => {
const personal = UserId === parseInt(KuskiIndex, 10);

// Check that level isn't locked or hidden
const lev = await levelInfo(LevelIndex);
if (lev.Locked || lev.Hidden) {
Expand Down Expand Up @@ -285,20 +288,29 @@ const getLeaderHistoryForLevel = async (
});

// Populate leader history with extra data
const include = [
{
model: Kuski,
as: 'KuskiData',
attributes: ['Kuski'],
},
];

if (personal) {
include.push({
model: TimeFile,
as: 'TimeFileData',
});
}

const leaderHistoryWithData = await AllFinished.findAll({
attributes: ['TimeIndex', 'Time', 'Driven'],
attributes: personal ? undefined : ['TimeIndex', 'Time', 'Driven'],
where: {
TimeIndex: {
[Op.in]: leaderHistory.map(r => r.TimeIndex),
},
},
include: [
{
model: Kuski,
as: 'KuskiData',
attributes: ['Kuski'],
},
],
include,
});

return leaderHistoryWithData;
Expand Down Expand Up @@ -336,12 +348,18 @@ router
res.json(data);
})
.get('/leaderhistory/:LevelIndex', async (req, res) => {
const auth = authContext(req);
let UserId = 0;
if (auth.auth) {
UserId = auth.userid;
}
const data = await getLeaderHistoryForLevel(
req.params.LevelIndex,
req.query.KuskiIndex,
req.query.BattleIndex,
req.query.from,
req.query.to,
UserId,
);
res.json(data);
})
Expand Down
22 changes: 21 additions & 1 deletion src/api/cups.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ const router = express.Router();
const getCups = async (ongoing = false) => {
const query = {
where: { Hidden: 0 },
attributes: {
include: [
[
sequelize.literal(
'(SELECT MIN(StartTime) FROM sitecup WHERE sitecup.CupGroupIndex = sitecupgroup.CupGroupIndex)',
),
'StartTime',
],
[
sequelize.literal(
'(SELECT MAX(EndTime) FROM sitecup WHERE sitecup.CupGroupIndex = sitecupgroup.CupGroupIndex)',
),
'EndTime',
],
],
},
};
if (ongoing) {
query.where.Finished = 0;
Expand Down Expand Up @@ -62,7 +78,11 @@ const getCups = async (ongoing = false) => {
];
}
const data = await SiteCupGroup.findAll(query);
return data;
return data.map(cup => ({
...cup.dataValues,
StartTime: moment(cup.dataValues.StartTime).format('X'),
EndTime: moment(cup.dataValues.EndTime).format('X'),
}));
};

const getCupById = async CupGroupIndex => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/levelstats.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ router
// if (req.params.type === 'pack') {}

const stats = await Level.findAll({
where: { LevelIndex: ids },
where: { LevelIndex: ids, Hidden: 0 },
attributes: ['LevelIndex', 'LevelName', 'LongName', 'Locked', 'Hidden'],
include: [
{
Expand Down
5 changes: 5 additions & 0 deletions src/data/models/SiteCup.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ const SiteCup = Model.define(
allowNull: true,
defaultValue: null,
},
Multiplier: {
type: DataType.INTEGER,
allowNull: false,
defaultValue: 0,
},
},
{
indexes: [{ fields: ['CupGroupIndex, LevelIndex, Designer'] }],
Expand Down
25 changes: 2 additions & 23 deletions src/dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ app.get('/shirt/:id', async (req, res, next) => {
}
});

app.get('/cupreplay/:id/:filename', async (req, res, next) => {
app.get('/cupreplay/:id/:filename/:code?', async (req, res, next) => {
try {
const { file, filename, MD5, UUID, TimeIndex } = await getReplayByCupTimeId(
req.params.id,
req.params.filename,
req.params.code,
);
if (MD5 && UUID && TimeIndex) {
res.set({
Expand Down Expand Up @@ -110,28 +111,6 @@ app.get('/cupreplay/:id/:filename', async (req, res, next) => {
}
});

app.get('/cupreplay/:id/:filename/:code', async (req, res, next) => {
try {
const { file, filename } = await getReplayByCupTimeId(
req.params.id,
req.params.filename,
req.params.code,
);
const readStream = new stream.PassThrough();
readStream.end(file);
res.set({
'Content-disposition': `attachment; filename=${filename}`,
'Content-Type': 'application/octet-stream',
});
readStream.pipe(res);
} catch (e) {
next({
status: 403,
msg: e.message,
});
}
});

app.get('/level/:id', async (req, res, next) => {
try {
const { file, filename } = await getLevel(req.params.id);
Expand Down
21 changes: 15 additions & 6 deletions src/utils/cups.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ export const pointsSystem2 = [
17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6,
];

const getPoints = (pos, pointSystem) => {
const getPoints = (pos, pointSystem, eventMultiplier) => {
const multiplier = eventMultiplier ? eventMultiplier : 1;
let pts = points;
if (pointSystem === 1) {
pts = pointsSystem2;
}
if (pts[pos]) {
return pts[pos] * 10;
return pts[pos] * 10 * multiplier;
}
if (pointSystem === 1) {
if (pos > 49 && pos < 100) {
return 109 - pos;
return 109 - pos * multiplier;
}
}
return 10;
return 10 * multiplier;
};

export const filterResults = (events, ownerId = [], loggedId = 0, cupGroup) => {
Expand Down Expand Up @@ -86,14 +87,22 @@ export const filterResults = (events, ownerId = [], loggedId = 0, cupGroup) => {
if (!firstDrawPos) {
firstDrawPos = drawPos + 1;
}
combinedPoints += getPoints(drawPos, cupGroup?.PointSystem);
combinedPoints += getPoints(
drawPos,
cupGroup?.PointSystem,
event.Multiplier,
);
}
const drawPoints = combinedPoints / draws.length;
filteredResults[pos].Points = drawPoints;
filteredResults[pos].Position = firstDrawPos;
} else {
// otherwise assign points normally
filteredResults[pos].Points = getPoints(pos, cupGroup?.PointSystem);
filteredResults[pos].Points = getPoints(
pos,
cupGroup?.PointSystem,
event.Multiplier,
);
filteredResults[pos].Position = pos + 1;
}
});
Expand Down
7 changes: 7 additions & 0 deletions src/utils/recap.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ const cutoffs = {
LevelIndex: [521136, 566340],
ReplayIndex: [4346, 4455, 13676, 16653],
},
2024: {
TimeIndex: [210565301, 224565896],
BattleIndex: [188873, 198085],
ChatIndex: [8673084, 8961618],
LevelIndex: [566339, 583727],
ReplayIndex: [16652, 30832],
},
};

const timeKuski = async year => {
Expand Down

0 comments on commit 30774a4

Please sign in to comment.