-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateJsonComponents.py
75 lines (64 loc) · 2.71 KB
/
createJsonComponents.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
import json
import operator
import random
#this file creates a list of actions in json format that then can be used to
#automatically update the actions in the current program. This json list
#makes it where the automatic updater doesn't have to parse what actions are
#currently available but instead it can delete them and start fresh
#every time
class Component:
name=""
clockTime=0
failureWeight=0.0
cost=0
computingPower=""
def __init__(self,name,clockTime,failureWeight,cost,computingPower):
self.name=name
self.clockTime=clockTime
self.failureWeight=failureWeight
self.cost=cost
self.computingPower=computingPower
def componentToJson(component):
jsonObject=json.dumps(component.__dict__)
return jsonObject
def createPreviousComponentList():
componentList=[]
componentList.append(Component("DatabaseAThread",2,0.01,0,"3-currentCount*0.01"))
componentList.append(Component("DatabaseBThread",2,0.01,0,"3.5-currentCount*.2"))
componentList.append(Component("L1Server",30,0.05,100,5))
componentList.append(Component("L2Server",30,0.05,150,7))
componentList.append(Component("QualityChange",60,0.02,60,0))
return componentList
def generateRandomComponent(actionName):
cost=0
total=random.randint(150,250)
while cost==0:
clockTime=random.randint(5,120)
compPower=random.randint(3,15)
failureWeight=random.uniform(0.01,0.2)
cost=round((total-3.33*clockTime+20*compPower-2000*failureWeight))
if cost < 20 or cost > 300:
cost=0
#I will probably need to adjust the compPower results later but
#test it out and see
return Component(actionName,clockTime,failureWeight,cost,compPower)
def autogenerateServers(componentList,countOfTacticsToGenerate):
originalServerTacticCount=len([item for item in componentList if item.name.find("Server")!=-1])
currentServerTacticCount = originalServerTacticCount
while currentServerTacticCount - originalServerTacticCount < countOfTacticsToGenerate:
currentServerTacticCount=currentServerTacticCount+1
actionName="L%dServer" % (currentServerTacticCount)
componentList.append(generateRandomComponent(actionName))
return componentList
def addAutogeneratedComponents(componentList):
componentList=autogenerateServers(componentList,3)
return componentList
def main():
componentList=createPreviousComponentList()
componentList=addAutogeneratedComponents(componentList)
with open('components.json','w') as fout:
for component in sorted(componentList,key=operator.attrgetter('name')):
fout.write(componentToJson(component))
fout.write("\n")
if __name__=="__main__":
main()