Skip to content

Commit

Permalink
added interactive-table-pop-endpoint and bug fixes for the interactiv…
Browse files Browse the repository at this point in the history
…e table pop
  • Loading branch information
cophilot committed Feb 7, 2024
1 parent 2a7d265 commit 8cccb33
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
6 changes: 4 additions & 2 deletions wannadb/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,11 @@ def __call__(
logger.info("Execute the pipeline.")
tick: float = time.time()
status_callback("Running the pipeline...", -1)


for ix, pipeline_element in enumerate(self._pipeline_elements):
pipeline_element(document_base, interaction_callback, status_callback, statistics[f"pipeline-element-{ix}"])
for i, pipeline_element in enumerate(self._pipeline_elements):
print(f"Running pipeline element {pipeline_element}...")
pipeline_element(document_base, interaction_callback, status_callback, statistics[f"pipeline-element-{str(i)}"])

status_callback("Running the pipeline...", 1)
tack: float = time.time()
Expand Down
6 changes: 6 additions & 0 deletions wannadb/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ def __hash__(self) -> int:

def __eq__(self, other) -> bool:
return isinstance(other, Attribute) and self._name == other._name and self._signals == other._signals

def toJSON(self):
print("toJSON")
return {
"name": self._name
}

@property
def name(self) -> str:
Expand Down
37 changes: 35 additions & 2 deletions wannadb_web/routing/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
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, DocumentBaseLoad, \
from wannadb_web.worker.tasks import CreateDocumentBase, BaseTask, DocumentBaseAddAttributes, DocumentBaseInteractiveTablePopulation, DocumentBaseLoad, \
DocumentBaseUpdateAttributes, DocumentBaseGetOrderedNuggets

core_routes = Blueprint('core_routes', __name__, url_prefix='/core')
Expand Down Expand Up @@ -120,6 +120,39 @@ def load_document_base():

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

@core_routes.route('/document_base/interactive', methods=['POST'])
def interactive_document_base():
"""
Endpoint for interactive document population
This endpoint is used to load a document base from a name and an organisation id.
Example Form Payload:
{
"authorization": "your_authorization_token"
"organisationId": "your_organisation_id",
"baseName": "your_document_base_name",
}
"""
form = request.form
authorization = form.get("authorization")
organisation_id: Optional[int] = form.get("organisationId")
base_name = form.get("baseName")

if (organisation_id is None or base_name is None
or authorization is None):
return make_response({"error": "missing parameters"}, 400)
_token = tokenDecode(authorization)

if _token is False:
return make_response({"error": "invalid token"}, 401)

user_id = _token.id

task = DocumentBaseInteractiveTablePopulation().apply_async(args=(user_id, base_name, organisation_id))

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


@core_routes.route('/document_base/attributes/add', methods=['POST'])
def document_base_attribute_add():
Expand Down Expand Up @@ -252,7 +285,7 @@ def task_update(task_id: str):

## todo: renaming of the endpoint

@core_routes.route('/fix_button', methods=['POST'])
@core_routes.route('/document_base/order/nugget', methods=['POST'])
def sort_nuggets():
"""
Endpoint for creating a document base.
Expand Down
2 changes: 1 addition & 1 deletion wannadb_web/worker/Web_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def find_additional_nuggets(nugget, documents):
)

matching_phase(self.document_base, self.interaction_callback, self.status_callback,
self.signals.statistics.msg())
Statistics(False))
self.signals.document_base_to_ui.emit(self.document_base)
self.signals.finished.emit(1)
except Exception as e:
Expand Down
4 changes: 4 additions & 0 deletions wannadb_web/worker/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ def to_json(self):
return json.loads(self.msg)

def emit(self, status: dict[str, Any]):
print("Status: " + str(status))
for key, value in status.items():
if isinstance(value, Attribute):
status[key] = value.toJSON()
self.redis.set(self.type, json.dumps(status))


Expand Down

0 comments on commit 8cccb33

Please sign in to comment.