Skip to content

Commit

Permalink
Revert "Merge branch 'add_validated_tree'"
Browse files Browse the repository at this point in the history
This reverts commit bc7563c, reversing
changes made to cc02010.
  • Loading branch information
khansadaoudi committed Oct 9, 2023
1 parent 82c7f28 commit d5056da
Show file tree
Hide file tree
Showing 20 changed files with 407 additions and 484 deletions.
19 changes: 2 additions & 17 deletions app/db_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
print('mode must be prod or dev')
exit()

if args.version != 'add_github' and args.version != 'add_constructicon' and args.version != 'all' and args.version != 'new_roles' and args.version != 'add_validated_tree':
if args.version != 'add_github' and args.version != 'add_constructicon' and args.version != 'all' and args.version != 'new_roles':
print('version must be add_github, add_constructicon or all')
exit()

Expand Down Expand Up @@ -49,18 +49,6 @@ def migrate_add_constructicon(engine):
def migrate_new_roles(engine):
with engine.connect() as connection:
connection.execute('UPDATE projectaccess SET access_level = 3 WHERE projectaccess.access_level == 2')


def migrate_add_validated_tree(engine):
with engine.connect() as connection:
connection.execute('ALTER TABLE projects RENAME COLUMN exercise_mode To blind_annotation_mode')
connection.execute('ALTER TABLE projects ADD config STRING')
connection.execute('ALTER TABLE projects ADD language STRING')
connection.execute('ALTER TABLE projects DROP show_all_trees')
connection.execute('ALTER TABLE exerciselevel RENAME COLUMN exercise_level TO blind_annotation_level')
connection.execute('ALTER TABLE exerciselevel RENAME TO blindannotationlevel')
connection.execute('CREATE TABLE user_tags (id INTEGER NOT NULL, user_id VARCHAR(256), tags JSONB, PRIMARY KEY(id), FOREIGN KEY(user_id) REFERENCES users(id))')


if args.version == 'add_github':
migrate_add_github(engine)
Expand All @@ -73,7 +61,4 @@ def migrate_add_validated_tree(engine):
migrate_add_constructicon(engine)

if args.version == 'new_roles':
migrate_new_roles(engine)

if args.version == 'add_validated_tree':
migrate_add_validated_tree(engine)
migrate_new_roles(engine)
13 changes: 4 additions & 9 deletions app/github/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
from typing import List

from flask import abort
from flask_login import current_user

from app import db
from app.config import Config
from app.projects.service import ProjectService
from app.utils.grew_utils import GrewService, grew_request , SampleExportService
from app.user.service import UserService
import app.samples.service as SampleService

from .model import GithubRepository, GithubCommitStatus
Expand All @@ -32,7 +30,7 @@ def get_github_synchronized_repository(project_id):
@staticmethod
def synchronize_github_repository(user_id, project_id, repository_name, branch, sha):

