Skip to content
Commits on Source (2)
......@@ -12,5 +12,5 @@ for root, folders, files in os.walk(ui_path):
outfile, ext = os.path.splitext(file)
if ext == ".ui":
outfile = outfile + ".py"
print(file,"->",outfile)
print(file, "->", outfile)
SP.check_call(["pyuic5", "--from-imports", "-o", outfile, file])
......@@ -11,22 +11,35 @@ config_file.touch()
cfg = profig.Config(str(config_file), strict=True)
cfg.init("history.bodies_url", ["https://www.edsm.net/dump/bodies.json"], "path_list", comment="history of bodies.json urls")
cfg.init("history.systems_url", ["https://www.edsm.net/dump/systemsWithCoordinates.json"], "path_list", comment="history of systems.json urls")
cfg.init(
"history.bodies_url",
["https://www.edsm.net/dump/bodies.json"],
"path_list",
comment="history of bodies.json urls",
)
cfg.init(
"history.systems_url",
["https://www.edsm.net/dump/systemsWithCoordinates.json"],
"path_list",
comment="history of systems.json urls",
)
cfg.init(
"history.bodies_path",
[os.path.join(config_dir, "data","bodies.json")],
[os.path.join(config_dir, "data", "bodies.json")],
"path_list",
comment="history of bodies.json download paths",
)
cfg.init(
"history.systems_path",
[os.path.join(config_dir, "data","systemsWithCoordinates.json")],
[os.path.join(config_dir, "data", "systemsWithCoordinates.json")],
"path_list",
comment="history of systems.json download paths",
)
cfg.init(
"history.stars_csv_path", [os.path.join(config_dir, "data","stars.csv")], "path_list", comment="history of paths for stars.csv"
"history.stars_csv_path",
[os.path.join(config_dir, "data", "stars.csv")],
"path_list",
comment="history of paths for stars.csv",
)
cfg.init("route.range", 7.56, comment="jump range")
cfg.init("route.primary", False, comment="only route through primary stars")
......@@ -40,7 +53,7 @@ cfg.init("route.prune.steps", 5, comment="number of steps before path gets prune
cfg.init("route.greediness", 0.5, comment="A* greediness")
cfg.init("folders.data_dir", os.path.join(config_dir, "data"), comment="Data directory")
cfg.init("GUI.theme", 'dark', comment="GUI theme to use")
cfg.init("GUI.theme", "dark", comment="GUI theme to use")
cfg.sync()
......@@ -114,8 +114,8 @@ class PreprocessJob(Job):
self.start()
def handle_progess(self, state):
sent=object()
if state.get("return",sent)!=sent:
sent = object()
if state.get("return", sent) != sent:
self.progress_dialog.close()
return
msg = "Processed: {}/{}".format(
......@@ -142,12 +142,12 @@ class RouterJob(Job):
self.progress_dialog.canceled.connect(self.cancel)
self.progress_dialog.show()
self.start()
self.state={}
self.state = {}
def handle_progess(self, state):
sent=object()
if state.get("return",sent)!=sent:
print(state['return'])
sent = object()
if state.get("return", sent) != sent:
print(state["return"])
self.progress_dialog.close()
route_win = WRoute(self.main_window, state["return"])
return
......@@ -249,7 +249,7 @@ class App(QApplication):
class WRoute(Ui_diag_route):
def __init__(self, main_window, hops):
super().__init__()
self.route=hops
self.route = hops
dialog = QDialog(main_window)
self.setupUi(dialog)
for n, item in enumerate(hops):
......@@ -262,7 +262,7 @@ class WRoute(Ui_diag_route):
item["system"],
"{body} ({star_type})".format(**item),
str(item["distance"]),
"<NotImplemented>", # Jump distance
"<NotImplemented>", # Jump distance
],
)
item.setFlags(item.flags() & ~Qt.ItemIsDropEnabled)
......
This diff is collapsed.
from flask import Flask,jsonify
from flask import Flask, jsonify
import uuid
import json
from webargs import fields,validate
from webargs import fields, validate
from webargs.flaskparser import use_args
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy_utils import Timestamp,generic_repr
from sqlalchemy_utils import Timestamp, generic_repr
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker, relationship, backref
from sqlalchemy.types import Float,String,Boolean
from sqlalchemy.types import Float, String, Boolean
app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///jobs.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///jobs.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(app)
db=SQLAlchemy(app)
@generic_repr
class Job(db.Model,Timestamp):
id = db.Column(db.String,default=lambda :str(uuid.uuid4()),primary_key=True)
jump_range = db.Column(db.Float,nullable=False)
mode = db.Column(db.String,default="bfs")
class Job(db.Model, Timestamp):
id = db.Column(db.String, default=lambda: str(uuid.uuid4()), primary_key=True)
jump_range = db.Column(db.Float, nullable=False)
mode = db.Column(db.String, default="bfs")
systems = db.Column(db.String)
permute= db.Column(db.String,default=None,nullable=True)
primary= db.Column(db.Boolean,default=False)
factor = db.Column(db.Float,default=0.5)
done = db.Column(db.DateTime,nullable=True,default=None)
started = db.Column(db.DateTime,nullable=True,default=None)
progress = db.Column(db.Float,default=0.0)
permute = db.Column(db.String, default=None, nullable=True)
primary = db.Column(db.Boolean, default=False)
factor = db.Column(db.Float, default=0.5)
done = db.Column(db.DateTime, nullable=True, default=None)
started = db.Column(db.DateTime, nullable=True, default=None)
progress = db.Column(db.Float, default=0.0)
#============================================================
# ============================================================
@classmethod
def new(cls,**kwargs):
obj=cls(**kwargs)
def new(cls, **kwargs):
obj = cls(**kwargs)
db.session.add(obj)
db.session.commit()
print(obj)
......@@ -40,19 +41,21 @@ class Job(db.Model,Timestamp):
@property
def dict(self):
ret={}
ret = {}
for col in self.__table__.columns:
ret[col.name]=getattr(self,col.name)
ret['systems']=json.loads(ret['systems'])
ret[col.name] = getattr(self, col.name)
ret["systems"] = json.loads(ret["systems"])
return ret
@dict.setter
def set_dict(self,*args,**kwargs):
def set_dict(self, *args, **kwargs):
raise NotImplementedError
db.create_all()
db.session.commit()
@app.errorhandler(422)
@app.errorhandler(400)
def handle_error(err):
......@@ -63,25 +66,35 @@ def handle_error(err):
else:
return jsonify({"errors": messages}), err.code
@app.route("/route",methods=["GET","POST"])
@use_args({
"jump_range":fields.Float(required=True),
"mode": fields.String(missing="bfs",validate=validate.OneOf(["bfs","greedy","a-star"])),
"systems": fields.DelimitedList(fields.String,required=True),
"permute": fields.String(missing=None,validate=validate.OneOf(["all", "keep_first", "keep_last", "keep_both"])),
"primary": fields.Boolean(missing=False),
"factor": fields.Float(missing=0.5)
})
@app.route("/route", methods=["GET", "POST"])
@use_args(
{
"jump_range": fields.Float(required=True),
"mode": fields.String(
missing="bfs", validate=validate.OneOf(["bfs", "greedy", "a-star"])
),
"systems": fields.DelimitedList(fields.String, required=True),
"permute": fields.String(
missing=None,
validate=validate.OneOf(["all", "keep_first", "keep_last", "keep_both"]),
),
"primary": fields.Boolean(missing=False),
"factor": fields.Float(missing=0.5),
}
)
def route(args):
args['systems']=json.dumps(args['systems'])
for k,v in args.items():
print(k,v)
return jsonify({'id':Job.new(**args).id})
args["systems"] = json.dumps(args["systems"])
for k, v in args.items():
print(k, v)
return jsonify({"id": Job.new(**args).id})
@app.route("/status/<uuid:job_id>")
def status(job_id):
job=db.session.query(Job).get_or_404(str(job_id))
job = db.session.query(Job).get_or_404(str(job_id))
return jsonify(job.dict)
if __name__=="__main__":
app.run(host="0.0.0.0",port=3777,debug=True)
\ No newline at end of file
if __name__ == "__main__":
app.run(host="0.0.0.0", port=3777, debug=True)
import svgwrite
import random
import time
from math import factorial,sin,cos,pi
from math import factorial, sin, cos, pi
from itertools import permutations
import tsp as m_tsp
def dist(p1,p2):
return dist2(p1,p2)**0.5
def dist(p1, p2):
return dist2(p1, p2) ** 0.5
def dist2(p1,p2):
diff=0
for a,b in zip(p1,p2):
diff+=(a-b)**2
def dist2(p1, p2):
diff = 0
for a, b in zip(p1, p2):
diff += (a - b) ** 2
return diff
def tsp(points):
res=[]
res = []
for idx in m_tsp.tsp(points)[1]:
res.append(points[idx])
return res
def make_points(n,size,min_dist=0):
min_dist*=min_dist
points=[]
while len(points)<n:
px,py=random.random(),random.random()
px*=size/2
py*=size/2
px+=70
py+=70
valid=True
def make_points(n, size, min_dist=0):
min_dist *= min_dist
points = []
while len(points) < n:
px, py = random.random(), random.random()
px *= size / 2
py *= size / 2
px += 70
py += 70
valid = True
for p in points:
if dist2(p,(px,py))<min_dist:
valid=False
if dist2(p, (px, py)) < min_dist:
valid = False
break
if valid:
points.append((px,py))
print("{}/{}".format(len(points),n))
points.append((px, py))
print("{}/{}".format(len(points), n))
return points
def generate(seed,name=None,small=False):
sd=1
def generate(seed, name=None, small=False):
sd = 1
if small:
sd=2
sd = 2
random.seed(seed)
w=2
max_rings=3
num_points=5
min_dist=10+10+20*(max_rings+1)
base_r=10
ring_step=lambda v:10+v*10
size=1000
w = 2
max_rings = 3
num_points = 5
min_dist = 10 + 10 + 20 * (max_rings + 1)
base_r = 10
ring_step = lambda v: 10 + v * 10
size = 1000
if name is None:
name=seed
dwg=svgwrite.Drawing(filename="out/{}.svg".format(name))
name = seed
dwg = svgwrite.Drawing(filename="out/{}.svg".format(name))
dwg.defs.add(dwg.style(".background { fill: #222; }"))
dwg.add(dwg.rect(size=('100%','100%'), class_='background'))
dwg.add(dwg.rect(size=("100%", "100%"), class_="background"))
print("Generating points...")
color="#eee"
pos=make_points(num_points,size,min_dist=min_dist)
color = "#eee"
pos = make_points(num_points, size, min_dist=min_dist)
print("TSP...")
pos=tsp(pos)
for (x1,y1),(x2,y2) in zip(pos,pos[1:]):
pos = tsp(pos)
for (x1, y1), (x2, y2) in zip(pos, pos[1:]):
if small:
x1/=sd
x2/=sd
y1/=sd
y2/=sd
line=dwg.add(dwg.line((x1,y1),(x2,y2),stroke_width=w,stroke=color))
x1 /= sd
x2 /= sd
y1 /= sd
y2 /= sd
line = dwg.add(dwg.line((x1, y1), (x2, y2), stroke_width=w, stroke=color))
for (px,py) in pos:
base_r=3
for (px, py) in pos:
base_r = 3
if small:
base_r=5
px/=sd
py/=sd
if random.random()>0.8:
dwg.add(dwg.circle((px,py),r=base_r+random.random()*base_r,stroke_width=w,stroke='#0ae')).fill('#0ae')
base_r = 5
px /= sd
py /= sd
if random.random() > 0.8:
dwg.add(
dwg.circle(
(px, py),
r=base_r + random.random() * base_r,
stroke_width=w,
stroke="#0ae",
)
).fill("#0ae")
else:
dwg.add(dwg.circle((px,py),r=base_r+random.random()*base_r,stroke_width=w,stroke=color)).fill(color)
r=base_r
for _ in range(random.randint(1,max_rings)):
dwg.add(
dwg.circle(
(px, py),
r=base_r + random.random() * base_r,
stroke_width=w,
stroke=color,
)
).fill(color)
r = base_r
for _ in range(random.randint(1, max_rings)):
if small:
random.random()
random.random()
random.random()
continue
r+=ring_step(random.random())
ring_col=color
if random.random()>0.75:
ring_col="#ea0"
circ=dwg.add(dwg.circle((px,py),r=r,stroke_width=w,stroke=ring_col))
circ.fill(color,opacity=0)
d=random.random()*pi*2
dx=cos(d)
dy=sin(d)
m=random.random()
moon=dwg.add(dwg.circle((px+dx*r,py+dy*r),r=2+2*m,stroke_width=w,stroke=ring_col))
r += ring_step(random.random())
ring_col = color
if random.random() > 0.75:
ring_col = "#ea0"
circ = dwg.add(dwg.circle((px, py), r=r, stroke_width=w, stroke=ring_col))
circ.fill(color, opacity=0)
d = random.random() * pi * 2
dx = cos(d)
dy = sin(d)
m = random.random()
moon = dwg.add(
dwg.circle(
(px + dx * r, py + dy * r),
r=2 + 2 * m,
stroke_width=w,
stroke=ring_col,
)
)
moon.fill(ring_col)
dwg.save()
seed=-4
generate(seed,"icon_1",small=False)
generate(seed,"icon_1_small",small=True)
seed = -4
generate(seed, "icon_1", small=False)
generate(seed, "icon_1_small", small=True)
[pytest]
qt_api=pyqt5
\ No newline at end of file