aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xblackboard2gradebook.tcl50
1 files changed, 41 insertions, 9 deletions
diff --git a/blackboard2gradebook.tcl b/blackboard2gradebook.tcl
index 609a479..69b6591 100755
--- a/blackboard2gradebook.tcl
+++ b/blackboard2gradebook.tcl
@@ -194,26 +194,26 @@ proc dbRequest {script} {
}
## adding students if they do not exist
-proc addStudentsFromDB { db } {
+proc addStudentsFromBlackboardDB { db } {
# blackboard does not provide the following info
set id unknownID
set section unknownSection
puts "Blackboard does not provide Student ID and Section number, skipping user addition"
- return
+ #return
set fname [list First Name]
set lname [list Last Name]
set eval_str [concat SELECT * FROM 'export_table']
set err [catch {
$db eval $eval_str v {
- set email $v(Username)@email.wm.edu
- dbRequest [list AddUserNonWeb $v($fname) $v($lname) $email student $id $section]
+ set username [blackboardUsername2local $v(Username)]
+ dbRequest [list AddUserNonWeb $v($fname) $v($lname) $username student $id $section]
}
} errStat ]
iferror $err $errStat
}
-proc foreignUsername2local { uname } {
+proc blackboardUsername2local { uname } {
return "$uname@email.wm.edu"
}
@@ -252,7 +252,7 @@ proc pickCols2import { cols2import skipCreationCol categories2import } {
return $reduced_list
}
-proc normilizeGrade { grade colInfo } {
+proc normilizeBlackboardGrade { grade colInfo } {
set shortCol [lindex $colInfo 0]
set category [lindex $colInfo 1]
set maxScore [lindex $colInfo 2]
@@ -266,12 +266,44 @@ proc normilizeGrade { grade colInfo } {
return $grade
}
+proc alias {alias target} {
+ # makes alias to a proc, borrowed from
+ # https://wiki.tcl-lang.org/page/proc+alias
+ set fulltarget [uplevel [list namespace which $target]]
+ if {$fulltarget eq {}} {
+ return -code error [list {no such command} $target]
+ }
+ set save [namespace eval [namespace qualifiers $fulltarget] {
+ namespace export}]
+ namespace eval [namespace qualifiers $fulltarget] {namespace export *}
+ while {[namespace exists [
+ set tmpns [namespace current]::[info cmdcount]]]} {}
+ set code [catch {set newcmd [namespace eval $tmpns [
+ string map [list @{fulltarget} [list $fulltarget]] {
+ namespace import @{fulltarget}
+ }]]} cres copts]
+ namespace eval [namespace qualifiers $fulltarget] [
+ list namespace export {*}$save]
+ if {$code} {
+ return -options $copts $cres
+ }
+ uplevel [list rename ${tmpns}::[namespace tail $target] $alias]
+ namespace delete $tmpns
+ return [uplevel [list namespace which $alias]]
+}
+
######################### START of the execution #########################
-addStudentsFromDB bdb
+alias foreignUsername2local blackboardUsername2local
+alias addStudentsFromForeignDB addStudentsFromBlackboardDB
+alias getForeignDBUsernames getBlackboardUsernames
+alias getForeignDBUserGrade getBlackboardUserGrade
+alias normilizeGrade normilizeBlackboardGrade
+
+addStudentsFromForeignDB bdb
# now for every user add their grades
-set username_list [getBlackboardUsernames bdb]
+set username_list [getForeignDBUsernames bdb]
set cols2import [getColListFromAnyTable bdb export_table]
set cols2import [ pickCols2import $cols2import $skipCreationCol $categories2import]
@@ -284,7 +316,7 @@ foreach col $cols2import {
}
foreach uname $username_list {
set locUname [foreignUsername2local $uname]
- set grade [getBlackboardUserGrade bdb $uname $col ]
+ set grade [getForeignDBUserGrade bdb $uname $col ]
set grade [normilizeGrade $grade $colInfo]
updateGrade $shortCol $locUname $grade
}