|
Home About
FAQs
General Admin Assist Student
Docs
Admin Assistant
CGI
Admin Assistant Download Form Student
Packages
AdminInterface Assignments AssistantInterface Form Interface Record Roster StudentInterface SystemVariables Teams VincentFile VincentLog |
|
0 #Teams module 1 #Copyright 2000 Matt Jadud 2 #This program is free software; you can redistribute it and/or 3 #modify it under the terms of the GNU General Public License 4 #as published by the Free Software Foundation; either version 2 5 #of the License, or (at your option) any later version. 6 # 7 #This program is distributed in the hope that it will be useful, 8 #but WITHOUT ANY WARRANTY; without even the implied warranty of 9 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 #GNU General Public License for more details. 11 # 12 #You should have received a copy of the GNU General Public License 13 #along with this program; if not, write to the Free Software 14 #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 15 16 17 use SystemVariables; 18 use Record; 19 20 package Teams; 21 22 my($DEBUG); 23 24 $DEBUG = 1; 25 26 sub randomizeAllTeams { 27 28 my($team_size, 29 @section_numbers, 30 @TeamRefs, 31 $section); 32 33 $team_size = $_[0]; 34 35 SystemVariables::DEBUG("Teams:", "Hello $team_size"); 36 37 @section_numbers = Record::getAllSectionNumbers(); 38 chomp(@section_numbers); 39 40 $index = 0; 41 42 #Go through building the teams for each section. 43 # Each array of strings is returned as a reference, so 44 # simply collect those references as an array of references. 45 foreach $section (@section_numbers) { 46 47 $TeamRefs[$index] = createTeamsInSection($section, $team_size); 48 $index++; 49 } 50 51 $index = 0; 52 $section_index = 0; 53 54 #For each reference to a list of teams, 55 # print out the teams in that array reference. 56 # Each array reference is equal to one section's 57 # teams, so it is safe to index through the section_numbers 58 # array as well, to keep track of what section we are dealing with. 59 foreach $teamRef (@TeamRefs) { 60 #SystemVariables::DEBUG("Teams:", "Teams for section ", $section_numbers[$section_index], "<HR>"); 61 foreach $team (@{$teamRef}) { 62 63 foreach $stu ((split(/s+/, $team))) { 64 if($stu) { 65 $TeamData{"_TEAMNUMBER"} = $index; 66 $team =~ s/^(s*)//g; 67 $TeamData{"_TEAMMEMBERS"} = $team; 68 Record::updateStudentRecord($stu, %TeamData); 69 } 70 } 71 72 SystemVariables::DEBUG("Teams:", "$index :", $team); 73 $index++; 74 75 } 76 $section_index++; 77 } 78 79 } 80 81 sub createTeamsInSection { 82 83 my($section_number, 84 $team_size, 85 $MasterList, 86 $usernames, 87 @Teams, 88 $teamcount, 89 $teamsize_count, 90 $randomized_list, 91 $team); 92 93 $section_number = $_[0]; 94 $team_size = $_[1]; 95 96 $usernames = Record::getAllUsernamesInSection($section_number); 97 @Teams = (); 98 $teamcount = 0; 99 $teamsize_count = 0; 100 101 $randomized_list = randomizeList($usernames); 102 103 #For each member of the randomized list, 104 # if we are still smaller than a team, go ahead and 105 # concat. their name onto the team string. 106 #Otherwise, index up the team count, reset the 107 # team size, and continue. 108 109 foreach $member (@{$randomized_list}) { 110 if($teamsize_count < $team_size) { 111 $Teams[$teamcount] .= " $member"; 112 $teamsize_count++; 113 } else { 114 $teamcount++; 115 $teamsize_count = 0; 116 117 #AH! Loosing one each time through the loop; 118 # I wasn't doing anything with every mod($team_size) 119 # students... so, I would loose around 4 people if 120 # the teamsize was five... AH! 121 $Teams[$teamcount] .= " $member"; 122 $teamsize_count++; 123 124 } 125 126 } 127 128 129 130 #Return a reference to the teams from this section. 131 return @Teams; 132 133 } 134 135 136 sub randomizeList { 137 138 my($list, 139 $total, 140 $remaining, 141 $thiselement, 142 $lastelement, 143 $rand, 144 $i); 145 146 $list = $_[0]; 147 148 $total = scalar(@{$list}); 149 $remaining = $total; 150 151 srand(time); #seed the random nmber generator 152 for ($i = 0; $i < $total; $i++) { 153 $rand = rand ($remaining); # random number, note $remaining = lastindex+1 154 #print $$list[$rand]; # for indexing rand is truncated 155 156 # "delete" current element 157 # by swaping current and last element, and decrementing $remaining counter 158 $thiselement = $$list[$rand]; 159 $lastelement = $$list[$remaining-1]; 160 $$list[$rand] = $lastelement; 161 $$list[$remaining-1] = $thiselement; 162 $remaining--; 163 } 164 165 return $list; 166 } 167 168 sub getAllTeamsInSection { 169 170 my($section, 171 @numbers, 172 $usernames, 173 $stu, 174 $record, 175 $num 176 ); 177 178 $section = $_[0]; 179 $usernames = Record::getAllUsernamesInSection($section); 180 181 #Grab each student's record, and push their team number 182 # onto the stack. 183 # 184 #Should I check for expiredness here? 185 # There should probably be checks all through the team stuff. 186 foreach $stu (@{$usernames}) { 187 chomp $stu; 188 $record = Record::getStudentRecord($stu); 189 #If a team has been defined for the student. 190 if(defined($$record{"_TEAMNUMBER"})) { 191 $num = $$record{"_TEAMNUMBER"}; 192 chomp $num; 193 #If the number isn't already in the list, 194 # add it. 195 if(!SystemVariables::existInList($num, @numbers)) { 196 push(@numbers, $$record{"_TEAMNUMBER"}); 197 } 198 } 199 } 200 201 return @numbers; 202 } 203 204 sub getAllTeamNumbers { 205 206 my(@sections, 207 @Teams, 208 $sec, 209 $teamnos, 210 $teamnum 211 ); 212 213 @sections = Record::getAllSectionNumbers(); 214 chomp @sections; 215 @Teams = (); 216 foreach $sec (@sections) { 217 218 $teamnos = getAllTeamsInSection($sec); 219 220 foreach $teamnum (@{$teamnos}) { 221 push(@Teams, $teamnum); 222 } 223 } 224 225 chomp @Teams; 226 227 undef %saw; 228 @Teams = grep(!$saw{$_}++, @Teams); 229 230 SystemVariables::DEBUG("Teams:", "Teams Found: ", @Teams); 231 232 233 return @Teams; 234 235 } 236 237 #Membership lists are not as easy to update as 238 # team numbers.... and, what is the best way 239 # to differentiate between the whole class, and 240 # an individual section?... well... I guess I just 241 # need to update everything... 242 sub updateMembershipLists { 243 244 @TeamMemberLists = (); 245 @usernames = Record::getAllStudentUsernames(); 246 247 SystemVariables::DEBUG("Teams:", "Processing Membership Lists."); 248 249 foreach $stu (@usernames) { 250 $record = Record::getStudentRecord($stu); 251 $number = $$record{"_TEAMNUMBER"}; 252 #SystemVariables::DEBUG("Teams:", $stu, " ", $number); 253 $TeamMemberLists[$number] .= " $stu"; 254 } 255 256 foreach $stu (@usernames) { 257 $record = Record::getStudentRecord($stu); 258 $number = $$record{"_TEAMNUMBER"}; 259 $members = $TeamMemberLists[$number]; 260 $members =~ s/^(s*)//g; 261 $$record{"_TEAMMEMBERS"} = $members; 262 Record::updateStudentRecord($stu, $record); 263 } 264 265 266 } 267 268 269 ##CONTRACT 270 # DEBUG 271 ##PURPOSE 272 # Debugging. 273 ##DEPENDANCIES 274 # None. 275 sub useDebugging())'>DEBUG { if(SystemVariables::useDebugging()) { print "Teams: ", @_, "n<P>"; } } 276 277 #Last executing statement 278 # in a package must be a return. 279 return 1; |
|
Last update: 1/6/01; 9:32:39 AM |