-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxpOptimizerResults.py
More file actions
155 lines (125 loc) · 5.49 KB
/
xpOptimizerResults.py
File metadata and controls
155 lines (125 loc) · 5.49 KB
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
from typing import Dict, List, Optional
class CharacterPropertyResults:
def __init__(self,
total_values: Dict[str, int] = None,
target_values: Dict[str, int] = None):
self.Total: Dict[str, int] = total_values if total_values is not None else dict()
self.Target: Dict[str, int] = target_values if target_values is not None else dict()
def __iter__(self) -> dict:
yield 'Total', self.Total
yield 'Target', self.Target
yield 'Missed', self.Missed
def __str__(self):
"""
Creates a markdown-table string representation of the object.
"""
name_width = max(len('Name'), max(len(name) for name in self.Total))
max_value_header_width = max(len(header_name) for header_name, _ in self)
value_width = max(max_value_header_width, max(len(str(value)) for value in self.Total.values()))
name_format = "{0:" + str(name_width) + "}"
value_format = "{0:<" + str(value_width) + "}"
# Table header
as_string = name_format.format('Name')
for column_name, _ in self:
as_string += ' | ' + value_format.format(column_name)
# Header separator
as_string += '\n' + '-' * name_width
for _, _ in self:
as_string += ' | ' + '-' * value_width
# Table rows
for row_name in self.Total:
as_string += '\n' + name_format.format(row_name)
for column_name, column_data in self:
as_string += ' | '
row_data = '-'
if column_name == 'Missed':
if row_name in self.Missed:
row_data = 'YES'
elif row_name in self.Target:
row_data = 'NO'
elif row_name in column_data:
row_data = column_data[row_name]
as_string += value_format.format(row_data)
return as_string
def __repr__(self):
return str(dict(self))
@property
def Missed(self) -> List[str]:
return [target for target, target_value in self.Target.items() if
target in self.Total and self.Total[target] < target_value]
class SkillResults(CharacterPropertyResults):
def __init__(self,
rating_values: Dict[str, int] = None,
total_values: Dict[str, int] = None,
target_values: Dict[str, int] = None):
super().__init__(total_values, target_values)
self.Rating: Dict[str, int] = rating_values if rating_values is not None else dict()
def __iter__(self) -> dict:
yield 'Rating', self.Rating
for d in super().__iter__():
yield d
class XPCost:
def __init__(self,
attribute_costs: int = 0,
skill_costs: int = 0,
total_costs: Optional[int] = None):
self.Attributes: int = attribute_costs
self.Skills: int = skill_costs
if total_costs is not None and self.Attributes + self.Skills != total_costs:
raise IOError(f"Total XP cost didn't sum up from Attribute & Skill costs: {self.Attributes} != "
f"{self.Skills} + {total_costs}")
def __eq__(self, other):
return self.Attributes == other.Attributes and self.Skills == other.Skills
@property
def Total(self):
return self.Attributes + self.Skills
def __iter__(self) -> dict:
yield 'Attributes', self.Attributes
yield 'Skills', self.Skills
yield 'Total', self.Total
def __str__(self):
"""
Creates a markdown-table string representation of the object.
"""
name_width = max(len('Name'), max(len(name) for name, _ in self))
value_width = max(len('Cost'), max(len(str(value)) for _, value in self))
def format_row(name: str, data, prefix: str = '\n') -> str:
return prefix + ("{0:" + str(name_width) + "}").format(name) + ' | ' + (
"{0:<" + str(value_width) + "}").format(data)
# Table header + separator
as_string = format_row('Name', 'Cost', prefix='')
# Header separator
as_string += format_row('-' * name_width, '-' * value_width)
# Table rows
for row_name, row_data in self:
as_string += format_row(row_name, row_data)
return as_string
def __repr__(self):
return str(dict(self))
class AttributeSkillOptimizerResults:
def __init__(self,
tier: int = None,
attributes: CharacterPropertyResults = CharacterPropertyResults(),
skills: SkillResults = SkillResults(),
traits: CharacterPropertyResults = CharacterPropertyResults(),
xp_cost: XPCost = XPCost()
):
self.Tier: Optional[int] = tier
self.Attributes: CharacterPropertyResults = attributes
self.Skills: SkillResults = skills
self.Traits: CharacterPropertyResults = traits
self.XPCost: XPCost = xp_cost
def __iter__(self) -> dict:
yield 'Tier', self.Tier
yield 'Attributes', dict(self.Attributes)
yield 'Skills', dict(self.Skills)
yield 'Traits', dict(self.Traits)
yield 'XPCost', dict(self.XPCost)
def __str__(self):
"""
Creates a markdown string-representation of the object.
"""
as_string = ""
for attr_name, _ in self:
as_string += f"\n## {attr_name}\n{getattr(self, attr_name)}\n"
return as_string