Changeset 9169 for main/waeup.kofa/branches/uli-async-update/tools
- Timestamp:
- 10 Sep 2012, 11:05:07 (12 years ago)
- Location:
- main/waeup.kofa/branches/uli-async-update
- Files:
-
- 3 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-async-update
- Property svn:mergeinfo changed
-
main/waeup.kofa/branches/uli-async-update/tools/copy_media_files.py
r8523 r9169 78 78 return 79 79 80 def copy_file( src,dst):80 def copy_file(file_src, file_dst): 81 81 create_path(os.path.dirname(dst)) 82 82 print "COPY FILE: %s -> %s" % (file_src, file_dst) -
main/waeup.kofa/branches/uli-async-update/tools/fix_import_file.py
r8785 r9169 65 65 'sex': 'gender', 66 66 'birthday': 'date', 67 'request_date': 'datetime',68 67 'marit_stat': 'marit_stat', 69 68 'session': 'session', … … 85 84 'lga': 'lga', 86 85 'order_id': 'no_int', 86 'uniben': 'former', 87 'nysc_year': 'year', 88 'alr_date': 'date', 89 'fst_sit_date': 'date', 90 'scd_sit_date': 'date', 91 'emp_start': 'date', 92 'emp_end': 'date', 93 'emp_start2': 'date', 94 'emp_end2': 'date', 95 'fst_sit_results': 'result', 96 'scd_sit_results': 'result', 97 'alr_results': 'result', 98 'email': 'email', 99 'fst_sit_type': 'sittype', 100 'scd_sit_type': 'sittype', 101 'resp_pay_reference': 'no_int', 102 'type': 'company', 103 'date': 'date', 104 'category': 'p_category', 105 'reg_transition': 'reg_state', # we completely change this column, 106 # since reg_state import is usually intended 107 'transition': 'reg_transition', 108 'payment_date': 'date', 109 'validation_date': 'date', 87 110 } 88 111 … … 90 113 COLNAME_MAPPING = { 91 114 # base data 115 'id': 'student_id', 92 116 'reg_state': 'state', 117 'reg_transition': 'state', 93 118 'jamb_reg_no': 'reg_number', 94 119 'matric_no': 'matric_number', 95 120 'birthday': 'date_of_birth', 96 121 'clr_ac_pin': 'clr_code', 122 # clearance 123 'hq_grade': 'hq_degree', 124 'uniben': 'former_matric', 125 'hq_type2': 'hq2_type', 126 'hq_grade2': 'hq2_degree', 127 'hq_school2': 'hq2_school', 128 'hq_matric_no2': 'hq2_matric_no', 129 'hq_session2': 'hq2_session', 130 'hq_disc2': 'hq2_disc', 131 'emp': 'employer', 132 'emp2': 'employer2', 133 'emp_position2': 'emp2_position', 134 'emp_start2': 'emp2_start', 135 'emp_end2': 'emp2_end', 136 'emp_reason2': 'emp2_reason', 97 137 # study course 98 138 'study_course': 'certificate', … … 117 157 'surcharge': 'surcharge_1', 118 158 'session_id': 'p_session', 159 'type': 'r_company', 119 160 } 120 161 … … 131 172 'courses_registered': 'courses registered', 132 173 'courses_validated': 'courses validated', 174 'admit': 'admitted', 175 'return': 'returning' 133 176 } 134 177 … … 143 186 """Replace input fieldnames by fieldnames of COLNAME_MAPPING. 144 187 """ 145 header = dict([(name, name) for name in fieldnames]) 188 # Remove whitespaces 189 header = dict([(name, name.strip()) for name in fieldnames]) 146 190 for in_name, out_name in COLNAME_MAPPING.items(): 147 if in_name not in header :191 if in_name not in header.values(): 148 192 continue 149 header[in_name] = out_name 193 # Inverse dictionary lookup 194 key = [key for key,value in header.items() if value==in_name][0] 195 header[key] = out_name 150 196 return header 151 197 … … 155 201 156 202 @classmethod 157 def student_id(self, value ):203 def student_id(self, value, row): 158 204 """ 'A123456' --> 'EA123456' 159 205 """ 160 206 if len(value) == 7: 161 return ' E' + value162 return value 163 164 @classmethod 165 def reg_state(self, value ):207 return 'B' + value 208 return value 209 210 @classmethod 211 def reg_state(self, value, row): 166 212 """ 'courses_validated' --> 'courses validated' 167 213 """ … … 169 215 170 216 @classmethod 171 def level(self, value): 217 def reg_transition(self, value, row): 218 if value == "admitted": 219 return "admit" 220 if value == "returning": 221 return "return" 222 return value 223 224 @classmethod 225 def level(self, value, row): 172 226 """ '000' --> '10' 227 '800' --> '999' if pg student 173 228 """ 174 229 try: … … 178 233 if number == 0: 179 234 return 10 235 if row.get('entry_mode') and row.get('entry_mode').startswith('pg'): 236 return 999 180 237 return number 181 238 182 239 @classmethod 183 def semester(self, value ):240 def semester(self, value, row): 184 241 """ '0' --> '9' 185 242 """ … … 193 250 194 251 @classmethod 195 def application_category(self, value ):252 def application_category(self, value, row): 196 253 """ '' --> 'no' 197 254 """ … … 201 258 202 259 @classmethod 203 def lga(self, value ):260 def lga(self, value, row): 204 261 """ Remove apostrophe 205 262 """ 206 263 if value == 'akwa_ibom_uru_offong_oruko': 207 264 return 'akwa_ibom_urue-offong-oruko' 265 if value == 'edo_ohionmwon': 266 return 'edo_orhionmwon' 267 268 if value == 'nassarawa_nassarawa': 269 return 'nassarawa_nassawara' 270 271 if value == 'kogi_mopa-muro-mopi': 272 return 'kogi_mopa-muro' 273 274 if value == 'delta_osimili-north': 275 return 'delta_oshielli-north' 276 277 if value == 'delta_osimili': 278 return 'delta_oshimili' 279 280 if value == 'delta_osimili-south': 281 return 'delta_oshimili-south' 208 282 try: 209 283 value = value.replace("'","") … … 220 294 221 295 @classmethod 222 def session(self, value ):296 def session(self, value, row): 223 297 """ '08' --> '2008' 224 298 '2008/2009' --> '2008' … … 244 318 245 319 @classmethod 246 def marit_stat(self, value): 320 def former(self, value, row): 321 """ True --> yes 322 '2008/2009' --> '2008' 323 """ 324 if value == 'True': 325 return 'yes' 326 return 327 328 @classmethod 329 def year(self, value, row): 330 """ '0' --> '' 331 """ 332 if value == '0': 333 return 334 if value == 'None': 335 return 336 return value 337 338 339 @classmethod 340 def marit_stat(self, value, row): 247 341 """ 'True'/'False' --> 'married'/'unmarried' 248 342 """ … … 256 350 257 351 @classmethod 258 def gender(self, value ):352 def gender(self, value, row): 259 353 """ 'True'/'False' --> 'f'/'m' 260 354 """ … … 268 362 269 363 @classmethod 270 def date(self, value ):364 def date(self, value, row): 271 365 """ 'yyyy/mm/dd' --> 'yyyy-mm-dd' 272 366 """ … … 283 377 284 378 @classmethod 285 def no_int(self, value ):286 """ Add hash .379 def no_int(self, value, row): 380 """ Add hash and skip numbers starting with 999999 287 381 """ 288 382 # We add the hash symbol to avoid automatic number transformation 289 383 # in Excel and Calc for further processing 290 value += '#' 291 return value 292 293 294 @classmethod 295 def datetime(self, value): 296 """ 'yyyy/mm/dd' --> 'yyyy-mm-dd' 297 """ 298 #print "IN: ", value 299 if value == "None": 300 value = "" 301 elif value == "": 302 value = "" 303 else: 304 #value = datetime.datetime.strptime(value, '%Y/%m/%d') 305 #value = datetime.datetime.strftime(value, '%Y-%m-%d') 384 try: 385 intvalue = int(value) 386 value += '#' 387 except: 306 388 pass 307 #print "OUT: ", value 308 return value 309 310 @classmethod 311 def mode(self, value): 389 if value.startswith('999999'): 390 return 391 return value 392 393 @classmethod 394 def mode(self, value, row): 312 395 if value == "transfer_fulltime": 313 396 return "transfer_ft" … … 317 400 318 401 @classmethod 319 def password(self, value ):402 def password(self, value, row): 320 403 if value == "not set": 321 404 return "" … … 323 406 324 407 @classmethod 325 def nationality(self, value ):408 def nationality(self, value, row): 326 409 if value == "nigeria": 327 410 return "NG" 328 return value 329 330 @classmethod 331 def phone(self, value): 411 if value == "niger": 412 return "NE" 413 return value 414 415 @classmethod 416 def sittype(self, value, row): 417 if value == "nabtec": 418 return "nabteb" 419 return value 420 421 @classmethod 422 def company(self, value, row): 423 if value == "online": 424 return "interswitch" 425 return value 426 427 @classmethod 428 def p_category(self, value, row): 429 if value == "acceptance": 430 return "clearance" 431 return value 432 433 @classmethod 434 def email(self, value, row): 435 return value.strip() 436 437 @classmethod 438 def phone(self, value, row): 332 439 """ '<num-seq1>-<num-seq2> asd' -> '--<num-seq1><num-seq2>' 333 440 … … 335 442 of numbers. 336 443 """ 444 if not value: 445 return 446 value = value.strip('#') 337 447 value = value.replace('-', '') 338 448 value = value.replace('/', '') 339 449 match = RE_PHONE.match(value) 340 450 phone = match.groups()[0] 341 value = '-%s' % phone 342 return value 451 if value.startswith('234'): 452 value = '+' + value[:3] + '-' + value[3:] 453 else: 454 value = '-%s' % phone 455 return value + '#' 456 457 @classmethod 458 def result(self, value, row): 459 try: 460 liste = eval(value) 461 except: 462 return 463 if isinstance(liste,list): 464 return [(i[0].lower(),i[1]) for i in liste] 465 return 343 466 344 467 … … 357 480 header = convert_fieldnames(reader.fieldnames) 358 481 writer.writerow(header) 482 if row.get('reg_state') == 'student_created': 483 # We do not reimport student records which have never been accessed. 484 continue 485 if row.get('status') == 'started': 486 # We do not reimport started payments. 487 continue 359 488 for key, value in row.items(): 489 # Remove unwanted whitespaces. 490 row[key] = row[key].strip() 360 491 if not key in OPTIONS.keys(): 361 492 continue … … 365 496 print "WARNING: cannot find converter %s" % conv_name 366 497 continue 367 row[key] = converter(row[key] )498 row[key] = converter(row[key], row) 368 499 try: 369 500 writer.writerow(row)
Note: See TracChangeset for help on using the changeset viewer.