[Mpuls-commits] r500 - in waska/trunk: . waskaweb/controllers waskaweb/lib waskaweb/templates waskaweb/templates/casemanagement/evaluation

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Apr 27 14:30:25 CEST 2009


Author: torsten
Date: 2009-04-27 14:30:24 +0200 (Mon, 27 Apr 2009)
New Revision: 500

Added:
   waska/trunk/waskaweb/lib/basicevaluation.py
   waska/trunk/waskaweb/templates/casemanagement/evaluation/evaluation_basic.mako
Modified:
   waska/trunk/ChangeLog.txt
   waska/trunk/development_wsgi.ini
   waska/trunk/production_wsgi.ini
   waska/trunk/waskaweb/controllers/evaluate.py
   waska/trunk/waskaweb/lib/evaluation_new.py
   waska/trunk/waskaweb/lib/helpers.py
   waska/trunk/waskaweb/templates/casemanagement/evaluation/evaluation_adele.mako
   waska/trunk/waskaweb/templates/main.mako
Log:
Added new evaluation stub. TODO: Write real evaliuation conditions


Modified: waska/trunk/ChangeLog.txt
===================================================================
--- waska/trunk/ChangeLog.txt	2009-04-24 08:09:52 UTC (rev 499)
+++ waska/trunk/ChangeLog.txt	2009-04-27 12:30:24 UTC (rev 500)
@@ -1,3 +1,16 @@
+2009-04-27	Torsten Irlaender  <torsten.irlaender at intevation.de>
+
+	Added new evaluation stub.
+
+	* waskaweb/controllers/evaluate.py,
+	  waskaweb/lib/helpers.py,
+	  waskaweb/lib/basicevaluation.py,
+	  waskaweb/lib/evaluation_new.py,
+	  waskaweb/templates/casemanagement/evaluation/evaluation_adele.mako,
+	  waskaweb/templates/casemanagement/evaluation/evaluation_basic.mako,
+	  waskaweb/templates/main.mako: Added new evaluation. Added category
+	  "unknown" to all evaluations.
+
 2009-03-31	Torsten Irlaender  <torsten.irlaender at intevation.de>
 
 	Added dropdown menu to select date for adele evaluation.

Modified: waska/trunk/development_wsgi.ini
===================================================================
--- waska/trunk/development_wsgi.ini	2009-04-24 08:09:52 UTC (rev 499)
+++ waska/trunk/development_wsgi.ini	2009-04-27 12:30:24 UTC (rev 500)
@@ -20,7 +20,7 @@
 # db_user:     first %s -> database name, second %s -> user
 db_database = ka_%s_db
 db_user     = ka_%s_%s
-db_host     = 192.168.11.17
+db_host     = 192.168.193.6
 db_port     = 5434
 
 # for connections to PDF2XFA server

Modified: waska/trunk/production_wsgi.ini
===================================================================
--- waska/trunk/production_wsgi.ini	2009-04-24 08:09:52 UTC (rev 499)
+++ waska/trunk/production_wsgi.ini	2009-04-27 12:30:24 UTC (rev 500)
@@ -16,7 +16,7 @@
 # db_user:     first %s -> database name, second %s -> user
 db_database = ka_%s_db
 db_user     = ka_%s_%s
-db_host     = 192.168.11.17
+db_host     = 192.168.193.6
 db_port     = 5434
 
 # for connections to PDF2XFA server

Modified: waska/trunk/waskaweb/controllers/evaluate.py
===================================================================
--- waska/trunk/waskaweb/controllers/evaluate.py	2009-04-24 08:09:52 UTC (rev 499)
+++ waska/trunk/waskaweb/controllers/evaluate.py	2009-04-27 12:30:24 UTC (rev 500)
@@ -38,6 +38,7 @@
 from waskaweb.lib.evaluation import *
 from waskaweb.lib.evaluation_new import Evaluation as NewEvaluation, EvaluationExportXML
 from waskaweb.lib.adelexml import AdeleXML
