-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_model.py
143 lines (121 loc) · 4.72 KB
/
_model.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
136
137
138
139
140
141
142
143
#Generic Attribute class to implement in all models
class Attr:
def __init__(self,name):
self.name = name
self.up = 0
self.low = 0
def update(self,low,up):
self.low = low
self.up = up
def __repr__(self):
s = str(self.low)+' < '+self.name +' < '+str(self.up)+'\n'
return s
#POM3 support
import os,sys,inspect
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe()))[0],"pom3")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
from pom3 import *
class Pom:
def __init__(self):
self.collection = {}
self.names = ["Culture", "Criticality", "CriticalityModifier",
"InitialKnown", "InterDependency", "Dynamism",
"Size", "Plan", "TeamSize"]
LOWS = [0.1, 0.82, 2, 0.40, 1, 1, 0, 0, 1]
UPS = [0.9, 1.20, 10, 0.70, 100, 50, 4, 5, 44]
for _n,n in enumerate(self.names):
self.collection[n] = Attr(n)
self.collection[n].update(LOWS[_n],UPS[_n])
def update(self,fea,cond,thresh):
ind = self.names.index(fea)
if cond:
self.collection[fea].update(self.collection[fea].low,
thresh)
else:
self.collection[fea].update(thresh,
self.collection[fea].up)
def trials(self,N,verbose=False):
inp = []
import random
for _ in range(N):
t = []
for n in self.names:
t.append(round(random.uniform(self.collection[n].low,
self.collection[n].up),2))
inp.append(t)
import pom3_builder
header,rows = pom3_builder.pom3_csvmaker(self.names,inp,verbose)
return header,rows
#XOMO support
import os,sys,inspect
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe()))[0],"xomo")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
from xomo import *
class Xomo:
def __init__(self,
out=os.environ["HOME"]+"/tmp/xomo",
data = "data",
model=None):
def theModel(model):
#default model is flight
if not model:
model = "flight"
return model
self.collection = {}
self.model = theModel(model)
self.c = Cocomo("xomo/"+data+"/"+self.model)
self.out = out + "/" + self.model + ".csv"
self.data = data
self.names = ["aa", "sced", "cplx", "site", "resl", "acap",
"etat", "rely","data", "prec", "pmat", "aexp",
"flex", "pcon", "tool", "time","stor", "docu",
"b", "plex", "pcap", "kloc", "ltex", "pr",
"ruse", "team", "pvol"]
#LOWs and UPs are defined in data/* files according to models
for _n,n in enumerate(self.names):
self.collection[n] = Attr(n)
k = filter(lambda x: x.txt == n,self.c.about())[0]
self.collection[n].update(k.min,k.max)
def update(self,fea,cond,thresh):
def applydiffs(c,col,m,thresh,verbose):
k = filter(lambda x: x.txt == col,c.about())[0]
if verbose: print k.txt,k.min,k.max,">before"
if m == "max":
max = thresh
k.update(k.min,max,m=c)
elif m == "min":
min = thresh
k.update(min,k.max,m=c)
if verbose: print k.txt, k.min, k.max,">after"
if cond:
self.collection[fea].up = thresh
applydiffs(self.c,fea,'max',thresh)
else:
self.collection[fea].low = thresh
applydiffs(self.c,fea,'min',thresh)
def trials(self,N,verbose=False):
for _n,n in enumerate(self.names):
k = filter(lambda x: x.txt == n,self.c.about())[0]
if verbose: print k.txt,k.min,k.max,">before"
k.update(self.collection[n].low,
self.collection[n].up,
m=self.c)
if verbose: print k.txt, k.min, k.max,">after"
if verbose:
print "Sample of 5"
for _ in range(5):
print n, self.c.xys()[0][n]
self.c.xys(verbose=False)
header,rows = self.c.trials(n=N,out=self.out,verbose=False,write=False)
return header,rows
def xomod(N=50):
x = Xomo(model="ground")
print x.trials(N,False)
def pom3d(N=50):
p = Pom()
p.trials(100,True)
if __name__ == "__main__":
#pom3d()
xomod()