-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathrender_html_assets.py
157 lines (147 loc) · 6.49 KB
/
render_html_assets.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
import render_html
import eve_sde_tools
import eve_esi_tools
def __dump_corp_assets_tree_nested(
glf,
parent_location_id,
location_id,
corp_assets_data,
corp_assets_tree,
corp_ass_names_data,
foreign_structures_data,
eve_market_prices_data,
sde_type_ids,
sde_inv_names,
sde_inv_items,
sde_market_groups):
region_id, region_name, loc_name, foreign = eve_esi_tools.get_assets_location_name(
location_id,
sde_inv_names,
sde_inv_items,
corp_ass_names_data,
foreign_structures_data)
itm_dict = None
loc_dict = corp_assets_tree[str(location_id)]
type_id = loc_dict["type_id"] if "type_id" in loc_dict else None
group_id = eve_sde_tools.get_basis_market_group_by_type_id(sde_type_ids, sde_market_groups, type_id)
items = loc_dict["items"] if "items" in loc_dict else None
nested_quantity = None
items_quantity = None
base_price = None
volume = None
if not (items is None):
nested_quantity = len(items)
if itm_dict is None:
itm_dict = corp_assets_data[loc_dict["index"]] if "index" in loc_dict else None
if not (itm_dict is None):
items_quantity = itm_dict["quantity"]
if str(type_id) in sde_type_ids:
__type_dict = sde_type_ids[str(type_id)]
if "basePrice" in __type_dict:
base_price = __type_dict["basePrice"] * items_quantity
if "volume" in __type_dict:
volume = __type_dict["volume"] * items_quantity
if type_id is None:
__price_dict = None
else:
__price_dict = next((p for p in eve_market_prices_data if p['type_id'] == int(type_id)), None)
glf.write(
'<div class="media">\n'
' <div class="media-left media-top">{img}</div>\n'
' <div class="media-body">\n'
' <h4 class="media-heading" id="id{id}">{where}{what}{iq}{nq}</h4>\n'
' {parent_id}<span class="label label-info">{id}</span>{loc_flag}{foreign}\n'
' {grp}{base}{average}{adjusted}{volume}\n'.
format(
img='<img class="media-object icn32" src="{src}">'.format(src=render_html.__get_img_src(type_id, 32)) if not (type_id is None) else "",
where='{} '.format(loc_name) if not (loc_name is None) else "",
what='<small>{}</small> '.format(eve_sde_tools.get_item_name_by_type_id(sde_type_ids, type_id)) if not (type_id is None) else "",
parent_id='<a href="#id{id}"><span class="label label-primary">parent:{id}</span></a> '.format(id=parent_location_id) if not (parent_location_id is None) else "",
id=location_id,
nq=' <span class="badge">{}</span>'.format(items_quantity) if not (items_quantity is None) and (items_quantity > 1) else "",
iq=' <span class="label label-info">{}</span>'.format(nested_quantity) if not (nested_quantity is None) and (nested_quantity > 1) else "",
loc_flag=' <span class="label label-default">{}</span>'.format(itm_dict["location_flag"]) if not (itm_dict is None) else "",
foreign='<br/><span class="label label-warning">foreign</span>' if foreign else "",
grp='</br><span class="label label-success">{}</span>'.format(sde_market_groups[str(group_id)]["nameID"]["en"]) if not (group_id is None) else "",
base='</br>base: {:,.1f} ISK'.format(base_price) if not (base_price is None) else "",
average='</br>average: {:,.1f} ISK'.format(__price_dict["average_price"]*items_quantity) if not (items_quantity is None) and not (__price_dict is None) and ("average_price" in __price_dict) else "",
adjusted='</br>adjusted: {:,.1f} ISK'.format(__price_dict["adjusted_price"]*items_quantity) if not (items_quantity is None) and not (__price_dict is None) and ("adjusted_price" in __price_dict) else "",
volume='</br>{:,.1f} m³'.format(volume) if not (volume is None) else ""
)
)
if not (items is None):
for itm in items:
__dump_corp_assets_tree_nested(
glf,
location_id,
itm,
corp_assets_data,
corp_assets_tree,
corp_ass_names_data,
foreign_structures_data,
eve_market_prices_data,
sde_type_ids,
sde_inv_names,
sde_inv_items,
sde_market_groups)
glf.write(
' </div>\n'
'</div>\n'
)
def __dump_corp_assets_tree(
glf,
corp_assets_data,
corp_assets_tree,
corp_ass_names_data,
foreign_structures_data,
eve_market_prices_data,
sde_type_ids,
sde_inv_names,
sde_inv_items,
sde_market_groups):
glf.write("""
<!-- BEGIN: collapsable group (locations) -->
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<ul class="media-list">
<li class="media">""")
if "roots" in corp_assets_tree:
roots = corp_assets_tree["roots"]
for loc_id in roots:
__dump_corp_assets_tree_nested(
glf,
None,
loc_id,
corp_assets_data,
corp_assets_tree,
corp_ass_names_data,
foreign_structures_data,
eve_market_prices_data,
sde_type_ids,
sde_inv_names,
sde_inv_items,
sde_market_groups)
glf.write(""" </li>
</ul>
</div>
<!-- END: collapsable group (locations) -->
""")
def dump_assets_tree_into_report(
ws_dir,
sde_type_ids,
sde_inv_names,
sde_inv_items,
sde_market_groups,
corp_assets_data,
corp_ass_names_data,
foreign_structures_data,
eve_market_prices_data,
corp_assets_tree):
glf = open('{dir}/assets_tree.html'.format(dir=ws_dir), "wt+", encoding='utf8')
try:
render_html.__dump_header(glf, "Corp Assets")
#__dump_any_into_modal_header(glf, "Corp Assets")
__dump_corp_assets_tree(glf, corp_assets_data, corp_assets_tree, corp_ass_names_data, foreign_structures_data, eve_market_prices_data, sde_type_ids, sde_inv_names, sde_inv_items, sde_market_groups)
#__dump_any_into_modal_footer(glf)
render_html.__dump_footer(glf)
finally:
glf.close()