[Mpuls-commits] r619 - in wasko/branches/1.0: . waskaweb/controllers waskaweb/lib waskaweb/templates/evaluation

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Oct 6 09:46:10 CEST 2009


Author: torsten
Date: 2009-10-06 09:46:09 +0200 (Tue, 06 Oct 2009)
New Revision: 619

Modified:
   wasko/branches/1.0/ChangeLog.txt
   wasko/branches/1.0/waskaweb/controllers/evaluate.py
   wasko/branches/1.0/waskaweb/lib/helpers.py
   wasko/branches/1.0/waskaweb/lib/validators.py
   wasko/branches/1.0/waskaweb/templates/evaluation/evaluate.mako
Log:
Implemented mor filters for evaluation


Modified: wasko/branches/1.0/ChangeLog.txt
===================================================================
--- wasko/branches/1.0/ChangeLog.txt	2009-10-05 10:27:52 UTC (rev 618)
+++ wasko/branches/1.0/ChangeLog.txt	2009-10-06 07:46:09 UTC (rev 619)
@@ -1,3 +1,15 @@
+2009-10-06	Torsten Irlaender	<torsten.irlaender at intevation.de> 
+
+	Implemented searchfiters for evaluations
+
+	* waskaweb/controllers/evaluate.py,
+	  waskaweb/lib/helpers.py,
+	  waskaweb/lib/validators.py,
+	  waskaweb/templates/evaluation/evaluate.mako: Added filters for phase
+	  and type of ending. Bases on the filters in connection with dates a
+	  sql query is generated which is used to build the base amount of
+	  cases for the evaluation.
+
 2009-10-05	Torsten Irlaender	<torsten.irlaender at intevation.de> 
 
 	Fixed logbuch evalauation

Modified: wasko/branches/1.0/waskaweb/controllers/evaluate.py
===================================================================
--- wasko/branches/1.0/waskaweb/controllers/evaluate.py	2009-10-05 10:27:52 UTC (rev 618)
+++ wasko/branches/1.0/waskaweb/controllers/evaluate.py	2009-10-06 07:46:09 UTC (rev 619)
@@ -8,7 +8,7 @@
 from waskaweb.lib.validators import EvaluationFormValidator
 from waskaweb.lib.base import *
 from waskaweb.lib.db import db
-from waskaweb.lib.helpers import format_date 
+from waskaweb.lib.helpers import format_date, get_phasesuccessors 
 from libmpuls.evaluation.config import EvaluationConfig
 from libmpuls.evaluation.evaluation import EvaluationSet
 from libmpuls.evaluation.export import EvaluationExportXML, EvaluationExportCSV, EvaluationExportHTML
@@ -54,6 +54,12 @@
 
     options['typelist'] = c.evalconfig.get_evaluations()
 
+    phases = []
+    for p in g.mpuls_config.get('search', 'phases'):
+        pt = [t for t in p.values() if int(t) >= 0]
+        phases.extend(pt)
+    options['phase'] =  phases
+
     # convert dates to locale
     options['start_date'] = format_date(options['start_date']) 
     options['end_date']   = format_date(options['end_date']) 
@@ -94,9 +100,60 @@
                 errors={}, \
                 auto_insert_errors=False)
 
+    def _get_evalparams(self, form_result):
+        params = {}
+        params['start_date'] = str(form_result['start_date'])
+        params['end_date'] = str(form_result['end_date'])
+        params['typelist'] = form_result['typelist']
+        params['phase']    = form_result['phase']
+        params['ending']    = form_result['type_ending']
+
+        # Dates
+        # Build timeframes bases on selected phases.
+        dates = []
+        all_phases = []
+        tdates = []
+        phase = params.get('phase')
+        dates.append('( ')
+        if params.get('start_date') and params.get('end_date'):
+            if phase:
+                for p in phase:
+                    if int(p) >= 0: # phase is unknown -> has no start and endphase
+                        sdf = g.mpuls_config.get('agency-fields-mapping', 'date_phase%s_start' % p)
+                        edf = g.mpuls_config.get('agency-fields-mapping', 'date_phase%s_end' % p) 
+                        suc = get_phasesuccessors(p)
+                        all_phases.extend(suc)
+                        tdates.append("('%s'::date <= %s AND '%s'::date >= %s AND phase IN (%s) )" % (params.get('start_date'), edf, params.get('end_date'), sdf, ",".join(["%s" % s for s in suc])))
+                    else:
+                        tdates.append('phase IN (-1)')
+                dates.append(" OR ".join(tdates))
+            else:
+                dates.append("FALSE")
+        else:
+            dates.append("TRUE")
+        dates.append(' )')
+
+        # Type of ending
+        ending = " TRUE " 
+        if params['ending']:
+            ending = "cm_end_art in ( %s )" % ", ".join(['%s' % e for e in params['ending']])
+
+        params['sql'] = "SELECT %%(fields)s from master_tbl_eval_total_view m WHERE %s AND %s" % ("".join(dates), ending)
+
+        #Datefields
+        if all_phases:
+            params['start_date_field'] = g.mpuls_config.get('agency-fields-mapping', 'date_phase%s_start' % min(all_phases))
+            params['end_date_field'] = g.mpuls_config.get('agency-fields-mapping', 'date_phase%s_start' % max(all_phases))
+        else:
+            params['start_date_field'] = g.mpuls_config.get('evaloptions', 'default-start-date-field')
+            params['end_date_field'] =  g.mpuls_config.get('evaloptions', 'default-end-date-field')
+        return params
+
+
     def evaluateAction(self):
             '''Return an HTML file containing the result of one or more evaluations.'''
             params = formencode.variabledecode.variable_decode(request.params)
