Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions audino/backend/routes/current_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from .projects import give_users_examples
from backend import app, db
from backend.models import Project, User, Data, Segmentation
from .helper_functions import retrieve_database, general_error, missing_data
from .helper_functions import retrieve_database, general_error, missing_data, count_segmentations
from .logger import post_log_msg
from . import api

Expand Down Expand Up @@ -58,7 +58,7 @@ def fetch_data_for_project(project_id):
).distinct().subquery()

categories = ["pending", "completed", "marked_review", "all"]
data = retrieve_database(project_id, segmentations, categories)
data = retrieve_database(project_id, segmentations, categories, request_user)
app.logger.info(data)
paginate_data = data[active].paginate(page, 10, False)

Expand All @@ -74,7 +74,7 @@ def fetch_data_for_project(project_id):
"created_on": "a date",
# data_point.created_at.strftime("%B %d, %Y"),
"is_marked_for_review": data_point.is_marked_for_review,
"number_of_segmentations": len(data_point.segmentations),
"number_of_segmentations": count_segmentations(data_point, project, request_user),
"sampling_rate": data_point.sampling_rate,
"clip_length": data_point.clip_length,
"sample": data_point.sample
Expand All @@ -85,7 +85,7 @@ def fetch_data_for_project(project_id):
count_data = {key: value.count() for key, value in data.items()}
app.logger.info("HELLO")
except Exception as e:
return general_error("Error fetching all projects", e)
return general_error("Error fetching all projects 1", e)

return (
jsonify(
Expand Down Expand Up @@ -157,7 +157,7 @@ def get_next_data(project_id, data_value):
)
count_data = {key: value.count() for key, value in data.items()}
except Exception as e:
return general_error("Error fetching all projects", e)
return general_error("Error fetching all projects 2", e)

return (
jsonify(
Expand Down Expand Up @@ -232,7 +232,7 @@ def get_next_data2(project_id, dv, page_data):
)
count_data = {key: value.count() for key, value in data.items()}
except Exception as e:
return general_error("Error fetching all projects", e)
return general_error("Error fetching all projects 3", e)

return (
jsonify(
Expand Down
28 changes: 25 additions & 3 deletions audino/backend/routes/helper_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flask import jsonify, request

from backend import app, db
from backend.models import User, Data
from backend.models import User, Data, Project,Segmentation
from sqlalchemy.sql.expression import false, true, null
from sqlalchemy import or_
"""return and log an error message that is not a specific error"""
Expand Down Expand Up @@ -47,8 +47,19 @@ def check_admin_permissions(identity, json=True):
def retrieve_database(project_id, segmentations, categories, request_user=None,
big_key=None):
data = {}
app.logger.info(project_id)
project = Project.query.get(project_id)
app.logger.info(project)
if (project.is_example):
segmentations = (
db.session.query(Segmentation.data_id)
.filter(request_user.username == Segmentation.created_by)
.distinct().subquery()
)

app.logger.info("hello?")
if ("pending" in categories):
if (request_user is not None):
if (request_user is not None and big_key is not None):
data["pending"] = (
db.session.query(Data)
.filter(or_(Data.sample != true(), Data.sample == null()))
Expand All @@ -69,7 +80,7 @@ def retrieve_database(project_id, segmentations, categories, request_user=None,
)

if ("completed" in categories):
if (request_user is not None):
if (request_user is not None and big_key is not None):
data["completed"] = (
db.session.query(Data)
.filter(or_(Data.sample != true(), Data.sample == null()))
Expand Down Expand Up @@ -128,3 +139,14 @@ def check_login(username, password, role_id):
return (jsonify(message="Please provide your role!",
type="ROLE_MISSING"), 400)
return None, None

def count_segmentations(data_point, project, request_user):
size = len(data_point.segmentations)
count = 0
if project.is_example:
for i in range (0, size):
segment = data_point.segmentations[i]
if segment.created_by == request_user.username:
count += 1
else: count = size
return count
3 changes: 3 additions & 0 deletions audino/backend/routes/project_segmentations.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ def get_segmentations_for_data(project_id, data_id):

segmentations = []
for segment in data.segmentations:
if (project.is_example and
segment.created_by != request_user.username):
break
resp = {
"segmentation_id": segment.id,
"start_time": segment.start_time,
Expand Down