From c9bc26e03d6c3ff5ceeeb65d4d91191d87c0a240 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Sat, 29 Apr 2017 14:29:43 -0700 Subject: [PATCH] Minor Pythonicisms. NFC. --- copycat/coderack.py | 5 ++--- copycat/slipnode.py | 13 +++++-------- copycat/workspaceString.py | 13 ++++--------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/copycat/coderack.py b/copycat/coderack.py index 8fab168..eb7cf24 100644 --- a/copycat/coderack.py +++ b/copycat/coderack.py @@ -196,9 +196,8 @@ class Coderack(object): rule = Rule(self.ctx, facet, description, category, relation) rule.updateStrength() if description and relation: - depths = description.conceptualDepth + relation.conceptualDepth - depths /= 200.0 - urgency = math.sqrt(depths) * 100.0 + averageDepth = (description.conceptualDepth + relation.conceptualDepth) / 2.0 + urgency = 100.0 * math.sqrt(averageDepth / 100.0) else: urgency = 0 self.newCodelet('rule-strength-tester', urgency, [rule]) diff --git a/copycat/slipnode.py b/copycat/slipnode.py index 824ebf0..3a7ff48 100644 --- a/copycat/slipnode.py +++ b/copycat/slipnode.py @@ -72,11 +72,6 @@ class Slipnode(object): linkLength = self.shrunkLinkLength return 100.0 - linkLength - def update(self): - act = self.activation - self.oldActivation = act - self.buffer -= self.activation * (100.0 - self.conceptualDepth) / 100.0 - def linked(self, other): """Whether the other is among the outgoing links""" return any(l.points_at(other) for l in self.outgoingLinks) @@ -129,6 +124,10 @@ class Slipnode(object): logging.info('Got no bond') return result + def update(self): + self.oldActivation = self.activation + self.buffer -= self.activation * (100.0 - self.conceptualDepth) / 100.0 + def spread_activation(self): if self.fully_active(): for link in self.outgoingLinks: @@ -140,9 +139,7 @@ class Slipnode(object): self.activation = min(max(0, self.activation), 100) def jump(self, random): - if self.activation <= jump_threshold(): - return - if self.clamped: + if self.clamped or self.activation <= jump_threshold(): return value = (self.activation / 100.0) ** 3 if random.coinFlip(value): diff --git a/copycat/workspaceString.py b/copycat/workspaceString.py index 736cd1a..a797a0b 100644 --- a/copycat/workspaceString.py +++ b/copycat/workspaceString.py @@ -14,21 +14,16 @@ class WorkspaceString(object): self.letters = [] self.length = len(s) self.intraStringUnhappiness = 0.0 - if not self.length: - return - position = 0 - for c in self.string.upper(): + for position, c in enumerate(self.string.upper(), 1): value = ord(c) - ord('A') - letter = Letter(self, position + 1, self.length) + letter = Letter(self, position, self.length) letter.workspaceString = self letter.addDescription(slipnet.objectCategory, slipnet.letter) - letter.addDescription(slipnet.letterCategory, - slipnet.letters[value]) - letter.describe(position + 1, self.length) + letter.addDescription(slipnet.letterCategory, slipnet.letters[value]) + letter.describe(position, self.length) workspace.buildDescriptions(letter) self.letters += [letter] - position += 1 def __repr__(self): return '' % self.string