Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/pages/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,19 @@ const Admin: NextPage = () => {
modifyCodeSubmissions(false);
};

const aggregateMatchesByMinute = (matches: Match[]) => {
if (!matches) {
const aggregateMatchesByMinute = (matchArr: Match[]) => {
if (!matchArr) {
return [];
}
const matchesProcessed = matchArr
.map((elem) => ({
timestamp: new Date(elem.timestamp),
}))
.sort((a, b) => (a.timestamp > b.timestamp ? 1 : -1));

const aggregatedData: { [id: string]: number } = {};
matches.forEach((item: Match) => {
const minute = new Date(item.timestamp).toLocaleString('en-US', {
matchesProcessed.forEach((item) => {
const minute = item.timestamp.toLocaleString('en-US', {
month: 'numeric',
day: 'numeric',
hour: 'numeric',
Expand All @@ -248,6 +254,7 @@ const Admin: NextPage = () => {
time,
matches: aggregatedData[time],
}));

return chartData;
};

Expand Down
17 changes: 11 additions & 6 deletions src/pages/api/admin/admin-match-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,18 @@ function processData(items: Record<string, AttributeValue>[] | undefined) {

const procItems = items.map((item: Record<string, AttributeValue>) => ({
id: item.match_id ? item.match_id.N?.toString() : '-1',
player1:
item.players && item.players.L && item.players.L[0] && item.players.L[0].M
? item.players.L[0].M.teamName.S
: 'unknown',
player1: item.sk ? item.sk.S?.slice(5) : 'unknown',
/* eslint-disable no-nested-ternary */
player2:
item.players && item.players.L && item.players.L[1] && item.players.L[1].M
? item.players.L[1].M.teamName.S
item.players &&
item.players.L &&
item.players.L[0] &&
item.players.L[0].M &&
item.players.L[1] &&
item.players.L[1].M
? item.players.L[0].M.current.BOOL
? item.players.L[1].M.teamName.S
: item.players.L[0].M.teamName.S
: 'unknown',
category: item.category ? item.category.S : 'unknown',
map: item.map && item.map.S ? item.map.S : 'unknown',
Expand Down