Skip to content

Commit

Permalink
Merge branch 'main' into update_nugget
Browse files Browse the repository at this point in the history
  • Loading branch information
cophilot authored Feb 7, 2024
2 parents 8cccb33 + 7b1bbc3 commit 952b32e
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 8 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/new_stable_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Create New Stable Version

on:
workflow_dispatch:

jobs:
create_pull_request:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: stable
base: main
title: Automated New Stable Version
body: This pull request was automatically created by the workflow and contains the latest stable version of the repository.
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ RUN pip install --use-pep517 pytest

FROM build as worker

FROM build as worker-prod

#copy the rest
COPY . .


FROM build as dev
Expand All @@ -51,10 +55,8 @@ CMD ["mypy","--install-types", "--non-interactive"]
CMD ["flask", "--app", "app", "--debug", "run","--host","0.0.0.0", "--port", "8000" ]


FROM build as prod
FROM worker-prod as prod

#copy the rest
COPY . .

RUN chmod +x wannadb_web/entrypoint.sh

Expand Down
1 change: 1 addition & 0 deletions docker-compose-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ services:
- wannadb
- redis


postgres:
image: postgres
container_name: postgres-container
Expand Down
3 changes: 3 additions & 0 deletions wannadb_web/postgres/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def getDocument_by_name(document_name: str, organisation_id: int, user_id: int)
"""

select_query = sql.SQL("""SELECT id,content,content_byte
FROM documents d
JOIN membership m ON d.organisationid = m.organisationid
WHERE d.name = (%s) AND m.userid = (%s) AND m.organisationid = (%s)
Expand Down Expand Up @@ -211,8 +212,10 @@ def getDocumentsForOrganization(organisation_id: int):
return doc_array

def getDocumentBaseForOrganization(organisation_id: int):

select_query = sql.SQL("""SELECT id, name,content,content_byte
FROM documents
WHERE organisationid = (%s)
""")
result = execute_query(select_query, (organisation_id,))
Expand Down
6 changes: 5 additions & 1 deletion wannadb_web/routing/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
from wannadb_web.Redis.RedisCache import RedisCache
from wannadb_web.util import tokenDecode
from wannadb_web.worker.data import Signals

from wannadb_web.worker.tasks import CreateDocumentBase, BaseTask, DocumentBaseAddAttributes, DocumentBaseInteractiveTablePopulation, DocumentBaseLoad, \
DocumentBaseUpdateAttributes, DocumentBaseGetOrderedNuggets


core_routes = Blueprint('core_routes', __name__, url_prefix='/core')

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -90,6 +92,7 @@ def create_document_base():

@core_routes.route('/document_base/load', methods=['POST'])
def load_document_base():

"""
Endpoint for loading a document base.
Expand Down Expand Up @@ -184,6 +187,7 @@ def document_base_attribute_add():

attributes_strings = attributes_string.split(",")


attributes = []
for att in attributes_string:
attributes.append(Attribute(att))
Expand All @@ -198,7 +202,6 @@ def document_base_attribute_add():

return make_response({'task_id': task.id}, 202)


@core_routes.route('/document_base/attributes/update', methods=['POST'])
def document_base_attribute_update():
"""
Expand Down Expand Up @@ -322,3 +325,4 @@ def sort_nuggets():
task = DocumentBaseGetOrderedNuggets().apply_async(args=(user_id, base_name, organisation_id, document_id))

return make_response({'task_id': task.id}, 202)

1 change: 1 addition & 0 deletions wannadb_web/routing/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from wannadb_web.postgres.queries import deleteDocumentContent, getDocument, getDocumentsForOrganization, \
updateDocumentContent, getDocumentBaseForOrganization

from wannadb_web.util import tokenDecode
from wannadb_web.postgres.transactions import addDocument

Expand Down
5 changes: 3 additions & 2 deletions wannadb_web/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def tokenDecode(string: str):
try:
decoded_token = jwt.decode(string, _jwtkey, leeway=datetime.timedelta(minutes=1), algorithms="HS256",
verify=True)
except jwt.ExpiredSignatureError:
return False
#except jwt.ExpiredSignatureError:
except:
return None
user = decoded_token.get('user')
_id = int(decoded_token.get('id'))
exp = decoded_token.get('exp')
Expand Down
8 changes: 8 additions & 0 deletions wannadb_web/worker/Web_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def document_base(self, value: DocumentBase):
raise TypeError("Document base must be of type DocumentBase!")
self._document_base = value
self.signals.document_base_to_ui.emit(value)
return

def get_ordert_nuggets(self, document_id: int):
document = getDocument(document_id, self.user_id)
Expand Down Expand Up @@ -231,6 +232,13 @@ def update_document_base_to_bson(self):
self.signals.error.emit(Exception("Document ID not set!"))
return
try:
print("BASE")
print(self.document_base)
print("ID")
print(self.document_id)
print("ATT")
print(self.document_base.attributes)

status = updateDocumentContent(self.document_id, self.document_base.to_bson())
if status is False:
logger.error(f"Document base could not be saved to BSON! Document {self.document_id} does not exist!")
Expand Down
4 changes: 3 additions & 1 deletion wannadb_web/worker/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def document_base_to_json(document_base: DocumentBase):
'msg': {"attributes ": [attribute.name for attribute in document_base.attributes],
"nuggets": [nugget_to_json(nugget) for nugget in document_base.nuggets]
}

}


Expand All @@ -76,14 +77,15 @@ def __init__(self, user_id: str):
def to_json(self) -> dict[str, str]:
return {"user_id": self.__user_id,
self.feedback.type: self.feedback.to_json(),

self.error.type: self.error.to_json(),
self.status.type: self.status.to_json(),
self.finished.type: self.finished.to_json(),
self.document_base_to_ui.type: self.document_base_to_ui.to_json(),
self.statistics.type: self.statistics.to_json(),
self.feedback_request_to_ui.type: self.feedback_request_to_ui.to_json(),
self.cache_db_to_ui.type: self.cache_db_to_ui.to_json()}

def reset(self):
RedisCache(self.__user_id).delete_user_space()

Expand Down
3 changes: 2 additions & 1 deletion wannadb_web/worker/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def run(self, user_id: int, document_ids: list[int], attributes_strings: list[st
"""
init api
"""
## todo hier muss self.request.id durchgeleitet werden und in signals(request_id) gespeichert werden
api = WannaDB_WebAPI(user_id, base_name, organisation_id)

"""
Expand Down Expand Up @@ -301,7 +302,6 @@ def run(self, user_id: int, base_name: str, organisation_id: int):
self.update(State.SUCCESS)
return self


class DocumentBaseGetOrderedNuggets(BaseTask):
name = "DocumentBaseGetOrderedNuggets"

Expand Down Expand Up @@ -383,3 +383,4 @@ def match_feedback(nugget: Union[str, InformationNugget], document: Document,
"nugget": nugget,
"not-a-match": None
}

0 comments on commit 952b32e

Please sign in to comment.