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

Custom view #60

Merged
merged 15 commits into from
Mar 29, 2024
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
24 changes: 23 additions & 1 deletion data-parser/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,28 @@ def flatten(xs):
submission_files = []
userdetail_files = []
exercisetasks_files = []
user_consents_files = []
datafiles = [f for f in listdir('./data/') if isfile(join('./data/', f))]

course_names = set()

for f in datafiles:
[course_name, file_name] = f.split(' - ', 1)
course_names.add(course_name)
if 'Submissions' in file_name:
submission_files.append(f)
elif 'Exercise tasks' in file_name:
exercisetasks_files.append(f)
elif 'User Details' in file_name:
userdetail_files.append(f)
elif 'User Consents' in file_name:
user_consents_files.append(f)

# Sort the files by date, most recent first
submission_files = sorted(submission_files, key=lambda x: (x.split(' ')[-1]), reverse=True)
exercisetasks_files = sorted(exercisetasks_files, key=lambda x: (x.split(' ')[-1]), reverse=True)
userdetail_files = sorted(userdetail_files, key=lambda x: (x.split(' ')[-1]), reverse=True)
user_consents_files = sorted(user_consents_files, key=lambda x: (x.split(' ')[-1]), reverse=True)

try:
exercise_tasks = pl.read_csv(join('./data/', exercisetasks_files[0]))
Expand All @@ -62,6 +69,13 @@ def flatten(xs):
except OSError as error:
print(error)

try:
user_consents = pl.read_csv(join('./data/', user_consents_files[0])).select(['course_id', 'question','user_id','research_consent'])

except OSError as error:
print(error)


cleaned_subs = (submissions
.join(user_details.select(pl.exclude('created_at')), on='user_id', how='left')
.join(exercise_tasks.select(['id', 'exercise_type']), left_on='exercise_task_id', right_on='id', how='left')
Expand All @@ -70,6 +84,13 @@ def flatten(xs):
.sort('created_at', descending=True)
.unique(subset=['exercise_task_id', 'user_id'], keep='first')
)
user_consents = user_consents.with_columns(
pl.col('question').str.replace_all(',', '').str.replace('Hyväksyn että ', '').str.slice(0, 40)
)

user_consents = user_consents.pivot(index="user_id", columns="question", values="research_consent", aggregate_function=None)

user_details = user_details.join(user_consents, how='left', on='user_id')

# The map of private-specs: { exercise_task_id : { private_spec } }
exercise_tasks_map = dict([(x[0], json.loads(x[4])) for x in exercise_tasks.rows() if 'factorial' in x[3]])
Expand Down Expand Up @@ -189,5 +210,6 @@ def flatten(xs):
else: print(error)

dt = datetime.now().strftime('%d-%m-%Y %H:%M:%S')
filename = f'./parsed-outputs/Submissions {dt}.csv'
course_name = '-'.join(course_names)
filename = f'./parsed-outputs/Survey_data-{course_name}-{dt}.csv'
user_details.write_csv(filename, has_header=True, quote='"', null_value='', separator=';')
8 changes: 4 additions & 4 deletions src/components/PdfDownload/PdfGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ const PDFSumFactorReport: React.FC<React.PropsWithChildren<SubmissionProps>> = (
const userLabel: string = userName ?? userVar?.label ?? "Your Score"
const userPlacement =
(100 * (-(start as number) + userScore)) / ((finnish as number) - (start as number))
const userLabelWidth = (100 * getTextWidth(userLabel, "15px Raleway")) / 100
const userLabelWidth = getTextWidth(userLabel, "9px Raleway")
const labelPlacement =
userPlacement >= 100 - userLabelWidth ? userPlacement - userLabelWidth - 4 : userPlacement + 4
return (
Expand Down Expand Up @@ -292,9 +292,9 @@ const MyDoc: React.FC<React.PropsWithChildren<CustomViewIframeState>> = (props)
.flatMap((exercise) => {
return exercise.exercise_tasks.flatMap((task) => {
const grading = task.grading as CustomViewExerciseTaskGrading
const answer = task.user_answer
? ((task.user_answer as CustomViewExerciseTaskSubmission[])[0].data_json as UserAnswer)
: null
const answer =
((task.user_answer as CustomViewExerciseTaskSubmission)?.data_json as UserAnswer) ?? null

const pubSpec = task.public_spec as PublicSpec
const gradingFeedback = grading.feedback_json
? (grading.feedback_json as ExerciseFeedback)
Expand Down
2 changes: 0 additions & 2 deletions src/pages/iframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ const Iframe: React.FC<React.PropsWithChildren<unknown>> = () => {
const [state, setState] = useState<State | null>(null)

const callback = useCallback((messageData: unknown, port: MessagePort) => {
//const messageData = customViewState as SetStateMessage
if (isSetStateMessage(messageData)) {
console.log("Messagedata:", messageData)
ReactDOM.flushSync(() => {
if (messageData.view_type === "answer-exercise") {
setState({
Expand Down
Loading
Loading