-
Notifications
You must be signed in to change notification settings - Fork 0
/
Base.py
135 lines (98 loc) · 2.77 KB
/
Base.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from subprocess import call
import os,sys,re,glob
def Format_Real(t):
return "%.6f" % t
def Max(x1,x2):
if (x2>x1):
return x2
return x1
def Min(x1,x2):
if (x2<x1):
return x2
return x1
def Intervals(t1,t2,n):
dt=(t2-t1)/(1.0*n)
t=t1
ts=[]
for i in range( n+1 ):
ts.append(t)
t+=dt
return ts
def t2Interval(ts,t):
j=-1
for k in range(1, len(ts) ):
if (t>=ts[k-1] and t<ts[k]):
j=k
return j
def Convex(v,w,eta):
return v*(1.0-eta) +w*eta
def System(command,switches,args1,args2=[]):
for switch in switches:
if (switches[ switch ].__class__.__name__=="int"):
switches[ switch ]=str(switches[ switch ])
command+=" "+switch+" "+switches[ switch ]
for arg in args1:
command+=" "+arg
for arg in args2:
command+=" "+arg
os.system(command)
return command
def List_Slice(items,n):
ritems=[[]]
current=0
for item in items:
ritems[ current ].append(item)
if ( len(ritems[ current ])>=n ):
ritems.append([])
current+=1
return ritems
from Args import Args
from File import File
from Path import Path
class Base(Args,File,Path):
ClassName=""
def __init__(self):
return
def GetClassName(self):
print "ClassName",self.ClassName
value=self.ClassName
if (value==""):
self.ClassName=self.__class__.__name__
return self.ClassName
def Hash2Obj(self,vals):
for x in vals:
setattr(self, x, vals[x] )
##! ??? defunct
def get_class_members(self,klass):
print "9999999999999999",klass
ret = dir(klass)
if hasattr(klass,'__bases__'):
print "9999999999999999",klass.__bases__
for base in klass.__bases__:
ret = ret + get_class_members(base)
return
def File_2_Dict(self,file):
f=open(file,'r')
lines=f.read()
f.close()
lines=lines.splitlines()
dict={}
for line in lines:
comps=re.split(r'\s*[:=]\s*', line)
if (len(comps)==2):
attr=comps[0]
attr=re.sub(r'\s+',"",attr)
value=comps[1]
value=re.sub(r'^\s+',"",value)
value=re.sub(r'\s+$',"",value)
value=re.sub(r',$',"",value)
dict[ attr ]=value
return dict
##!
##! Color Convex Combination
##!
def Color_Convex(self,t,color1,color2):
color=color1*(1.0-t)+color2*t
for i in range( len(color) ):
color[i]=str(int(color[i]))
return "rgb("+",".join(color)+")"