- Timestamp:
- 21 Sep 2012, 08:19:35 (12 years ago)
- Location:
- main/waeup.kofa/branches/uli-zc-async
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/branches/uli-zc-async
- Property svn:mergeinfo changed
/main/waeup.kofa/branches/uli-async-update removed /main/waeup.kofa/branches/uli-autoinclude-less removed /main/waeup.kofa/trunk removed
- Property svn:mergeinfo changed
-
main/waeup.kofa/branches/uli-zc-async/tools/fix_import_file.py
r9209 r9211 65 65 'sex': 'gender', 66 66 'birthday': 'date', 67 'request_date': 'datetime', 67 68 'marit_stat': 'marit_stat', 68 69 'session': 'session', … … 84 85 'lga': 'lga', 85 86 '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 'core_or_elective': 'bool',105 'category': 'p_category',106 'reg_transition': 'reg_state', # we completely change this column,107 # since reg_state import is usually intended108 'transition': 'reg_transition',109 'payment_date': 'date',110 'validation_date': 'date',111 87 } 112 88 … … 114 90 COLNAME_MAPPING = { 115 91 # base data 116 'id': 'student_id',117 92 'reg_state': 'state', 118 'reg_transition': 'state',119 93 'jamb_reg_no': 'reg_number', 120 94 'matric_no': 'matric_number', 121 95 'birthday': 'date_of_birth', 122 96 'clr_ac_pin': 'clr_code', 123 # clearance124 'hq_grade': 'hq_degree',125 'uniben': 'former_matric',126 'hq_type2': 'hq2_type',127 'hq_grade2': 'hq2_degree',128 'hq_school2': 'hq2_school',129 'hq_matric_no2': 'hq2_matric_no',130 'hq_session2': 'hq2_session',131 'hq_disc2': 'hq2_disc',132 'emp': 'employer',133 'emp2': 'employer2',134 'emp_position2': 'emp2_position',135 'emp_start2': 'emp2_start',136 'emp_end2': 'emp2_end',137 'emp_reason2': 'emp2_reason',138 97 # study course 139 98 'study_course': 'certificate', … … 158 117 'surcharge': 'surcharge_1', 159 118 'session_id': 'p_session', 160 'type': 'r_company',161 119 } 162 120 … … 173 131 'courses_registered': 'courses registered', 174 132 'courses_validated': 'courses validated', 175 'admit': 'admitted',176 'return': 'returning'177 133 } 178 134 … … 187 143 """Replace input fieldnames by fieldnames of COLNAME_MAPPING. 188 144 """ 189 # Remove whitespaces 190 header = dict([(name, name.strip()) for name in fieldnames]) 145 header = dict([(name, name) for name in fieldnames]) 191 146 for in_name, out_name in COLNAME_MAPPING.items(): 192 if in_name not in header .values():147 if in_name not in header: 193 148 continue 194 # Inverse dictionary lookup 195 key = [key for key,value in header.items() if value==in_name][0] 196 header[key] = out_name 149 header[in_name] = out_name 197 150 return header 198 151 … … 202 155 203 156 @classmethod 204 def student_id(self, value , row):157 def student_id(self, value): 205 158 """ 'A123456' --> 'EA123456' 206 159 """ 207 160 if len(value) == 7: 208 return ' K' + value209 return value 210 211 @classmethod 212 def reg_state(self, value , row):161 return 'E' + value 162 return value 163 164 @classmethod 165 def reg_state(self, value): 213 166 """ 'courses_validated' --> 'courses validated' 214 167 """ … … 216 169 217 170 @classmethod 218 def reg_transition(self, value, row): 219 if value == "admitted": 220 return "admit" 221 if value == "returning": 222 return "return" 223 return value 224 225 @classmethod 226 def level(self, value, row): 171 def level(self, value): 227 172 """ '000' --> '10' 228 '800' --> '999' if pg student229 173 """ 230 174 try: … … 234 178 if number == 0: 235 179 return 10 236 if row.get('entry_mode') and row.get('entry_mode').startswith('pg'):237 return 999238 180 return number 239 181 240 182 @classmethod 241 def semester(self, value , row):183 def semester(self, value): 242 184 """ '0' --> '9' 243 185 """ … … 251 193 252 194 @classmethod 253 def application_category(self, value , row):195 def application_category(self, value): 254 196 """ '' --> 'no' 255 197 """ … … 259 201 260 202 @classmethod 261 def lga(self, value , row):203 def lga(self, value): 262 204 """ Remove apostrophe 263 205 """ 264 206 if value == 'akwa_ibom_uru_offong_oruko': 265 207 return 'akwa_ibom_urue-offong-oruko' 266 if value == 'edo_ohionmwon':267 return 'edo_orhionmwon'268 269 if value == 'nassarawa_nassarawa':270 return 'nassarawa_nassawara'271 272 if value == 'kogi_mopa-muro-mopi':273 return 'kogi_mopa-muro'274 275 if value == 'delta_osimili-north':276 return 'delta_oshielli-north'277 278 if value == 'delta_osimili':279 return 'delta_oshimili'280 281 if value == 'delta_osimili-south':282 return 'delta_oshimili-south'283 208 try: 284 209 value = value.replace("'","") … … 295 220 296 221 @classmethod 297 def session(self, value , row):222 def session(self, value): 298 223 """ '08' --> '2008' 299 224 '2008/2009' --> '2008' … … 319 244 320 245 @classmethod 321 def former(self, value, row): 322 """ True --> yes 323 '2008/2009' --> '2008' 324 """ 325 if value == 'True': 326 return 'yes' 327 return 328 329 @classmethod 330 def bool(self, value, row): 331 """ True --> 1 332 """ 333 if value in ('TRUE', 'True'): 334 return '1' 335 elif value in ('FALSE', 'False'): 336 return '0' 337 return 338 339 @classmethod 340 def year(self, value, row): 341 """ '0' --> '' 342 """ 343 if value == '0': 344 return 345 if value == 'None': 346 return 347 return value 348 349 350 @classmethod 351 def marit_stat(self, value, row): 246 def marit_stat(self, value): 352 247 """ 'True'/'False' --> 'married'/'unmarried' 353 248 """ … … 361 256 362 257 @classmethod 363 def gender(self, value , row):258 def gender(self, value): 364 259 """ 'True'/'False' --> 'f'/'m' 365 260 """ … … 373 268 374 269 @classmethod 375 def date(self, value , row):270 def date(self, value): 376 271 """ 'yyyy/mm/dd' --> 'yyyy-mm-dd' 377 272 """ … … 388 283 389 284 @classmethod 390 def no_int(self, value , row):391 """ Add hash and skip numbers starting with 999999285 def no_int(self, value): 286 """ Add hash. 392 287 """ 393 288 # We add the hash symbol to avoid automatic number transformation 394 289 # in Excel and Calc for further processing 395 try: 396 intvalue = int(value) 397 value += '#' 398 except: 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') 399 306 pass 400 if value.startswith('999999'): 401 return 402 return value 403 404 @classmethod 405 def mode(self, value, row): 307 #print "OUT: ", value 308 return value 309 310 @classmethod 311 def mode(self, value): 406 312 if value == "transfer_fulltime": 407 313 return "transfer_ft" … … 411 317 412 318 @classmethod 413 def password(self, value , row):319 def password(self, value): 414 320 if value == "not set": 415 321 return "" … … 417 323 418 324 @classmethod 419 def nationality(self, value , row):325 def nationality(self, value): 420 326 if value == "nigeria": 421 327 return "NG" 422 if value == "niger": 423 return "NE" 424 return value 425 426 @classmethod 427 def sittype(self, value, row): 428 if value == "nabtec": 429 return "nabteb" 430 return value 431 432 @classmethod 433 def company(self, value, row): 434 if value == "online": 435 return "interswitch" 436 return value 437 438 @classmethod 439 def p_category(self, value, row): 440 if value == "acceptance": 441 return "clearance" 442 return value 443 444 @classmethod 445 def email(self, value, row): 446 return value.strip() 447 448 @classmethod 449 def phone(self, value, row): 328 return value 329 330 @classmethod 331 def phone(self, value): 450 332 """ '<num-seq1>-<num-seq2> asd' -> '--<num-seq1><num-seq2>' 451 333 … … 453 335 of numbers. 454 336 """ 455 if not value:456 return457 value = value.strip('#')458 337 value = value.replace('-', '') 459 338 value = value.replace('/', '') 460 339 match = RE_PHONE.match(value) 461 340 phone = match.groups()[0] 462 if value.startswith('234'): 463 value = '+' + value[:3] + '-' + value[3:] 464 else: 465 value = '-%s' % phone 466 return value + '#' 467 468 @classmethod 469 def result(self, value, row): 470 try: 471 liste = eval(value) 472 except: 473 return 474 if isinstance(liste,list): 475 return [(i[0].lower(),i[1]) for i in liste] 476 return 341 value = '-%s' % phone 342 return value 477 343 478 344 … … 491 357 header = convert_fieldnames(reader.fieldnames) 492 358 writer.writerow(header) 493 if row.get('reg_state') == 'student_created':494 # We do not reimport student records which have never been accessed.495 continue496 if row.get('status') == 'started':497 # We do not reimport started payments.498 continue499 359 for key, value in row.items(): 500 # Remove unwanted whitespaces.501 row[key] = row[key].strip()502 360 if not key in OPTIONS.keys(): 503 361 continue … … 507 365 print "WARNING: cannot find converter %s" % conv_name 508 366 continue 509 row[key] = converter(row[key] , row)367 row[key] = converter(row[key]) 510 368 try: 511 369 writer.writerow(row)
Note: See TracChangeset for help on using the changeset viewer.