+            #params = request.params
             validator    = EvaluationFormValidator() 
             form_result  = {}
             form_errors  = {}
@@ -118,6 +175,7 @@
             try:
                 form_result  = validator.to_python(params)
             except formencode.Invalid, error:
+                print error
                 form_result = error.value
                 form_errors = error.error_dict or {}
                 c.evaloptions = get_search_options(session.get('evaluation.options'), id)
@@ -128,18 +186,19 @@
                         auto_insert_errors=False)
 
             # Build evaluation
+            eval_params = self._get_evalparams(form_result)
             try:
                 try:
                     evalconfig   = EvaluationConfig(
                                     get_configfile(form_result['id']),
                                     conn,
-                                    str(form_result['start_date']), 
-                                    str(form_result['end_date']),
-                                    form_result['start_date_field'], 
-                                    form_result['end_date_field'], 
+                                    eval_params['start_date'], 
+                                    eval_params['end_date'],
+                                    eval_params['start_date_field'], 
+                                    eval_params['end_date_field'], 
                                     None,
-                                    form_result['sql'], 
-                                    form_result['typelist'])
+                                    eval_params['sql'], 
+                                    eval_params['typelist'])
                     evalset      = EvaluationSet(evalconfig, True)
                     evalset.evaluate()
                     c.result = evalset.export(EvaluationExportHTML(show_percent=form_result['show_percent']))

Modified: wasko/branches/1.0/waskaweb/lib/helpers.py
===================================================================
--- wasko/branches/1.0/waskaweb/lib/helpers.py	2009-10-05 10:27:52 UTC (rev 618)
+++ wasko/branches/1.0/waskaweb/lib/helpers.py	2009-10-06 07:46:09 UTC (rev 619)
@@ -373,6 +373,38 @@
 def safe_unicode(s):
     return u''.join([c for c in s if ord(c) > 127 or c in PRINTABLE])
 
+
+# Phases helpers. Used in evaluation
+def get_phasesuccessors(p):
+    #p = int(p)
+    phasesuc = []
+    pairs = g.mpuls_config.get('phases', 'pairs')[0]
+    for phase, symbols in pairs.iteritems():
+        if p in symbols:
+            for pair in phase_successors_path(phase, None, True):
+                phasesuc.extend(pairs.get(pair))
+    return phasesuc
+
+def phase_successors(phase):
+    try:
+        suc = g.mpuls_config.get('phases', 'successors')[0][phase]
+        return suc
+    except KeyError:
+        return []
+
+def phase_successors_path(phase, path=None, include_root=False):
+    '''returns list of phase ids (not phasepairs)'''
+    if not path:
+        path = []
+        if include_root:
+            path.append(phase)
+    for p in phase_successors(phase):
+        path.append(p)
+        phase_successors_path(p, path=path)
+    return path
+
+    return phasesuc
+
 # Unicode <-> Str converters. The whole code is fu*&%d  up with mixed str and unicode. So we need some helpers to convert.
 
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

Modified: wasko/branches/1.0/waskaweb/lib/validators.py
===================================================================
--- wasko/branches/1.0/waskaweb/lib/validators.py	2009-10-05 10:27:52 UTC (rev 618)
+++ wasko/branches/1.0/waskaweb/lib/validators.py	2009-10-06 07:46:09 UTC (rev 619)
@@ -427,9 +427,11 @@
     agencyid            = formencode.validators.String(if_missing=g.mpuls_config.get('common', 'agencyname'))
     start_date          = MyDateConverter(if_missing='')
     end_date            = MyDateConverter(if_missing='')
