[Mpuls-commits] r2328 - wasko/branches/2.0/mpulsweb/model
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Apr 14 09:10:08 CEST 2010
Author: torsten
Date: 2010-04-14 09:10:07 +0200 (Wed, 14 Apr 2010)
New Revision: 2328
Modified:
wasko/branches/2.0/mpulsweb/model/phase.py
Log:
* mpulsweb/model/phase.py: Fixed checking neighborship of to
phaseparts, which is needed to determine if a phase can be started.
Modified: wasko/branches/2.0/mpulsweb/model/phase.py
===================================================================
--- wasko/branches/2.0/mpulsweb/model/phase.py 2010-04-14 07:09:41 UTC (rev 2327)
+++ wasko/branches/2.0/mpulsweb/model/phase.py 2010-04-14 07:10:07 UTC (rev 2328)
@@ -55,21 +55,59 @@
def __init__(self):
self.phases = PhaseList()
+ self.suc = {}
+ self.pre = {}
+ def _get_suc(p):
+ ps = []
+ s = g.mpuls_config.get('phases', 'successors')[0].get(p)
+ for p in s:
+ for pp in g.mpuls_config.get('phases', 'pairs')[0].get(p)[0]:
+ ps.append(pp[0])
+ return ps
+
+ # Build successors and predessesors of the phases
+ for p in g.mpuls_config.get('phases', 'phases'):
+ pp = g.mpuls_config.get('phases', 'pairs')[0].get(p)
+ if len(pp) == 2:
+ self.suc[pp[0]] = []
+ self.suc[pp[0]].extend(pp[1])
+ self.suc[pp[1]] = []
+ self.suc[pp[1]].extend(_get_suc(p))
+
+ for k, v in self.suc.iteritems():
+ for p in v:
+ self.pre[p] = []
+ self.pre[p].extend(k)
+
def load(self, id):
factory = InstanceFactory(g.formedTree, PostgresDBInterface())
it = factory.loadInstanceTreeByIdentifier(id)
+
for p in g.mpuls_config.get('phases', 'phases'):
desc = g.mpuls_config.get('phases', 'description')[0].get(p)
pair = g.mpuls_config.get('phases', 'pairs')[0].get(p)
- start = StartPhasePart(pair[0], p, it)
- end = EndPhasePart(pair[1], p, it)
+ start = StartPhasePart(pair[0], p, it,
+ self.suc.get(pair[0], []),
+ self.pre.get(pair[0], []))
+ end = EndPhasePart(pair[1], p, it,
+ self.suc.get(pair[1], []),
+ self.pre.get(pair[1], []))
self.phases.append(Phase(start, end, desc))
+
+ self.phases.set_suc(self.suc)
+ self.phases.set_pre(self.pre)
return self.phases
class PhaseList(list):
+ def set_suc(self, suc):
+ self.suc = suc
+
+ def set_pre(self, pre):
+ self.pre = pre
+
def get_current_phase_id(self):
'''Returns id of current active phasepart'''
p = self.get_current_phase()
@@ -90,6 +128,14 @@
p.phase = '-1'
return p
+ def get_path(self, phasepart_id):
+ '''Returns a list of phaseparts id from start to the given phasepart_id'''
+ path = []
+ for pp in self.pre.get(phasepart_id, []):
+ path.extend(self.get_path(pp))
+ path.append(pp)
+ return path
+
def is_valid(self):
'''Returns true if all phaseparts up to the current phase are ok.
This means all requierd fields are filled out and all checks for
@@ -114,7 +160,6 @@
raise ConsistenceCheckException(CASE_NOT_CONSISTENT
% phases.description)
-
class Phase:
def __init__(self, start, end, description):
@@ -143,12 +188,15 @@
class PhasePart:
- def __init__(self, id, phase, it):
+ def __init__(self, id, phase, it, suc, pre):
+ log.debug('Creating PhasePart with id: %s' % id)
self.id = id
self.it = it
self.phase = phase
self.active = False
self.date = None
+ self.suc = suc
+ self.pre = pre
self.fields = []
if not it: return
@@ -180,6 +228,10 @@
warnings = []
self.date = field.getValue()
+ def is_neighbor(self, phase):
+ log.debug("phase: %s suc: %s, pre: %s" % (self.id, self.suc, self.pre))
+ return (phase in self.suc) or (phase in self.pre)
+
def getLinks(self):
out = []
if len(self.fields) > 0:
@@ -198,35 +250,20 @@
def is_anonymizable(self):
return self.id not in g.mpuls_config.get('phases', 'notanonymizable')
- def is_neighbor(self, phase):
- suc = False
- pre = False
- phase = int(phase)
- cphase = int(self.phase)
- for p, s in g.mpuls_config.get('phases', 'successors')[0].iteritems():
- s = [int(id) for id in s]
- p = int(p)
- if p == cphase:
- log.debug("is %s suc (%s) of %s: %s" % (phase, s, cphase, phase in s))
- suc = phase in s
- log.debug("%s, %s" % (cphase, s))
- if cphase in s:
- log.debug("is %s pre (%s) of %s: %s" % (cphase, p, s, p == phase))
- pre = (p == phase)
- if pre or suc: return True
def is_ok(self, fields=None):
# 1. Simulate switching the phase
# Setting values will trigger evaluation error rules. This way we can
# check logic rules which are modeled as errors.
- case_id = self.it.getRootNode().getIdentifier()
- realid = "%s:%s" % (PHASEFIELD, case_id)
- try:
- values = {realid: self.id}
- self.it.setData(values)
- except:
- return False
+ #case_id = self.it.getRootNode().getIdentifier()
+ #realid = "%s:%s" % (PHASEFIELD, case_id)
+ #try:
+ # values = {realid: self.id}
+ # self.it.setData(values)
+ #except:
+ # log.exception('Can not set phase: %s' % values)
+ # return False
# 2. Check rules
for field in self.fields:
@@ -242,15 +279,11 @@
class StartPhasePart(PhasePart):
-
pass
-
class EndPhasePart(PhasePart):
-
pass
-
class Field:
def __init__(self, name, page, rules, it):
More information about the Mpuls-commits
mailing list