-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBiographicTable.py
199 lines (179 loc) · 7.47 KB
/
BiographicTable.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import ModuleHelper
import re
import random
class BiographicTable( object ) :
"""This class defines Tables Definitions for 'biographic' elements for Curriculum generation. """
_tables = None
_equipments = None
_jobsToSkills = None
_skills = None
def __init__(self, name = None, comments = None ):
"""BiographicTable Constructor. """
self.name = name
self.comments = comments
self.contents = []
self.linksTo = []
self.addins = []
def __str__(self) :
"""BiographicTable to str. """
str = "BiographicTable ( % s , % s ) \n" % (self.name, self.comments)
str += "\t contents: %s \n" % (self.contents)
str += "\t linksTo: %s \n" % (self.linksTo)
str += "\t addins: %s \n" % (self.addins)
return str
def appendContent( self, content) :
self.contents.append( content )
def appendLinks( self, link) :
self.linksTo.append( link )
def appendAddin( self, addin) :
self.addins.append( addin )
@classmethod
def subLoad( self, tables, fileInConfig ) :
"""Sub Function to load tables !"""
if (tables != None) :
return tables
tables = {}
data = ModuleHelper.loadFileConfig( fileInConfig )
nextTable = None
nextSubTable = None
for line in data :
resultTableHead = re.match( "^Table (.*?)(\t(.*?))?(\t(.*?))?$", line)
resultTableContent = re.match( "^\t(.*?)(\t\[(.*?)\])?(\t\{(.*?)\})?$", line )
if (resultTableHead != None) :
if (nextTable != None) :
tables[ nextTable.name ] = nextTable
nextTable = BiographicTable( resultTableHead.groups()[0], resultTableHead.groups()[2] )
## print ( resultTableHead.groups() )
elif (resultTableContent != None) :
nextTable.appendContent( resultTableContent.groups()[0] );
nextTable.appendLinks( resultTableContent.groups()[2] );
nextTable.appendAddin( resultTableContent.groups()[4] );
if (nextTable != None) :
tables[ nextTable.name ] = nextTable
return tables
@classmethod
def loadBiographicsTables( self ) :
"""Load / Return Biographic Tables"""
return self.subLoad( self._tables, "biographyCyberAge" )
@classmethod
def loadEquipmentTables( self ) :
"""Load / Return Equipment Tables"""
return self.subLoad( self._equipments, "tableEquipementsCyberAge" )
@classmethod
def loadJobsToSkills( self ) :
if (self._jobsToSkills != None) :
return self._jobsToSkills
self._jobsToSkills = {}
data = ModuleHelper.loadFileConfig( "metiersEtTalentsCyberAge" )
nextTable = None
for line in data :
resultTableHead = re.match( "^(.*?)\t(.*?)$", line)
if (resultTableHead != None) :
if (nextTable != None) :
self._jobsToSkills[ nextTable.name ] = nextTable
nextTable = BiographicJob( resultTableHead.groups()[0], \
resultTableHead.groups()[1].split( ";" ) )
if (nextTable != None) :
self._jobsToSkills[ nextTable.name ] = nextTable
return self._jobsToSkills
@classmethod
def loadSkills( self ) :
if (self._skills != None) :
return self._skills
self._skills = {}
data = ModuleHelper.loadFileConfig( "talentsCyberAge" )
nextTable = None
for line in data :
resultTableHead = re.match( "^(.*?)\t(.*?)(\t\[(.*?)\])?$", line)
if (resultTableHead != None) :
if (nextTable != None) :
self._skills[ nextTable.name ] = nextTable
values = None
if (resultTableHead.groups()[3] != None) :
values = resultTableHead.groups()[3].split( ";" )
nextTable = BiographicSkill( resultTableHead.groups()[0], \
resultTableHead.groups()[1], \
values )
if (nextTable != None) :
self._skills[ nextTable.name ] = nextTable
return self._skills
class BiographicElement( object ) :
"""This class defines Selected Biographic Elements choosen from BioGraphic Tables """
def __init__(self, name ):
self.contents = []
self.contents.append( name )
self.addins = []
def __str__(self) :
"""BiographicElement to str. """
str = "BiographicElement() \n"
str += "\t contents: %s \n" % (self.contents)
str += "\t addins: %s \n" % (self.addins)
return str
class BiographicJob( object ) :
"""This class defines Biographic Jobs and related Skills """
def __init__(self, name = None, skills = None ):
"""BiographicJob Constructor. """
self.name = name
self.skills = skills
def __str__(self) :
"""BiographicJob to str. """
str = "BiographicJob() \n"
str += "\t name: %s \n" % (self.name)
str += "\t skills: %s \n" % (self.skills)
return str
class BiographicSkill( object ) :
"""This class defines Biographic Skills """
def __init__(self, name = None, level = None, possibilities = None ):
"""BiographicSkill Constructor. """
self.name = name
self.level = level
self.possibilities = possibilities
def __str__(self) :
"""BiographicSkill to str. """
str = "BiographicSkill() \n"
str += "\t name: %s \n" % (self.name)
str += "\t level: %s \n" % (self.level)
str += "\t possibilities: %s \n" % (self.possibilities)
return str
def selectRandomBiographic( tables ) :
"""Choose randomly an element from a randomly choosen BiographicTable. """
orientation = tables[ "d'Orientation" ]
## print( orientation )
bioELT = None
while (orientation != None) :
contents = orientation.contents
links = orientation.linksTo
addins = orientation.addins
index = random.randint(0, len(contents) - 1 )
## print( "%d (%d, %d, %d)" %( index, len(contents), len(links), len(addins) ) )
content = contents[index]
link = links[index]
addin = addins[index]
## ## ## Generate / complete a BiographicElement
if (bioELT == None) :
bioELT = BiographicElement( content )
else :
bioELT.contents.append( content )
if (addin != None) :
bioELT.addins = addin.split( ";" )
if (link != None) :
if (link == "Cicatrices") :
orientation = tables[ "Cicatrices-localisation" ]
bioELT.contents.append( "Cicatrice : %s" %( random.choice( orientation.contents ) ) )
orientation = tables[ "Cicatrices-gravité" ]
bioELT.contents.append( "Cicatrice : %s" %( random.choice( orientation.contents ) ) )
orientation = None;
else:
orientation = tables[ link ];
else :
orientation = None
## print( bioELT )
return bioELT
def selectBiographicElements( number ) :
results = []
tables = BiographicTable.loadBiographicsTables()
for i in range(0, number) :
results.append( selectRandomBiographic( tables ) )
return results