chore(formatting): ran black to format sources
This commit is contained in:
parent
45c11da77d
commit
6f2940947e
6 changed files with 1172 additions and 166 deletions
|
@ -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)
|
||||
|
|
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 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)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=3777, debug=True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue