Ignore:
Timestamp:
8 Jan 2008, 18:33:19 (17 years ago)
Author:
joachim
Message:

should fix all fixable, some lgas have been added some edited to/in
local_gov_areas.xml

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part2.py

    r2982 r2997  
    1616    def set_trace():
    1717        pass
     18
    1819
    1920mtool = context.portal_membership
     
    3940    response.write("%s<br>\n\r" % s)
    4041
    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             continue
    56         if state not in states:
    57             states.append(state)
    58         if lga not in lgas:
    59             lgas.append(lga)
    60         d[k] = v
    61     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)
    6263
     64difference = context.waeup_tool.difference
     65re_split = context.waeup_tool.re_split
    6366#logger.info('')
    6467student_records = context.students_catalog()
     
    6871commit_after = 100
    6972logger.info('started to fix %d records in students_catalog' % total)
    70 d,states,lgas = getLGAs()
     73mapping = context.waeup_tool.getStatesLgas()
     74states = mapping['states']
     75lgas = mapping['lgas']
     76words_dict = mapping['word_dict']
    7177d = {}
    7278for student_record in student_records:
    7379    # skip record without lga value
     80    count += 1
    7481    if not student_record.lga:
    7582        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
    7985    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))
    8187        continue
    8288    #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             continue
    90     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         continue
    95     count += 1
    96     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 = False
    100         while True:
    101             if lga in lgas:
    102                 found = True
     89    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
    103109                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)
    111115            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:
    119123    #     break
    120124to_edit = len(d)
Note: See TracChangeset for help on using the changeset viewer.