+from waskaweb.lib.basicevaluation import BasicEvaluation
 from waskaweb.lib.evaluation_new import *
 from waskaweb.lib.search import CaseSearch
 from waskaweb.lib.validators import SearchCaseForm 
@@ -161,6 +162,32 @@
         c.eval = evaluation.perform()
         return render('casemanagement/evaluation/evaluation_adele.mako')
 
+    def evaluateBasic(self):
+        params = {}
+        params['start_date'] = '2008-09-01'
+        params['end_date']   = '2009-05-31'
+        c.select = 2
+        if request.params:
+            if request.params.get('timeframe') == '1':
+                params['start_date'] = '2008-09-01'
+                params['end_date']   = '2008-12-31'
+                c.select = 1
+            else:
+                params['start_date'] = '2009-01-01'
+                params['end_date']   = '2009-03-31'
+                c.select = 2
+
+        params['agencyid']   = 'inte0002'
+
+        y,m,d = [int(i) for i in params['start_date'].split('-')]
+        c.start_date = datetime(y,m,d)
+        y,m,d = [int(i) for i in params['end_date'].split('-')]
+        c.end_date = datetime(y,m,d)
+
+        evaluation = BasicEvaluation(params)
+        c.eval = evaluation.perform()
+        return render('casemanagement/evaluation/evaluation_basic.mako')
+
     @checkRole(('admin_ka', 'cm_ka', 'pt_dlr', 'pb_ka'))
     def evaluate(self, id, reset=0):
         reset = self._checkBool(reset)

