def post_process(self): """ Perform some post processing tasks on the completed graph. Emit warnings and/or highlight occurrences of possible bugs: -- Items put multiple times -- Steps prescribed multiple times -- Steps prescribed without being run -- Items gotten without a put and items put without a get -- Nodes with no path to the final finalize. """ # warn for items in sequence of node ids appearing more than once def warn_on_duplicates(sequence, verb): # print a warning on duplicates in a sequence counts = Counter(sequence) for k in counts: if counts[k] > 1: print >> sys.stderr, "Warning: %s %s %d times." % ( self.property(k, 'label', ''), verb, counts[k]) # emit warning if set of node id's is nonempty, and set color if given def warn_on_existence(s, msg, color=None): if len(s) > 0: if color: map(lambda n: self.set_property(n, 'color', color), s) else: map(lambda n: self.set_property(n, 'penwidth', 2.5), s) print >> sys.stderr, "Highlighting in %s:\n%s: %s" % ( color if color else 'bold', msg, ', '.join( map(lambda i: self.property(i, 'label', ''), s))) warn_on_duplicates(self._steps_prescribed.keys(), "prescribed") warn_on_duplicates(self._items_put, "put") # warn on items gotten but not put or put without get gotten_without_put = set(self._items_gotten).difference( set(self._items_put)) put_without_get = set(self._items_put).difference( set(self._items_gotten)) warn_on_existence(gotten_without_put, "Items with GET without PUT", styles.color('get_without_put')) warn_on_existence(put_without_get, "Items with PUT without GET", styles.color('put_without_get')) # warn on nodes that have no path to the finalize if self.finalize_node is not None: trans = self.transpose() visits = {self.finalize_node} trans.bfs(self.finalize_node, visitor=visits.add) warn_on_existence( set(self).difference(visits), "Nodes without path to FINALIZE")
def post_process(self): """ Perform some post processing tasks on the completed graph. Emit warnings and/or highlight occurrences of possible bugs: -- Items put multiple times -- Steps prescribed multiple times -- Steps prescribed without being run -- Items gotten without a put and items put without a get -- Nodes with no path to the final finalize. """ # warn for items in sequence of node ids appearing more than once def warn_on_duplicates(sequence, verb): # print a warning on duplicates in a sequence counts = Counter(sequence) for k in counts: if counts[k] > 1: print >>sys.stderr, "Warning: %s %s %d times." % ( self.property(k, 'label', ''), verb, counts[k]) # emit warning if set of node id's is nonempty, and set color if given def warn_on_existence(s, msg, color=None): if len(s) > 0: if color: map(lambda n: self.set_property(n, 'color', color), s) else: map(lambda n: self.set_property(n, 'penwidth', 2.5), s) print >>sys.stderr, "Highlighting in %s:\n%s: %s" % ( color if color else 'bold', msg, ', '.join(map(lambda i: self.property(i, 'label', ''), s))) warn_on_duplicates(self._steps_prescribed.keys(), "prescribed") warn_on_duplicates(self._items_put, "put") # warn on items gotten but not put or put without get gotten_without_put = set(self._items_gotten).difference(set(self._items_put)) put_without_get = set(self._items_put).difference(set(self._items_gotten)) warn_on_existence(gotten_without_put, "Items with GET without PUT", styles.color('get_without_put')) warn_on_existence(put_without_get, "Items with PUT without GET", styles.color('put_without_get')) # warn on nodes that have no path to the finalize if self.finalize_node is not None: trans = self.transpose() visits = {self.finalize_node} trans.bfs(self.finalize_node, visitor = visits.add) warn_on_existence(set(self).difference(visits), "Nodes without path to FINALIZE")
def style_item(self, item_id, label, collection_name, item_tag): """Style the node for an item.""" self.set_property(item_id, "shape", styles.shape('item')) self.set_property(item_id, "color", styles.color('item', collection_name)) self.set_property(item_id, "label", label) self.set_property(item_id, "tag", item_tag) self.set_property(item_id, "name", collection_name) self.set_property(item_id, "type", "item")
def style_item(self, item_id, label, collection): """Style the node for an item.""" self.set_property(item_id, "shape", styles.shape('item')) self.set_property(item_id, "color", styles.color('item', collection)) self.set_property(item_id, "label", label)
def style_step(self, step_id): """Style the node for a step.""" self.set_property(step_id, "color", styles.color('step'))
def style_step(self, step_id, step_name, step_tag): """Style the node for a step.""" self.set_property(step_id, "color", styles.color('step')) self.set_property(step_id, "tag", step_tag) self.set_property(step_id, "name", step_name) self.set_property(step_id, "type", "step")