Mercurial > hg > lib > markup
changeset 10:73bb35b96624
show good hit output
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Thu, 27 May 2021 06:09:01 -0400 |
parents | 0d1670ab37df |
children | e411408d64ec |
files | python/safe.py |
diffstat | 1 files changed, 32 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- 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()