Skip to content

Commit

Permalink
Parts Browser Added
Browse files Browse the repository at this point in the history
* @wrobz wrote a program that takes the data from the old spreadsheet and turned it all into simple to edit and control JSON files
* They also included a Browser that you can run through Python on your local PC. It lets you see lists of the parts that can be filtered, searched and edited directly.
* This is now the ONLY way to add / edit / move / change parts for RP-1
  • Loading branch information
pap1723 committed Dec 15, 2018
1 parent b574252 commit 2c921f7
Show file tree
Hide file tree
Showing 125 changed files with 111,791 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
104 changes: 104 additions & 0 deletions Source/Tech Tree/Parts Browser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
21 changes: 21 additions & 0 deletions Source/Tech Tree/Parts Browser/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Matt

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.
9 changes: 9 additions & 0 deletions Source/Tech Tree/Parts Browser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# RP-0-Parts-Browser
This is a browser/editor application for the RP-0 parts list (converted to json files per mod) that can also generate the needed configs from it.

To get it working:
1. It uses Python 3, so that needs to be installed.
2. It uses flask, so: pip install flask
3. Flask uses slugify (I think) so: pip install slugify
4. Then you should be able to hit: python app.py
5. Point your browser at: http://localhost:5000/dashboard
1 change: 1 addition & 0 deletions Source/Tech Tree/Parts Browser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

151 changes: 151 additions & 0 deletions Source/Tech Tree/Parts Browser/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
import os
import json

from flask import jsonify
from part_data import PartData
from flask import Flask, g
from flask import Blueprint, abort, g, render_template, redirect, request, url_for
from slugify import slugify
from tree_engine_cfg_generator import generate_engine_tree
from tree_parts_cfg_generator import generate_parts_tree
from ecm_engines_cfg_generator import generate_ecm_engines
from ecm_parts_cfg_generator import generate_ecm_parts
from identical_parts_cfg_generator import generate_identical_parts

part_data = PartData()

def create_app(test_config=None):

# create and configure the app
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SECRET_KEY='dev'
)

if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile('config.py', silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)

# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass

# a simple page that says hello
@app.route('/hello')
def hello():
return 'Hello, World!'

@app.route('/api/part_data')
def all_part_data():
return jsonify({"data": part_data.parts})

@app.route('/api/unique_values_for_column/<column_name>')
def unique_values_for_column(column_name):
sorted_values = list(part_data.unique_values_for_columns[column_name])
sorted_values.sort()
return jsonify({"data": sorted_values})
@app.route('/api/combo_options/<column_name>')
def combo_options(column_name):
sorted_values = list(part_data.unique_values_for_columns[column_name])
sorted_values.sort()
return jsonify({"data": list(map(lambda x: {column_name: x}, sorted_values))})

@app.route('/api/export_to_json')
def export_to_json():
for mod in part_data.unique_values_for_columns['mod']:
parts_for_mod = list(filter(lambda x: x['mod'] == mod, part_data.parts))
parts_for_mod.sort(key=lambda x: x['name'] if x['name'] is not None and len(x['name']) > 0 else x['title'] )
text_file = open("data/" + make_safe_filename(mod) + ".json", "w")
text_file.write(json.dumps(parts_for_mod, indent=4, separators=(',', ': ')))
text_file.close()
return "true"
@app.route('/api/generate_tree_engine_configs')
def generate_tree_engine_configs():
generate_engine_tree(part_data.parts)
return "true"

@app.route('/api/generate_tree_parts_configs')
def generate_tree_parts_configs():
generate_parts_tree(part_data.parts)
return "true"

@app.route('/api/generate_ecm_engines_configs')
def generate_ecm_engines_configs():
generate_ecm_engines(part_data.parts)
return "true"

@app.route('/api/generate_ecm_parts_configs')
def generate_ecm_parts_configs():
generate_ecm_parts(part_data.parts)
return "true"

@app.route('/api/generate_identical_parts_configs')
def generate_identical_parts_configs():
generate_identical_parts(part_data.parts)
return "true"

@app.route('/api/generate_all_configs')
def generate_all_configs():
generate_parts_tree(part_data.parts)
generate_engine_tree(part_data.parts)
generate_identical_parts(part_data.parts)
generate_ecm_parts(part_data.parts)
generate_ecm_engines(part_data.parts)
return "true"

@app.route('/api/commit_changes', methods=['POST'])
def commit_changes():
queued_changes = request.get_json()
for row_id in queued_changes['queued_changes']:
part = part_data.get_part_by_name(queued_changes['queued_changes'][row_id]['name'])
for field_name in queued_changes['queued_changes'][row_id]['changes']:
part[field_name] = queued_changes['queued_changes'][row_id]['changes'][field_name]['new']
export_to_json()
return "true"

def commit_change_set(change_set):
part = part_data.get_part_by_name(change_set['name']);

app.register_blueprint(bp)
app.run()
return app

def make_safe_filename(s):
def safe_char(c):
if c.isalnum():
return c
else:
return "_"
return "".join(safe_char(c) for c in s).rstrip("_")

bp = Blueprint("part", __name__, url_prefix="/")

@bp.route("/")
def index():
"""
Render the homepage.
"""
parts = []
parts_final = []

return render_template("browser/index.html", parts=parts_final)


@bp.route("/dashboard", methods=["GET", "POST"])
def dashboard():
"""
Render the dashboard page.
"""
if request.method == "GET":
return render_template("browser/dashboard.html", parts=part_data.parts)

return render_template("browser/dashboard.html", parts=part_data.parts)


if __name__ == "__main__":
create_app()
Loading

0 comments on commit 2c921f7

Please sign in to comment.