Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorndown committed Feb 7, 2024
1 parent 75e75d4 commit 955098b
Show file tree
Hide file tree
Showing 19 changed files with 654 additions and 415 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
basePath: process.env.NODE_ENV === 'production' ? '/zuweiser' : '',
basePath: process.env.GITHUB_ACTIONS === 'true' ? '/zuweiser' : '',
}
6 changes: 3 additions & 3 deletions src/components/Activities.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export const Activities = ({ onChange }: Props) => {
const isIdColumn = (column: string) => column.toLowerCase() === 'id'
const isTitleColumn = (column: string) =>
column.toLowerCase().startsWith('name') ||
column.toLowerCase().startsWith('title')
column.toLowerCase().startsWith('titel')
const isLimitColumn = (column: string) =>
column.toLowerCase().startsWith('limit') ||
column.toLowerCase().includes('limit') ||
column.toLowerCase().includes('max')
const isMinimumColumn = (column: string) =>
column.toLowerCase().startsWith('minimum')
column.toLowerCase().includes('minimum')

const columnHeads = useMemo(() => table?.[0] ?? [], [table])
const rows = useMemo(() => table?.slice(1) ?? [], [table])
Expand Down
3 changes: 0 additions & 3 deletions src/components/CapacityCheck.module.css

This file was deleted.

4 changes: 1 addition & 3 deletions src/components/CapacityCheck.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export const CapacityCheck: FunctionComponent<Props> = ({
activitiesConfig
}) => {
const minimumCapacity = useMemo(
() =>
participantsConfig.participants.length *
participantsConfig.activitiesPerPerson,
() => participantsConfig.participants.length,
[activitiesConfig, participantsConfig]
)
const actualCapacity = useMemo(() => {
Expand Down
55 changes: 48 additions & 7 deletions src/components/MatchedActivity.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
import { FunctionComponent } from 'react'
import type { AssignableActivity } from '../core/model'
import { FunctionComponent, useMemo } from 'react'
import {
AssignableActivity,
AssignableParticipant,
ParticipantsConfig
} from '../core/model'

type Props = {
activity: AssignableActivity
participantsData: Record<string, string[]>
participantsConfig: ParticipantsConfig
}

export const MatchedActivity: FunctionComponent<Props> = ({
activity,
participantsData
participantsData,
participantsConfig
}) => {
const participants: {
participant: AssignableParticipant
execution: number
}[] = useMemo(
() =>
Array.from(activity.allParticipants()).map((participants) => ({
participant: participants,
execution: participants.activities.find(
(value) => value.activity.id === activity.id
).execution
})),
[activity]
)

const buildActivityResultHeader = (activity: AssignableActivity) =>
`${activity.title} (${activity.participants.length} / ${activity.limit})`
`${activity.title} (${participants.length} / ${activity.limit * participantsConfig.activitiesPerPerson})`

const getOtherPriorities = (
participant: AssignableParticipant
): string | undefined => {
return participant.activities
.filter((value) => value.activity.id !== activity.id)
.map(
({ activity, execution }) => `${activity.title} (Prio ${participant.priorities.indexOf(activity.id) + 1})`
)
.join(', ')
}

return (
<article
Expand All @@ -26,19 +58,28 @@ export const MatchedActivity: FunctionComponent<Props> = ({
<th />
<th />
<th>Priorität</th>
{participantsConfig.activitiesPerPerson > 1 && (
<th>Durchführung</th>
)}
</tr>
</thead>
<tbody>
{activity.participants.map((participant, index) => (
<tr key={`participant-${participant.id}`}>
{participants.map(({ participant, execution }, index) => (
<tr
key={`participant-${participant.id}`}
title={`Andere Kurse: ${getOtherPriorities(participant)}`}
>
<td>{index + 1}</td>
{participantsData[participant.id].map((p, i) => (
{participantsData[participant.id]?.map((p, i) => (
<td key={`property-${i}`}>{p}</td>
))}
<td className="priority-column">
{participant.priorities.indexOf(activity.id) +
1}
</td>
{participantsConfig.activitiesPerPerson > 1 && (
<td>{execution}</td>
)}
</tr>
))}
</tbody>
Expand Down
3 changes: 2 additions & 1 deletion src/components/Message.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.container {
padding: 0.3rem 0.2rem;
padding: 0.35rem 0.5rem;
border-radius: 0.25rem;
}
2 changes: 1 addition & 1 deletion src/components/Message.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FunctionComponent, PropsWithChildren } from 'react'
import classNames from 'classnames'
import styles from './CapacityCheck.module.css'
import styles from './Message.module.css'

type Props = {
type: 'ok' | 'bad' | 'warn'
Expand Down
6 changes: 2 additions & 4 deletions src/components/Participants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Participants = ({ onChange }: Props) => {

const isIdColumn = (column: string) => column.toLowerCase() === 'id'
const isPriorityColumn = (column: string) =>
column.toLowerCase().startsWith('prio')
column.toLowerCase().includes('prio') || column.toLowerCase().includes('wahl')

const columnHeads = useMemo(() => table?.[0] ?? [], [table])
const rows = useMemo(() => table?.slice(1) ?? [], [table])
Expand All @@ -56,9 +56,7 @@ export const Participants = ({ onChange }: Props) => {
return []
}

const priorityColumns = columnHeads.filter((columnHead) =>
columnHead.toLowerCase().startsWith('prio')
)
const priorityColumns = columnHeads.filter(isPriorityColumn)
return columnHeads.map((column) => {
if (isIdColumn(column)) {
return { label: column, matchedAsLabel: 'ID', matchedAs: 'id' }
Expand Down
8 changes: 6 additions & 2 deletions src/components/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ import { FunctionComponent } from 'react'
import type { MatchResult } from '../core/matcher'
import { UnassignableParticipants } from './UnassignableParticipants'
import { MatchedActivity } from './MatchedActivity'
import {ParticipantsConfig} from '../core/model'

type Props = {
result: MatchResult
participantsData: Record<string, string[]>
participantsConfig: ParticipantsConfig
}

export const Results: FunctionComponent<Props> = ({
result,
participantsData
participantsData, participantsConfig
}) => {
return (
<div>
<h2>Resultat</h2>
<Statistics result={result} />
<Statistics result={result} particpantsConfig={participantsConfig} />
<UnassignableParticipants
result={result}
participantsData={participantsData}
participantsConfig={participantsConfig}
/>

<section>
Expand All @@ -30,6 +33,7 @@ export const Results: FunctionComponent<Props> = ({
key={`activity-${activity.id}`}
activity={activity}
participantsData={participantsData}
participantsConfig={participantsConfig}
/>
))}
</div>
Expand Down
71 changes: 50 additions & 21 deletions src/components/Statistics.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import { BarChart } from './BarChart'
import { MatchResult } from '../core/matcher'
import { FunctionComponent } from 'react'
import _range from 'lodash/range'
import { ParticipantsConfig } from '../core/model'

type Props = {
result: MatchResult
particpantsConfig: ParticipantsConfig
}

export const Statistics: FunctionComponent<Props> = ({ result }) => {
export const Statistics: FunctionComponent<Props> = ({
result,
particpantsConfig
}) => {
const getXLabel = (priority: number) => `${priority + 1}. Priorität`
const computePriorityDistribution = (results: MatchResult): number[] => {
const distribution: Record<string, number> = {}
for (const activity of results.activities) {
for (const participant of activity.participants) {
const fullfilledPriority = participant.priorities.indexOf(
activity.id
)
if (!distribution[getXLabel(fullfilledPriority)]) {
distribution[getXLabel(fullfilledPriority)] = 1
} else {
distribution[getXLabel(fullfilledPriority)]++
for (const execution of _range(1)) {
for (const participant of activity.allParticipants()) {
const fullfilledPriority = participant.priorities.indexOf(
activity.id
)
if (!distribution[getXLabel(fullfilledPriority)]) {
distribution[getXLabel(fullfilledPriority)] = 1
} else {
distribution[getXLabel(fullfilledPriority)]++
}
}
}
}
Expand All @@ -35,7 +43,12 @@ export const Statistics: FunctionComponent<Props> = ({ result }) => {
<thead>
<tr>
<th>Kurs</th>
<th>Zugewiesene Teilnehmer</th>
{_range(
0,
particpantsConfig.activitiesPerPerson
).map((execution) => (
<th>Durchführung {execution + 1}</th>
))}
<th>Minimum</th>
<th>Limit</th>
</tr>
Expand All @@ -44,9 +57,18 @@ export const Statistics: FunctionComponent<Props> = ({ result }) => {
{result.activities.map((activity) => (
<tr key={`activity-${activity.id}`}>
<td>{activity.title}</td>
<td className="number">
{activity.participants.length}
</td>
{_range(
0,
particpantsConfig.activitiesPerPerson
).map((execution) => (
<td className="number">
{
activity.participants[
execution + 1
]?.length
}
</td>
))}
<td className="number">
{activity.minimum}
</td>
Expand All @@ -55,14 +77,21 @@ export const Statistics: FunctionComponent<Props> = ({ result }) => {
))}
<tr className="totals">
<td>Total</td>
<td className="number">
{
result.participants.filter(
(student) =>
!student.needsMoreActivities()
).length
}
</td>
{_range(
0,
particpantsConfig.activitiesPerPerson
).map((execution) => (
<td className="number">
{result.activities.reduce(
(sum, activity) =>
activity.participantsByExecution(
execution + 1
).length + sum,
0
)}
</td>
))}

<td className="number">
{result.activities
.map((course) => course.minimum)
Expand Down
Loading

0 comments on commit 955098b

Please sign in to comment.