Skip to content

Commit

Permalink
Merge pull request #5 from allofphysicsgraph/works
Browse files Browse the repository at this point in the history
more incremental approach to make changes
  • Loading branch information
bhpayne authored Sep 7, 2024
2 parents e84ab54 + 397bb35 commit f450ade
Show file tree
Hide file tree
Showing 14 changed files with 557 additions and 327 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
certs
.env
flask/users_sqlite.db
flask/logs
neo4j_pdg/plugins/
neo4j_pdg/logs
neo4j_pdg/data
23 changes: 20 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@
# todo: docker kill $(docker ps -q); make up

up_monitor:
if (! docker stats --no-stream ); then open /Applications/Docker.app; while (! docker stats --no-stream ); do echo "Waiting for Docker to launch..."; sleep 1; done; fi; docker compose up --build --force-recreate --remove-orphans
if (! docker stats --no-stream ); then open /Applications/Docker.app; while (! docker stats --no-stream ); do echo "Waiting for Docker to launch..."; sleep 1; done; fi;
docker ps
if [ `docker ps | wc -l` -gt 1 ]; then \
docker kill $$(docker ps -q); \
fi
docker ps
docker run -it --rm -v `pwd`:/scratch allofphysicscom-flask /bin/bash -c 'for filename in /scratch/flask/*.py; do echo $$filename; done | xargs black'
docker compose up --build --force-recreate --remove-orphans

up:
if (! docker stats --no-stream ); then open /Applications/Docker.app; while (! docker stats --no-stream ); do echo "Waiting for Docker to launch..."; sleep 1; done; fi; docker compose up --build --force-recreate --remove-orphans --detach
if (! docker stats --no-stream ); then open /Applications/Docker.app; while (! docker stats --no-stream ); do echo "Waiting for Docker to launch..."; sleep 1; done; fi;
docker ps
if [ `docker ps | wc -l` -gt 1 ]; then \
docker kill $$(docker ps -q); \
fi
docker ps
docker run -it --rm -v `pwd`:/scratch allofphysicscom-flask /bin/bash -c 'for filename in /scratch/flask/*.py; do echo $$filename; done | xargs black'
docker compose up --build --force-recreate --remove-orphans --detach


down:
docker compose down


kill:
docker kill $(docker ps -q)
docker ps
docker kill $$(docker ps -q)


# This will remove:
Expand All @@ -24,3 +39,5 @@ kill:
clear:
docker system prune


# EOF
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ services:
# https://stackoverflow.com/questions/48465046/run-neo4j-with-docker-compose-neo4j-not-accessible-from-localhost7474
# https://medium.com/@faaizhussain/neo4j-4-0-docker-compose-9bead6634c8
neo4j_docker:
image: neo4j:4.4.4-community
image: neo4j:4.4.4-community # https://hub.docker.com/_/neo4j/tags
restart: unless-stopped
hostname: neo4j_host
#network_mode: "bridge"
Expand Down
1 change: 0 additions & 1 deletion flask/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions flask/Dockerfile.gunicorn
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ COPY common_lib.py \
json_schema.py \
Makefile \
pdg_api.py \
pg_library \
schema.sql \
sql_db.py \
user.py \
Expand Down
67 changes: 39 additions & 28 deletions flask/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
# inspired by https://news.ycombinator.com/item?id=33844117
from typing import NewType, Dict, List


# https://docs.python.org/3/library/sqlite3.html
import sqlite3

Expand All @@ -52,7 +51,6 @@
import neo4j
from neo4j import GraphDatabase


