# HG changeset patch # User Henry S. Thompson # Date 1622110141 14400 # Node ID 73bb35b9662478e177c74b8fa58c8d76777d2493 # Parent 0d1670ab37df583d7950befb299da4c3128bd03e show good hit output diff -r 0d1670ab37df -r 73bb35b96624 python/safe.py --- a/python/safe.py Wed May 26 13:52:53 2021 -0400 +++ b/python/safe.py Thu May 27 06:09:01 2021 -0400 @@ -3,23 +3,26 @@ import sys, math from util import * -from bisect import insort_left as insort +from bisect import insort def usage(): - print("""Usage: safe.py [-d n] + print("""Usage: safe.py [-d n] [filename] n is maximum distance of landing to some point in the cluster, default is 10. Feed stdin with lines from the output of cluster.py, having produced air.tsv with the same settings as the cluster input, and lava.tsv with a lower-bound on Y of 0""") +n=10.0 if len(sys.argv)>1: - if sys.argv.pop(1)!='-d': - usage() - exit(1) - n=float(sys.argv.pop(1)) + if sys.argv[1]=='-d': + sys.argv.pop() + n=float(sys.argv.pop(1)) + +if len(sys.argv)>1: + infile=open(sys.argv.pop(1)) else: - n=10.0 + infile=sys.stdin class Block: '''Shared by Air and Lava, @@ -42,7 +45,6 @@ except KeyError: tc[k]=[y] # convert to lists of intervals - # Simplest case first for k,yy in tc.items(): tyy=[yy] ii=[] @@ -60,7 +62,7 @@ break if clean: break - self.columns[k]=ii + self.columns[k]=set(ii) # so we can merge later def readPoints(self,file): file.readline() @@ -88,18 +90,32 @@ ka=[(a[0],a[2]) for a in A.points if d(a,p)<=n] return [(k,A.columns[k],L.columns[k]) for k in ka if k in L.columns] -readHeaders(sys.modules['__main__'],sys.stdin,False) -for l in sys.stdin: +readHeaders(sys.modules['__main__'],infile,False) +for l in infile: c=eval(l) ss=[] hits={} misses=[] for p in c: - s=safety(p) - if s: - pass + ss=safety(p) + if ss: + for (k,a,l) in ss: + try: + (aa,ll)=hits[k] + aa.update(a) + ll.update(l) + except KeyError: + hits[k]=(a,l) else: misses.append(p) print(c) - print(' %s nearby landing zones'%( - (lambda nm,nc:'No' if nm==nc else nc-nm)(len(misses),len(c)))) + if hits: + print(' %s nearby landing columns'%len(hits)) + for k in sorted(hits.keys(),key=lambda k:k[0]): + aa,ll=hits[k] + print("%s: %s %s"%(k,sorted(list(aa)),sorted(list(ll)))) + else: + print(' No nearby landing zones') + +if infile!=sys.stdin: + infile.close()