Added: waska/trunk/waskaweb/lib/basicevaluation.py
===================================================================
--- waska/trunk/waskaweb/lib/basicevaluation.py	2009-04-24 08:09:52 UTC (rev 499)
+++ waska/trunk/waskaweb/lib/basicevaluation.py	2009-04-27 12:30:24 UTC (rev 500)
@@ -0,0 +1,195 @@
+# -*- coding: utf-8 -*-
+#
+# (c) 2008 by Intevation GmbH
+# This is Free software under the GPLv3. 
+# See LICENSE comming with the source of 'mpuls'
+# for details.
+#
+# author: Torsten Irländer <torsten.irlaender at intevation.de>
+#
+import re, logging
+from datetime import datetime
+from waskaweb.lib.db import db
+from waskaweb.lib.evaluation_new import *
+log = logging.getLogger(__name__)
+
+#JSA.02.12345.08
+EXP_DOKNR  = re.compile('^JSA\.0[0-2]{1}\.([0-9]{5})\.[0-9]{2}$')
+EXP_TYPE   = re.compile('^([0-9]{1,2},?)+$')
+EXP_DATE   = re.compile('^\d{4}-\d{2}-\d{2}$')
+
+SQL_TABLE      = "master_tbl_eval_total_view"
+SQL_GENDER_FIELD   = 'geschlecht'
+SQL_FKZ = """(TRUE)"""
+SQL_CM = """
+-- Nur CM-Faelle
+((kompetenzfeststellung = '1' 
+    or (kompetenzfeststellung = '-1' and phase in (2,3,4,5))
+) 
+or (bereich_berufliche_qualifizierung = '1' or bereich_berufsvorbereitung = '1'
+   or bildender_bereich = '1' or bereich_lebensbewaeltigung = '1' or
+   sonstiger_foerderbedarf = '1'))"""
+
+# begin,ende,begin,begin,begin,ende,begin,ende,ende,begin,begin,begin,ende,begin,ende
+SQL_TIME = """TRUE"""
+SQL_TIME2 = """
+(
+    --
+    -- Ausfiltern der Faelle, die definitiv nicht in Frage kommen
+    --
+    -- Status schwebend geloescht
+    not (s.status = 3)
+    -- Status nicht beendet aber schon anonymisiert
+    and not (s.status = 5 and beendigung_5 is NULL)
+    -- Beendigung vor BZ
+    and not (coalesce(beendigung_5, now()) < '%s'::date)
+    -- Begin nach BZ
+    and not (coalesce(datum_feststellung, '1970-01-01'::date) > '%s'::date)
+    -- Begin vor BZ aber auch letzte Aktualisierung vor BZ
+    and not (coalesce(datum_feststellung, '1970-01-01'::date) < '%s'::date
+             and s.zugriff < '%s'::date)
+    -- Kein Begin und Erstgespraech nicht im BZ
+    and not (datum_feststellung IS NULL and (coalesce(erstgespraech,
+    '1970-01-01'::date) < '%s'::date or coalesce(erstgespraech,
+    '1970-01-01'::date) > '%s'::date)
+    )
+)
+and (
+    --
+    -- Nur Faelle die den Kriterien entsprechen 
+    --
+    -- Beendigung im BZ
+    (coalesce(beendigung_5, now()) >= '%s'::date 
+    and coalesce(beendigung_5, now()) <= '%s'::date) 
+    or (
+      -- Beendigung nach BZ
+      coalesce(beendigung_5, now()) >= '%s'::date 
+      and (
+    -- Begin vor BZ und Aktualisierung nach Begin BZ
+    (datum_feststellung < '%s'::date and s.zugriff >=
+    '%s'::date) 
+    or 
+    -- Begin im BZ
+    (datum_feststellung >= '%s'::date 
+    and datum_feststellung <= '%s'::date)
+      )
+      -- Erstgespraech innerhalb des BZ
+      or ( erstgespraech >= '%s'::date and erstgespraech <=
+      '%s'::date)
+    )
+)
+"""
+# Alte Abfrage
+#SQL_TIME = """(datum_feststellung <= '%s'::date and coalesce(beendigung_5, now()) >= '%s'::date)"""
+# Für die erste Auswertung geändert. Auch alle Bestandskunden sollen zunächst
+# als Eintritte gezählt werden.Damit ist die Anzahl der CM Kunden = Eintritte.
+# SQL_EINTRITTE_GESAMT           = """('%s'::date <= datum_feststellung and '%s'::date >= datum_feststellung)"""
+SQL_GESAMT = """TRUE"""
+SQL_CMKUNDEN = SQL_CM
+
+EVALUATION = {'1': SQL_GESAMT,
+              '2': SQL_CMKUNDEN
+              }
+
+DEFAULT_EVALUATIONS = ['1','2']
+
+EVAL_NAMES = {'1': u'Fälle gesamt',
+              '2': u'CM-Fälle gesamt',
+              }
+
+EVAL_DESCRIPTIONS = {'1': u'Anzahl der Teilnehmer/innen, die im Auswertungszeitraum in der Einrichtung betreut wurden.',
+              '2': u'Gesamtanzahl der Teilnehmer/innen, die im Auswertungszeitraum als CM-Kunden betreut wurden.',
+              }
+
+class BasicEvaluation(Evaluation):
+    def __init__(self, params):
+        Evaluation.__init__(self, params)
+
+    def _setup(self):
+        self.evaluation_mapping  = EVALUATION
+        self.default_evaluations = DEFAULT_EVALUATIONS
+        self.sql_base_query      = SQL_BASE_QUERY
+        self.sql_table           = SQL_TABLE
+        self.sql_gender          = SQL_GENDER_FIELD
+
+        #custom
+        self.sql_time_frame      = SQL_TIME
+        self.sql_fkz             = SQL_FKZ
+
+    def _build_sql(self, where):
+        out = []
+        try:
+            #out.append(self.sql_fkz % self.agency)
+            # begin,ende,begin,begin,begin,ende
+            begin = self.start_date
+            ende  = self.end_date
+            #out.append(self.sql_time_frame % (begin,ende,begin,begin,begin,ende,begin,ende,ende,begin,begin,begin,ende,begin,ende))
+            out.append(self.sql_time_frame) 
+
+        except StandardError, err:
+            print "Fehler: %s" % err
+        try:
+            out.append(where % (self.start_date, self.end_date))
+        except StandardError, err:
+            out.append(where)
+            pass # Maybe the where clause does not have any time restrictions
+        where = " and ".join(out)
+        sql = Evaluation._build_sql(self, where)
+        return sql
+
+#class AdeleXML:
+#
+#    def perform(self, params):
+#        doknr      = params.get('doknr')
+#        start_date = params.get('start_date')
+#        end_date   = params.get('end_date')
+#        typelist   = params.get('typelist')
+#
+#        #TEST Remove for production
+#        doknr = 'JSA.02.12345.08'
+#        start_date = '2008-01-01'
+#        end_date = '2008-12-31'
+#
+#        #Do some checks on the incoming data
+#        if not doknr or not EXP_DOKNR.match(doknr): return "INVALID: 'doknr'"
+#        if not start_date or not EXP_DATE.match(start_date): return "INVALID: 'start_date'"
+#        if not end_date or not EXP_DATE.match(end_date): return "INVALID: 'end_date'"
+#        if not typelist:
+#            TYPELIST = DEFAULT_EVALUATIONS
+#        else:
+#            if not EXP_TYPE.match(typelist): return "INVALID: 'typelist'"
+#            TYPELIST = typelist.split(',')
+#
+#        #Make evaluation on the collected cases
+#        try:
+#            out = []
+#            out.append(XML_HEADER % (doknr, start_date, end_date)) 
+#            for id in TYPELIST:
+#                SQL_WHERE = EVALUATION.get(str(id), 'TRUE')
+#
+#                # If the timeinterval was not or not full provied set timeframe
+#                # to a very large interval 
+#                if not start_date or not end_date:
+#                    start_date = '1970-01-01'
+#                    end_date = '%s' % datetime.today().strftime('%Y-%m-%d') 
+#
+#                TIMEFRAME = SQL_TIME % (end_date, start_date)
+#
+#                # Try to set the dates in the where clause
+#                try:
+#                    SQL_WHERE = SQL_WHERE % (start_date, end_date)
+#                except:
+#                    pass # Ignore. Maybe the sql query does not have any
+#                         # datefields
+#
+#                sql = SQL_BASE_QUERY % (SQL_GROUPBY, SQL_TABLE, TIMEFRAME, SQL_WHERE , SQL_GROUPBY)
+#                eval = EvaluationQuery(id, sql)
+#                eval.perform()
+#                out.append(XML_EVALBLOCK % (eval.id, eval.men, eval.women, eval.men+eval.women))
+#            out.append(XML_FOOTER)
+#        except StandardError, err:
+#            log.error(err)
+#
+#        return "\n".join(out)
+
+# vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

