Skip to content

Commit

Permalink
add basic formatting and remove unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
guzmanlopez committed Oct 23, 2024
1 parent f55bf0a commit 4541487
Show file tree
Hide file tree
Showing 82 changed files with 11,029 additions and 8,629 deletions.
2 changes: 0 additions & 2 deletions api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@

from .deckhand import blueprint as deckhand

19 changes: 7 additions & 12 deletions api/deckhand.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import json
from http.client import BAD_REQUEST
from flask import Blueprint, make_response, request, g


from flask import Blueprint, g, make_response, request
from sqlalchemy.orm import scoped_session, sessionmaker

from model import DeckhandEventRaw

import json

from db import db
from model import DeckhandEventRaw

blueprint = Blueprint('DeckhandApi', __name__)
blueprint = Blueprint("DeckhandApi", __name__)


# ORM Session
# orm_session = scoped_session(sessionmaker())

@blueprint.route('/', methods=['PUT', 'POST'])

@blueprint.route("/", methods=["PUT", "POST"])
def event():
d = request.get_json()

Expand All @@ -25,7 +23,4 @@ def event():
db.session.add(event)
db.session.commit()

# for i in r:
# print(i);

return make_response(('', 200))
return make_response(("", 200))
22 changes: 11 additions & 11 deletions config/defaults.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
SECRET_KEY='not_so_secret'
DEBUG=True
DBUSER="edge"
DBNAME="edge"
THALOS_VIDEO_DIR="/thalos/videos"
THALOS_CAM_NAME='cam1'
VIDEO_OUTPUT_DIR='/videos'
VIDEO_PASSPHRASE_FILE='/dev/null'
THALOS_VIDEO_SUFFIX='.avi.done'
BOAT_NAME=''
DB_TABLES_VERSION='v1'
SECRET_KEY = "not_so_secret"
DEBUG = True
DBUSER = "edge"
DBNAME = "edge"
THALOS_VIDEO_DIR = "/thalos/videos"
THALOS_CAM_NAME = "cam1"
VIDEO_OUTPUT_DIR = "/videos"
VIDEO_PASSPHRASE_FILE = "/dev/null"
THALOS_VIDEO_SUFFIX = ".avi.done"
BOAT_NAME = ""
DB_TABLES_VERSION = "v1"
1 change: 0 additions & 1 deletion db.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()
33 changes: 15 additions & 18 deletions dbdumps/create_dump.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
#!/bin/bash

SCRIPTNAME="$0"
SCRIPTDIR="$(dirname -- "$( readlink -f -- "$0")")"
SCRIPTDIR="$(dirname -- "$(readlink -f -- "$0")")"

function help {
echo "usage: $SCRIPTNAME [--dbuser USER] [--dbname NAME] "
exit 1
echo "usage: $SCRIPTNAME [--dbuser USER] [--dbname NAME] "
exit 1
}

DBNAME=edge
DBUSER=edge

while (( "$#" )); do
while (("$#")); do
case $1 in
--dbuser)
shift && DBUSER="$1" || help
;;
--dbname)
shift && DBNAME="$1" || help
;;
*)
help
;;
--dbuser)
shift && DBUSER="$1" || help
;;
--dbname)
shift && DBNAME="$1" || help
;;
*)
help
;;
esac
shift
done


pg_dump --clean -U "$DBUSER" "$DBNAME" > "$SCRIPTDIR/$(date -u -Iseconds | cut -f1 -d + )Z.pgdump"



pg_dump --clean -U "$DBUSER" "$DBNAME" >"$SCRIPTDIR/$(date -u -Iseconds | cut -f1 -d +)Z.pgdump"
36 changes: 17 additions & 19 deletions dbdumps/reset_schema.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
#!/bin/bash

SCRIPTNAME="$0"
SCRIPTDIR="$(dirname -- "$( readlink -f -- "$0")")"

SCRIPTDIR="$(dirname -- "$(readlink -f -- "$0")")"

DBNAME=edge
DBUSER=edge

