Skip to content

Commit

Permalink
Adding sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregczc committed Apr 6, 2020
1 parent 992426b commit a1feafe
Show file tree
Hide file tree
Showing 1,714 changed files with 158,138 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/logo/
/.idea/
*.pyc
48 changes: 48 additions & 0 deletions RC_Calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# coding: utf-8

# RC-Calc: An all-in-one R/C & FPV flying stuff calculator
# Copyright (C) 2020 Grégoire CAHUZAC <gregoire.cahuzac@outlook.fr>
# This file is part of RC-Calc. <https://github.com/Gregczc/RC-Calc>

# RC-Calc is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.

# RC-Calc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with RC-Calc. If not, see <http://www.gnu.org/licenses/>.


import webbrowser
from flask import Flask
from web.battery_configurator import battery_configurator
from web.cell_inventory import cell_inventory
from web.current_sensor import current_sensor
from web.exit import exit
from web.flight_time import flight_time
from web.flying_wing_design import flying_wing_design
from web.index import index
from web.motor import motor

app = Flask(__name__, static_folder="./web/static/", template_folder="./web/templates")

app.register_blueprint(battery_configurator, url_prefix='/battery-configurator')
app.register_blueprint(cell_inventory, url_prefix='/cell-inventory')
app.register_blueprint(current_sensor, url_prefix='/current-sensor')
app.register_blueprint(exit, url_prefix='/exit')
app.register_blueprint(flight_time, url_prefix='/flight-time')
app.register_blueprint(flying_wing_design, url_prefix='/flying-wing-design')
app.register_blueprint(index, url_prefix='/')
app.register_blueprint(motor, url_prefix='/motor')

if __name__ == '__main__':

webbrowser.open('http://localhost:8888/', new=2)
print(app.url_map)
app.run(port=8888)
print("Server shutdown. Bye!")
21 changes: 21 additions & 0 deletions docs/pyinstaller-procedure.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Compiling the project into an unique exe file
=============================================

notes:
Do not forget to properly set the path vatriable
`set FLASK_APP=hello.py`
I have encountered issues with setuptools>45. Downgrading it made pyinstaller work fine.

Pyinstaller intresting parameters:

- F: To bundle everything in a single file
- w: to avoid displaying the console
- --add-data: to add folders to the build directory
- i: to add an icon

Command usage:

For now :

pyinstaller -F -i logo/rc-calc-256.ico RC_Calc.py

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask
Empty file added web/__int__.py
Empty file.
40 changes: 40 additions & 0 deletions web/battery_configurator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# coding: utf-8

# RC-Calc: An all-in-one R/C & FPV flying stuff calculator
# Copyright (C) 2020 Grégoire CAHUZAC <gregoire.cahuzac@outlook.fr>
# This file is part of RC-Calc. <https://github.com/Gregczc/RC-Calc>

# RC-Calc is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.

# RC-Calc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with RC-Calc. If not, see <http://www.gnu.org/licenses/>.


from flask import Blueprint, render_template
import sqlite3


def open_database():
# Needs to be redone

# Open the database
conn = sqlite3.connect('../db/RC-Calc.db')

# Closing database
conn.close()


battery_configurator = Blueprint('battery-configurator', __name__)


@battery_configurator.route('/')
def show():
return render_template('battery-configurator.html')
50 changes: 50 additions & 0 deletions web/cell_inventory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# coding: utf-8

# RC-Calc: An all-in-one R/C & FPV flying stuff calculator
# Copyright (C) 2020 Grégoire CAHUZAC <gregoire.cahuzac@outlook.fr>
# This file is part of RC-Calc. <https://github.com/Gregczc/RC-Calc>

# RC-Calc is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.

# RC-Calc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with RC-Calc. If not, see <http://www.gnu.org/licenses/>.


from flask import Blueprint, render_template
import io
import sqlite3


def open_database():
# Needs to be redone

# Open the database
conn = sqlite3.connect('../db/RC-Calc.db')

# Creating the flight-time table if it does not exists
conn.execute('''CREATE TABLE IF NOT EXISTS cell_table
(name text, voltage real, energy real, weight real, max_current real, price real)''')

# Save changes
conn.commit()

html = io.open("./py/web/html/cell-inventory.html", "r", encoding="utf-8").read()

# Closing database
conn.close()


cell_inventory = Blueprint('cell-inventory', __name__)


@cell_inventory.route('/')
def show():
return render_template('cell-inventory.html')
28 changes: 28 additions & 0 deletions web/current_sensor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# coding: utf-8

# RC-Calc: An all-in-one R/C & FPV flying stuff calculator
# Copyright (C) 2020 Grégoire CAHUZAC <gregoire.cahuzac@outlook.fr>
# This file is part of RC-Calc. <https://github.com/Gregczc/RC-Calc>

# RC-Calc is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.

# RC-Calc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with RC-Calc. If not, see <http://www.gnu.org/licenses/>.


from flask import Blueprint, render_template

current_sensor = Blueprint('current-sensor', __name__)


@current_sensor.route('/')
def show():
return render_template('current-sensor.html')
36 changes: 36 additions & 0 deletions web/exit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# coding: utf-8

# RC-Calc: An all-in-one R/C & FPV flying stuff calculator
# Copyright (C) 2020 Grégoire CAHUZAC <gregoire.cahuzac@outlook.fr>
# This file is part of RC-Calc. <https://github.com/Gregczc/RC-Calc>

# RC-Calc is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.

# RC-Calc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with RC-Calc. If not, see <http://www.gnu.org/licenses/>.


from flask import Blueprint, render_template, after_this_request, request

exit = Blueprint('exit', __name__)


@exit.route('/')
def show():

