Changeset 2997 for WAeUP_SRP/base/skins
- Timestamp:
- 8 Jan 2008, 18:33:19 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part2.py
r2982 r2997 16 16 def set_trace(): 17 17 pass 18 18 19 19 20 mtool = context.portal_membership … … 39 40 response.write("%s<br>\n\r" % s) 40 41 41 def getLGAs():42 voc = getattr(context.portal_vocabularies,'local_gov_areas')43 states = []44 lgas = []45 d = {}46 for k,v in voc.items():47 parts = v.split(' / ')48 if len(parts) == 1:49 state = parts[0].lower()50 lga = ""51 elif len(parts) == 2:52 state = parts[0].lower()53 lga = "_".join(parts[1].lower().split())54 else:55 continue56 if state not in states:57 states.append(state)58 if lga not in lgas:59 lgas.append(lga)60 d[k] = v61 return (d,states,lgas)42 # def getLGAs(): 43 # voc = getattr(context.portal_vocabularies,'local_gov_areas') 44 # states = [] 45 # lgas = [] 46 # d = {} 47 # for k,v in voc.items(): 48 # parts = v.split(' / ') 49 # if len(parts) == 1: 50 # state = parts[0].lower() 51 # lga = "" 52 # elif len(parts) == 2: 53 # state = parts[0].lower() 54 # lga = "_".join(parts[1].lower().split()) 55 # else: 56 # continue 57 # if state not in states: 58 # states.append(state) 59 # if lga not in lgas: 60 # lgas.append(lga) 61 # d[k] = v 62 # return (d,states,lgas) 62 63 64 difference = context.waeup_tool.difference 65 re_split = context.waeup_tool.re_split 63 66 #logger.info('') 64 67 student_records = context.students_catalog() … … 68 71 commit_after = 100 69 72 logger.info('started to fix %d records in students_catalog' % total) 70 d,states,lgas = getLGAs() 73 mapping = context.waeup_tool.getStatesLgas() 74 states = mapping['states'] 75 lgas = mapping['lgas'] 76 words_dict = mapping['word_dict'] 71 77 d = {} 72 78 for student_record in student_records: 73 79 # skip record without lga value 80 count += 1 74 81 if not student_record.lga: 75 82 continue 76 #skip records with correct lga key value 77 if student_record.lga.find('_') > -1: 78 continue 83 # if student_record.lga.find(' ') < 0: 84 # continue 79 85 if student_record.lga.startswith('no state'): 80 logger.info("found invalid lga %s of %s" % (student_record.lga,student_record.id))86 #logger.info("found invalid lga %s of %s" % (student_record.lga,student_record.id)) 81 87 continue 82 88 #rwrite("%s: %s" % (student_record.id,student_record.lga)) 83 sl = student_record.lga.split(' / ')84 if len( sl) != 2:85 sl = student_record.lga.split('/')86 if len(sl) != 2:87 logger.info("found invalid lga %s of %s" % (student_record.lga,student_record.id))88 #rwrite("wrong size %s: %s" % (student_record.id,sl))89 continue90 state = sl[0].lower().strip()91 lga = sl[1].lower().strip()92 if not lga or not state:93 logger.info("found invalid lga %s of %s" % (student_record.lga,student_record.id))94 continue95 count += 196 if len(d) and not len(d) % commit_after:97 logger.info("found %d correct state/lga combinations of %d so far" % (len(d),count))98 if state in states:99 found = False100 while True:101 if lga in lgas:102 found = True89 words = student_record.lga 90 if len(words.split(' / ')) == 2: 91 words = words.replace(' / ',' ') 92 words = re_split('[^a-zA-Z0-9/]',words) 93 lga_words = [] 94 for word in words: 95 if word: 96 lga_words += word.lower(), 97 lga_words.sort() 98 # state = sl[0].lower().strip() 99 # state = '_'.join(state.split()) 100 # lga = sl[1].lower().strip() 101 # if not lga or not state: 102 # logger.info("found invalid lga %s of %s" % (student_record.lga,student_record.id)) 103 # continue 104 state_lga = '' 105 while not state_lga: 106 for k,l in words_dict.items(): 107 if lga_words == l: 108 state_lga = k 103 109 break 104 lga = lga.replace(' ','-') 105 if lga in lgas: 106 found = True 107 break 108 if found: 109 #msg = "found %s for %s" % (state_lga,student_record.id) 110 state_lga = state + '_' + lga 110 break 111 if state_lga: 112 if state_lga != student_record.lga: 113 msg = "found %s is %s for %s " % (state_lga,student_record.lga,student_record.id) 114 #rwrite(msg) 111 115 d[student_record.id] = state_lga 112 #else:113 #msg = "no '%s' '%s' for %s" % (state,lga,student_record.id)114 #rwrite(msg)115 #else:116 #msg = "no state '%s' '%s' for %s" % (state,lga,student_record.id)117 #rwrite(msg)118 # if count > 150:116 if len(d) and not len(d) % commit_after: 117 logger.info("found %d to correct state/lga combinations of %d so far" % (len(d),count)) 118 else: 119 msg = "already corrected %s : %s for %s " % (state_lga,student_record.lga,student_record.id) 120 else: 121 msg = "no '%s' for %s" % (lga_words,student_record.id) 122 # if count > 2000: 119 123 # break 120 124 to_edit = len(d)
Note: See TracChangeset for help on using the changeset viewer.