#!/usr/bin/env python3 # example: dtnsim -n 10 -M Log | ./p-coverage 10 50 import sys def main(): # Extract N and p from command-line arguments. n = int(sys.argv[1]) p = float(sys.argv[2]) # Calcurate the stop criteria. threshold = n * p / 100 # The number of recipients. # NOTE: Only a single agent is infected at the beginning. nreceived = 1 # Read every line from STDIN. for line in sys.stdin: # Remove the trailing newline. line = line.rstrip() # Ignore non-forwarding log. if not 'forward' in line: continue # Discard duplicate message transmissions. if 'dup' in line: continue # Count the number of recipients. nreceived += 1 # Delivered to more than p% agents? if nreceived >= threshold: time, *rest = line.split('\t') print(time) break if __name__ == "__main__": main()