Skip to content

Commit

Permalink
Create new api for NIMBUS
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
light-weaver committed Jan 28, 2024
1 parent 3fe7cbe commit 2b7a2b9
Show file tree
Hide file tree
Showing 7 changed files with 606 additions and 90 deletions.
20 changes: 17 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,28 @@

api = Api(app)

ACCESS_EXPIRES = timedelta(hours=1)

db_user = "bhupindersaini"
db_password = ""
db_host = "localhost"
db_port = "5432"
db_name = "DESDEO"

ACCESS_EXPIRES = timedelta(hours=2)
app.config["PROPAGATE_EXCEPTIONS"] = True
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///app.db"
app.config[
"SQLALCHEMY_DATABASE_URI"
] = f"postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}"

#app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///database.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SECRET_KEY"] = "secret-key"
app.config["JWT_SECRET_KEY"] = "jwt-secret-key"
app.config["JWT_TOKEN_LOCATION"] = ["headers"]
app.config["JWT_ACCESS_TOKEN_EXPIRES"] = ACCESS_EXPIRES



jwt = JWTManager(app)

# db = SQLAlchemy(app)
Expand Down Expand Up @@ -74,8 +86,10 @@ def check_if_token_revoked(jwt_header, jwt_payload):
api.add_resource(method_resources.MethodControl, "/method/control")

# Add nimbus endpoints

api.add_resource(nimbus.Initialize, "/nimbus/initialize")
api.add_resource(nimbus.Iterate, "/nimbus/iterate")
api.add_resource(nimbus.Save, "/nimbus/save")
api.add_resource(nimbus.Choose, "/nimbus/choose")

# Add questionnaire endpoints
api.add_resource(
Expand Down
12 changes: 12 additions & 0 deletions models/method_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import dill
from database import db

from sqlalchemy.dialects import postgresql

# to be able to serialize lambdified expressions returned by SymPy
# This might break some serializations!
dill.settings["recurse"] = True
Expand All @@ -22,3 +24,13 @@ def __repr__(self):
f"Method = id:{self.id}, name:{self.name}, user_id:{self.user_id}, minimize:{self.minimize}, "
f"status:{self.status}, last_request:{self.last_request}"
)


class Preference(db.Model):
"""Database model for storing preferences temporarily (for UTOPIA)."""

__tablename__ = "preference"
id = db.Column(db.Integer, primary_key=True, unique=True)
method = db.Column(db.String, nullable=False)
preference = db.Column(postgresql.JSON, nullable=False)
date = db.Column(db.DateTime, nullable=False)
20 changes: 19 additions & 1 deletion models/problem_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import dill
from sqlalchemy.orm import validates, Mapped

from sqlalchemy.dialects import postgresql

from database import db
from sqlalchemy.orm import validates

# to be able to serialize lambdified expressions returned by SymPy
# This might break some serializations!
Expand Down Expand Up @@ -47,3 +50,18 @@ def validate_dict(self, _, dict_):
"The dictrionary supplied to SolutionArchive must contain the keys 'variables' and 'objectives'"
)
return dict_


class UTOPIASolutionArchive(db.Model):
__tablename__ = "UTOPIAsolutionarchive"
id = db.Column(db.Integer, primary_key=True, unique=True)
user_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
problem_id = db.Column(db.Integer, db.ForeignKey("problem.id"), nullable=False)
preference = db.Column(db.Integer, db.ForeignKey("preference.id"), nullable=False)
method_name=db.Column(db.String(100), nullable=False)
objectives = db.Column(postgresql.ARRAY(db.Float), nullable=False)
variables = db.Column(postgresql.ARRAY(db.Float), nullable=True)
saved = db.Column(db.Boolean, nullable=False)
current = db.Column(db.Boolean, nullable=False)
chosen = db.Column(db.Boolean, nullable=False)
date = db.Column(db.DateTime, nullable=False)
83 changes: 82 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Werkzeug = ">=2.2"
desdeo-mcdm = "^1.3.2"
desdeo-emo = "^1.5.0"
ruff = "^0.1.6"
psycopg2-binary = "^2.9.9"

[tool.poetry.dev-dependencies]
flake8 = "^3.8.4"
Expand Down Expand Up @@ -111,8 +112,8 @@ line-length = 120
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.11.
target-version = "py312"
# Assume Python 3.9.
target-version = "py39"

[tool.ruff.per-file-ignores]
# Ignore certain rules in test files
Expand Down
Loading

0 comments on commit 2b7a2b9

Please sign in to comment.