-    start_date_field    = formencode.validators.String(not_empty=True)
-    end_date_field      = formencode.validators.String(not_empty=True)
+    start_date_field    = formencode.validators.String(if_missing=g.mpuls_config.get('evaloptions', 'default-start-date-field'))
+    end_date_field      = formencode.validators.String(if_missing=g.mpuls_config.get('evaloptions', 'default-end-date-field'))
     typelist            = formencode.ForEach(formencode.validators.String(), convert_to_list=True)
+    type_ending         = formencode.ForEach(formencode.validators.String(), convert_to_list=True)
+    phase               = formencode.ForEach(formencode.validators.String(), convert_to_list=True)
     show_percent        = formencode.validators.Bool(if_missing=False)
 
 class ExtraTimeFormValidator1(BaseFormValidator):

Modified: wasko/branches/1.0/waskaweb/templates/evaluation/evaluate.mako
===================================================================
--- wasko/branches/1.0/waskaweb/templates/evaluation/evaluate.mako	2009-10-05 10:27:52 UTC (rev 618)
+++ wasko/branches/1.0/waskaweb/templates/evaluation/evaluate.mako	2009-10-06 07:46:09 UTC (rev 619)
@@ -15,31 +15,28 @@
 <div>
 <form action="/evaluate/evaluateAction" method="POST">
 <input type="hidden" name="id">
-<input type="hidden" name="phase">
-<input type="hidden" name="sql">
 <h2>${_('Setup evaluation')}</h2>
 <table>
   <tr>
     <td class="label">${_('Name')}</td>
-    <td colspan="2">${c.evalconfig.get_setname()}</td>
+    <td>${c.evalconfig.get_setname()}</td>
   </tr>
   <tr>
     <td class="label">${_('Description')}</td>
-    <td colspan="2">${c.evalconfig.get_setdesc()}</td>
+    <td>${c.evalconfig.get_setdesc()}</td>
   </tr>
   <tr>
   <tr>
-    <td class="label">Start</td>
+    <td class="label">Phase</td>
     <td>
-      <select name="start_date_field">
-        <option value="m.erstgespraech">Begin Eingansdokumentation</optioen>
-        <option value="coalesce(datum_cm_start, now())">Ende Eingansdokumentation</optioen>
-        <option value="datum_cm_start">Begin Casemenagement</option>
-        <option value="coalesce(datum_cm_ende, now())">Ende Casemanagement</option>
-        <option value="nbetr_start">Begin Nachbetreuung</option>
-        <option value="coalesce(nbetr_ende, now())">Ende Nachbetreuung</option>
-      </select>
+      <input type="checkbox" name="phase" value="-1"> Unbekannt<br>
+      <input type="checkbox" name="phase" value="0"> Eingabsdokumentation<br>
+      <input type="checkbox" name="phase" value="2"> Casemanagement<br>
+      <input type="checkbox" name="phase" value="4"> Nachbetreuung<br>
     </td>
+  </tr>
+  <tr>
+    <td class="label">Start</td>
     <td>
       <input type="text" name="start_date" class="datefield"><form:error name="start_date" format="">
     </td>
@@ -47,17 +44,15 @@
   <tr>
     <td class="label">Ende</td>
     <td>
-      <select name="end_date_field">
-        <option value="m.erstgespraech">Begin Eingansdokumentation</optioen>
-        <option value="coalesce(datum_cm_start, now())">Ende Eingansdokumentation</optioen>
-        <option value="datum_cm_start">Begin Casemenagement</option>
-        <option value="coalesce(datum_cm_ende, now())">Ende Casemanagement</option>
-        <option value="nbetr_start">Begin Nachbetreuung</option>
-        <option value="coalesce(nbetr_ende, now())">Ende Nachbetreuung</option>
-      </select>
+      <input type="text" name="end_date" class="datefield"><form:error name="end_date" format="">
     </td>
+  </tr>
+  <tr>
+    <td class="label">Art der Beendigung</td>
     <td>
-      <input type="text" name="end_date" class="datefield"><form:error name="end_date" format="">
+      <input type="checkbox" value="1" name="type_ending"/> erfolgreiche Reintegration in die Schule<br/>
+      <input type="checkbox" value="2" name="type_ending"/> sonstige Beendigung<br/> 
+      <input type="checkbox" value="3" name="type_ending"/> Abbruch<br/>
     </td>
   </tr>
   % if session.has_key('evaluation.options'):



More information about the Mpuls-commits mailing list