# https://hplgit.github.io/web4sciapps/doc/pub/._web4sa_flask004.html
from flask import (
Flask,
Expand All @@ -71,7 +69,8 @@
from flask_wtf import FlaskForm, CSRFProtect, Form # type: ignore

# https://github.com/TypeError/secure
import secure # type: ignore
import secure # type: ignore

# what feature gets added? See https://improveandrepeat.com/2020/10/python-friday-43-add-security-headers-to-your-flask-application/

# https://flask-login.readthedocs.io/en/latest/_modules/flask_login/mixins.html
Expand Down Expand Up @@ -130,6 +129,7 @@

sys.path.append("pg_library")
import neo4j_query
import list_of_valid

# Database Credentials
# "bolt" vs "neo4j" https://community.neo4j.com/t/different-between-neo4j-and-bolt/18498
Expand Down Expand Up @@ -166,6 +166,8 @@
print("Neo4j exception: " + str(er))


import importlib

print(
"flask",
importlib.metadata.version("flask"),
Expand Down Expand Up @@ -213,12 +215,12 @@
app.config.from_object(
Config
) # https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-iii-web-forms
app.config[
"UPLOAD_FOLDER"
] = "/home/appuser/app/uploads" # https://flask.palletsprojects.com/en/1.1.x/patterns/fileuploads/
app.config[
"SEND_FILE_MAX_AGE_DEFAULT"
] = 0 # https://stackoverflow.com/questions/34066804/disabling-caching-in-flask
app.config["UPLOAD_FOLDER"] = (
"/home/appuser/app/uploads" # https://flask.palletsprojects.com/en/1.1.x/patterns/fileuploads/
)
app.config["SEND_FILE_MAX_AGE_DEFAULT"] = (
0 # https://stackoverflow.com/questions/34066804/disabling-caching-in-flask
)
app.config["DEBUG"] = True

# https://stackoverflow.com/a/24226084/1164295
Expand Down Expand Up @@ -291,7 +293,7 @@
# the logger will handle only INFO, WARNING, ERROR, and CRITICAL messages
# and will ignore DEBUG messages
level=logging.DEBUG,
format="%(asctime)s|%(filename)-13s|%(levelname)-5s|%(lineno)-4d|%(funcName)-20s|%(message)s" # ,
format="%(asctime)s|%(filename)-13s|%(levelname)-5s|%(lineno)-4d|%(funcName)-20s|%(message)s", # ,
# https://stackoverflow.com/questions/6290739/python-logging-use-milliseconds-in-time-format/7517430#7517430
# datefmt="%m/%d/%Y %I:%M:%S %f %p", # https://strftime.org/
)
Expand Down Expand Up @@ -1562,9 +1564,8 @@ def historical_precedents():
a static page
"""
logger.info("[trace]")
return render_template(
"historical_precedents.html", title="historical precedents"
)
return render_template("historical_precedents.html", title="historical precedents")


@app.route("/comparison_of_design_options_cas", methods=["GET", "POST"])
def comparison_of_design_options_cas():
Expand All @@ -1573,39 +1574,47 @@ def comparison_of_design_options_cas():
"""
logger.info("[trace]")
return render_template(
"comparison_of_design_options_cas.html", title="Comparison of Design Options Documentation"
"comparison_of_design_options_cas.html",
title="Comparison of Design Options Documentation",
)


@app.route("/comparison_of_design_options_proofs", methods=["GET", "POST"])
def comparison_of_design_options_proofs():
"""
a static page
"""
logger.info("[trace]")
return render_template(
"comparison_of_design_options_proofs.html", title="Comparison of Design Options Documentation"
"comparison_of_design_options_proofs.html",
title="Comparison of Design Options Documentation",
)


@app.route("/comparison_of_design_options_syntax", methods=["GET", "POST"])
def comparison_of_design_options_syntax():
"""
a static page
"""
logger.info("[trace]")
return render_template(
"comparison_of_design_options_syntax.html", title="Comparison of Design Options Documentation"
"comparison_of_design_options_syntax.html",
title="Comparison of Design Options Documentation",
)


@app.route("/comparison_of_design_options_database", methods=["GET", "POST"])
def comparison_of_design_options_database():
"""
a static page
"""
logger.info("[trace]")
return render_template(
"comparison_of_design_options_database.html", title="Comparison of Design Options Documentation"
"comparison_of_design_options_database.html",
title="Comparison of Design Options Documentation",
)


@app.route("/design_principles_and_goals", methods=["GET", "POST"])
def design_principles_and_goals():
"""
Expand All @@ -1617,7 +1626,6 @@ def design_principles_and_goals():
)



# @app.route("/example_T_f_d3js", methods=["GET", "POST"])
# def example_T_f_d3js():
# """
Expand Down Expand Up @@ -3093,9 +3101,9 @@ def update_symbols(deriv_id: str, step_id: str):
for expr_local_id in step_dict["inputs"] + step_dict["outputs"]:
expr_global_id = dat["expr local to global"][expr_local_id]
try:
derivation_dimensions_validity_dict[
expr_global_id
] = vdim.validate_dimensions(expr_global_id, path_to_db)
derivation_dimensions_validity_dict[expr_global_id] = (
vdim.validate_dimensions(expr_global_id, path_to_db)
)
except Exception as err:
logger.error(this_step_id + ": " + str(err))
flash("in step " + this_step_id + ": " + str(err))
Expand Down Expand Up @@ -3594,9 +3602,9 @@ def review_derivation(deriv_id: str):
for expr_local_id in step_dict["inputs"] + step_dict["outputs"]:
expr_global_id = dat["expr local to global"][expr_local_id]
try:
derivation_dimensions_validity_dict[
expr_global_id
] = vdim.validate_dimensions(expr_global_id, path_to_db)
derivation_dimensions_validity_dict[expr_global_id] = (
vdim.validate_dimensions(expr_global_id, path_to_db)
)
except Exception as err:
logger.error(this_step_id + ": " + str(err))
flash("in step " + this_step_id + ": " + str(err))
Expand Down Expand Up @@ -4191,10 +4199,13 @@ def create_new_inf_rule():
)


@app.route("/pg/frontpage", methods=["GET", "POST"])
def pg_frontpage():
"""
"""
@app.route("/pg/", methods=["GET", "POST"])
def pg_main():
""" """
trace_id = str(random.randint(1000000, 9999999))
print("[TRACE] func: pdg_app/main start " + trace_id)
query_time_dict = {} # type: Dict[str, float]

# performance TODO: replace the counts below with
# MATCH (n) RETURN distinct labels(n), count(*)

Expand Down
Loading

0 comments on commit f450ade

Please sign in to comment.