def __init__(self, filename, outputfile=sys.stdout, max_tstmp=0): ScenarioRunner.__init__(self, filename) self._callables = {} self._callables['churn'] = self.churn self._callables['churn_pattern'] = self.churn_pattern print >> sys.stderr, "Looking for max_timestamp, max_peer... in %s" % filename, self.max_peer = 0 for (tstmp, lineno, clb, args) in self._parse_scenario(filename): max_tstmp = max(tstmp, max_tstmp) print >> sys.stderr, "\tfound %d and %d" % (max_tstmp, self.max_peer) _max_peer = self.max_peer print >> sys.stderr, "Preprocessing file...", for (tstmp, lineno, clb, args) in self._parse_scenario(filename): print >> outputfile, self.file_buffer[1][lineno - 1][1] if clb in self._callables: for peer in self.yes_peers: for line in self._callables[clb](tstmp, max_tstmp, *args): print >> outputfile, line, '{%s}' % peer print >> sys.stderr, "\tdone"
def __init__(self, filename, outputfile=sys.stdout, max_tstmp=sys.maxint): ScenarioRunner.__init__(self, filename) self._callables = {} self._callables['online'] = self.online self._callables['offline'] = self.offline self._callables['add_friend'] = self.add_friend self._peer_state = defaultdict(lambda: "offline") self._peer_friends = defaultdict(list) self._time_online = defaultdict(lambda :[0, 0, 0, 0]) self._prev_online = defaultdict(int) self._prev_offline = defaultdict(int) self.max_online = self.max_offline = 0 sorted_scenario = defaultdict(list) prev_tstmp = -1 for (tstmp, lineno, clb, args) in self._parse_scenario(filename): if clb in self._callables and tstmp < max_tstmp: sorted_scenario[tstmp].append((self.yes_peers, clb, args)) tstmps = sorted_scenario.keys() tstmps.sort() for tstmp in tstmps: for yes_peers, clb, args in sorted_scenario[tstmp]: for peer in yes_peers: self._callables[clb](tstmp, peer, *args) if prev_tstmp != tstmp: self.print_connections(tstmp, outputfile) prev_tstmp = tstmp self.print_averages(outputfile, tstmps[-1])
def __init__(self, filename, outputfile=sys.stdout, max_tstmp=sys.maxint): ScenarioRunner.__init__(self, filename) self._callables = {} self._callables['online'] = self.online self._callables['offline'] = self.offline self._callables['add_friend'] = self.add_friend self._peer_state = defaultdict(lambda: "offline") self._peer_friends = defaultdict(list) self._time_online = defaultdict(lambda: [0, 0, 0, 0]) self._prev_online = defaultdict(int) self._prev_offline = defaultdict(int) self.max_online = self.max_offline = 0 sorted_scenario = defaultdict(list) prev_tstmp = -1 for (tstmp, lineno, clb, args) in self._parse_scenario(filename): if clb in self._callables and tstmp < max_tstmp: sorted_scenario[tstmp].append((self.yes_peers, clb, args)) tstmps = sorted_scenario.keys() tstmps.sort() for tstmp in tstmps: for yes_peers, clb, args in sorted_scenario[tstmp]: for peer in yes_peers: self._callables[clb](tstmp, peer, *args) if prev_tstmp != tstmp: self.print_connections(tstmp, outputfile) prev_tstmp = tstmp self.print_averages(outputfile, tstmps[-1])