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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Feb 16 09:57:54 CET 2010


Author: torsten
Date: 2010-02-16 09:57:53 +0100 (Tue, 16 Feb 2010)
New Revision: 1584

Modified:
   wasko/branches/2.0/waskaweb/lib/evaluation.py
Log:
* waskaweb/lib/evaluation.py (Evaluation_14.perform): Evaluation is
now done dynamically based on configuration.


Modified: wasko/branches/2.0/waskaweb/lib/evaluation.py
===================================================================
--- wasko/branches/2.0/waskaweb/lib/evaluation.py	2010-02-15 20:14:55 UTC (rev 1583)
+++ wasko/branches/2.0/waskaweb/lib/evaluation.py	2010-02-16 08:57:53 UTC (rev 1584)
@@ -149,39 +149,12 @@
     def perform(self):
         #{'art': [anzahl, dauer]}
         unique_cases = []
-        result = { '-2': [0,0],
-                   '-1': [0,0],
-                   '1': [0,0],
-                   '2': [0,0],
-                   '3': [0,0],
-                   '4': [0,0],
-                   '5': [0,0],
-                   '6': [0,0],
-                   '7': [0,0],
-                   '8': [0,0],
-                   '9': [0,0],
-                   '10': [0,0],
-                   '11': [0,0],
-                   '12': [0,0],
-                   '13': [0,0],
-                   '14': [0,0],
-                   '15': [0,0],
-                   '16': [0,0],
-                   '17': [0,0],
-                   '18': [0,0],
-                   'sum_cat1': [0,0],
-                   'sum_cat2': [0,0],
-                   'sum_cat3': [0,0],
-                   'sum_cat4': [0,0],
-                   'sum_cat5': [0,0],
-                   'sum_all': [0,0],
-                   'avg_cat1': [0,0],
-                   'avg_cat2': [0,0],
-                   'avg_cat3': [0,0],
-                   'avg_cat4': [0,0],
-                   'avg_cat5': [0,0],
-                   'avg_all': [0,0]
-                 }
+        result = {}
+        for num, category in enumerate(g.mpuls_config.get('logbook', 'categories')):
+            for item in category.get('items'):
+                result[item] = [0,0]
+            result['sum_cat%s' % num] = [0,0]
+        result['sum_all']= [0,0]
         try:
             try:
                 conn = db.getConnection()
@@ -202,47 +175,23 @@
 
                     result[type][0] += num
                     result[type][1] += duration
+        
+                    # Search category of the item and sum num and duration
+                    for cnum, category in enumerate(
+                        g.mpuls_config.get('logbook', 'categories')):
 
-                    if type in ['1','2','3','4','5']:
-                        result['sum_cat1'][0] += num
-                        result['sum_cat1'][1] += int(duration)
-                    if type in ['6', '7', '8']:
-                        result['sum_cat2'][0] += num
-                        result['sum_cat2'][1] += int(duration)
-                    if type in ['9', '10', '11', '12', '13', '14', '18']:
-                        result['sum_cat3'][0] += num
-                        result['sum_cat3'][1] += int(duration)
-                    if type in ['15', '16', '17', '-2']:
-                        result['sum_cat4'][0] += num
-                        result['sum_cat4'][1] += int(duration)
-                    if type in ['-1']:
-                        result['sum_cat5'][0] += num
-                        result['sum_cat5'][1] += int(duration)
+                        if type in category.get('items'):
+                            result['sum_cat%s' % cnum][0] += num 
+                            result['sum_cat%s' % cnum][1] += int(duration)
+                            break;
 
                     result['sum_all'][0] += num
                     result['sum_all'][1] += int(duration)
 
-                divisor = count
-                if divisor == 0:
-                    divisor = 1
-
-                result['avg_cat1'][0] = count 
-                result['avg_cat1'][1] = format_number(float(result['sum_cat1'][1] / divisor))
-                result['avg_cat2'][0] = count 
-                result['avg_cat2'][1] = format_number(float(result['sum_cat2'][1] / divisor))
-                result['avg_cat3'][0] = count 
-                result['avg_cat3'][1] = format_number(float(result['sum_cat3'][1] / divisor))
-                result['avg_cat4'][0] = count 
-                result['avg_cat4'][1] = format_number(float(result['sum_cat4'][1] / divisor))
-                result['avg_cat5'][0] = count 
-                result['avg_cat5'][1] = format_number(float(result['sum_cat5'][1] / divisor))
-                result['avg_all'][0] = count 
-                result['avg_all'][1] = format_number(float(result['sum_all'][1] / divisor))
-
                 return result
             except StandardError, e:
-                traceback.print_exc(file=sys.stderr)
-                print >> sys.stderr, "No results for eval 14"
+                log.exception(e)
+                raise
         finally:
             db.recycleConnection(conn, cur)
 



More information about the Mpuls-commits mailing list