github_repository = {
github_repository ={
"project_id": project_id,
"user_id": user_id,
"repository_name": repository_name,
Expand Down Expand Up @@ -222,7 +220,8 @@ def delete_file_from_github(access_token, project_name, full_name, sample_name):
def delete_sample_from_project(project_name, sample_name):
project = ProjectService.get_by_name(project_name)
GrewService.delete_sample(project_name, sample_name)
SampleService.SampleBlindAnnotationLevelService.delete_by_sample_name(project.id, sample_name)
SampleService.SampleRoleService.delete_by_sample_name(project.id, sample_name)
SampleService.SampleExerciseLevelService.delete_by_sample_name(project.id, sample_name)


class GithubService:
Expand Down Expand Up @@ -335,11 +334,7 @@ def create_tree(access_token, full_name, updated_samples, project_name, username
tree = []
sample_names, sample_content_files = GrewService.get_samples_with_string_contents(project_name, updated_samples)
for sample_name, sample in zip(sample_names,sample_content_files):
if (username == 'validated'):
owner_username = UserService.get_by_id(current_user.id).username
content = GrewService.get_validated_trees_filled_up_with_owner_trees(project_name, sample_name, owner_username)
else:
content = sample.get(username)
content = sample.get(username)
sha = GithubService.create_blob_for_updated_file(access_token, full_name, content)
blob = {"path": sample_name+".conllu", "mode":"100644", "type":"blob", "sha": sha}
tree.append(blob)
Expand Down
42 changes: 6 additions & 36 deletions app/grew/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,25 @@ def post(self, project_name: str):
class SearchResource(Resource):
"Search"
def post(self, project_name: str):

parser = reqparse.RequestParser()
parser.add_argument(name="pattern", type=str)
parser.add_argument(name="userType", type=str)
args = parser.parse_args()

pattern = args.get("pattern")
trees_type = args.get("userType")
user_type = args.get("userType")

user_type = 'all' if trees_type == 'pending' else trees_type

reply = GrewService.search_pattern_in_graphs(project_name, pattern, user_type)

if reply["status"] != "OK":
abort(400)

trees = {}
for m in reply["data"]:
if m["user_id"] == "":
abort(409)
conll = m["conll"]
trees = formatTrees_new(m, trees, conll)

search_results = {}
if trees_type == "pending":
for sample_name, sample_results in trees.items():
search_results[sample_name] = {
sent_id: result for sent_id, result in sample_results.items() if 'validated' not in result["conlls"].keys()
}
else:
search_results = trees

return search_results
return trees


@api.route("/<string:project_name>/sample/<string:sample_name>/search")
Expand All @@ -111,15 +98,8 @@ def post(self, project_name: str, sample_name: str):
args = parser.parse_args()

pattern = args.get("pattern")
trees_type = args.get("userType")

user_type = 'all' if trees_type == 'pending' else trees_type

user_type = args.get("userType")
reply = GrewService.search_pattern_in_graphs(project_name, pattern, user_type)

if reply["status"] != "OK":
abort(400)

trees = {}
for m in reply["data"]:
if m["sample_id"] != sample_name:
Expand All @@ -128,16 +108,7 @@ def post(self, project_name: str, sample_name: str):
abort(409)
conll = m["conll"]
trees = formatTrees_new(m, trees, conll)

search_results = {}
if trees_type == 'pending':
search_results[sample_name] = {
sent_id: result for sent_id, result in trees[sample_name].items() if 'validated' not in result["conlls"].keys()
}
else:
search_results = trees

return search_results
return trees

@api.route("/<string:project_name>/try-package")
class TryPackageResource(Resource):
Expand Down Expand Up @@ -187,8 +158,6 @@ def post(self, project_name):
user_ids = { "one": [current_user.username, "__last__"] }
elif tableType=='recent':
user_ids = { "one": ["__last__"] }
elif tableType=='validated':
user_ids = { "one": ["validated"]}
elif tableType=='all':
user_ids = "all"
reply = grew_request(
Expand Down Expand Up @@ -298,6 +267,7 @@ def post_process_diffs(grew_search_results, other_users, features):
matches[other_user_id] = list_matches
conlls[other_user_id] = grew_search_results[sample_name][sent_id]["conlls"][other_user_id]
if len(conlls) > 0 :
print('test')
post_processed_results[sample_name][sent_id] = {
"sentence": grew_search_results[sample_name][sent_id]["sentence"],
"sample_name": sample_name,
Expand Down
8 changes: 3 additions & 5 deletions app/lexicon/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ def post(self, project_name: str):
lexicon_type=args.get("lexiconType")
prune=args.get("prune")

if lexicon_type == 'user':
if lexicon_type=='user':
user_ids = { "one": [current_user.username] }
elif lexicon_type == 'user_recent':
elif lexicon_type=='user_recent':
user_ids = { "one": [current_user.username, "__last__"] }
elif lexicon_type == 'recent':
elif lexicon_type=='recent':
user_ids = { "one": ["__last__"] }
elif lexicon_type == 'validated':
user_ids = { "one": ["validated"] }
elif lexicon_type=='all':
user_ids = "all"

Expand Down
10 changes: 4 additions & 6 deletions app/projects/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ def post(self) -> Project:
parser = reqparse.RequestParser()
parser.add_argument(name="projectName", type=str)
parser.add_argument(name="description", type=str)
parser.add_argument(name="blindAnnotationMode", type=bool)
parser.add_argument(name="showAllTrees", type=bool)
parser.add_argument(name="exerciseMode", type=bool)
parser.add_argument(name="visibility", type=int)
parser.add_argument(name="config", type=str)
parser.add_argument(name="language", type=str)
args = parser.parse_args()

# Sanitize the project name to correspond to Grew folders requirements
Expand All @@ -116,11 +115,10 @@ def post(self) -> Project:
new_project_attrs: ProjectInterface = {
"project_name": projectName,
"description": args.description,
"blind_annotation_mode": args.blindAnnotationMode,
"show_all_trees": args.showAllTrees,
"exercise_mode": args.exerciseMode,
"visibility": args.visibility,
"freezed": False,
"config": args.config,
"language": args.language
}

# KK : TODO : put all grew request in a seperated file and add error catching
Expand Down
5 changes: 2 additions & 3 deletions app/projects/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ class ProjectInterface(TypedDict, total=False):
description: str
image: Any
visibility: int
blind_annotation_mode: bool
show_all_trees: bool
exercise_mode: bool
freezed: bool
config: str
language: str


class ProjectExtendedInterface(ProjectInterface, total=False):
Expand Down
5 changes: 2 additions & 3 deletions app/projects/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ class Project(db.Model, BaseM):
description = Column(String(256))
image = Column(String(256), nullable=True)
visibility = Column(Integer)
blind_annotation_mode = Column(Boolean, default=False)
show_all_trees = Column(Boolean, default=True)
exercise_mode = Column(Boolean, default=False)
diff_mode = Column(Boolean, default=False)
diff_user_id = Column(String(256), nullable=True)
freezed = Column(Boolean, default=False)
config = Column(String(256), nullable=True)
language = Column(String(256), nullable=True)

feature = db.relationship("ProjectFeature", cascade="all,delete", backref="projects")
meta_feature = db.relationship("ProjectMetaFeature", cascade="all,delete", backref="projects")
Expand Down
10 changes: 4 additions & 6 deletions app/projects/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ class ProjectSchema(Schema):
description = fields.String(attribute="description")
image = BlobImageField(attribute="image")
visibility = fields.Integer(attribute="visibility")
blindAnnotationMode = fields.Boolean(attribute="blind_annotation_mode")
showAllTrees = fields.Boolean(attribute="show_all_trees")
exerciseMode = fields.Boolean(attribute="exercise_mode")
freezed = fields.Boolean(attribute="freezed")
config = fields.String(attribute="config")
language = fields.String(attribute="language")


class ProjectExtendedSchema(ProjectSchema):
Expand Down Expand Up @@ -59,10 +58,9 @@ class ProjectSchemaCamel(Schema):
description = fields.String(attribute="description")
image = BlobImageField(attribute="image")
visibility = fields.Integer(attribute="visibility")
blindAnnotationMode = fields.Boolean(attribute="blind_annotation_mode")
showAllTrees = fields.Boolean(attribute="show_all_trees")
exerciseMode = fields.Boolean(attribute="exercise_mode")
freezed = fields.Boolean(attribute="freezed")
config = fields.String(attribute="config")
language = fields.String(attribute="language")
diffMode = fields.Boolean(attribute="diff_mode")
diffUserId = fields.String(attribute="diff_user_id")

Expand Down
1 change: 1 addition & 0 deletions app/projects/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .interface import ProjectExtendedInterface, ProjectInterface
from .model import Project, ProjectAccess, ProjectFeature, ProjectMetaFeature, DefaultUserTrees
from ..utils.grew_utils import grew_request
from ..samples.model import SampleRole


class ProjectService:
Expand Down
2 changes: 0 additions & 2 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ def register_routes(api, app, root="api"):
from app.projects import register_routes as attach_projects
from app.samples import register_routes as attach_samples
from app.trees import register_routes as attach_trees
from app.tags import register_routes as attach_tags
from app.lexicon import register_routes as attach_lexicon
from app.constructicon import register_routes as attach_constructicon
from app.grew import register_routes as attach_grew
Expand All @@ -16,7 +15,6 @@ def register_routes(api, app, root="api"):
attach_projects(api, app, root)
attach_samples(api, app, root)
attach_trees(api, app, root)
attach_tags(api, app, root)
attach_lexicon(api, app, root)
attach_constructicon(api, app, root)
attach_grew(api, app, root)
Expand Down
Loading

0 comments on commit d5056da

Please sign in to comment.