shutdown_hook = request.environ.get('werkzeug.server.shutdown')

@after_this_request
def shutdown_flask(response):
shutdown_hook()
return response

return render_template('exit.html')
149 changes: 149 additions & 0 deletions web/flight_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# coding: utf-8

# RC-Calc: An all-in-one R/C & FPV flying stuff calculator
# Copyright (C) 2020 Grégoire CAHUZAC <gregoire.cahuzac@outlook.fr>
# This file is part of RC-Calc. <https://github.com/Gregczc/RC-Calc>

# RC-Calc is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.

# RC-Calc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with RC-Calc. If not, see <http://www.gnu.org/licenses/>.


import io
import sqlite3
from flask import Blueprint


def open_db():
# Needs a complete re-write

# Opening the database
conn = sqlite3.connect('./db/RC-Calc.db')

# Creating the flight-time table if it does not exists
conn.execute('''CREATE TABLE IF NOT EXISTS flight_time_table
(number real, aircraft text, distance real, flight_time real, description text)''')

# Counting number of records in flight_time_table
n_flights = conn.execute('''SELECT COUNT(*) FROM flight_time_table;''')

# Getting the POST info from the user
# form = cgi.FieldStorage()

# Save changes
conn.commit()

# Closing database
conn.close()


def new_entry_form(plane):

return """
<div class="card">
<div class="card-header text-center">New Entry</div>
<div class="card-body">
<form class="form-group row" method="POST" action="" novalidate>
<div class="form-group text-center">
<label for="formFlightNumber-""" + plane + """">#</label>
<input type="text" class="form-control form-control-sm formFlightNumber" id="formFlightNumber-""" + plane + """" placeholder="1" readonly name="formFlightNumber-""" + plane + """">
</div>
<div class="form-group text-center">
<label for="formFlightTime-""" + plane + """">Flight Time</label>
<div class="input-group input-group-sm">
<input type="time" class="form-control formFlightTime" id="formFlightTime-""" + plane + """" name="formFlightTime-""" + plane + """">
<div class="invalid-tooltip">Please enter the flight time.</div>
</div>
</div>
<div class="form-group text-center">
<label for="formDistance-""" + plane + """">Distance</label>
<div class="input-group input-group-sm">
<input type="number" step="0.1" min="0" class="form-control formDistance" id="formDistance-""" + plane + """" placeholder="45.4" name="formDistance-""" + plane + """">
<div class="input-group-append">
<span class="input-group-text">km</span>
</div>
<div class="invalid-tooltip">Please enter the distance flown.</div>
</div>
</div>
<div class="form-group text-center">
<label for="formEnergy-""" + plane + """">Energy</label>
<div class="input-group input-group-sm">
<input type="number" step="0.1" min="0" class="form-control formEnergy" id="formEnergy-""" + plane + """" placeholder="53.2" name="formEnergy-""" + plane + """">
<div class="input-group-append">
<span class="input-group-text">Wh</span>
</div>
<div class="invalid-tooltip">Please enter the energy used.</div>
</div>
</div>
<div class="form-group text-center">
<label for="formBattery-""" + plane + """">Battery</label>
<div class="input-group input-group-sm">
<input type="number" step="0.1" min="0" class="form-control formBattery" id="formBattery-""" + plane + """" placeholder="125.2" name="formBattery-""" + plane + """">
<div class="input-group-append">
<div class="input-group-text">Wh</div>
</div>
<div class="invalid-tooltip">Please enter the battery energy.</div>
</div>
</div>
<div class="form-group text-center">
<label for="formDescription-""" + plane + """">Description </label>
<div class="input-group input-group-sm">
<textarea class="form-control formDescription" id="formDescription-""" + plane + """" placeholder="eg. With 12x6 propeller, without wind, pretty aggressive flight etc." name="formDescription-""" + plane + """"></textarea>
<div class="invalid-tooltip">Please enter a description.</div>
</div>
</div>
<div class="form-group text-center">
<label for="formSave-""" + plane + """" class="invisible">Save</label>
<div class="input-group">
<button type="submit" class="btn btn-primary btn-sm form-control-sm text-bottom formSave" id="formSave-""" + plane + """" name="formSave-""" + plane + """" value="clicked">Save</button>
</div>
</div>
</form>
</div>
</div>
"""


flight_time = Blueprint('flight-time', __name__)


@flight_time.route('/')
def show():
# Getting the usual content of flight-time.html as a string
html = io.open("./web/templates/flight-time.html", "r", encoding="utf-8").read()

plane_list = ["Skyhunter", "S800", "Easystar"]

for number, plane in enumerate(plane_list):
tab_header = "<a class=\"nav-item nav-link "
tab_header += "active\"" if not number else "\""
tab_header += " id=\"nav-" + plane + "-tab\" data-toggle=\"tab\" href=\"#nav-" + plane + "\" role=\"tab\" aria-controls=\"nav-"
tab_header += plane + "\" aria-selected=\""
tab_header += "true" if not number else "false"
tab_header += "\">" + plane + "</a>\n\t\t\t\t\t<!-- Plane tab header marker -->"

html = html.replace("""<!-- Plane tab header marker -->""", tab_header)

tab_content = "<div class=\"tab-pane fade show "
tab_content += "active\"" if not number else "\""
tab_content += " id=\"nav-" + plane + "\" role=\"tabpanel\" aria-labelledby=\"nav-" + plane + "-tab\">"
tab_content += new_entry_form(plane) + "</div>\n\t\t\t\t<!-- Plane tab content marker -->"

html = html.replace("""<!-- Plane tab content marker -->""", tab_content)

return html
Loading

0 comments on commit a1feafe

Please sign in to comment.