Modified: waska/trunk/waskaweb/lib/evaluation_new.py
===================================================================
--- waska/trunk/waskaweb/lib/evaluation_new.py	2009-04-24 08:09:52 UTC (rev 499)
+++ waska/trunk/waskaweb/lib/evaluation_new.py	2009-04-27 12:30:24 UTC (rev 500)
@@ -249,7 +249,7 @@
         body_dic                                = {}
         body_dic['name']                        = self.get_name(eval.id)
         body_dic['description']                 = self.get_description(eval.id)
-        body_dic['result']                      = [eval.men, eval.women, eval.men+eval.women]
+        body_dic['result']                      = [eval.men, eval.women, eval.unknown, eval.men+eval.women+eval.unknown]
         self.result_dic['evaluations'][eval.id] = body_dic 
 
     def _set_footer(self):
@@ -285,6 +285,7 @@
         self.result = {}
         self.men    = 0
         self.women  = 0
+        self.unknown  = 0
 
     def perform(self): 
         conn, cur = None, None
@@ -297,8 +298,10 @@
                 self.result[r[0]] = r[1]
                 if r[0] == 1: # men
                     self.men = int(r[1])
-                if r[0] == 0: # women
+                elif r[0] == 0: # women
                     self.women = int(r[1])
+                else:
+                    self.unknown = int(r[1])
         except StandardError, err:
             #log.error(err)
             print "Error with query %s" % self.sql

