summaryrefslogtreecommitdiff
path: root/GradeBook_lib.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'GradeBook_lib.tcl')
-rwxr-xr-xGradeBook_lib.tcl52
1 files changed, 42 insertions, 10 deletions
diff --git a/GradeBook_lib.tcl b/GradeBook_lib.tcl
index f534c84..0b91928 100755
--- a/GradeBook_lib.tcl
+++ b/GradeBook_lib.tcl
@@ -27,6 +27,7 @@ proc default_grades_category {} {
Quiz\
HomeWork\
LabReport\
+ Participation\
MidTerm\
FinalExam\
]
@@ -34,17 +35,33 @@ proc default_grades_category {} {
}
proc getGradingWeights { } {
- return [ list \
- HomeWork .15 \
- Quiz .10 \
- LabReport .25 \
- Participation .05 \
- MidTerm .20 \
- Final .25 \
- ]
+ set category_name_weight_list {}
+ set eval_str [concat SELECT CategoryName,CategoryWeight FROM GradesCategoryTable]
+ set err [catch {
+ db eval $eval_str v {
+ set category $v(CategoryName)
+ set weight $v(CategoryWeight)
+ if { ![string is double -strict $weight] } {
+ htmlInfoMsg "weight for category: $category is not a number, setting it to 0"
+ set weight 0
+ ModifyWeightForGradesCategory db $category 0
+ }
+ lappend category_name_weight_list $category $weight
+ }
+ } errStat ]
+ if { $err } {
+ dbg "we should never be here if GradesCategoryTable exists" 1
+ dbg $errStat 1
+ htmlErrorMsg $errStat
+ }
+ return $category_name_weight_list
}
proc isCalculateTotalForCategorySet { category } {
+ if {![db exists {SELECT 1 FROM GradesCategoryTable WHERE CategoryName=$category}]} {
+ dbg "Category: $category does not exists in the GradesCategoryTable, setting CalculateTotal to false" 3
+ return false
+ }
switch $category {
"unset" {set flag false}
Quiz {set flag true}
@@ -355,6 +372,19 @@ proc GetDefaultGradesTableColumn {} {
return $l
}
+proc ModifyNeedsTotalForGradesCategory {db category flag} {
+ if {![db exists {SELECT 1 FROM GradesCategoryTable WHERE CategoryName=$category}]} {
+ dbg "Category: $category already does not exists in the GradesCategoryTable, creating it" 3
+ AddGradesCategory db $category
+ }
+ set eval_str [concat UPDATE GradesCategoryTable SET \"NeedsTotal\"='$flag' WHERE \"CategoryName\"=\'$category\']
+ set err [catch {db eval $eval_str } errStat]
+ if { $err } {
+ htmlErrorMsg $errStat
+ dbg "the following error happen: $errStat" 3
+ }
+}
+
proc ModifyWeightForGradesCategory {db category weight} {
if {![db exists {SELECT 1 FROM GradesCategoryTable WHERE CategoryName=$category}]} {
dbg "Category: $category already does not exists in the GradesCategoryTable, creating it" 3
@@ -379,11 +409,13 @@ proc AddGradesCategory {db category} {
htmlErrorMsg $errStat
dbg "the following error happen: $errStat" 3
}
+ ModifyWeightForGradesCategory db $category 0
+ ModifyNeedsTotalForGradesCategory db $category false
}
proc CreateGradesCategoryTable {db} {
# construct sql string for table creation
- set sql_str {CREATE TABLE GradesCategoryTable(CategoryName text, CategoryWeight float)}
+ set sql_str {CREATE TABLE GradesCategoryTable(CategoryName text, CategoryWeight float, NeedsTotal text)}
set err [catch {db eval $sql_str } errStat]
if { $err && ($errStat ne "table GradesCategoryTable already exists") } {
@@ -424,7 +456,7 @@ proc UpdateGradesCategores { db permission_list user } {
proc EditGradesCategories { db permission_list user } {
global script_name
- lappend column_list CategoryName CategoryWeight
+ lappend column_list CategoryName CategoryWeight NeedsTotal
set sql_column_list [join $column_list ","]
puts {<div class="change_categories">}
puts {<div class="categories_table">}