ED_LRR/ed_lrr_gui/html_export.py

47 lines
1.2 KiB
Python

# -*- coding: utf-8 -*-
import jinja2
import os
tmpl_path = os.path.join(os.path.dirname(__file__), "html_export_template.html.jinja2")
def dist(p1, p2):
s = 0
for c1, c2 in zip(p1, p2):
s += (c1 - c2) ** 2
return s ** 0.5
colors = {
"O": "#0000FF",
"B": "#140AF0",
"A": "#3C1EDC",
"F": "#EEEEEE",
"G": "#969646",
"K": "#B43C1E",
"M": "#FF280A",
"L": "#FF1E00",
"T": "#800000",
"Y": "#800000",
"White Dwarf": "#5D67EF",
"Neutron": "#99A0FF",
}
entries = []
prev = route[0]
num = 1
for hop in route[1:]:
prev["jump_dist"] = "{:.2f} Ly".format(dist(hop["pos"], prev["pos"]))
prev["num"] = num
prev["color"] = colors.get(prev["star_type"].split()[0], "#eee")
prev["distance"] = "{} Ls".format(prev["distance"])
entries.append(prev)
prev = hop
num += 1
prev["jump_dist"] = "0 Ly"
prev["distance"] = "{} Ls".format(prev["distance"])
prev["num"] = num
prev["color"] = colors.get(prev["star_type"].split()[0], "#eee")
entries.append(prev)
tmpl = jinja2.Template(open(tmpl_path).read())
open("route.html", "w").write(tmpl.render(route=entries))