-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_stats.py
executable file
·214 lines (179 loc) · 5.45 KB
/
read_stats.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 18 14:42:50 2020
@author: planetmaker
"""
import json
import pandas as pd
def read_json_file(filename):
with open(filename) as file:
data = json.load(file)
return data
def read_data():
craftplans = read_json_file('json/crafplan.json')
words_item = read_json_file('json/words_de_item.json')
words_sbrick = read_json_file('json/words_de_sbrick.json')
items = read_json_file('json/items.json')
resources = read_json_file('json/resource_stats.json')
def get_resource_table():
resources = read_json_file('json/resource_stats.json')
def get_item_property_translation(cryt):
"""
Parameters
----------
cryt : string
the cryptic name of a material property like 'armour fixation'
used in the json files
Returns
-------
clear : string
the readable property type of the material
"""
# TODO get the actual meaning of these cryptic strings
values = {
"mpftMpAT": "Rüstungsfixierung (-wattierung?)",
"mpftMpBT": "mpftMpBT",
"mpftMpC": "Gegengewicht",
"mpftMpCA": "mpftMpCA",
"mpftMpCF": "mpftMpCF",
"mpftMpCR": "mpftMpCR",
"mpftMpE": "mpftMpE",
"mpftMpED": "Juwel (-enfassung?)",
"mpftMpEN": "mpftMpEN",
"mpftMpG": "Griff",
"mpftMpGA": "mpftMpGA",q
"mpftMpH": "mpftMpH",
"mpftMpJH": "mpftMpJH",
"mpftMpL": "Klinge",
"mpftMpM": "Schaft",
"mpftMpMF": "magischer Fokus",
"mpftMpP": "mpftMpP",
"mpftMpPE": "mpftMpPE",
"mpftMpPES":"mpftMpPES",
"mpftMpPR": "mpftMpPR",
"mpftMpRE": "Rüstungswattierung (-fixierung?)",
"mpftMpRI": "Rüstungsbindung (Kleidung?)",
"mpftMpSH": "mpftMpSH",
"mpftMpSU": "Juwelenfassung (Juwel?)",
"mpftMpTK": "mpftMpTK",
"mpftMpVE": "Kleidung (Rüstungsbindung?)",
}
return values[crypt]
def get_ecosystem_from_number(num):
values = {
0: 'None',
1: '',
2: '',
3: '',
4: '',
5: '',
6: 'Urwurzeln',
}
try:
ret = values[num]
except:
ret = None
return ret
def get_colour_from_number(num):
colour_str = ""
return colour_str
class names():
def __init__(self):
pass
class items():
j_items = dict()
def __init__(self):
self.j_items = read_json_file('json/items.json')
# _items = pd.DataFrame.from_dict(j_items)
def get_by_id(self, id):
try:
return self.j_items[id]
except:
return None
def get_all(self):
return self.j_items
class crafting_plans():
"""
Methods related to the treatment of the crafting plans
"""
plans = dict()
def __init__(self):
"""
Initialize the crafting plan array from the files and
convert it into an easier-to-use pandas table
Returns
-------
None.
"""
j_plans = read_json_file('json/craftplan.json')
self.plans = dict()
# num = 0
for plan,item in j_plans.items():
try:
stats = item['mpft']
stats['item_type'] = item['item_type']
stats['name'] = ""
self.plans[plan] = stats
except:
print('Error on ',plan, ': ', item)
pass
def get_by_id(self, id):
try:
return self.plans[id]
except:
print('Plan not found: ', id)
return None
def get_all(self):
return self.plans
def get_list(self):
l = list()
for name,prop in self.plans.items():
l.append(name)
return l
class resources():
"""
Methods related to treatment of the ressource stats
"""
ress = dict()
def __init__(self, items):
"""
Initialize the ressource info array from the files and
convert it into an easier-to-use pandas table
Returns
-------
None.
"""
j_ress = read_json_file('json/resource_stats.json')
self.ress = dict()
# num = 0
for material,item in j_ress.items():
mat_stats = items.get_by_id(material)
if mat_stats is None:
print('No stats found for material: ', material)
continue
# num += 1
# if num > 50:
# return
for prop,stats in item['stats'].items():
stats['material'] = material
stats = {**stats, **mat_stats}
if prop in self.ress:
self.ress[prop] = self.ress[prop].append({k: v for k,v in stats.items()}, ignore_index=True)
else:
self.ress[prop] = pd.DataFrame({k: [v] for k,v in stats.items()})
def get_materials(self, prop):
# return self.mpftMpAT
try:
return self.ress[prop]
except:
return None
def get_all(self):
return self.ress
def get_material_properties(self, material, usage):
try:
usage_mats = self.ress[usage]
return usage_mats[usage_mats['material'] == material]
except:
print('Material not found in usage:', material, usage_mats)
return None