Modified: waska/trunk/waskaweb/lib/helpers.py
===================================================================
--- waska/trunk/waskaweb/lib/helpers.py	2009-04-24 08:09:52 UTC (rev 499)
+++ waska/trunk/waskaweb/lib/helpers.py	2009-04-27 12:30:24 UTC (rev 500)
@@ -33,6 +33,7 @@
 from pylons import c, cache, config, g, request, response, session
 from webhelpers import *
 from waskaweb.lib.adelexml import EVAL_NAMES, EVAL_DESCRIPTIONS
+from waskaweb.lib.basicevaluation import EVAL_NAMES as EVAL_NAMES2, EVAL_DESCRIPTIONS as EVAL_DESCRIPTIONS2
 from pylons.i18n import _
 
 import datetime
@@ -46,6 +47,12 @@
 def get_adele_description(id):
     return EVAL_DESCRIPTIONS.get(str(id), 'Keine Beschreibung vorhanden')
 
+def get_fortschreibung_name(id=None):
+    return EVAL_NAMES2.get(str(id), 'Auswertung Nr: %s' % id) 
+
+def get_fortschreibung_description(id):
+    return EVAL_DESCRIPTIONS2.get(str(id), 'Keine Beschreibung vorhanden')
+
 def hasRole(rolelist):
     try:
         user = session['USER_AUTHORIZED']

Modified: waska/trunk/waskaweb/templates/casemanagement/evaluation/evaluation_adele.mako
===================================================================
--- waska/trunk/waskaweb/templates/casemanagement/evaluation/evaluation_adele.mako	2009-04-24 08:09:52 UTC (rev 499)
+++ waska/trunk/waskaweb/templates/casemanagement/evaluation/evaluation_adele.mako	2009-04-27 12:30:24 UTC (rev 500)
@@ -41,16 +41,21 @@
   <tr>
     <td>männlich</td>
     <td class="num">${r['result'][0]}</td>
-    <td class="num">${h.formatNumber(float(r['result'][0]) /float(r['result'][2] or 1)*100)}%</td>
+    <td class="num">${h.formatNumber(float(r['result'][0]) /float(r['result'][3] or 1)*100)}%</td>
   </tr>
   <tr>
     <td>weiblich</td>
     <td class="num">${r['result'][1]}</td>
-    <td class="num">${h.formatNumber(float(r['result'][1]) /float(r['result'][2] or 1)*100)}%</td>
+    <td class="num">${h.formatNumber(float(r['result'][1]) /float(r['result'][3] or 1)*100)}%</td>
   </tr>
   <tr>
+    <td>unbekannt</td>
+    <td class="num">${r['result'][2]}</td>
+    <td class="num">${h.formatNumber(float(r['result'][2]) /float(r['result'][3] or 1)*100)}%</td>
+  </tr>
+  <tr>
     <td>gesamt</td>
-    <td class="num">${r['result'][2]}</td>
+    <td class="num">${r['result'][3]}</td>
     <td class="num">100%</td>
   <tr>
 </table>

