blob: 0fe0d162db55fa1980a7dde86f9932d894e2adf8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
% ----------------------------------------------------------------------------
% the XSIM package - grades module
%
% eXercise Sheets IMproved
%
% ----------------------------------------------------------------------------
% Clemens Niederberger
% Web: https://github.com/cgnieder/xsim
% E-Mail: contact@mychemistry.eu
% ----------------------------------------------------------------------------
% Copyright 2017 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Clemens Niederberger.
% ----------------------------------------------------------------------------
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% ----------------------------------------------------------------------------
\XSIMmodule{grades}{distribute goal sums to grades}
\xsim_load_modules:n {goals}
\msg_new:nnn {xsim} {grade-unknown}
{ The~ grade~ `#1'~ has~ never~ been~ declared~ \msg_line_context: }
\bool_new:N \l__xsim_grades_half_bool
\fp_new:N \l__xsim_grade_round_fp
\fp_zero:N \l__xsim_grade_round_fp
\prop_new:N \l__xsim_relative_grades_prop
\tl_new:N \l__xsim_grade_split_tl
\cs_new:Npn \__xsim_fp_round_to_half:n #1
{ round( 2*(#1),0)/2 }
\cs_new:Npn \__xsim_grades_round:n #1
{ round ( #1 , \l__xsim_grade_round_fp ) }
% #1: factor
% #2: goal sum
\cs_new:Npn \__xsim_grade_rounded:nn #1#2
{
\bool_if:NTF \l__xsim_grades_half_bool
{ \__xsim_fp_round_to_half:n }
{ \__xsim_grades_round:n }
{ (#1) * (#2) }
}
\cs_new_protected:Npn \xsim_declare_relative_grades:n #1
{
\seq_set_split:NVn \l__xsim_tmpa_seq \l__xsim_grade_split_tl {#1}
\seq_map_inline:Nn \l__xsim_tmpa_seq
{ \__xsim_declare_relative_grade:w ##1 \q_stop }
\xsim_verbose:n {Declaring~ relative~ grade~ distribution}
}
\cs_new_protected:Npn \__xsim_declare_relative_grade:w #1 = #2 \q_stop
{
\tl_set:Nx \l__xsim_tmpa_tl { \tl_trim_spaces:n {#1} }
\tl_set:Nx \l__xsim_tmpb_tl { \tl_trim_spaces:n {#2} }
\prop_put:NVV \l__xsim_relative_grades_prop
\l__xsim_tmpa_tl
\l__xsim_tmpb_tl
}
% #1: grade
% #2: sum of points
% #3: code after grade requirement if == 1
% #4: code after grade requirement if != 1
\cs_new_protected:Npn \xsim_get_grade:nnnn #1#2#3#4
{
\prop_get:NnNTF \l__xsim_relative_grades_prop {#1} \l__xsim_tmpa_tl
{
\xsim_print_goal:nnn
{
min(
\__xsim_grade_rounded:nn
{ \l__xsim_tmpa_tl }
{#2} ,
#2
)
}
{#3}
{#4}
}
{ \msg_error:nnn {xsim} {grade-unknown} {#1} }
}
% #1: grade
% #2: goal
% #3: code after grade requirement if == 1
% #4: code after grade requirement if != 1
\cs_new_protected:Npn \xsim_get_grade_goal:nnnn #1#2#3#4
{
\xsim_if_goal_exists:nTF {#2}
{
\xsim_get_grade:nnnn
{#1}
{ \use:c {g__xsim_total_goal_#2_fp} }
{#3}
{#4}
}
{ \msg_error:nnn {xsim} {goal-unknown} {#2} }
}
% #1: grade
% #2: goal list (separated with +)
% #3: code after grade requirement if == 1
% #4: code after grade requirement if != 1
\cs_new_protected:Npn \xsim_get_grade_requirement:nnnn #1#2#3#4
{
\seq_set_split:Nnn \l__xsim_tmpa_seq {+} {#2}
\fp_zero:N \l__xsim_tmpa_fp
\seq_map_inline:Nn \l__xsim_tmpa_seq
{
\fp_add:Nn \l__xsim_tmpa_fp
{ \use:c {g__xsim_total_goal_\tl_trim_spaces:n {##1} _fp} }
}
\xsim_get_grade:nnnn {#1} { \l__xsim_tmpa_fp } {#3} {#4}
}
% #1: grade
% #2: code after grade requirement if == 1
% #3: code after grade requirement if != 1
\cs_new_protected:Npn \xsim_get_absolute_grade_requirement:nnn #1#2#3
{
\fp_zero:N \l__xsim_tmpa_fp
\xsim_foreach_goal:n
{
\fp_add:Nn \l__xsim_tmpa_fp
{ \use:c {g__xsim_total_goal_##1_fp} }
}
\xsim_get_grade:nnnn {#1} { \l__xsim_tmpa_fp } {#2} {#3}
}
\keys_define:nn {xsim/grades}
{
round .fp_set:N = \l__xsim_grade_round_fp ,
half .bool_set:N = \l__xsim_grades_half_bool ,
split .tl_set:N = \l__xsim_grade_split_tl ,
split .initial:n = {,}
}
% ----------------------------------------------------------------------------
\tex_endinput:D
|