Skip to content

Commit

Permalink
added export and point customisation, small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanGrims committed Sep 28, 2024
1 parent f04700a commit 3fc8550
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 46 deletions.
93 changes: 91 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@mdui/icons": "^1.0.2",
"@tanstack/react-table": "^8.11.2",
"crypto-js": "^4.2.0",
"file-saver": "^2.0.5",
"firebase": "^10.7.1",
"javascript-lp-solver": "^0.4.24",
"jsonpath": "^1.1.1",
Expand All @@ -31,7 +32,8 @@
"react-qr-code": "^2.0.12",
"react-router-dom": "^6.21.0",
"react-table": "^7.8.0",
"sort-by": "^0.0.2"
"sort-by": "^0.0.2",
"xlsx": "^0.18.5"
},
"devDependencies": {
"@types/react": "^18.2.43",
Expand Down
21 changes: 16 additions & 5 deletions python/assign.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def assign():
if decoded_token["uid"] == uid:
# read more data from the request

# prefences = {studentId (string): {grade: string, selected: [idProject1, idProject2, ...], name: string},}
# prefences = {studentId (string): {selected: [idProject1, idProject2, ...], points: [number, number, number]},}
preferences = data.get("preferences")
print(
preferences
) # => {'1': {'name': 'Johan', 'selected': [1, 2, 3]}, '2': {'name': 'Sara', 'selected': [1, 2, 3]}, '3': {'name': 'Karl', 'selected': [1, 2, 3]}, '4': {'name': 'Anna', 'selected': [1, 2, 3]}, '5': {'name': 'Eva', 'selected': [1, 2, 3]}}
) # => {'1': {'points': [1,2,4], 'selected': [1, 2, 3]}, '2': {'points': [1,2,4], 'selected': [1, 2, 3]}, '3': {'points': [1,2,4], 'selected': [1, 2, 3]}, '4': {'points': [1,2,4], 'selected': [1, 2, 3]}, '5': {'points': [1,2,4], 'selected': [1, 2, 3]}}

# projects = {projectId: {title: string, max: string}}
projects = data.get("projects")
Expand Down Expand Up @@ -99,9 +99,20 @@ def assign():

# Objective function: Minimize preference scores and overbooking penalties
problem += pulp.lpSum(
scores["first"] * x[i, student_preferences[i][0]]
+ scores["second"] * x[i, student_preferences[i][1]]
+ scores["third"] * x[i, student_preferences[i][2]]
(
preferences[list(student_ids.keys())[i]].get(
"points", [scores["first"], scores["second"], scores["third"]]
)[0]
* x[i, student_preferences[i][0]]
+ preferences[list(student_ids.keys())[i]].get(
"points", [scores["first"], scores["second"], scores["third"]]
)[1]
* x[i, student_preferences[i][1]]
+ preferences[list(student_ids.keys())[i]].get(
"points", [scores["first"], scores["second"], scores["third"]]
)[2]
* x[i, student_preferences[i][2]]
)
for i in range(num_participants)
) + pulp.lpSum(10 * o[j] for j in range(num_courses))

Expand Down
3 changes: 2 additions & 1 deletion src/admin/NewVote.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { generateRandomHash } from "./utils";

export default function NewVote() {
const [title, setTitle] = React.useState("");
const [selectCount, setSelectCount] = React.useState();
const [selectCount, setSelectCount] = React.useState(3);
const [startTime, setStartTime] = React.useState();
const [endTime, setEndTime] = React.useState();

Expand Down Expand Up @@ -139,6 +139,7 @@ export default function NewVote() {
label="Anzahl der Wahlen"
type="number"
placeholder="3"
disabled
min={1}
max={10}
value={selectCount}
Expand Down
26 changes: 24 additions & 2 deletions src/admin/vote/Answers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import {
doc,
getDoc,
getDocs,
setDoc,
} from "firebase/firestore/lite";
import { confirm, prompt } from "mdui";
import { confirm } from "mdui";
import React from "react";
import { useLoaderData } from "react-router-dom";
import { db } from "../../firebase";
Expand Down Expand Up @@ -229,6 +228,7 @@ export default function Answers() {
<th>
<b>ID</b>
</th>
<th></th>
</tr>
</thead>
<tbody>
Expand All @@ -251,6 +251,28 @@ export default function Answers() {
<td key={i}>{answer.extraFields[i]}</td>
))}
<td>{answer.id}</td>
<td
style={{
cursor: "pointer",
color: "rgb(255, 100, 100)",
}}
onClick={() => {
confirm({
headline: "Löschen",
description:
"Sind Sie sicher, dass Sie diese Antwort löschen möchten?",
}).then(() => {
// Löschen
deleteDoc(
doc(db, `/votes/${vote.id}/choices/${answer.id}`)
).then(() => {
window.location.reload();
});
});
}}
>
Löschen
</td>
</tr>
))}
</tbody>
Expand Down
Loading

0 comments on commit 3fc8550

Please sign in to comment.