while (( "$#" )); do
while (("$#")); do
case $1 in
--dbuser)
shift && DBUSER="$1" || help
;;
--dbname)
shift && DBNAME="$1" || help
;;
*)
help
;;
--dbuser)
shift && DBUSER="$1" || help
;;
--dbname)
shift && DBNAME="$1" || help
;;
*)
help
;;
esac
shift
done


cd "$SCRIPTDIR/.."

if [ "$VIRTUAL_ENV" != "$(pwd)/venv" ] ; then
if [ "x$VIRTUAL_ENV" != "x" ] ; then
deactivate
fi
source venv/bin/activate
if [ "$VIRTUAL_ENV" != "$(pwd)/venv" ]; then
if [ "x$VIRTUAL_ENV" != "x" ]; then
deactivate
fi
source venv/bin/activate
fi


python -c 'from sqlalchemy import create_engine; \
from model import Base; \
engine = create_engine("postgresql+psycopg2://'$DBUSER'@/'$DBNAME'", echo=True); \
Expand Down
45 changes: 21 additions & 24 deletions dbdumps/restore_dump.sh
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
#!/bin/bash

SCRIPTNAME="$0"
SCRIPTDIR="$(dirname -- "$( readlink -f -- "$0")")"
SCRIPTDIR="$(dirname -- "$(readlink -f -- "$0")")"

function help {
echo "usage: $SCRIPTNAME [--dbuser USER] [--dbname NAME] [DUMPFILE]"
echo " DBDUMP_FILENAME defaults to the latest dumpfile, sorted by filename"
exit 1
echo "usage: $SCRIPTNAME [--dbuser USER] [--dbname NAME] [DUMPFILE]"
echo " DBDUMP_FILENAME defaults to the latest dumpfile, sorted by filename"
exit 1
}

DBNAME=edge
DBUSER=edge

DUMPFILE="$(ls $SCRIPTDIR/*.pgdump | sort | tail -n 1)"

while (( "$#" )); do
while (("$#")); do
case $1 in
--dbuser)
shift && DBUSER="$1" || help
;;
--dbname)
shift && DBNAME="$1" || help
;;
*)
if [ -e "$1" ] ; then
DUMPFILE="$1"
else
echo "file does not exist"
exit 1
fi
;;
--dbuser)
shift && DBUSER="$1" || help
;;
--dbname)
shift && DBNAME="$1" || help
;;
*)
if [ -e "$1" ]; then
DUMPFILE="$1"
else
echo "file does not exist"
exit 1
fi
;;
esac
shift
done


psql -U "$DBUSER" "$DBNAME" < $DUMPFILE



psql -U "$DBUSER" "$DBNAME" <$DUMPFILE
35 changes: 9 additions & 26 deletions dbdumps/seed_db.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
# from flask import Flask
# from flask_admin import Admin
import click

from sqlalchemy import create_engine, select
from sqlalchemy.orm import Session, sessionmaker
import os

from model import Base, RiskVector, Test, T

import sqlite3

from model import Base, FishAiData, GpsData, InternetData, RiskVector, Test
from model.internetdata import InternetData
from model import FishAiData, InternetData, GpsData

# app = Flask(__name__)
# app.config.from_object('config.defaults')

# if 'ENVIRONMENT' in os.environ:
# app.config.from_envvar('ENVIRONMENT')


# set optional bootswatch theme
# app.config['FLASK_ADMIN_SWATCH'] = 'cerulean'

def clear_db(session: Session):
result = session.execute(select(Test))
for t in result:
Expand All @@ -48,20 +31,20 @@ def clear_db(session: Session):


@click.command()
@click.option('--cleardb', default=False, is_flag=True)
@click.option('--dbname', default="edge")
@click.option('--dbuser', default="edge")
@click.option('--force', default=False, is_flag=True)
@click.option("--cleardb", default=False, is_flag=True)
@click.option("--dbname", default="edge")
@click.option("--dbuser", default="edge")
@click.option("--force", default=False, is_flag=True)
def cli(cleardb, dbname, dbuser, force):

if not force :
if not force:
import sys

print("This script is deprecated! run `venv/bin/alembic upgrade head` instead.")
print("if you really want to run this script, rerun with --force")
sys.exit(1)

