Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""Handles assessment scores. 

2""" 

3 

4from config import Names as N 

5from control.utils import pick as G, E 

6from control.html import HtmlElements as H 

7 

8 

9def presentScore(score, eid, derivation=True): 

10 """Presents the result of a score computation. 

11 

12 It shows the overall score, but it can also expand a derivation of the 

13 overall score. 

14 

15 Parameters 

16 ---------- 

17 score: dict 

18 Quantities relevant to the score and its derivation 

19 eid: ObjectId 

20 Id of the assessment of which the score has been taken. 

21 Only used to give the score presentation a unique identifier on the 

22 interface, so that the derivation can be collapsed and expanded 

23 in the presence of other score presentations. 

24 derivation: boolean, optional `True` 

25 If `False`, the derivation will be suppressed. 

26 """ 

27 

28 overall = G(score, N.overall, default=0) 

29 relevantScore = G(score, N.relevantScore, default=0) 

30 relevantMax = G(score, N.relevantMax, default=0) 

31 relevantN = G(score, N.relevantN, default=0) 

32 allMax = G(score, N.allMax, default=0) 

33 allN = G(score, N.allN, default=0) 

34 irrelevantN = allN - relevantN 

35 

36 fullScore = H.span( 

37 f"Score {overall}%", title="overall score of this assessment", cls="ass-score", 

38 ) 

39 if not derivation: 39 ↛ 40line 39 didn't jump to line 40, because the condition on line 39 was never true

40 return fullScore 

41 

42 scoreMaterial = H.div( 

43 [ 

44 H.div( 

45 [ 

46 H.p(f"""This assessment scores {relevantScore} points."""), 

47 H.p( 

48 f"""For this type of contribution there is a total of 

49 {allMax} points, divided over {allN} criteria. 

50 """ 

51 ), 

52 ( 

53 H.p( 

54 f"""However, 

55 {irrelevantN} 

56 rule{" is " if irrelevantN == 1 else "s are"} 

57 not applicable to this contribution, 

58 which leaves the total amount to 

59 {relevantMax} points, 

60 divided over {relevantN} criteria. 

61 """ 

62 ) 

63 if irrelevantN 

64 else E 

65 ), 

66 H.p( 

67 f"""The total score is expressed as a percentage: 

68 the fraction of {relevantScore} scored points 

69 with respect to {relevantMax} scorable points: 

70 {overall}%. 

71 """ 

72 ), 

73 ], 

74 cls="ass-score-deriv", 

75 ), 

76 ], 

77 cls="ass-score-box", 

78 ) 

79 

80 scoreWidget = H.detailx( 

81 (N.calc, N.dismiss), 

82 scoreMaterial, 

83 f"""{N.assessment}/{eid}/scorebox""", 

84 openAtts=dict(cls="button small", title="Show derivation"), 

85 closeAtts=dict(cls="button small", title="Hide derivation"), 

86 ) 

87 return (fullScore, *scoreWidget)