Mercurial > hg > lib > markup
comparison python/safe.py @ 7:3ee329b129c6
rename block properties, slightly revise result format
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Wed, 26 May 2021 09:18:49 -0400 |
parents | a01ff74f9fd7 |
children | fcef94b6324c |
comparison
equal
deleted
inserted
replaced
6:a01ff74f9fd7 | 7:3ee329b129c6 |
---|---|
28 class Air(Block): | 28 class Air(Block): |
29 def __init__(self,filename): | 29 def __init__(self,filename): |
30 with open(filename,'r') as air: | 30 with open(filename,'r') as air: |
31 Block.__init__(self,air) | 31 Block.__init__(self,air) |
32 air.readline() | 32 air.readline() |
33 aa=self.aa=[[float(i) for i in l.split('\t')[2].split(',')] for l in air] | 33 aa=self.blocks=[[float(i) for i in l.split('\t')[2].split(',')] for l in air] |
34 ad=self.ad={} | 34 ad=self.columns={} |
35 for a in aa: | 35 for a in aa: |
36 k=(a[0],a[2]) | 36 k=(a[0],a[2]) |
37 h=ad.get(k,500.0) | 37 h=ad.get(k,500.0) |
38 if a[1]<h: | 38 if a[1]<h: |
39 ad[k]=a[1] | 39 ad[k]=a[1] |
43 class Lava(Block): | 43 class Lava(Block): |
44 def __init__(self,filename): | 44 def __init__(self,filename): |
45 with open(filename,'r') as lava: | 45 with open(filename,'r') as lava: |
46 Block.__init__(self,lava) | 46 Block.__init__(self,lava) |
47 lava.readline() | 47 lava.readline() |
48 ll=self.ll={} | 48 ll=self.columns={} |
49 for l in lava: | 49 for l in lava: |
50 x=[float(i) for i in l.split('\t')[2].split(',')] | 50 x=[float(i) for i in l.split('\t')[2].split(',')] |
51 k=(x[0],x[2]) | 51 k=(x[0],x[2]) |
52 kk=ll.setdefault(k,list()) | 52 kk=ll.setdefault(k,list()) |
53 kk.append(x) | 53 kk.append(x[1]) |
54 | 54 |
55 L=Lava('lava.tsv') | 55 L=Lava('lava.tsv') |
56 | 56 |
57 def d(p1,p2): | 57 def d(p1,p2): |
58 dx=p1[0]-p2[0] | 58 dx=p1[0]-p2[0] |
59 dz=p1[1]-p2[1] | 59 dz=p1[1]-p2[1] |
60 dy=p1[2]-p2[2] | 60 dy=p1[2]-p2[2] |
61 return math.sqrt((dx*dx)+(dy*dy)+(dz*dz)) | 61 return math.sqrt((dx*dx)+(dy*dy)+(dz*dz)) |
62 | 62 |
63 def safety(p): | 63 def unsafe(p): |
64 ka=[(a[0],a[2]) for a in A.aa if d(a,p)<=n] | 64 ka=[(a[0],a[2]) for a in A.blocks if d(a,p)<=n] |
65 return [(k,ll[k]) for k in ka if k in L.ll] | 65 return [(k,A.columns[k],L.columns[k]) for k in ka if k in L.columns] |
66 | 66 |
67 readHeaders(sys.modules['__main__'],sys.stdin,False) | 67 readHeaders(sys.modules['__main__'],sys.stdin,False) |
68 for l in sys.stdin: | 68 for l in sys.stdin: |
69 c=eval(l) | 69 c=eval(l) |
70 s=[(p,safety(p)) for p in c] | 70 s=[(p,unsafe(p)) for p in c] |
71 print(s if s else 'No air',c) | 71 print(s if s else 'No air',c) |
72 | 72 |
73 | 73 |