Changeset 3014


Ignore:
Timestamp:
11 Jan 2008, 20:18:17 (17 years ago)
Author:
joachim
Message:

WAeUP LGA Widget uses new algorithm
ti_441_resolve_part1 + part2 also
part2 can now be used to rename lgas, a list of all not found lgas is
printed at the end.

Location:
WAeUP_SRP/base
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/base/WAeUPTool.py

    r3003 r3014  
    7878    def re_split(self,split_string,string):
    7979        return re.split(split_string,string)
    80 
     80    ###)
    8181
    8282    security.declareProtected(View,'difference') ###(
    8383    def difference(self,l1,l2):
    8484        return set(l1).difference(set(l2))
     85    ###)
    8586
    8687    def rwrite(self,s): ###(
     
    144145    ###)
    145146
     147    security.declareProtected(View,'findLga') ###(
     148    def findLga(self,words,words_dict):
     149        words = re.split('[^a-zA-Z0-9/]',words)
     150        lga_words = []
     151        for word in words:
     152            if word:
     153                lga_words += word.strip().lower(),
     154        lga_words.sort()
     155        state_lga = ''
     156        while not state_lga:
     157            for k,l in words_dict.items():
     158                if lga_words == l:
     159                    state_lga = k
     160                    break
     161            break
     162        return state_lga
     163    ###)
    146164    security.declareProtected(View,'getAccessInfo') ###(
    147165    def getAccessInfo(self,context):
  • WAeUP_SRP/base/Widgets.py

    r2875 r3014  
    580580
    581581    def _getLGAs(self):
    582         voc = getattr(self.portal_vocabularies,self.vocabulary)
    583582        if getattr(self,'_v_states',None) is not None and\
    584583           getattr(self,'_v_lgas',None) is not None and\
    585            getattr(self,'_v_d',None) is not None:
    586             return (_v_d,_v_states,_v_lgas)
    587         states = []
    588         lgas  = []
    589         d = {}
    590         for k,v in voc.items():
    591             parts = v.split(' / ')
    592             if len(parts) == 1:
    593                 state = parts[0].lower()
    594                 lga = ""
    595             elif len(parts) == 2:
    596                 state = parts[0].lower()
    597                 lga = "_".join(re.split('\W+',parts[1].lower()))
    598             else:
    599                 continue
    600             if state not in states:
    601                 states.append(state)
    602             if lga not in lgas:
    603                 lgas.append(lga)
    604             d[k] = v
    605         self._v_d = d
    606         self._v_state = state
    607         self._v_lga = lga
    608         return (d,states,lgas)
     584           getattr(self,'_v_d',None) is not None and\
     585           getattr(self,'_v_word_dict',None) is not None:
     586            return (self._v_d,self._v_states,self._v_lgas,self._v_word_dict)
     587        mapping = self.waeup_tool.getStatesLgas()
     588        self._v_d = mapping['lga_dict']
     589        self._v_states = mapping['states']
     590        self._v_lgas = mapping['lgas']
     591        self._v_word_dict = mapping['word_dict']
     592        return (self._v_d,self._v_states,self._v_lgas,self._v_word_dict)
     593
    609594
    610595    def validate(self, datastructure, **kw):
     
    619604            return 0
    620605        v = v.lower()
    621         combined,states,lgas = self._getLGAs()
     606        combined,states,lgas,word_dict = self._getLGAs()
    622607        datamodel = datastructure.getDataModel()
    623         if not self.state_field and not self.lga_field:
    624             if len(v) == 0 and self.is_required:
    625                 datastructure.setError(widget_id, "%s required" % widget_id)
     608        if self.state_field and self.lga_field:
     609            v = ' '.join((datastructure.get(self.state_field,""),
     610                              datastructure.get(self.lga_field,"")))
     611        state_lga = self.waeup_tool.findLga(v,word_dict)
     612        if not state_lga:
     613            if self.is_required:
     614                datastructure.setError(widget_id, "'%s' not a valid lga key" % v)
     615                #datastructure.setError(widget_id, "%s required" % widget_id)
    626616                return 0
    627             elif v not in combined.keys():
    628                 datastructure.setError(widget_id, "'%s' not a valid lga key" % v)
    629                 return 0
    630             datamodel[self.fields[0]] = v
    631         else:
    632             state = datastructure.get(self.state_field,"").lower()
    633             lga = datastructure.get(self.lga_field,"").lower()
    634             if widget_id == self.state_field:
    635                 if state not in states:
    636                     datastructure.setError(widget_id, "'%s' not a valid state" % v)
    637                     return 0
    638             elif widget_id == self.lga_field:
    639                 if lga not in lgas:
    640                     datastructure.setError(widget_id, "'%s' not a valid lga" % v)
    641                     return 0
    642             if len(state) == 0 or len(lga) == 0:
    643                 datastructure.setError(widget_id, "state AND lga must be given")
    644                 return 0
    645             datamodel[self.fields[0]] =   state + "_" + lga
     617            else:
     618                state_lga = v
     619        datamodel[self.fields[0]] = state_lga
    646620        return 1
    647621
  • WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part1.py

    r3009 r3014  
    5757    jamb_lga = getattr(getattr(students_folder,student_record.id),'application').getContent().jamb_lga
    5858    words = ' '.join((jamb_state, jamb_lga))
    59     words = re_split('[^a-zA-Z0-9/]',words)
    60     lga_words = []
    61     for word in words:
    62         if word:
    63             lga_words += word.lower(),
    64     lga_words.sort()
    65     state_lga = ''
    66     while not state_lga:
    67         for k,l in words_dict.items():
    68             if lga_words == l:
    69                 state_lga = k
    70                 break
    71         break
     59    # words = re_split('[^a-zA-Z0-9/]',words)
     60    # lga_words = []
     61    # for word in words:
     62    #     if word:
     63    #         lga_words += word.lower(),
     64    # lga_words.sort()
     65    # state_lga = ''
     66    # while not state_lga:
     67    #     for k,l in words_dict.items():
     68    #         if lga_words == l:
     69    #             state_lga = k
     70    #             break
     71    #     break
     72    state_lga = context.waeup_tool.findLga(words,words_dict)
    7273    if state_lga:
    7374        msg = "found %s is %s for %s " % (state_lga,student_record.lga,student_record.id)
     
    7879            logger.info("found %d to correct state/lga combinations of %d so far" % (len(d),count))
    7980    else:
    80         msg = "no '%s' for %s" % (lga_words,student_record.id)
     81        msg = "no '%s' for %s" % (words,student_record.id)
    8182        logger.info(msg)
    8283        #rwrite(msg)
  • WAeUP_SRP/base/skins/waeup_utilities/ti_441_resolve_part2.py

    r2997 r3014  
    6262#     return (d,states,lgas)
    6363
    64 difference = context.waeup_tool.difference
     64#difference = context.waeup_tool.difference
    6565re_split = context.waeup_tool.re_split
    6666#logger.info('')
     
    6969logger.info("found %d students" % total)
    7070count = 0
     71correctable = wrong = 1
    7172commit_after = 100
    7273logger.info('started to fix %d records in students_catalog' % total)
     
    7677words_dict = mapping['word_dict']
    7778d = {}
     79not_found_lgas = []
     80not_found_count = {}
     81rename_lgas = {}
     82rename_lgas['edo_orhionmwon'] = 'edo_ohionmwon'
    7883for student_record in student_records:
    7984    # skip record without lga value
     
    8792        continue
    8893    #rwrite("%s: %s" % (student_record.id,student_record.lga))
     94    if student_record.lga in rename_lgas.keys():
     95        correctable += 1
     96        d[student_record.id] = rename_lgas[student_record.lga]
     97        if len(d) and not len(d)  % commit_after:
     98            logger.info("found %d to correct state/lga combinations of %d so far" % (len(d),count))
     99        continue
    89100    words = student_record.lga
    90101    if len(words.split(' / ')) == 2:
    91102        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
    109                 break
    110         break
     103    state_lga = context.waeup_tool.findLga(words,words_dict)
    111104    if state_lga:
    112105        if state_lga != student_record.lga:
     106            correctable += 1
    113107            msg = "found %s is %s for %s " % (state_lga,student_record.lga,student_record.id)
    114108            #rwrite(msg)
     
    119113            msg = "already corrected %s : %s for %s " % (state_lga,student_record.lga,student_record.id)
    120114    else:
    121         msg = "no '%s' for %s" % (lga_words,student_record.id)
     115        wrong += 1
     116        msg = "no '%s' for %s" % (words,student_record.id)
     117        if len(words) > 2:
     118            if words not in not_found_lgas:
     119                not_found_lgas += words,
     120                not_found_count[words] = 1
     121            else:
     122                nfc = not_found_count[words]
     123                nfc += 1
     124                not_found_count[words] = nfc
     125        #rwrite(msg)
    122126    # if count > 2000:
    123127    #     break
     128not_found_lgas.sort()
     129for lga in not_found_lgas:
     130    msg = "not found %s count: %d" % (lga,not_found_count[lga])
     131    logger.info(msg)
    124132to_edit = len(d)
    125 logger.info("found %d correct state/lga combinations of %d" % (to_edit,count))
    126 
     133logger.info("found %d correctable state/lga combinations, not correctable %d total %d" % (correctable,
     134                                                                                          wrong,
     135                                                                                          count))
    127136edited = 1
    128137for student_id,lga in d.items():
Note: See TracChangeset for help on using the changeset viewer.