# engine = create_engine("sqlite:///db.db", echo=True)
engine = create_engine("postgresql+psycopg2://%s@/%s"%(dbuser, dbname), echo=True)
engine = create_engine("postgresql+psycopg2://%s@/%s" % (dbuser, dbname), echo=True)
SessionMaker = sessionmaker(engine)
session = SessionMaker()
if cleardb:
Expand Down
57 changes: 35 additions & 22 deletions edge_http.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import click
import os

from flask import Flask, g
import click
from flask import Flask
from flask_admin import Admin
from flask_admin.contrib.sqla import ModelView

from sqlalchemy import text
from sqlalchemy.orm import scoped_session, sessionmaker
import os

from db import db

app = Flask(__name__)

app.config.from_object('config.defaults')
if 'ENVIRONMENT' in os.environ:
app.config.from_envvar('ENVIRONMENT')
app.config.from_object("config.defaults")
if "ENVIRONMENT" in os.environ:
app.config.from_envvar("ENVIRONMENT")

# set optional bootswatch theme
app.config['FLASK_ADMIN_SWATCH'] = 'cerulean'
# Set optional bootswatch theme
app.config["FLASK_ADMIN_SWATCH"] = "cerulean"

app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql+psycopg2://%s@/%s"%(app.config['DBUSER'], app.config['DBNAME'])
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql+psycopg2://%s@/%s" % (
app.config["DBUSER"],
app.config["DBNAME"],
)

# engine = create_engine("postgresql+psycopg2://%s@/%s"%(app.config['DBUSER'], app.config['DBNAME']), echo=True)

# SessionMaker = scoped_session(sessionmaker(bind=engine))
db.init_app(app)

Expand All @@ -32,26 +32,38 @@
with app.app_context():
# Base.metadata.create_all(engine)
db.metadata.create_all(db.engine)

from alembic import command, config

cfg = config.Config("alembic.ini")
command.upgrade(cfg, "head")
with db.engine.begin() as connection:
connection.execute(text("SELECT setval('aifishdata_id_seq', (SELECT MAX(id) FROM aifishdata));"))
connection.execute(text("SELECT setval('boatschedules_id_seq', (SELECT MAX(id) FROM boatschedules));"))
connection.execute(text("SELECT setval('deckhandevents_id_seq', (SELECT MAX(id) FROM deckhandevents));"))
connection.execute(text("SELECT setval('internetdata_id_seq', (SELECT MAX(id) FROM internetdata));"))
connection.execute(text("SELECT setval('ondeckdata_id_seq', (SELECT MAX(id) FROM ondeckdata));"))
connection.execute(
text("SELECT setval('aifishdata_id_seq', (SELECT MAX(id) FROM aifishdata));")
)
connection.execute(
text("SELECT setval('boatschedules_id_seq', (SELECT MAX(id) FROM boatschedules));")
)
connection.execute(
text("SELECT setval('deckhandevents_id_seq', (SELECT MAX(id) FROM deckhandevents));")
)
connection.execute(
text("SELECT setval('internetdata_id_seq', (SELECT MAX(id) FROM internetdata));")
)
connection.execute(
text("SELECT setval('ondeckdata_id_seq', (SELECT MAX(id) FROM ondeckdata));")
)
connection.execute(text("SELECT setval('tests_id_seq', (SELECT MAX(id) FROM tests));"))
connection.execute(text("SELECT setval('tracks_id_seq', (SELECT MAX(id) FROM tracks));"))
connection.execute(text("SELECT setval('vectors_id_seq', (SELECT MAX(id) FROM vectors));"))


from api import deckhand
app.register_blueprint(deckhand, url_prefix='/deckhand')

app.register_blueprint(deckhand, url_prefix="/deckhand")

admin = Admin(app, name='Risk Assesment', template_mode='bootstrap3')

admin = Admin(app, name="Risk Assesment", template_mode="bootstrap3")


# work with session
Expand All @@ -68,9 +80,10 @@


@click.command()
@click.option('--port', default=50000)
@click.option("--port", default=50000)
def serve(port):
app.run(host="0.0.0.0", port=port)

if __name__ == '__main__':

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

0 comments on commit 4541487

Please sign in to comment.