Added: waska/trunk/waskaweb/templates/casemanagement/evaluation/evaluation_basic.mako
===================================================================
--- waska/trunk/waskaweb/templates/casemanagement/evaluation/evaluation_basic.mako	2009-04-24 08:09:52 UTC (rev 499)
+++ waska/trunk/waskaweb/templates/casemanagement/evaluation/evaluation_basic.mako	2009-04-27 12:30:24 UTC (rev 500)
@@ -0,0 +1,57 @@
+## -*- coding: utf-8 -*-
+<%inherit file="/main.mako"/>
+<%!  import waskaweb.lib.filters as F %>
+<%def name="buildNavipath()">
+  ${parent.buildNavipath()}
+  <li><a href="/case">${_('cm_np_root')}</a></li>
+  <li><a href="/evaluate/evaluateBasic">Fortschreibungsantrag</a></li>
+</%def>
+<h1>Auswertung Fortschreibungsantrag vom ${h.dd_mm_YYYY(c.start_date)} bis zum ${h.dd_mm_YYYY(c.end_date)}</h1>
+<h2>Zeitraum</h2>
+<div>
+<form name="timeframe" action="/evaluate/evaluateBasic">
+<p>Bitte wählen Sie den Zeitraum, für den die Auswertung durchgeführt werden soll</p>
+<p>
+<select name="timeframe">
+    <option value="1" selected>01.09.2008 - 31.05.2009</option>
+</select>
+<input type="submit" value="Auswerten">
+</p>
+</form>
+</div>
+&nbsp;<br>
+<hr>
+##% for k, r in c.eval['evaluations'].iteritems():
+% for key in sorted([int(s) for s in c.eval['evaluations'].keys()]):
+<% r = c.eval['evaluations'][str(key)] %>
+<h3>${h.get_fortschreibung_name(key)}</h3>
+<p>${h.get_fortschreibung_description(key)}</p>
+<table class"evaluation">
+  <tr>
+    <th clase="table_header_h">Geschlecht</th>
+    <th clase="table_header_h num">Anzahl</th>
+    <th clase="table_header_h num">Prozent</th>
+  </tr>
+  <tr>
+    <td>männlich</td>
+    <td class="num">${r['result'][0]}</td>
+    <td class="num">${h.formatNumber(float(r['result'][0]) /float(r['result'][3] or 1)*100)}%</td>
+  </tr>
+  <tr>
+    <td>weiblich</td>
+    <td class="num">${r['result'][1]}</td>
+    <td class="num">${h.formatNumber(float(r['result'][1]) /float(r['result'][3] or 1)*100)}%</td>
+  </tr>
+  <tr>
+    <td>unbekannt</td>
+    <td class="num">${r['result'][2]}</td>
+    <td class="num">${h.formatNumber(float(r['result'][2]) /float(r['result'][3] or 1)*100)}%</td>
+  </tr>
+  <tr>
+    <td>gesamt</td>
+    <td class="num">${r['result'][3]}</td>
+    <td class="num">100%</td>
+  <tr>
+</table>
+<hr>
+% endfor

Modified: waska/trunk/waskaweb/templates/main.mako
===================================================================
--- waska/trunk/waskaweb/templates/main.mako	2009-04-24 08:09:52 UTC (rev 499)
+++ waska/trunk/waskaweb/templates/main.mako	2009-04-27 12:30:24 UTC (rev 500)
@@ -69,7 +69,11 @@
         % if h.hasRole(['cm_ka']):
           <li><a href="${h.url_for(controller='/case', action='new')}"> ${_('menu_cm_link_new')}</a> </li>
           <li><a href="${h.url_for(controller='/case', action='importCase')}"> ${_('menu_cm_link_import')}</a> </li>
-        % endif
+      </ul>
+      % endif
+      <h1>${_('Auswertungen')}</h1>
+      <ul>
+        <li><a href="${h.url_for(controller='/evaluate', action='evaluateBasic')}">Fortschreibung</a></li>
         <li><a href="${h.url_for(controller='/evaluate', action='evaluateAdele')}">Zwischenbericht</a></li>
         <li><a href="${h.url_for(controller='/evaluate', action='evaluate', id=1, reset=1)}"> ${_('cm_actions_link_evaluate')}</a></li>
         %if session.get('hascaseerrors'):



More information about the Mpuls-commits mailing list