Skip to content
Commits on Source (50)
{{ if .Versions -}}
## [Unreleased]
{{ if .Unreleased.CommitGroups -}}
{{ range .Unreleased.CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} [{{.Hash.Short}}]({{ $.Info.RepositoryURL }}/commit/{{ .Hash.Short }})
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}
{{ range .Versions }}
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]{{ else }}{{ .Tag.Name }}{{ end }} - {{ datetime "2006-01-02" .Tag.Date }}
{{ range .CommitGroups -}}
### {{ .Title }}
{{ range .Commits -}}
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} [{{.Hash.Short}}]({{ $.Info.RepositoryURL }}/commit/{{ .Hash.Short }})
{{ end }}
{{ end -}}
{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}
{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}
{{- if .Versions }}
[Unreleased]: {{ $.Info.RepositoryURL }}/compare/{{ $latest := index .Versions 0 }}{{ $latest.Tag.Name }}...HEAD
{{ range .Versions -}}
{{ if .Tag.Previous -}}
[{{ .Tag.Name }}]: {{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}
{{ end -}}
{{ end -}}
{{ end -}}
style: gitlab
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://gitlab.com/Earthnuker/ed_lrr
options:
commits:
filters:
Type:
- feat
- fix
- perf
- refactor
- misc
- other
- docs
commit_groups:
title_maps:
feat: Features
fix: Bug Fixes
perf: Performance Improvements
refactor: Code Refactoring
misc: Miscellaneous
other: Other
docs: Documentation
header:
pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$"
pattern_maps:
- Type
- Scope
- Subject
notes:
keywords:
- BREAKING CHANGE
/target
/dist
/build
rust/target
rust/.history/
**/*.rs.bk
*.tmp
*.idx
.vscode/**
*.csv
*.router
plot.py
*.tmp
*.idx
*.pyd
build.bat
test.bat
__pycache__
DL
*.egg-info
build
*.pdf
.history
.tox
pip-wheel-metadata
rust/target/*
\ No newline at end of file
.eggs/
exe/
installer/Output/
## [Unreleased]
### Documentation
- Insert page break after table of contents [f027e02](https://gitlab.com/Earthnuker/ed_lrr/commit/f027e02)
- Update documentation to include basic description [714741a](https://gitlab.com/Earthnuker/ed_lrr/commit/714741a)
- Rename `doc` folder to `docs`, update outline [fb54bda](https://gitlab.com/Earthnuker/ed_lrr/commit/fb54bda)
- Add skeleton for documentation [dbc6f35](https://gitlab.com/Earthnuker/ed_lrr/commit/dbc6f35)
### Miscellaneous
- Update changelog template to make conversion to PDF easier [87550a9](https://gitlab.com/Earthnuker/ed_lrr/commit/87550a9)
- **formatting:** ran `cargo fmt` and `cargo clippy`, fixed all warnings [fb3f79b](https://gitlab.com/Earthnuker/ed_lrr/commit/fb3f79b)
## [v0.2.1] - 2019-08-05
### Bug Fixes
- **router:** Fixed some syntax errors created by botched merge [4b14643](https://gitlab.com/Earthnuker/ed_lrr/commit/4b14643)
## [v0.2.0] - 2019-08-05
### Features
- **GUI:** Implement route plotting and fuzzy search [c290d5e](https://gitlab.com/Earthnuker/ed_lrr/commit/c290d5e)
## [v0.1.0] - 2019-07-22
### Features
- **GUI:** Add Download functionality, update Rust code, update Python code [ec3972b](https://gitlab.com/Earthnuker/ed_lrr/commit/ec3972b)
## v0.0.0 - 2019-07-15
[Unreleased]: https://gitlab.com/Earthnuker/ed_lrr/compare/v0.2.1...HEAD
[v0.2.1]: https://gitlab.com/Earthnuker/ed_lrr/compare/v0.2.0...v0.2.1
[v0.2.0]: https://gitlab.com/Earthnuker/ed_lrr/compare/v0.1.0...v0.2.0
[v0.1.0]: https://gitlab.com/Earthnuker/ed_lrr/compare/v0.0.0...v0.1.0
MIT License
Copyright (c) 2019 Daniel Seiller
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
include rust/Cargo.toml
recursive-include rust/src *
\ No newline at end of file
include rust/Cargo.toml
include rust/.cargo/config
recursive-include rust/src *
# Prerequisites
- conda (miniconda/anaconda)
- Visual Studio 2019
- nightly rust compiler (`x86_64-pc-windows-msvc`)
# Testing
```bash
......@@ -14,7 +20,7 @@ rs_gui_test
conda create -n ed_lrr_gui_env python=3
conda activate ed_lrr_gui_env
python build_gui.py
pip install setuptools_rust
pip install setuptools_rust pyinstaller
pip install .
python setup.py build
python setup.py bdist_wheel
......@@ -38,4 +44,4 @@ cd ..
# TODO
- integrate callbacks into the GUI: WIP
- QTimer pulls from queue updates UI (every 100ms)
\ No newline at end of file
- QTimer pulls from queue updates UI (every 100ms)
image: Visual Studio 2019
platform: x64
version: 0.1.{build}
branches:
only:
- pyqt_gui
environment:
VCVARS: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat
VCVARSARG: x64
MINICONDA: C:\Miniconda3-x64
INNO: C:\Program Files (x86)\Inno Setup 6
build: off
artifacts:
- path: exe\__main__.dist\
name: ED_LRR
type: zip
- path: installer\Output\*.exe
name: Setup
type: file
install:
- set PATH=%MINICONDA%\\Library\\bin;%MINICONDA%\\Scripts;%USERPROFILE%\\.cargo\\bin;%PATH%
- set PATH=%INNO%;%PATH%
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
- rustup-init -y --default-toolchain nightly --default-host x86_64-pc-windows-msvc
- if defined VCVARS call "%VCVARS%" %VCVARSARG%
- conda activate
- conda update -y -n base -c defaults conda
- conda install -y -c conda-forge pycrypto nuitka
- pip install PyQt5 setuptools_rust
test_script:
- python build_gui.py
- pip install .[dev]
- python -m nuitka --plugin-enable=multiprocessing --remove-output --plugin-enable=qt-plugins --standalone --assume-yes-for-downloads --follow-imports --output-dir=exe ed_lrr_gui\__main__.py
- rename exe\__main__.dist\__main__.exe ED_LRR.exe
- cd installer
- iscc /QP ED_LRR.iss
import subprocess as SP
from glob import glob
import os
import shutil
import pkg_resources as pkg
from contextlib import contextmanager
@contextmanager
def in_dir(name,remove=False):
pwd=os.getcwd()
if os.path.isdir(name):
shutil.rmtree(name)
os.makedirs(name)
os.chdir(name)
yield
os.chdir(pwd)
if remove:
shutil.rmtree(name)
SP.check_call(["pip", "install", "PyQt5"])
ui_path = os.path.dirname(os.path.abspath(__file__))
for root, folders, files in os.walk(ui_path):
for file in files:
file = os.path.join(root, file)
outfile, ext = os.path.splitext(file)
if ext == ".ui":
outfile = outfile + ".py"
print(os.path.basename(file), "->", os.path.basename(outfile))
SP.check_call(["pyuic5", "--from-imports", "-o", outfile, file])
SP.check_call(["pip", "install", ".[dev]"])
main_py=os.path.abspath("ed_lrr_gui\__main__.py")
with in_dir("exe"):
with in_dir("pyinstaller"):
SP.check_call(
[
"pyinstaller",
"--clean",
"--noupx",
"-c",
'--key="ED_LRR_GUI"',
"--name",
"ED_LRR",
main_py,
]
)
with in_dir("nuitka"):
SP.check_call(
[
"python",
"-m",
"nuitka",
"--plugin-enable=multiprocessing",
"--plugin-enable=qt-plugins",
"--standalone",
"--follow-imports",
main_py,
]
)
# with in_dir("installer"):
# shutil.rmtree("Output")
# SP.check_call(["iscc", "/QP", "ED_LRR.iss"])
rm -rfv _*.pyd *.egg-info pip-wheel-metadata dist exe build __pycache__
cd rust
cargo clean
cargo clean --release
cd ..
\ No newline at end of file
{
"spellright.language": [
"de",
"en"
],
"spellright.documentTypes": [
"markdown",
"latex",
"plaintext"
]
}
MD = $(wildcard src/*.md)
DOTS = $(wildcard src/*.dot)
ASYS = $(wildcard src/*.asy)
PYS = $(wildcard src/img_*.py)
PDFS = $(MD:src/%.md=out/%.pdf)
IMG_PDFS = $(ASYS:src/%.asy=img/%.pdf) $(PYS:src/img_%.py=img/%.pdf) $(DOTS:src/%.dot=img/%.pdf)
IMGS = $(IMG_PDFS)
TEMPLATE = eisvogel
PDF_ENGINE = xelatex
PANDOC = pandoc
PANDOC_OPTIONS = -F panflute -F pandoc-citeproc --pdf-engine=$(PDF_ENGINE) --template $(TEMPLATE) -N --standalone --listings
GRAPHVIZ = dot
GRAPHVIZ_OPTIONS = -Tpdf
ASY = asy
ASY_OPTIONS = -noV -f pdf
PYTHON = python
PYTHON_OPTIONS =
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
.PHONY: clean all default
all: $(PDFS)
default: all
out/%.pdf: src/%.md $(IMGS) Makefile
$(PANDOC) $(PANDOC_OPTIONS) -o $@ $<
img/%.pdf: src/%.dot
$(GRAPHVIZ) $(GRAPHVIZ_OPTIONS) -o $@ $<
img/%.pdf: src/img_%.py
$(PYTHON) $(PYTHON_OPTIONS) $< $@
img/%.pdf: src/%.asy
$(ASY) $(ASY_OPTIONS) -o $@ $<
watch:
watchexec -w src -w data -w filters -w Makefile make all
clean:
-rm $(PDFS) $(IMGS)
import contextlib
import csv
import datetime
import hashlib
import io
import os
import re
import subprocess as SP
import sys
import tempfile
from functools import partial
import panflute as pf
from dateutil.parser import parse as dateparse
from jinja2 import Environment, PackageLoader, Template, select_autoescape
from panflute import *
def remove_pound(elem, doc):
if type(elem) == Str:
return Str(elem.text.lstrip("#"))
def fix_color(elem, doc):
if type(elem) == MetaMap:
for k in elem.content:
if k.endswith("-color"):
elem[k] = elem[k].walk(remove_pound)
def update_date(elem, doc):
if type(elem) == MetaMap:
datefmt = doc.get_metadata("datefmt", "%Y-%m-%d")
today = datetime.date.today().strftime(datefmt)
date = dateparse(doc.get_metadata("date", today)).date()
elem["date"] = MetaInlines(Str(date.strftime(datefmt)))
return elem
def csv_table(elem, doc):
if type(elem) == Para and len(elem.content) == 1 and type(elem.content[0]) == Image:
elem = elem.content[0]
ext = os.path.splitext(elem.url)[1][1:]
if ext == "csv":
caption = elem.content
has_header = elem.attributes.get("has-header", "false").lower() == "true"
with open(elem.url) as f:
reader = csv.reader(f)
body = []
for row in reader:
cells = [TableCell(Plain(Str(x))) for x in row]
body.append(TableRow(*cells))
header = body.pop(0) if has_header else None
ret = Table(*body, header=header, caption=caption)
return ret
def code_refs(elem, doc):
if type(elem) == Cite:
label = elem.content[0]
if type(label) == Str:
label = label.text
filename = re.findall(r"^\[@lst:(.*)\]$", label) or [None]
if filename[0] in doc.inc_files:
return [
RawInline(
"\\hyperref[{}]{{{}}}".format(filename[0], filename[0]),
format="tex",
)
]
def include_code(elem, doc):
if type(elem) == CodeBlock:
if "include" in elem.attributes:
filepath = elem.attributes.pop("include")
filename = os.path.split(filepath)[-1]
try:
elem.text += elem.text + open(filepath, encoding="utf-8").read()
elem.attributes["caption"] = filename
doc.inc_files.append(filename)
except Exception as e:
elem.text += "Error: {}".format(e)
return [RawBlock("\\label{{{}}}".format(filename), format="tex"), elem]
def py_eval(options, data, element, doc):
out_buffer = io.StringIO()
with contextlib.redirect_stdout(out_buffer):
exec(data, doc.pyenv)
out_buffer.seek(0)
return convert_text(out_buffer.read())
def jinja_py_filt(doc, file):
env = {}
code = open(file, encoding="utf-8").read()
exec(code, env)
return env["main"](doc)
def prepare(doc):
doc.inc_files = []
doc.env = Environment()
doc.pyenv = {}
filters = {"py": partial(jinja_py_filt, doc)}
doc.env.filters.update(filters)
def process_templates(elem, doc):
if type(elem) == CodeBlock:
if elem.classes == ["@"]:
args = {"meta": doc.get_metadata()}
return convert_text(doc.env.from_string(elem.text).render(args))
def yaml_filt(elem, doc):
tags = {"eval": py_eval}
return yaml_filter(elem, doc, tags=tags, strict_yaml=True)
def checkboxes(elem, doc):
if type(elem) in [Para, Plain]:
val = re.findall(r"^\[([xX]|\ )\] (.*)$", stringify(elem))
if val:
val = val[0][0].lower() == "x"
else:
return elem
marker = {
True: RawInline("$\\boxtimes$", format="latex"),
False: RawInline("$\\square$", format="latex"),
}[val]
cont = []
if val:
cont += elem.content[2:]
else:
cont += elem.content[4:]
return Plain(marker, Space, *cont)
return elem
def main(doc=None):
f = [
process_templates,
update_date,
csv_table,
include_code,
fix_color,
code_refs,
yaml_filt,
checkboxes,
]
return run_filters(f, prepare=prepare, doc=doc)
if __name__ == "__main__":
main()
---
# Metadata
title: ED_LRR
author:
- Daniel Seiller <earthnuker@gmail.com>
subtitle: 'Elite Dangerous: Long-Range Router'
# Formating
toc: true
lang: en
colorlinks: true
papersize: a4
numbersections: true
#Panflute options
panflute-filters: [multifilter]
panflute-path: 'filters'
#Template options
titlepage: true
toc-own-page: false
---
\pagebreak
# Implementation
## `stars.csv` format
### Columns
| Name | Content |
| --------- | ------------------------------------------------------------ |
| id | unique ID-Number (not equal to id or id64, just a sequential number) |
| star_type | Type of Star |
| system | Name of System |
| body | Name of Star |
| mult | Jump Range Multiplier (1.5 for White Dwarfs, 4.0 for Neutron Stars) |
| distance | Distance from arrival in Ls |
| x,y,z | Position in Galactic Coordinates with Sol at (0,0,0) |
## `stars.idx` format
`bincode` serialized data:
- **[u64]**: List of byte offset for records (entry 0=first recod, entry 1= second record, etc)
## Routing Algorithms
### Breadth-First Search (BFS)
Standard Breadth-First Search, always finds the shortest route
### A*-Search
Modified A*-Search with adjustable "greediness". Priority Queue weighted by $\text{number of jumps from start system} + (\text{estimated number of jumps to target system} * \text{greediness})$
A greediness of 0 is equivalent to BFS and a greediness of $\infty$ is equivalent to Greedy-Search
### Greedy-Search
Priority Queue weighted by minimum distance to target, prefers systems with high multiplier (Neutron Stars and White Dwarfs)
## Optimizations
### Ellipse elimination
Only consider systems within an ellipsoid with source and destination as the foci, the width of the ellipsoid is adjustable
## Routing Graphs
### File format
`bincode` serialized data:
- *bool* **primary**: flag to indicate that graph only includes primary stars
- *f32* **range**: jump range for routing graph
- *[u8]* **file_hash**: sha3 hash of `stars.csv` from which graph was generated
- *String* **path**: path to `stars.csv` from which graph was generated
- *FnvHashMap* **graph**: Hashmap mapping systems to the systems from which they can be rached, traversed from destination system backwards to source to reconstruct route
# Usage
<!--
TODO: Add screenshots
-->
## Preprocessing Data
## Plotting a Route
# [Changelog](https://gitlab.com/Earthnuker/ed_lrr/blob/pyqt_gui/CHANGELOG.md)
import heapq
import sys
import numpy as np
import pylab as PL
from scipy.spatial.ckdtree import cKDTree
exit()
def vec(a, b):
return b - a
def bfs(points):
return
def in_ellipse(p, f1, f2, r, offset=0):
df = ((f1 - f2) ** 2).sum(0) ** 0.5
d_f1 = ((p - f1) ** 2).sum(1) ** 0.5
d_f2 = ((p - f2) ** 2).sum(1) ** 0.5
return (d_f1 + d_f2) < (df * (1 + r))
num_points = 100000
p_orig = np.random.normal(0, 10, size=(num_points, 2))
tree = cKDTree(p_orig)
f1 = np.array([0, -30])
f2 = -f1 # np.random.normal(0, 20, (3,))
# r = 2 ** ((n / cnt) - cnt)
mask = in_ellipse(p_orig, f1, f2, 0.1)
p = p_orig[mask]
p_orig = p_orig[~mask]
colors = np.random.random(p.shape[0])
fig = PL.gcf()
PL.scatter(
p_orig[:, 0],
p_orig[:, 1],
marker=".",
s=0.2,
edgecolor="None",
c=[(0.0, 0.0, 0.0)],
alpha=0.75,
rasterized=True,
)
PL.scatter(
p[:, 0], p[:, 1], marker="s", s=0.2, edgecolor="None", c=colors, rasterized=True
)
PL.plot(f1[0], f1[1], "r.", label="Source")
PL.plot(f2[0], f2[1], "g.", label="Destination")
max_v = max(p_orig[:, 0].max(), p_orig[:, 1].max(), f1[0], f1[1], f2[0], f2[1]) + 2
min_v = min(p_orig[:, 0].min(), p_orig[:, 1].min(), f1[0], f1[1], f2[0], f2[1]) - 2
PL.xlim(min_v, max_v)
PL.ylim(min_v, max_v)
PL.legend()
PL.savefig(sys.argv[1], dpi=1200)
from _ed_lrr import *
from . import gui
from .preprocess import Preprocessor
from .router import Router
import sys
import os
import requests as RQ
from datetime import datetime, timedelta
from PyQt5.QtCore import QThread, pyqtSignal, Qt
from PyQt5.QtWidgets import (
QMainWindow,
QApplication,
QFileDialog,
QProgressDialog,
QTreeWidgetItem,
)
from urllib.request import Request, urlopen
import gzip
from PyQt5.QtGui import QPalette, QColor
import ed_lrr_gui
import ed_lrr_gui.config as cfg
from ed_lrr_gui.gui.ed_lrr import Ui_ED_LRR
import multiprocessing as MP
def sizeof_fmt(num, suffix="B"):
for unit in ["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"]:
if abs(num) < 1024.0:
return "{:.02f}{}{}".format(num, unit, suffix)
num /= 1024.0
return "{:.02f}{}{}".format(num, "Yi", suffix)
def t_round(dt):
return dt - dt % timedelta(seconds=1)
class ProgressDialog(QProgressDialog):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowModality(Qt.WindowModal)
class DownloadThread(QThread):
progress = pyqtSignal("PyQt_PyObject")
def __init__(self, systems_url, systems_file, bodies_url, bodies_file):
super().__init__()
self.systems_url = systems_url
self.systems_file = systems_file
self.bodies_url = bodies_url
self.bodies_file = bodies_file
self.running = True
def __del__(self):
self.wait()
def stop(self):
self.running = False
def run(self):
jobs = [
(self.systems_url, self.systems_file),
(self.bodies_url, self.bodies_file),
]
for url, dest in jobs:
outfile = url.split("/")[-1]
size = RQ.head(url, headers={"Accept-Encoding": "None"})
size.raise_for_status()
size = int(size.headers.get("Content-Length", 0))
with open(dest, "wb") as of:
resp = RQ.get(url, stream=True)
for chunk in resp.iter_content(1024 * 1024):
of.write(chunk)
self.progress.emit(
{"done": of.tell(), "size": size, "outfile": outfile}
)
if not self.running:
return
class App(QApplication):
def __init__(self):
super().__init__(sys.argv)
self.setStyle("Fusion")
self.set_pallete()
def set_pallete(self):
colors = {
"Window": QColor(53, 53, 53),
"WindowText": Qt.white,
"Base": QColor(15, 15, 15),
"AlternateBase": QColor(53, 53, 53),
"ToolTipBase": Qt.white,
"ToolTipText": Qt.white,
"Text": Qt.white,
"Button": QColor(53, 53, 53),
"ButtonText": Qt.white,
"BrightText": Qt.red,
"Highlight": QColor(255, 128, 0),
"HighlightedText": Qt.black,
}
palette = QPalette()
for entry, color in colors.items():
palette.setColor(getattr(QPalette, entry), color)
if color == Qt.darkGray:
palette.setColor(
QPalette.Disabled, getattr(QPalette, entry), QColor(53, 53, 53)
)
else:
palette.setColor(
QPalette.Disabled, getattr(QPalette, entry), Qt.darkGray
)
self.setPalette(palette)
class ED_LRR(Ui_ED_LRR):
dl_thread = None
diag_prog = None
dl_started = None
def __init__(self):
super().__init__()
self.config = cfg.load()
def get_open_file(self, filetypes, callback=None):
fileName, _ = QFileDialog.getOpenFileName(
self.main_window,
"Open file",
str(cfg.data_dir),
filetypes,
options=QFileDialog.DontUseNativeDialog,
)
if callback:
return callback(fileName)
return fileName
def get_save_file(self, filetypes, callback=None):
fileName, _ = QFileDialog.getSaveFileName(
self.main_window,
"Save file",
str(cfg.data_dir),
filetypes,
options=QFileDialog.DontUseNativeDialog,
)
if callback:
return callback(fileName)
return fileName
def set_sys_lst(self, path):
if path not in self.config.history_out_path:
self.config.history_out_path.append(path)
self.inp_sys_lst.addItem(path)
self.inp_out_pp.addItem(path)
def set_bodies_file(self, path):
if path not in self.config.history_bodies_path:
self.config.history_bodies_path.append(path)
self.inp_bodies_pp.addItem(path)
def set_systems_file(self, path):
if path not in self.config.history_systems_path:
self.config.history_systems_path.append(path)
self.inp_systems_pp.addItem(path)
def update_dropdowns(self):
import queue
import ctypes
from math import floor
import click
from click_default_group import DefaultGroup
import requests as RQ
from ed_lrr_gui import Router
from ed_lrr_gui import Preprocessor
import ed_lrr_gui.gui as ED_LRR_GUI
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@click.group(invoke_without_command=True,context_settings=CONTEXT_SETTINGS)
@click.pass_context
def main(ctx):
"Elite: Dangerous long range router, command line interface"
if ctx.invoked_subcommand is None:
ctx.invoke(gui)
return
def log(self, *args):
t = datetime.today()
msg_t = "[{}] {}".format(t, str.format(*args))
self.txt_log.append(msg_t)
def set_comp_mode(self, _):
if self.rd_comp.isChecked():
comp_mode = "Compute Route"
self.btn_add.setText("Search+Add")
if self.rd_precomp.isChecked():
comp_mode = "Precompute Graph"
self.btn_add.setText("Select")
self.log("COMP_MODE", comp_mode)
self.lst_sys.setEnabled(self.rd_comp.isChecked())
self.btn_rm.setEnabled(self.rd_comp.isChecked())
self.cmb_mode.setEnabled(self.rd_comp.isChecked())
self.btn_permute.setEnabled(self.rd_comp.isChecked())
self.lbl_keep.setEnabled(self.rd_comp.isChecked())
self.lbl_mode.setEnabled(self.rd_comp.isChecked())
self.chk_permute_keep_first.setEnabled(self.rd_comp.isChecked())
self.chk_permute_keep_last.setEnabled(self.rd_comp.isChecked())
self.set_route_mode(self.rd_precomp.isChecked() or None)
def set_route_mode(self, mode=None):
if mode == None:
mode = self.cmb_mode.currentText()
self.lbl_greedyness.setEnabled(mode == "A*-Search")
self.sld_greedyness.setEnabled(mode == "A*-Search")
self.log("ROUTE_MODE", mode)
def set_greedyness(self, value):
self.lbl_greedyness.setText("Greedyness Factor ({:.0%})".format(value / 100))
def sys_to_dict(self, n):
header = [
self.lst_sys.headerItem().data(c, 0)
for c in range(self.lst_sys.headerItem().columnCount())
]
system = [
self.lst_sys.topLevelItem(n).data(c, 0)
for c in range(self.lst_sys.topLevelItem(n).columnCount())
]
return dict(zip(header, system))
def run(self):
settings = {}
settings["permute"] = (
self.chk_permute_keep_first.checkState(),
self.chk_permute_keep_last.checkState(),
)
settings["range"] = self.sb_range.value()
settings["systems"] = [
self.sys_to_dict(i) for i in range(self.lst_sys.topLevelItemCount())
]
print(settings)
progress = ProgressDialog(
"(Not actually computing)", "Cancel", 0, 0, self.main_window
)
progress.setWindowTitle("Computing Route")
progress.setFixedSize(400, 100)
progress.setRange(0, 0)
progress.show()
def add_system(self):
n = self.lst_sys.topLevelItemCount() + 1
name = self.inp_sys.text()
item = QTreeWidgetItem(
self.lst_sys, [str(n) + ". Name: " + name, "Type: " + name[::-1]]
)
item.sys_id = "SYS_ID_HERE"
item.setFlags(item.flags() & ~Qt.ItemIsDropEnabled)
def remove_system(self):
root = self.lst_sys.invisibleRootItem()
for item in self.lst_sys.selectedItems():
root.removeChild(item)
def dl_canceled(self):
if self.dl_thread:
print("Cancel!")
return
@main.command()
@click.option("--debug",help="Debug print",is_flag=True)
def gui(debug):
"Run the ED LRR GUI (default)"
if not debug:
ctypes.windll.kernel32.FreeConsole()
sys.stdin=open("NUL","rt")
sys.stdout=open("NUL","wt")
sys.stderr=open("NUL","wt")
sys.exit(ED_LRR_GUI.main())
@main.command()
@click.option("--url","-u",help="Base URL",default="https://www.edsm.net/dump/",show_default=True)
@click.option("--systems","-s",help="Target path for systemsWithCoordinates.json",default="systemsWithCoordinates.json",show_default=True)
@click.option("--bodies","-b",help="Target path for bodies.json",default="bodies.json",show_default=True)
def download(*args,**kwargs):
"Download EDSM dumps"
print("Download:",args,kwargs)
click.pause()
@main.command()
def preprocess(*args,**kwargs):
"Preprocess EDSM dumps"
print("PreProcess:",ctx,args,kwargs)
click.pause()
@main.command()
@click.option("--path","-i",required=True,metavar="<path>",help="Path to stars.csv",default="./stars.csv",type=click.Path(exists=True,dir_okay=False),show_default=True )
@click.option("--precomp_file","-pf",metavar="<path>",help="Precomputed routing graph to use",type=click.Path(exists=True,dir_okay=False))
@click.option("--range","-r",required=True,metavar="<float>",help="Jump range (Ly)",type=click.FloatRange(min=0))
@click.option("--prune","-d",default=(0,0),metavar="<n> <m>",help="Prune search branches",nargs=2,type=click.Tuple([click.IntRange(min=0),click.FloatRange(min=0)]))
@click.option("--permute","-p",type=click.Choice(["all","keep_first","keep_last","keep_both"]),default=None,help="Permute hops to find shortest route",show_default=True)
@click.option("--primary","-ps",is_flag=True,default=False,help="Only route through primary stars")
@click.option("--factor","-g",metavar="<float>",default=0.5,help="Greedyness factor for A-Star",show_default=True)
@click.option("--mode","-m",default="bfs",help="Search mode",type=click.Choice(["bfs","a-star","greedy"]),show_default=True)
@click.argument('systems',nargs=-1)
def route(**kwargs):
"Compute a route"
if kwargs['prune']==(0,0):
kwargs['prune']=None
def to_string(state):
if state:
return "[{}] {}".format(state['depth'],state['system'])
keep_first,keep_last={
"all":(False,False),
"keep_first":(True,False),
"keep_last":(False,True),
"keep_both":(True,True),
None: (False,False)
}[kwargs['permute']]
args=[kwargs['systems'],kwargs['range'],kwargs['prune'],kwargs['mode'],kwargs['primary'],kwargs['permute']!=None,keep_first,keep_last,kwargs['factor'],None,kwargs['path']]
with click.progressbar(length=100,label="Computing route",show_percent=True,item_show_func=to_string,width=50) as pbar:
router=Router(*args)
router.start()
state={}
pstate={}
while not (router.queue.empty() and router.is_alive()==False):
try:
self.dl_thread.progress.disconnect()
except TypeError:
event = router.queue.get(True,0.1)
state.update(event)
if state!=pstate:
pbar.current_item=state.get("status")
if pbar.current_item:
pbar.pos=floor(pbar.current_item["prc_done"]*10)/10
pbar.update(0)
pstate=state
except queue.Empty:
pass
self.dl_thread.stop()
self.dl_thread.wait()
self.diag_prog.close()
self.dl_thread = None
self.diag_prog = None
self.dl_started = None
def handle_progress(self, args):
filename = os.path.split(args["outfile"])[-1]
if self.diag_prog is None:
self.diag_prog = ProgressDialog("", "Cancel", 0, 1000, self.main_window)
if self.dl_thread:
self.diag_prog.canceled.connect(self.dl_canceled)
self.diag_prog.show()
t_elapsed = datetime.today() - self.dl_started
rate = args["done"] / t_elapsed.total_seconds()
remaining = (args["size"] - args["done"]) / rate
rate = round(rate, 2)
# print(rate, remaining)
try:
t_rem = timedelta(seconds=remaining)
except OverflowError:
t_rem = "-"
msg = "Downloading {} [{}/{}] ({}/s)\n[{}/{}]".format(
filename,
sizeof_fmt(args["done"]),
sizeof_fmt(args["size"]),
sizeof_fmt(rate),
t_round(t_elapsed),
t_round(t_rem),
)
self.diag_prog.setLabelText(msg)
self.diag_prog.setWindowTitle("Downloading EDSM Dumps")
self.diag_prog.setValue((args["done"] * 1000) // args["size"])
def run_download(self):
if self.dl_thread:
return
self.dl_started = datetime.today()
self.dl_thread = DownloadThread(
self.inp_systems_dl.currentText(),
self.inp_systems_dest_dl.currentText(),
self.inp_bodies_dl.currentText(),
self.inp_bodies_dest_dl.currentText(),
)
self.dl_thread.progress.connect(self.handle_progress)
self.dl_thread.start()
print(".")
def setup_signals(self):
self.btn_download.clicked.connect(self.run_download)
self.inp_systems_dest_dl.setCurrentText(r"D:\devel\rust\ed_lrr_gui\DL\s.json")
self.inp_bodies_dest_dl.setCurrentText(r"D:\devel\rust\ed_lrr_gui\DL\b.json")
self.set_greedyness(self.sld_greedyness.value())
self.cmb_mode.currentTextChanged.connect(self.set_route_mode)
self.rd_comp.toggled.connect(self.set_comp_mode)
self.rd_precomp.toggled.connect(self.set_comp_mode)
self.sld_greedyness.valueChanged.connect(self.set_greedyness)
self.btn_go.clicked.connect(self.run)
self.btn_add.clicked.connect(self.add_system)
self.btn_rm.clicked.connect(self.remove_system)
self.btn_out_browse_pp.clicked.connect(
lambda: self.get_save_file("CSV File (*.csv)", self.set_sys_lst)
)
self.btn_sys_lst_browse.clicked.connect(
lambda: self.get_open_file("CSV File (*.csv)", self.set_sys_lst)
)
self.btn_bodies_browse_pp.clicked.connect(
lambda: self.get_open_file("JSON File (*.json)", self.set_bodies_file)
)
self.btn_bodies_dest_browse_dl.clicked.connect(
lambda: self.get_save_file("JSON File (*.json)", self.set_bodies_file)
)
self.btn_systems_browse_pp.clicked.connect(
lambda: self.get_open_file("JSON File (*.json)", self.set_systems_file)
)
self.btn_systems_dest_browse_dl.clicked.connect(
lambda: self.get_save_file("JSON File (*.json)", self.set_systems_file)
)
def handle_close(self):
cfg.write(self.config)
print("BYEEEEEE!")
def setupUi(self, MainWindow, app):
super().setupUi(MainWindow)
self.update_dropdowns()
self.main_window = MainWindow
self.app = app
self.setup_signals()
self.lst_sys.setHeaderLabels(["Name", "Type"])
self.set_route_mode()
def main():
app = App()
MainWindow = QMainWindow()
ui = ED_LRR()
ui.setupUi(MainWindow, app)
MainWindow.show()
ret = app.exec_()
ui.handle_close()
exit(ret)
if __name__ == "__main__":
pbar.pos=100
pbar.update(0)
print(state.get("result"))
print("DONE!")
@main.command()
@click.option("--path","-i",required=True,help="Path to stars.csv",default="./stars.csv",type=click.Path(exists=True,dir_okay=False),show_default=True )
@click.option("--precomp_file","-pc",help="Precomputed routing graph to use",type=click.Path(exists=True,dir_okay=False))
@click.option("--range","-r",required=True,help="Jump range (Ly)",type=click.FloatRange(min=0))
@click.option("--primary","-ps",help="Only route through primary stars")
@click.option("--output","-o",required=True,help="Output path",default="./stars.idx",type=click.Path(exists=False,dir_okay=False),show_default=True )
@click.argument('systems',nargs=-1)
def precompute(*args,**kwargs):
"Precompute routing graph"
print("PreComp:",ctx,args,kwargs)
if __name__ == '__main__':
MP.freeze_support()
main()
main()
\ No newline at end of file
import pathlib
from collections import namedtuple
import appdirs
import yaml
from collections import namedtuple
config_dir = pathlib.Path(appdirs.user_config_dir("ED_LRR"))
config_dir.mkdir(parents=True, exist_ok=True)
......
from .main import main
\ No newline at end of file
......@@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'D:\devel\rust\ed_lrr_gui\ed_lrr_gui\gui\ed_lrr.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
# Created by: PyQt5 UI code generator 5.13.1
#
# WARNING! All changes made in this file will be lost!
......@@ -26,6 +26,11 @@ class Ui_ED_LRR(object):
ED_LRR.setDocumentMode(False)
ED_LRR.setTabShape(QtWidgets.QTabWidget.Rounded)
self.centralwidget = QtWidgets.QWidget(ED_LRR)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.centralwidget.sizePolicy().hasHeightForWidth())
self.centralwidget.setSizePolicy(sizePolicy)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
......@@ -214,9 +219,6 @@ class Ui_ED_LRR(object):
self.rd_precomp.setObjectName("rd_precomp")
self.gr_mode.addWidget(self.rd_precomp, 0, 2, 1, 1)
self.formLayout_2.setLayout(3, QtWidgets.QFormLayout.FieldRole, self.gr_mode)
self.btn_permute = QtWidgets.QPushButton(self.tab_route)
self.btn_permute.setObjectName("btn_permute")
self.formLayout_2.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.btn_permute)
self.lst_sys = QtWidgets.QTreeWidget(self.tab_route)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
......@@ -231,16 +233,17 @@ class Ui_ED_LRR(object):
self.lst_sys.setAlternatingRowColors(True)
self.lst_sys.setSelectionMode(QtWidgets.QAbstractItemView.ExtendedSelection)
self.lst_sys.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
self.lst_sys.setHeaderHidden(True)
self.lst_sys.setHeaderHidden(False)
self.lst_sys.setObjectName("lst_sys")
self.lst_sys.headerItem().setText(0, "1")
self.lst_sys.headerItem().setText(0, "Name")
self.lst_sys.header().setVisible(False)
self.formLayout_2.setWidget(7, QtWidgets.QFormLayout.SpanningRole, self.lst_sys)
self.sb_range = QtWidgets.QDoubleSpinBox(self.tab_route)
self.sb_range.setObjectName("sb_range")
self.formLayout_2.setWidget(8, QtWidgets.QFormLayout.FieldRole, self.sb_range)
self.formLayout_2.setWidget(9, QtWidgets.QFormLayout.FieldRole, self.sb_range)
self.lbl_range = QtWidgets.QLabel(self.tab_route)
self.lbl_range.setObjectName("lbl_range")
self.formLayout_2.setWidget(8, QtWidgets.QFormLayout.LabelRole, self.lbl_range)
self.formLayout_2.setWidget(9, QtWidgets.QFormLayout.LabelRole, self.lbl_range)
self.gr_opts = QtWidgets.QGridLayout()
self.gr_opts.setObjectName("gr_opts")
self.cmb_mode = QtWidgets.QComboBox(self.tab_route)
......@@ -268,16 +271,16 @@ class Ui_ED_LRR(object):
self.lbl_mode = QtWidgets.QLabel(self.tab_route)
self.lbl_mode.setObjectName("lbl_mode")
self.gr_opts.addWidget(self.lbl_mode, 0, 1, 1, 1)
self.formLayout_2.setLayout(9, QtWidgets.QFormLayout.SpanningRole, self.gr_opts)
self.formLayout_2.setLayout(10, QtWidgets.QFormLayout.SpanningRole, self.gr_opts)
self.btn_go = QtWidgets.QPushButton(self.tab_route)
self.btn_go.setFlat(False)
self.btn_go.setObjectName("btn_go")
self.formLayout_2.setWidget(10, QtWidgets.QFormLayout.LabelRole, self.btn_go)
self.formLayout_2.setWidget(11, QtWidgets.QFormLayout.LabelRole, self.btn_go)
self.gridLayout_4 = QtWidgets.QGridLayout()
self.gridLayout_4.setObjectName("gridLayout_4")
self.chk_permute_keep_last = QtWidgets.QCheckBox(self.tab_route)
self.chk_permute_keep_last.setObjectName("chk_permute_keep_last")
self.gridLayout_4.addWidget(self.chk_permute_keep_last, 0, 2, 1, 1)
self.gridLayout_4.addWidget(self.chk_permute_keep_last, 0, 3, 1, 1)
self.chk_permute_keep_first = QtWidgets.QCheckBox(self.tab_route)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
......@@ -286,7 +289,7 @@ class Ui_ED_LRR(object):
self.chk_permute_keep_first.setSizePolicy(sizePolicy)
self.chk_permute_keep_first.setTristate(False)
self.chk_permute_keep_first.setObjectName("chk_permute_keep_first")
self.gridLayout_4.addWidget(self.chk_permute_keep_first, 0, 1, 1, 1)
self.gridLayout_4.addWidget(self.chk_permute_keep_first, 0, 2, 1, 1)
self.lbl_keep = QtWidgets.QLabel(self.tab_route)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
......@@ -294,8 +297,14 @@ class Ui_ED_LRR(object):
sizePolicy.setHeightForWidth(self.lbl_keep.sizePolicy().hasHeightForWidth())
self.lbl_keep.setSizePolicy(sizePolicy)
self.lbl_keep.setObjectName("lbl_keep")
self.gridLayout_4.addWidget(self.lbl_keep, 0, 0, 1, 1)
self.gridLayout_4.addWidget(self.lbl_keep, 0, 1, 1, 1)
self.formLayout_2.setLayout(4, QtWidgets.QFormLayout.FieldRole, self.gridLayout_4)
self.chk_permute = QtWidgets.QCheckBox(self.tab_route)
self.chk_permute.setObjectName("chk_permute")
self.formLayout_2.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.chk_permute)
self.btn_search = QtWidgets.QPushButton(self.tab_route)
self.btn_search.setObjectName("btn_search")
self.formLayout_2.setWidget(8, QtWidgets.QFormLayout.LabelRole, self.btn_search)
self.tabs.addTab(self.tab_route, "")
self.tab_log = QtWidgets.QWidget()
self.tab_log.setObjectName("tab_log")
......@@ -317,14 +326,24 @@ class Ui_ED_LRR(object):
self.menu.setObjectName("menu")
self.menu_file = QtWidgets.QMenu(self.menu)
self.menu_file.setObjectName("menu_file")
self.menuWindow = QtWidgets.QMenu(self.menu)
self.menuWindow.setObjectName("menuWindow")
self.menuStyle = QtWidgets.QMenu(self.menuWindow)
self.menuStyle.setObjectName("menuStyle")
ED_LRR.setMenuBar(self.menu)
self.bar_status = QtWidgets.QStatusBar(ED_LRR)
self.bar_status.setObjectName("bar_status")
ED_LRR.setStatusBar(self.bar_status)
self.menu_act_quit = QtWidgets.QAction(ED_LRR)
self.menu_act_quit.setObjectName("menu_act_quit")
self.actionA = QtWidgets.QAction(ED_LRR)
self.actionA.setObjectName("actionA")
self.actionB = QtWidgets.QAction(ED_LRR)
self.actionB.setObjectName("actionB")
self.menu_file.addAction(self.menu_act_quit)
self.menuWindow.addAction(self.menuStyle.menuAction())
self.menu.addAction(self.menu_file.menuAction())
self.menu.addAction(self.menuWindow.menuAction())
self.retranslateUi(ED_LRR)
self.tabs.setCurrentIndex(2)
......@@ -358,12 +377,12 @@ class Ui_ED_LRR(object):
self.tabs.setTabText(self.tabs.indexOf(self.tab_preprocess), _translate("ED_LRR", "Preprocess"))
self.lbl_sys_lst.setText(_translate("ED_LRR", "System List"))
self.btn_sys_lst_browse.setText(_translate("ED_LRR", "..."))
self.btn_add.setText(_translate("ED_LRR", "Search+Add"))
self.btn_add.setText(_translate("ED_LRR", "Add"))
self.inp_sys.setPlaceholderText(_translate("ED_LRR", "System Name"))
self.btn_rm.setText(_translate("ED_LRR", "Remove"))
self.rd_comp.setText(_translate("ED_LRR", "Compute Route"))
self.rd_precomp.setText(_translate("ED_LRR", "Precompute Graph"))
self.btn_permute.setText(_translate("ED_LRR", "Permute"))
self.lst_sys.headerItem().setText(1, _translate("ED_LRR", "Type"))
self.lbl_range.setText(_translate("ED_LRR", "Jump Range (Ly)"))
self.cmb_mode.setCurrentText(_translate("ED_LRR", "Breadth-First Search"))
self.cmb_mode.setItemText(0, _translate("ED_LRR", "Breadth-First Search"))
......@@ -376,8 +395,14 @@ class Ui_ED_LRR(object):
self.chk_permute_keep_last.setText(_translate("ED_LRR", "Last"))
self.chk_permute_keep_first.setText(_translate("ED_LRR", "First"))
self.lbl_keep.setText(_translate("ED_LRR", "Keep Endpoints:"))
self.chk_permute.setText(_translate("ED_LRR", "Permute"))
self.btn_search.setText(_translate("ED_LRR", "Search All"))
self.tabs.setTabText(self.tabs.indexOf(self.tab_route), _translate("ED_LRR", "Route"))
self.tabs.setTabText(self.tabs.indexOf(self.tab_log), _translate("ED_LRR", "Log"))
self.menu_file.setTitle(_translate("ED_LRR", "File"))
self.menuWindow.setTitle(_translate("ED_LRR", "Window"))
self.menuStyle.setTitle(_translate("ED_LRR", "Style"))
self.menu_act_quit.setText(_translate("ED_LRR", "Quit"))
self.menu_act_quit.setShortcut(_translate("ED_LRR", "Ctrl+Q"))
self.actionA.setText(_translate("ED_LRR", "A"))
self.actionB.setText(_translate("ED_LRR", "B"))