[Mpuls-commits] r1587 - wasko/branches/2.0/waskaweb/lib

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Feb 16 10:55:49 CET 2010


Author: torsten
Date: 2010-02-16 10:55:46 +0100 (Tue, 16 Feb 2010)
New Revision: 1587

Modified:
   wasko/branches/2.0/waskaweb/lib/evaluation.py
Log:
* waskaweb/lib/evaluation.py: General cleanup. Removed unused code und
not used imports.


Modified: wasko/branches/2.0/waskaweb/lib/evaluation.py
===================================================================
--- wasko/branches/2.0/waskaweb/lib/evaluation.py	2010-02-16 09:04:16 UTC (rev 1586)
+++ wasko/branches/2.0/waskaweb/lib/evaluation.py	2010-02-16 09:55:46 UTC (rev 1587)
@@ -23,118 +23,24 @@
 # the Bundesministerium fuer Familie, Senioren, Frauen und Jugend and 
 # European Social Fund resources.
 
-import sys
-import traceback
-import codecs
-import cStringIO as StringIO
-from types import TupleType
 
-import psycopg2
-
 from pylons import app_globals as g
 
-from mpulsweb.lib.helpers import format_number, timedelta_in_minutes 
-from mpulsweb.lib.base import _, c, session
+from mpulsweb.lib.helpers import timedelta_in_minutes 
 from mpulsweb.lib.db import db
 
-def where_ids(compressed, idname="id"):
-    if not compressed:
-        return "FALSE"
-    between = "%s BETWEEN %%d AND %%d" % idname
-    single  = "%s = %%d" % idname
-    return " OR ".join([(type(x) is TupleType and between or single) % x 
-        for x in compressed])
-
-class Evaluation:
-    def __init__(self, compressed_ids=None):
-        self.total_valid = 0;
-        self.total_valid_cm = 0;
-        self.allcases = 0;
-        self.compressed_ids = compressed_ids # addition where statement
-                                             # to define a subset of cases
-        conn, c1 = None, None
-        try:
-            try:
-                conn = db.getConnection()
-                c1 = conn.cursor()
-
-                # All cases (including invalid)
-                c1.execute("""SELECT count(id) from master_tbl_eval_total_view m""")
-                self.allcases = c1.fetchone()[0]
-
-                # All cases (valid)
-                c1.execute("""SELECT count(id) from master_tbl_eval_total_view m WHERE %s""" % self.where_clause(self.compressed_ids))
-                self.total_valid = c1.fetchone()[0]
-
-                # All "beratungsfälle" (valid)
-                c1.execute("""SELECT count(id) from master_tbl_eval_total_view m WHERE phase IN (-1,0,1,6,7) AND %s""" % self.where_clause(self.compressed_ids))
-                self.total_valid_beratung = c1.fetchone()[0]
-
-                # All "cm-fälle" (valid)
-                c1.execute("""SELECT count(id) from master_tbl_eval_incm_view m WHERE %s""" % self.where_clause(self.compressed_ids))
-                self.total_valid_cm = c1.fetchone()[0]
-
-                # All finished "cm-fälle" (valid)
-                c1.execute("""SELECT count(id) from master_tbl_eval_incm_view m where phase IN (3,4,5) AND %s""" % self.where_clause(self.compressed_ids))
-                self.total_valid_cmfinished = c1.fetchone()[0]
-
-                c1.close(); c1 = None
-
-            finally:
-                db.recycleConnection(conn, c1)
-        except:
-            traceback.print_exc(file=sys.stderr)
-            print >> sys.stderr, "Error! Could not get connection in evaluation"
-
-    def getTotal(self):
-        return self.allcases
-
-    def getTotalValid(self):
-        return self.total_valid
-
-    def where_clause(self, ids, field="id"):
-        return "(%s)" % where_ids(ids, field)
-
-    def perform(self):
-        '''overwrite this to do the calculation'''
-        pass
-
-    def export(self):
-        '''returns current evalution as an UTF-8 encoded string'''
-        out = None
-        try:
-            Writer = codecs.getwriter('latin-1')
-            out = StringIO.StringIO()
-            latin1 = Writer(out, errors='replace')
-            self.doExport(latin1)
-            latin1.flush()
-            return out.getvalue()
-        finally:
-            if out:
-                try: out.close()
-                except: pass
-
-    def doExport(self, out):
-        '''overwrite this to do the CVS export'''
-        pass
-
-
-class Evaluation_14(Evaluation):
-    """Zeitaufwände aus dem Logbuch abgeschlossene Beratungsfälle"""
+class Evaluation_18:
+    """Zeitaufwände aus dem Logbuch aller Fälle"""
     def __init__(self, compressed_ids):
-        Evaluation.__init__(self, compressed_ids)
-        self.export_label = _('cm_eval_header_effort') 
-        self.export_eval_what = u"abgeschlossene Beratungsfälle"
-        self.sql  = """SELECT sum(l.dauer) AS dauer, count(l.dauer) AS anzahl, l.art, m.id 
+        self.sql  = """SELECT sum(coalesce(l.dauer, '0 second'::interval)) AS dauer, count(l.id) AS anzahl, l.art, m.id
             FROM ka_logbuch_tbl_view l
             JOIN master_tbl_eval_total_view m
             ON m.id = l.master_id
-            WHERE m.phase = 7
-            AND %s 
-            AND l.dauer IS NOT NULL 
+            WHERE l.master_id = %s
+            AND l.art <> '0'
             GROUP BY l.art, m.id 
             ORDER BY l.art
-        """ % self.where_clause(self.compressed_ids, "l.master_id")
+        """ % compressed_ids[0]
 
     def perform(self):
         unique_cases = []
@@ -184,20 +90,4 @@
         finally:
             db.recycleConnection(conn, cur)
 
-class Evaluation_18(Evaluation_14):
-    """Zeitaufwände aus dem Logbuch aller Fälle"""
-    def __init__(self, compressed_ids):
-        Evaluation.__init__(self, compressed_ids)
-        self.export_label = _('cm_eval_header_effort')
-        self.export_eval_what = u"alle Jugendliche"
-        self.sql  = """SELECT sum(coalesce(l.dauer, '0 second'::interval)) AS dauer, count(l.id) AS anzahl, l.art, m.id
-            FROM ka_logbuch_tbl_view l
-            JOIN master_tbl_eval_total_view m
-            ON m.id = l.master_id
-            WHERE %s
-            AND l.art <> '0'
-            GROUP BY l.art, m.id 
-            ORDER BY l.art
-        """ % self.where_clause(self.compressed_ids, "l.master_id")
-
 # vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:



More information about the Mpuls-commits mailing list