Skip to content

Commit

Permalink
some uncommited changes from March 29th on pdf repport
Browse files Browse the repository at this point in the history
  • Loading branch information
anadis504 committed May 27, 2024
1 parent a30f2e9 commit d420368
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 63 deletions.
129 changes: 72 additions & 57 deletions src/components/PdfDownload/PdfGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface SubmissionProps {
answer?: UserAnswer
gradingFeedback: ExerciseFeedback | null
userVariables?: UserVariablesMap | null
exercise_name?: string
}

const styles = StyleSheet.create({
Expand Down Expand Up @@ -196,16 +197,20 @@ const PDFSumFactorReport: React.FC<React.PropsWithChildren<SubmissionProps>> = (
publicSpec,
answer,
userVariables,
exercise_name,
}) => {
const sumFactor = (publicSpec as Survey)?.sumFactor
if (!sumFactor || !sumFactor.categories) {
return null
}
const userScore =
calculateSumFactorScore(
(publicSpec as Survey)?.content,
answer?.answeredQuestions as AnsweredSurveyItem[],
) ?? 0
const userScore = calculateSumFactorScore(
(publicSpec as Survey)?.content,
answer?.answeredQuestions as AnsweredSurveyItem[],
)

if (!userScore) {
return null
}
const userName =
(userVariables != null && sumFactor.userVariable?.globalKey) ?? userVariables
? (userVariables[sumFactor.userVariable?.globalKey ?? ""] as string)
Expand All @@ -231,50 +236,55 @@ const PDFSumFactorReport: React.FC<React.PropsWithChildren<SubmissionProps>> = (
const labelPlacement =
userPlacement >= 100 - userLabelWidth ? userPlacement - userLabelWidth - 4 : userPlacement + 4
return (
<View style={{ marginHorizontal: 10 }}>
<Svg height={`160`} width={`100%`} viewBox={`0 0 240 120`}>
<Circle
cx={`${userPlacement}%`}
cy={`${13}%`}
r="4"
fill="tomato"
stroke="brown"
strokeWidth="2"
/>
<Text x={`${labelPlacement}%`} y={`16%`} style={{ fontSize: 9, color: "#706d6d" }}>
{`${userLabel}`}
</Text>
{sortedBars.map((car, idx) => {
return (
<>
<Rect
key={idx}
fill={car.color}
width={`${car.barWidth}%`}
height={`20%`}
x={`${(100 * (car.from - start)) / (finnish - start)}%`}
y={`26%`}
></Rect>
<Rect
key={10 * idx}
fill={car.color}
width={`8%`}
height={`15%`}
x={`0%`}
y={`${53 + idx * 15}%`}
></Rect>
<Text
x={`10%`}
y={`${66 + idx * 15}%`}
style={{ textAlign: "left", marginBottom: "2px", fontSize: 8, color: "#706d6d" }}
>
{car.label}
</Text>
</>
)
})}
</Svg>
</View>
<>
<View style={{ paddingBottom: "10px" }}>
<Text>{exercise_name}</Text>
</View>
<View style={{ marginHorizontal: 10 }}>
<Svg height={`160`} width={`100%`} viewBox={`0 0 240 120`}>
<Circle
cx={`${userPlacement}%`}
cy={`${13}%`}
r="4"
fill="tomato"
stroke="brown"
strokeWidth="2"
/>
<Text x={`${labelPlacement}%`} y={`16%`} style={{ fontSize: 9, color: "#706d6d" }}>
{`${userLabel}`}
</Text>
{sortedBars.map((car, idx) => {
return (
<>
<Rect
key={idx}
fill={car.color}
width={`${car.barWidth}%`}
height={`20%`}
x={`${(100 * (car.from - start)) / (finnish - start)}%`}
y={`26%`}
></Rect>
<Rect
key={10 * idx}
fill={car.color}
width={`8%`}
height={`15%`}
x={`0%`}
y={`${53 + idx * 15}%`}
></Rect>
<Text
x={`10%`}
y={`${66 + idx * 15}%`}
style={{ textAlign: "left", marginBottom: "2px", fontSize: 8, color: "#706d6d" }}
>
{car.label}
</Text>
</>
)
})}
</Svg>
</View>
</>
)
}

Expand Down Expand Up @@ -339,16 +349,21 @@ const MyDoc: React.FC<React.PropsWithChildren<CustomViewIframeState>> = (props)
style={[styles.item, { paddingBottom: "20px" }]}
wrap={false}
>
<View style={{ paddingBottom: "10px" }}>
<Text>{exercise.exercise_name}</Text>
</View>
<PDFFactorReport
key={exercise.task_id}
gradingFeedback={exercise.gradingFeedback}
userVariables={user_vars}
></PDFFactorReport>
{exercise.gradingFeedback && (
<>
<View style={{ paddingBottom: "10px" }}>
<Text>{exercise.exercise_name}</Text>
</View>
<PDFFactorReport
key={exercise.task_id}
gradingFeedback={exercise.gradingFeedback}
userVariables={user_vars}
></PDFFactorReport>
</>
)}
{exercise.answer && (
<PDFSumFactorReport
exercise_name={exercise.exercise_name}
key={exercise.task_id}
gradingFeedback={null}
userVariables={user_vars}
Expand Down
18 changes: 12 additions & 6 deletions src/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,23 @@ export const calculateSumFactorScore = (
)

let score = 0
let answered = true

weightedItems.map((item) => {
const answeredItem = answeredQuestions.find((ans) => {
return ans.surveyItemId === item.id
})
score +=
item.answer.factorialOptions?.find((opt) => {
return opt.name === answeredItem?.answer
})?.value ?? 0
})?.answer
if (answeredItem) {
score +=
item.answer.factorialOptions?.find((opt) => {
return opt.name === answeredItem
})?.value ?? 0
} else {
answered = false
}
})

return score
return answered ? score : null
}

/**
Expand Down

0 comments on commit d420368

Please sign in to comment.