aboutsummaryrefslogtreecommitdiff
path: root/GradeBook_lib.tcl
diff options
context:
space:
mode:
authorEugeniy Mikhailov <evgmik@gmail.com>2011-04-15 18:19:23 -0400
committerEugeniy Mikhailov <evgmik@gmail.com>2011-04-15 18:19:23 -0400
commit5b811426160684adce4c8757b2264fd8999c0720 (patch)
tree0a8a999b84fbedf70f0840db3d118e43d7f0dfe7 /GradeBook_lib.tcl
parent0ffbae198ea0757e7037c7690fb65bc14e487315 (diff)
downloadGradeBook-5b811426160684adce4c8757b2264fd8999c0720.tar.gz
GradeBook-5b811426160684adce4c8757b2264fd8999c0720.zip
added NeedsTotal column for the grades category
Ignore-this: f48b307f443f045bdd47174dd8b45f7d darcs-hash:20110415221923-067c0-f07c2652552e9e3692f533d74903047557def263.gz
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">}