Skip to content

Commit

Permalink
<merge> pull changes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
kirianguiller committed Nov 13, 2020
2 parents 28c8ce6 + 9b7f590 commit 5df19b9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ auth_config.py

# scrap
z_sandbox/
app/klang/data_dev
app/klang/data_test

# databases
app/*.sqlite
Expand Down
44 changes: 9 additions & 35 deletions app/grew/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from app.projects.service import ProjectService
from app.user.service import UserService
from app.utils.grew_utils import grew_request
from app.utils.grew_utils import GrewService, grew_request
from flask import Response, abort, current_app, request
from flask_login import current_user
from flask_restx import Namespace, Resource, reqparse
Expand All @@ -13,7 +13,6 @@
) # noqa



@api.route("/<string:project_name>/try-rule")
class TryRuleResource(Resource):
def post(self, project_name: str):
Expand Down Expand Up @@ -97,53 +96,38 @@ def post(self, project_name: str):
args = parser.parse_args()

pattern = args.get("pattern")
reply = grew_request(
"searchPatternInGraphs",
data={"project_id": project_name, "pattern": pattern},
)
reply = GrewService.search_pattern_in_graphs(project_name, pattern)
if reply["status"] != "OK":
abort(400)
trees = {}

# print(121212,reply["data"])
# matches={}
# reendswithnumbers = re.compile(r"_(\d+)$")

for m in reply["data"]:
if m["user_id"] == "":
abort(409)
conll = grew_request(
"getConll",
data={
"sample_id": m["sample_id"],
"project_id": project_name,
"sample_id": m["sample_id"],
"sent_id": m["sent_id"],
"user_id": m["user_id"],
},
)
if conll["status"] != "OK":
abort(404)
conll = conll["data"]
# trees=project_service.formatTrees(m, trees, conll, m['user_id'])
trees = formatTrees_new(m, trees, conll)
# print(56565,trees)
js = json.dumps(trees)
resp = Response(js, status=200, mimetype="application/json")
return resp
return trees


@api.route("/<string:project_name>/samples/<string:sample_name>/search")
@api.route("/<string:project_name>/sample/<string:sample_name>/search")
class SearchInSampleResource(Resource):
def get(self, project_name: str, sample_name: str):
def post(self, project_name: str, sample_name: str):
"""
Aplly a grew search inside a project and sample
"""
reply = grew_request(
"getSamples", data={"project_id": project_name}
)
reply = grew_request("getSamples", data={"project_id": project_name})
data = reply.get("data")
samples_name = [sa["name"] for sa in data]

if not sample_name in samples_name:
abort(404)

Expand All @@ -152,17 +136,8 @@ def get(self, project_name: str, sample_name: str):
args = parser.parse_args()

pattern = args.get("pattern")
reply = grew_request(
"searchPatternInGraphs",
data={"project_id": project_name, "pattern": pattern},
)
if reply["status"] != "OK":
abort(400)

reply = GrewService.search_pattern_in_graphs(project_name, pattern)
trees = {}
# matches={}
# reendswithnumbers = re.compile(r"_(\d+)$")

for m in reply["data"]:
if m["sample_id"] != sample_name:
continue
Expand All @@ -181,8 +156,7 @@ def get(self, project_name: str, sample_name: str):
if conll["status"] != "OK":
abort(404)
conll = conll["data"]
# trees=project_service.formatTrees(m, trees, conll, m['user_id'])

trees = formatTrees_new(m, trees, conll)
return trees


Expand Down
1 change: 0 additions & 1 deletion app/projects/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def get(self, projectName: str):
@accepts(schema=ProjectSchemaCamel, api=api)
def put(self, projectName: str):
"""Modify a single project (by it's name)"""
print("KK request.parsed_obj", request.parsed_obj)
changes: ProjectInterface = request.parsed_obj
project = ProjectService.get_by_name(projectName)

Expand Down
18 changes: 17 additions & 1 deletion app/utils/grew_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def grew_request(fct_name, data={}, files={}):
)
print(error_message)
abort(500, {"message": error_message})

response = json.loads(response.text)
if response.get("status") != "OK":
if "data" in response:
Expand Down Expand Up @@ -108,6 +107,7 @@ def get_samples(project_id : str):
return grew_samples

@staticmethod
<<<<<<< HEAD
def create_sample(project_id: str, sample_id: str):
reply = grew_request(
"newSample",
Expand Down Expand Up @@ -136,3 +136,19 @@ def delete_sample(project_id: str, sample_id: str) -> None:

# @staticmethod
# def save_tree()
=======
def search_pattern_in_graphs(project_id: str, pattern: str, user_ids = []):
if current_app.config["ENV"] == "prod":
data = {
"project_id": project_id,
"pattern": pattern,
}
else:
data = {
"project_id": project_id,
"pattern": pattern,
"user_ids": "[{}]".format(",".join(user_ids)),
}
reply = grew_request("searchPatternInGraphs", data=data)
return reply
>>>>>>> origin/main

0 comments on commit 5df19b9

Please sign in to comment.