Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate results for series in administration #256

Merged
merged 4 commits into from
Dec 9, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.actions {
margin-top: .5rem;
display: flex;
justify-content: flex-end;
justify-content: flex-start;
column-gap: 20px;
}
27 changes: 21 additions & 6 deletions src/components/SemesterAdministration/SemesterAdministration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ export const SemesterAdministration: FC = () => {

const [textareaContent, setTextareaContent] = useState('')

const getSemesterResults = async () => {
const {data} = await axios.get<Result[]>(`/api/competition/semester/${semesterId}/results`)
const getResults = async (seriesId: number | null) => {
const isSemester = seriesId === null
const {data} = await axios.get<Result[]>(
isSemester ? `/api/competition/semester/${semesterId}/results` : `/api/competition/series/${seriesId}/results`,
)
setTextareaContent(
data
.map((result: Result) => {
Expand All @@ -55,9 +58,14 @@ export const SemesterAdministration: FC = () => {
}
}
const name = `${result.registration.profile.first_name} ${result.registration.profile.last_name}`
const subtotal = result.subtotal[0]
const points = result.solutions[1].map((problem) => problem.points).join('&')
return `${rank}&${name}&${result.registration.school.abbreviation}&${result.registration.grade}&${subtotal}&${points}&${result.total}\\\\`
if (isSemester) {
const subtotal = result.subtotal[0]
const points = result.solutions[1].map((problem) => problem.points).join('&')
return `${rank}&${name}&${result.registration.school.abbreviation}&${result.registration.grade}&${subtotal}&${points}&${result.total}\\\\`
} else {
const points = result.solutions[0].map((problem) => problem.points).join('&')
return `${rank}&${name}&${result.registration.school.abbreviation}&${result.registration.grade}&${points}&${result.total}\\\\`
}
})
.join('\n'),
)
Expand Down Expand Up @@ -110,7 +118,14 @@ export const SemesterAdministration: FC = () => {
))}
<h3>Generovanie dát</h3>
<div className={styles.actions}>
<Button onClick={getSemesterResults}>Poradie série</Button>
{[...semester.series_set].reverse().map((series) => (
<div key={series.id}>
<Button onClick={() => getResults(series.id)}>Poradie {series.order}. série</Button>
</div>
))}
<Button onClick={() => getResults(null)}>Poradie semestra</Button>
</div>
<div className={styles.actions}>
<Button onClick={() => getPostalCards(false)}>Štítky na školy</Button>
<Button onClick={() => getPostalCards(true)}>Štítky na školy (iba papierové riešenia)</Button>
<Link href={`/api/competition/semester/${semesterId}/participants-export/`}>Zoznam riešiteľov</Link>
Expand Down
2 changes: 1 addition & 1 deletion src/types/api/generated/competition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export interface Series {
}

export interface SeriesWithProblems {
id?: number
id: number
can_participate?: any
is_registered?: any
problems: Problem[]
Expand Down
Loading