-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrganization.py
81 lines (65 loc) · 2.53 KB
/
Organization.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
from random import randint
from texttable import Texttable
import pickle
import numpy as np
class Organization:
def __init__(self, P, S, Pe):
self.numProj = P
self.numSkill = S
self.numPeop = Pe
self._generateSkillReq()
self._generateSocioMat()
self._generateSkillDist()
def _generateSocioMat(self):
possibilities = [-1, 0, 1]
self.socioMat = [[possibilities[randint(0, 2)] for _ in range(self.numPeop)] for _ in range(self.numPeop)]
#print([len(i) for i in self.socioMat], len(self.socioMat))
def _generateSkillDist(self):
temp = 1
self.skillDist = []
for i in self.skillReq.sum(axis = 0):
self.skillDist.append(list(range(temp, temp + i)))
temp = temp + i
def _generateSkillReq(self):
lims = self.numPeop
lis = [randint(1, lims) for _ in range(self.numProj * self.numSkill)]
while sum(lis) != self.numPeop:
lims = lims >> 1 if lims > (self.numPeop*2) / (self.numProj + self.numSkill) else lims
del lis
lis = [randint(1, lims) for _ in range(self.numProj * self.numSkill)]
print(lis, sum(lis), lims)
#dd = input()
self.skillReq = np.reshape(lis, (self.numProj, self.numSkill))
def display(self):
print("Number of People :", self.numPeop)
print("Number of Skills :", self.numSkill)
print("Number of Projects :", self.numProj)
self._printSkillDistTable()
self._printSkillReqTable()
#self._printSocioMat()
def _printSocioMat(self):
print("Sociometric Matrix")
t = Texttable()
t.add_row([""] + ["p" + str(i + 1) for i in range(self.numPeop)])
for i in range(self.numPeop):
t.add_row(["p" + str(i + 1)] + self.socioMat[i])
print(t.draw())
def _printSkillDistTable(self):
print("Skill Distribution")
t = Texttable()
t.add_row(["s" + str(i + 1) for i in range(self.numSkill)])
t.add_row([i for i in self.skillDist])
print(t.draw())
def _printSkillReqTable(self):
print("Requirements")
t = Texttable()
t.add_row([""] + ["s" + str(i + 1) for i in range(self.numSkill)])
for i in range(self.numProj):
t.add_row(["p" + str(i + 1)] + list(self.skillReq[i]))
print(t.draw())
if __name__ == "__main__":
org = Organization(3, 3, 50)
org.display()
x = input()
with open('filename3.pickle', 'wb') as handle:
pickle.dump(org, handle)