chore(formatting): ran black to format sources
This commit is contained in:
parent
45c11da77d
commit
6f2940947e
|
@ -12,5 +12,5 @@ for root, folders, files in os.walk(ui_path):
|
||||||
outfile, ext = os.path.splitext(file)
|
outfile, ext = os.path.splitext(file)
|
||||||
if ext == ".ui":
|
if ext == ".ui":
|
||||||
outfile = outfile + ".py"
|
outfile = outfile + ".py"
|
||||||
print(file,"->",outfile)
|
print(file, "->", outfile)
|
||||||
SP.check_call(["pyuic5", "--from-imports", "-o", outfile, file])
|
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 = 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(
|
||||||
cfg.init("history.systems_url", ["https://www.edsm.net/dump/systemsWithCoordinates.json"], "path_list", comment="history of systems.json urls")
|
"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(
|
cfg.init(
|
||||||
"history.bodies_path",
|
"history.bodies_path",
|
||||||
[os.path.join(config_dir, "data","bodies.json")],
|
[os.path.join(config_dir, "data", "bodies.json")],
|
||||||
"path_list",
|
"path_list",
|
||||||
comment="history of bodies.json download paths",
|
comment="history of bodies.json download paths",
|
||||||
)
|
)
|
||||||
cfg.init(
|
cfg.init(
|
||||||
"history.systems_path",
|
"history.systems_path",
|
||||||
[os.path.join(config_dir, "data","systemsWithCoordinates.json")],
|
[os.path.join(config_dir, "data", "systemsWithCoordinates.json")],
|
||||||
"path_list",
|
"path_list",
|
||||||
comment="history of systems.json download paths",
|
comment="history of systems.json download paths",
|
||||||
)
|
)
|
||||||
cfg.init(
|
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.range", 7.56, comment="jump range")
|
||||||
cfg.init("route.primary", False, comment="only route through primary stars")
|
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("route.greediness", 0.5, comment="A* greediness")
|
||||||
cfg.init("folders.data_dir", os.path.join(config_dir, "data"), comment="Data directory")
|
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()
|
cfg.sync()
|
||||||
|
|
|
@ -114,8 +114,8 @@ class PreprocessJob(Job):
|
||||||
self.start()
|
self.start()
|
||||||
|
|
||||||
def handle_progess(self, state):
|
def handle_progess(self, state):
|
||||||
sent=object()
|
sent = object()
|
||||||
if state.get("return",sent)!=sent:
|
if state.get("return", sent) != sent:
|
||||||
self.progress_dialog.close()
|
self.progress_dialog.close()
|
||||||
return
|
return
|
||||||
msg = "Processed: {}/{}".format(
|
msg = "Processed: {}/{}".format(
|
||||||
|
@ -142,12 +142,12 @@ class RouterJob(Job):
|
||||||
self.progress_dialog.canceled.connect(self.cancel)
|
self.progress_dialog.canceled.connect(self.cancel)
|
||||||
self.progress_dialog.show()
|
self.progress_dialog.show()
|
||||||
self.start()
|
self.start()
|
||||||
self.state={}
|
self.state = {}
|
||||||
|
|
||||||
def handle_progess(self, state):
|
def handle_progess(self, state):
|
||||||
sent=object()
|
sent = object()
|
||||||
if state.get("return",sent)!=sent:
|
if state.get("return", sent) != sent:
|
||||||
print(state['return'])
|
print(state["return"])
|
||||||
self.progress_dialog.close()
|
self.progress_dialog.close()
|
||||||
route_win = WRoute(self.main_window, state["return"])
|
route_win = WRoute(self.main_window, state["return"])
|
||||||
return
|
return
|
||||||
|
@ -249,7 +249,7 @@ class App(QApplication):
|
||||||
class WRoute(Ui_diag_route):
|
class WRoute(Ui_diag_route):
|
||||||
def __init__(self, main_window, hops):
|
def __init__(self, main_window, hops):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.route=hops
|
self.route = hops
|
||||||
dialog = QDialog(main_window)
|
dialog = QDialog(main_window)
|
||||||
self.setupUi(dialog)
|
self.setupUi(dialog)
|
||||||
for n, item in enumerate(hops):
|
for n, item in enumerate(hops):
|
||||||
|
@ -262,7 +262,7 @@ class WRoute(Ui_diag_route):
|
||||||
item["system"],
|
item["system"],
|
||||||
"{body} ({star_type})".format(**item),
|
"{body} ({star_type})".format(**item),
|
||||||
str(item["distance"]),
|
str(item["distance"]),
|
||||||
"<NotImplemented>", # Jump distance
|
"<NotImplemented>", # Jump distance
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
item.setFlags(item.flags() & ~Qt.ItemIsDropEnabled)
|
item.setFlags(item.flags() & ~Qt.ItemIsDropEnabled)
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,38 +1,39 @@
|
||||||
from flask import Flask,jsonify
|
from flask import Flask, jsonify
|
||||||
import uuid
|
import uuid
|
||||||
import json
|
import json
|
||||||
from webargs import fields,validate
|
from webargs import fields, validate
|
||||||
from webargs.flaskparser import use_args
|
from webargs.flaskparser import use_args
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
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.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import scoped_session, sessionmaker, relationship, backref
|
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 = Flask(__name__)
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///jobs.db'
|
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///jobs.db"
|
||||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
||||||
|
|
||||||
|
db = SQLAlchemy(app)
|
||||||
|
|
||||||
db=SQLAlchemy(app)
|
|
||||||
|
|
||||||
@generic_repr
|
@generic_repr
|
||||||
class Job(db.Model,Timestamp):
|
class Job(db.Model, Timestamp):
|
||||||
id = db.Column(db.String,default=lambda :str(uuid.uuid4()),primary_key=True)
|
id = db.Column(db.String, default=lambda: str(uuid.uuid4()), primary_key=True)
|
||||||
jump_range = db.Column(db.Float,nullable=False)
|
jump_range = db.Column(db.Float, nullable=False)
|
||||||
mode = db.Column(db.String,default="bfs")
|
mode = db.Column(db.String, default="bfs")
|
||||||
systems = db.Column(db.String)
|
systems = db.Column(db.String)
|
||||||
permute= db.Column(db.String,default=None,nullable=True)
|
permute = db.Column(db.String, default=None, nullable=True)
|
||||||
primary= db.Column(db.Boolean,default=False)
|
primary = db.Column(db.Boolean, default=False)
|
||||||
factor = db.Column(db.Float,default=0.5)
|
factor = db.Column(db.Float, default=0.5)
|
||||||
done = db.Column(db.DateTime,nullable=True,default=None)
|
done = db.Column(db.DateTime, nullable=True, default=None)
|
||||||
started = 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)
|
progress = db.Column(db.Float, default=0.0)
|
||||||
|
|
||||||
#============================================================
|
# ============================================================
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new(cls,**kwargs):
|
def new(cls, **kwargs):
|
||||||
obj=cls(**kwargs)
|
obj = cls(**kwargs)
|
||||||
db.session.add(obj)
|
db.session.add(obj)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
print(obj)
|
print(obj)
|
||||||
|
@ -40,19 +41,21 @@ class Job(db.Model,Timestamp):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def dict(self):
|
def dict(self):
|
||||||
ret={}
|
ret = {}
|
||||||
for col in self.__table__.columns:
|
for col in self.__table__.columns:
|
||||||
ret[col.name]=getattr(self,col.name)
|
ret[col.name] = getattr(self, col.name)
|
||||||
ret['systems']=json.loads(ret['systems'])
|
ret["systems"] = json.loads(ret["systems"])
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
@dict.setter
|
@dict.setter
|
||||||
def set_dict(self,*args,**kwargs):
|
def set_dict(self, *args, **kwargs):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
db.create_all()
|
db.create_all()
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(422)
|
@app.errorhandler(422)
|
||||||
@app.errorhandler(400)
|
@app.errorhandler(400)
|
||||||
def handle_error(err):
|
def handle_error(err):
|
||||||
|
@ -63,25 +66,35 @@ def handle_error(err):
|
||||||
else:
|
else:
|
||||||
return jsonify({"errors": messages}), err.code
|
return jsonify({"errors": messages}), err.code
|
||||||
|
|
||||||
@app.route("/route",methods=["GET","POST"])
|
|
||||||
@use_args({
|
@app.route("/route", methods=["GET", "POST"])
|
||||||
"jump_range":fields.Float(required=True),
|
@use_args(
|
||||||
"mode": fields.String(missing="bfs",validate=validate.OneOf(["bfs","greedy","a-star"])),
|
{
|
||||||
"systems": fields.DelimitedList(fields.String,required=True),
|
"jump_range": fields.Float(required=True),
|
||||||
"permute": fields.String(missing=None,validate=validate.OneOf(["all", "keep_first", "keep_last", "keep_both"])),
|
"mode": fields.String(
|
||||||
"primary": fields.Boolean(missing=False),
|
missing="bfs", validate=validate.OneOf(["bfs", "greedy", "a-star"])
|
||||||
"factor": fields.Float(missing=0.5)
|
),
|
||||||
})
|
"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):
|
def route(args):
|
||||||
args['systems']=json.dumps(args['systems'])
|
args["systems"] = json.dumps(args["systems"])
|
||||||
for k,v in args.items():
|
for k, v in args.items():
|
||||||
print(k,v)
|
print(k, v)
|
||||||
return jsonify({'id':Job.new(**args).id})
|
return jsonify({"id": Job.new(**args).id})
|
||||||
|
|
||||||
|
|
||||||
@app.route("/status/<uuid:job_id>")
|
@app.route("/status/<uuid:job_id>")
|
||||||
def status(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)
|
return jsonify(job.dict)
|
||||||
|
|
||||||
if __name__=="__main__":
|
|
||||||
app.run(host="0.0.0.0",port=3777,debug=True)
|
if __name__ == "__main__":
|
||||||
|
app.run(host="0.0.0.0", port=3777, debug=True)
|
||||||
|
|
174
icon/make.py
174
icon/make.py
|
@ -1,109 +1,133 @@
|
||||||
import svgwrite
|
import svgwrite
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
from math import factorial,sin,cos,pi
|
from math import factorial, sin, cos, pi
|
||||||
from itertools import permutations
|
from itertools import permutations
|
||||||
import tsp as m_tsp
|
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):
|
def dist2(p1, p2):
|
||||||
diff=0
|
diff = 0
|
||||||
for a,b in zip(p1,p2):
|
for a, b in zip(p1, p2):
|
||||||
diff+=(a-b)**2
|
diff += (a - b) ** 2
|
||||||
return diff
|
return diff
|
||||||
|
|
||||||
|
|
||||||
def tsp(points):
|
def tsp(points):
|
||||||
res=[]
|
res = []
|
||||||
for idx in m_tsp.tsp(points)[1]:
|
for idx in m_tsp.tsp(points)[1]:
|
||||||
res.append(points[idx])
|
res.append(points[idx])
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def make_points(n,size,min_dist=0):
|
def make_points(n, size, min_dist=0):
|
||||||
min_dist*=min_dist
|
min_dist *= min_dist
|
||||||
points=[]
|
points = []
|
||||||
while len(points)<n:
|
while len(points) < n:
|
||||||
px,py=random.random(),random.random()
|
px, py = random.random(), random.random()
|
||||||
px*=size/2
|
px *= size / 2
|
||||||
py*=size/2
|
py *= size / 2
|
||||||
px+=70
|
px += 70
|
||||||
py+=70
|
py += 70
|
||||||
valid=True
|
valid = True
|
||||||
for p in points:
|
for p in points:
|
||||||
if dist2(p,(px,py))<min_dist:
|
if dist2(p, (px, py)) < min_dist:
|
||||||
valid=False
|
valid = False
|
||||||
break
|
break
|
||||||
if valid:
|
if valid:
|
||||||
points.append((px,py))
|
points.append((px, py))
|
||||||
print("{}/{}".format(len(points),n))
|
print("{}/{}".format(len(points), n))
|
||||||
return points
|
return points
|
||||||
def generate(seed,name=None,small=False):
|
|
||||||
sd=1
|
|
||||||
if small:
|
|
||||||
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
|
|
||||||
if name is None:
|
|
||||||
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'))
|
|
||||||
print("Generating points...")
|
|
||||||
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:]):
|
|
||||||
if small:
|
|
||||||
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
|
def generate(seed, name=None, small=False):
|
||||||
|
sd = 1
|
||||||
|
if small:
|
||||||
|
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
|
||||||
|
if name is None:
|
||||||
|
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"))
|
||||||
|
print("Generating points...")
|
||||||
|
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:]):
|
||||||
if small:
|
if small:
|
||||||
base_r=5
|
x1 /= sd
|
||||||
px/=sd
|
x2 /= sd
|
||||||
py/=sd
|
y1 /= sd
|
||||||
if random.random()>0.8:
|
y2 /= sd
|
||||||
dwg.add(dwg.circle((px,py),r=base_r+random.random()*base_r,stroke_width=w,stroke='#0ae')).fill('#0ae')
|
line = dwg.add(dwg.line((x1, y1), (x2, y2), stroke_width=w, stroke=color))
|
||||||
|
|
||||||
|
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")
|
||||||
else:
|
else:
|
||||||
dwg.add(dwg.circle((px,py),r=base_r+random.random()*base_r,stroke_width=w,stroke=color)).fill(color)
|
dwg.add(
|
||||||
r=base_r
|
dwg.circle(
|
||||||
for _ in range(random.randint(1,max_rings)):
|
(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:
|
if small:
|
||||||
random.random()
|
random.random()
|
||||||
random.random()
|
random.random()
|
||||||
random.random()
|
random.random()
|
||||||
continue
|
continue
|
||||||
r+=ring_step(random.random())
|
r += ring_step(random.random())
|
||||||
ring_col=color
|
ring_col = color
|
||||||
if random.random()>0.75:
|
if random.random() > 0.75:
|
||||||
ring_col="#ea0"
|
ring_col = "#ea0"
|
||||||
circ=dwg.add(dwg.circle((px,py),r=r,stroke_width=w,stroke=ring_col))
|
circ = dwg.add(dwg.circle((px, py), r=r, stroke_width=w, stroke=ring_col))
|
||||||
circ.fill(color,opacity=0)
|
circ.fill(color, opacity=0)
|
||||||
d=random.random()*pi*2
|
d = random.random() * pi * 2
|
||||||
dx=cos(d)
|
dx = cos(d)
|
||||||
dy=sin(d)
|
dy = sin(d)
|
||||||
m=random.random()
|
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 = dwg.add(
|
||||||
|
dwg.circle(
|
||||||
|
(px + dx * r, py + dy * r),
|
||||||
|
r=2 + 2 * m,
|
||||||
|
stroke_width=w,
|
||||||
|
stroke=ring_col,
|
||||||
|
)
|
||||||
|
)
|
||||||
moon.fill(ring_col)
|
moon.fill(ring_col)
|
||||||
|
|
||||||
dwg.save()
|
dwg.save()
|
||||||
|
|
||||||
|
|
||||||
seed=-4
|
seed = -4
|
||||||
generate(seed,"icon_1",small=False)
|
generate(seed, "icon_1", small=False)
|
||||||
generate(seed,"icon_1_small",small=True)
|
generate(seed, "icon_1_small", small=True)
|
||||||
|
|
Loading…
Reference in New Issue