PEP 008, mostly lines too long
This commit is contained in:
@ -5,6 +5,13 @@ from workspaceString import WorkspaceString
|
||||
unknownAnswer = '?'
|
||||
|
||||
|
||||
def __adjustUnhappiness(values):
|
||||
result = sum(values) / 2
|
||||
if result > 100.0:
|
||||
result = 100.0
|
||||
return result
|
||||
|
||||
|
||||
class Workspace(object):
|
||||
def __init__(self):
|
||||
#logging.debug('workspace.__init__()')
|
||||
@ -15,7 +22,8 @@ class Workspace(object):
|
||||
self.interStringUnhappiness = 0.0
|
||||
|
||||
def __repr__(self):
|
||||
return '<Workspace trying %s:%s::%s:?>' % (self.initialString, self.modifiedString, self.targetString)
|
||||
return '<Workspace trying %s:%s::%s:?>' % (
|
||||
self.initialString, self.modifiedString, self.targetString)
|
||||
|
||||
def setStrings(self, initial, modified, target):
|
||||
self.targetString = target
|
||||
@ -33,16 +41,15 @@ class Workspace(object):
|
||||
self.modified = WorkspaceString(self.modifiedString)
|
||||
self.target = WorkspaceString(self.targetString)
|
||||
|
||||
def __adjustUnhappiness(self, values):
|
||||
result = sum(values) / 2
|
||||
if result > 100.0:
|
||||
result = 100.0
|
||||
return result
|
||||
|
||||
def assessUnhappiness(self):
|
||||
self.intraStringUnhappiness = self.__adjustUnhappiness([o.relativeImportance * o.intraStringUnhappiness for o in self.objects])
|
||||
self.interStringUnhappiness = self.__adjustUnhappiness([o.relativeImportance * o.interStringUnhappiness for o in self.objects])
|
||||
self.totalUnhappiness = self.__adjustUnhappiness([o.relativeImportance * o.totalUnhappiness for o in self.objects])
|
||||
self.intraStringUnhappiness = __adjustUnhappiness([
|
||||
o.relativeImportance * o.intraStringUnhappiness
|
||||
for o in self.objects])
|
||||
self.interStringUnhappiness = __adjustUnhappiness([
|
||||
o.relativeImportance * o.interStringUnhappiness
|
||||
for o in self.objects])
|
||||
self.totalUnhappiness = __adjustUnhappiness([
|
||||
o.relativeImportance * o.totalUnhappiness for o in self.objects])
|
||||
|
||||
def assessTemperature(self):
|
||||
self.calculateIntraStringUnhappiness()
|
||||
@ -50,20 +57,23 @@ class Workspace(object):
|
||||
self.calculateTotalUnhappiness()
|
||||
|
||||
def calculateIntraStringUnhappiness(self):
|
||||
values = [o.relativeImportance * o.intraStringUnhappiness for o in self.objects]
|
||||
values = [o.relativeImportance * o.intraStringUnhappiness
|
||||
for o in self.objects]
|
||||
value = sum(values) / 2.0
|
||||
self.intraStringUnhappiness = min(value, 100.0)
|
||||
|
||||
def calculateInterStringUnhappiness(self):
|
||||
values = [o.relativeImportance * o.interStringUnhappiness for o in self.objects]
|
||||
values = [o.relativeImportance * o.interStringUnhappiness
|
||||
for o in self.objects]
|
||||
value = sum(values) / 2.0
|
||||
self.interStringUnhappiness = min(value, 100.0)
|
||||
|
||||
def calculateTotalUnhappiness(self):
|
||||
for o in self.objects:
|
||||
logging.info("object: %s, totalUnhappiness: %d, relativeImportance: %d" % (
|
||||
o, o.totalUnhappiness, o.relativeImportance * 1000))
|
||||
values = [o.relativeImportance * o.totalUnhappiness for o in self.objects]
|
||||
logging.info("%s, totalUnhappiness: %d, relativeImportance: %d",
|
||||
o, o.totalUnhappiness, o.relativeImportance * 1000)
|
||||
values = [o.relativeImportance * o.totalUnhappiness
|
||||
for o in self.objects]
|
||||
value = sum(values) / 2.0
|
||||
self.totalUnhappiness = min(value, 100.0)
|
||||
|
||||
@ -81,12 +91,15 @@ class Workspace(object):
|
||||
return [o for o in self.objects if o != anObject]
|
||||
|
||||
def numberOfUnrelatedObjects(self):
|
||||
"""A list of all objects in the workspace that have at least one bond slot open."""
|
||||
objects = [o for o in self.objects if o.string == self.initial or o.string == self.target]
|
||||
"""A list of all objects in the workspace with >= 1 open bond slots"""
|
||||
objects = [o for o in self.objects
|
||||
if o.string == self.initial or o.string == self.target]
|
||||
#print 'A: %d' % len(objects)
|
||||
objects = [o for o in objects if not o.spansString()]
|
||||
#print 'B: %d' % len(objects)
|
||||
objects = [o for o in objects if (not o.leftBond and not o.leftmost) or (not o.rightBond and not o.rightmost)]
|
||||
objects = [o for o in objects
|
||||
if (not o.leftBond and not o.leftmost) or
|
||||
(not o.rightBond and not o.rightmost)]
|
||||
#print 'C: %d' % len(objects)
|
||||
#objects = [ o for o in objects if ]
|
||||
#print 'D: %d' % len(objects)
|
||||
@ -94,22 +107,25 @@ class Workspace(object):
|
||||
|
||||
def numberOfUngroupedObjects(self):
|
||||
"""A list of all objects in the workspace that have no group."""
|
||||
objects = [o for o in self.objects if o.string == self.initial or o.string == self.target]
|
||||
objects = [o for o in self.objects if
|
||||
o.string == self.initial or o.string == self.target]
|
||||
objects = [o for o in objects if not o.spansString()]
|
||||
objects = [o for o in objects if not o.group]
|
||||
return len(objects)
|
||||
|
||||
def numberOfUnreplacedObjects(self):
|
||||
"""A list of all objects in the inital string that have not been replaced."""
|
||||
"""A list of all unreplaced objects in the inital string"""
|
||||
from letter import Letter
|
||||
|
||||
objects = [o for o in self.objects if o.string == self.initial and isinstance(o, Letter)]
|
||||
objects = [o for o in self.objects
|
||||
if o.string == self.initial and isinstance(o, Letter)]
|
||||
objects = [o for o in objects if not o.replacement]
|
||||
return len(objects)
|
||||
|
||||
def numberOfUncorrespondingObjects(self):
|
||||
"""A list of all objects in the inital string that have not been replaced."""
|
||||
objects = [o for o in self.objects if o.string == self.initial or o.string == self.target]
|
||||
"""A list of all uncorresponded objects in the inital string"""
|
||||
objects = [o for o in self.objects
|
||||
if o.string == self.initial or o.string == self.target]
|
||||
objects = [o for o in objects if not o.correspondence]
|
||||
return len(objects)
|
||||
|
||||
@ -127,7 +143,8 @@ class Workspace(object):
|
||||
def slippages(self):
|
||||
result = []
|
||||
if self.changedObject and self.changedObject.correspondence:
|
||||
result = [m for m in self.changedObject.correspondence.conceptMappings]
|
||||
result = [m for m in
|
||||
self.changedObject.correspondence.conceptMappings]
|
||||
for objekt in workspace.initial.objects:
|
||||
if objekt.correspondence:
|
||||
for mapping in objekt.correspondence.slippages():
|
||||
@ -148,9 +165,7 @@ class Workspace(object):
|
||||
def buildDescriptions(self, objekt):
|
||||
for description in objekt.descriptions:
|
||||
description.descriptionType.buffer = 100.0
|
||||
#logging.info("Set buffer to 100 for " + description.descriptionType.get_name());
|
||||
description.descriptor.buffer = 100.0
|
||||
#logging.info("Set buffer to 100 for " + description.descriptor.get_name());
|
||||
if description not in self.structures:
|
||||
self.structures += [description]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user