Skip to content

Commit

Permalink
Add endpoint to metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledk2 committed Oct 28, 2023
1 parent 7450776 commit b5e6a69
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
20 changes: 15 additions & 5 deletions omero_search_engine/api/stats/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

from . import stats
from tools.utils.logs_analyser import get_search_terms
from flask import Response
from flask import Response, send_file
from omero_search_engine import search_omero_app
import os


@stats.route("/", methods=["GET"])
Expand All @@ -29,17 +31,25 @@ def index():

@stats.route("/<resource>/search_terms", methods=["GET"])
def search_terms(resource):
from omero_search_engine import search_omero_app

logs_folder = search_omero_app.config.get("SEARCHENGINE_LOGS_FOLDER")
content = get_search_terms(logs_folder, resource=resource, return_file_content=True)

return Response(
content,
mimetype="text/csv",
headers={
"Content-disposition": "attachment; filename=%s_stats.csv" % (resource)
},
)

return "OMERO search engine (search_terms API)"


@stats.route("/metadata", methods=["GET"])
def get_metadata():
base_folder = "/etc/searchengine/"
if not os.path.isdir(base_folder):
base_folder = os.path.expanduser("~")
metadata = os.path.join(base_folder, "metadata.csv")
if os.path.isfile(metadata):
return send_file(metadata, as_attachment=True)
else:
return "No metadata is avilable"
4 changes: 2 additions & 2 deletions omero_search_engine/validation/results_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ def get_omero_stats():
base_folder = "/etc/searchengine/"
if not os.path.isdir(base_folder):
base_folder = os.path.expanduser("~")
stats_file = os.path.join(base_folder, "stats.csv")
metadata_file = os.path.join(base_folder, "metadata.csv")

from omero_search_engine.api.v1.resources.resource_analyser import (
get_restircted_search_terms,
Expand Down Expand Up @@ -677,7 +677,7 @@ def get_omero_stats():
print("Value is empty string", dat["Key"])
report = "\n".join(data)

with open(stats_file, "w") as f:
with open(metadata_file, "w") as f:
f.write(report)


Expand Down

0 comments on commit b5e6a69

Please sign in to comment.