Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
29a8af2
init
Sean1572 Nov 12, 2021
e7c4688
Fixed piha and pyrenote merger page
Sean1572 Nov 21, 2021
d353b8f
Working on rec system
Sean1572 Nov 21, 2021
9b40bf0
Current code that works with a single annotator
Sean1572 Dec 13, 2021
f8dcff7
Fixed small bugs with second and third tester
Sean1572 Dec 14, 2021
62b7236
Added feature that only shows annotations made by you
Sean1572 Dec 14, 2021
e08c379
Display clips that only the users annotated for IOU
Sean1572 Dec 16, 2021
80469bd
Update piha.py
Sean1572 Dec 17, 2021
22ba703
Added ability determine most recent clip
Sean1572 Dec 20, 2021
9c867e4
Added Threshold, Max User Limit, and debug view on data
Sean1572 Dec 20, 2021
55e5cfe
show previous values when editing project
Sean1572 Dec 20, 2021
a7ca1d3
Added confidence and retirement status to csv
Sean1572 Dec 20, 2021
3966b0e
Added see what clips are retired from data portal
Sean1572 Dec 20, 2021
5847517
Block retired clips from view
Sean1572 Dec 20, 2021
2a49956
Fixed bugs with normal use
Sean1572 Dec 20, 2021
6f54e11
Merge branch 'main' into clip-retirement
Sean1572 Dec 20, 2021
413a95b
bugs and made it easier to run confidence
Sean1572 Jan 6, 2022
b9c1311
Changed confidence score from precision to global Iou
Sean1572 Jan 7, 2022
1790f6f
bug-proofed dataframes and added mutliple labels
Sean1572 Jan 12, 2022
de69281
Updated TODO messages
Sean1572 Jan 12, 2022
11f2810
Update piha.py
Sean1572 Jan 13, 2022
9d81308
Merge branch 'main' into clip-retirement
Sean1572 May 2, 2022
143bf8d
Replaced IOU with Pairwise (#262)
Sean1572 May 2, 2022
b081796
Error Handler for confidence
Sean1572 May 12, 2022
967ce1f
Fixed No Relevant Audio Bug
Sean1572 May 23, 2022
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"python.linting.pycodestyleEnabled": false,
"python.linting.enabled": true,
"python.linting.enabled": false,
"python.linting.pylintEnabled": true
}
51 changes: 50 additions & 1 deletion audino/backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,41 @@ class Data(db.Model):

confident_check = db.Column("confident_check", db.Boolean(), default=False)

confidence = db.Column("confidence", db.Float(), default=0.0, nullable=False)

users_reviewed = db.Column("users_reviewed", db.JSON(), nullable=False, default={})
num_reviewed = db.Column("num_reviewed", db.Integer(), nullable=False, default=0)

iou_matrix = db.Column("iou_matrix", db.String(5000), nullable=False, default="")

def update_marked_review(self, marked_review):
self.is_marked_for_review = marked_review

def set_iou_matrix(self, iou_matrix):
self.iou_matrix = iou_matrix

def set_segmentations(self, segmentations):
self.segmentations = segmentations

def set_confident_check(self, confident_check):
self.confident_check = confident_check

def set_confidence(self, confidence):
if (self.users_reviewed is not None):
if (len(self.users_reviewed) > 1): ##TODO Deterimine how to set this
self.confidence = confidence

def set_previous_users(self, user):
if (self.users_reviewed is None):
self.users_reviewed = {}
test = self.users_reviewed
test[user] = user
self.users_reviewed = test
self.num_reviewed = len(test)

def get_previous_users(self):
return self.users_reviewed

def to_dict(self):
return {
"original_filename": self.original_filename,
Expand All @@ -123,6 +149,7 @@ def to_dict(self):
"sampling_rate": self.sampling_rate,
"clip_length": self.clip_length,
"confident_check": self.confident_check,
"confidence": self.confidence,
}


Expand Down Expand Up @@ -256,6 +283,16 @@ class Project(db.Model):
"is_example", db.Boolean(), nullable=True, default=False
)

is_iou = db.Column(
"is_iou", db.Boolean(), nullable=True, default=False
)

threshold = db.Column(
"threshold", db.Float(), default=0.75, nullable=False
)
max_users = db.Column(
"max_users", db.Integer(), default=5, nullable=False
)
is_deleted = db.Column(
"is_deleted",
db.Boolean(),
Expand All @@ -272,7 +309,12 @@ class Project(db.Model):

def set_is_example(self, is_example):
self.is_example = is_example
app.logger.info(self.is_example)
def set_is_iou(self, is_iou, threshold, max_users):
self.is_iou = is_iou
if (threshold is not None):
self.threshold = threshold / 100
if (max_users is not None):
self.max_users = max_users

def set_name(self, newUsername):
self.name = newUsername
Expand Down Expand Up @@ -354,6 +396,12 @@ class Segmentation(db.Model):
back_populates="segmentations",
)

counted = db.Column("counted", db.Integer(), default=0)

def set_counted(self, counted):
self.counted = counted


def set_start_time(self, start_time):
self.start_time = start_time

Expand Down Expand Up @@ -395,6 +443,7 @@ def to_dict(self):
"last_modified": self.last_modified,
"last_modified_by": self.last_modified_by["data"],
"time_spent": self.time_spent,
"counted": self.counted
}


Expand Down
2 changes: 2 additions & 0 deletions audino/backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ WTForms==2.2.1
flask-jwt-extended==3.25.0
flask-redis==0.4.0
mutagen==1.45.1
pandas==1.3.4
scipy==1.7.2
28 changes: 15 additions & 13 deletions audino/backend/routes/JsonLabelsToCsv.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,36 @@ def JsonToText(data):
csv = []
text = write_row(text, ['IN FILE', 'CLIP LENGTH', 'OFFSET', 'DURATION',
'MAX FREQ', 'MIN FREQ', 'SAMPLE RATE', 'MANUAL ID'
'TIME_SPENT', 'LAST MOD BY', 'LAST MOD DATE', 'LAST MOD TIME'])
'TIME_SPENT', 'LAST MOD BY', 'CONFIDENCE', 'RETIRED', 'COUNTED',]) #Added 3 columns
csv.append(['IN FILE', 'CLIP LENGTH', 'OFFSET', 'DURATION', 'MAX FREQ',
'MIN FREQ', 'SAMPLE RATE', 'MANUAL ID', 'TIME_SPENT',
'LAST MOD BY', 'LAST MOD DATE', 'LAST MOD TIME'])
'LAST MOD BY', 'CONFIDENCE', 'RETIRED', 'COUNTED',])
for audio in data:
sampling_rate = audio['sampling_rate']
clip_length = audio['clip_length']
original_filename = audio['original_filename']
confidence = audio['confidence']
retired = audio['retired']
segments = audio['segmentations']

app.logger.info(audio)
for region in segments:
end = region['end_time']
start = region['start_time']
max_freq = region['max_freq']
min_freq = region['min_freq']
time_spent = region['time_spent']
counted = region['counted']
last_mod = datetime_json_compare(region['last_modified_by'])
if len(region['annotations']) == 0:
label = "No class of interest"
text = write_row(text, [original_filename, clip_length, start,
round((end-start), 4), max_freq, min_freq,
sampling_rate, label,

time_spent, last_mod])
time_spent, last_mod, confidence, retired, counted])
csv.append([original_filename, clip_length, start,
round((end-start), 4), max_freq, min_freq,
sampling_rate, label,
time_spent, last_mod])
time_spent, last_mod, confidence, retired, counted])
else:
for labelCate in region['annotations'].values():
#print(labelCate)
Expand All @@ -92,22 +94,22 @@ def JsonToText(data):
round((end-start), 4),
max_freq, min_freq,
sampling_rate, label,
time_spent, last_mod])
time_spent, last_mod, confidence, retired, counted])
csv.append([original_filename, clip_length, start,
round((end-start), 4),
max_freq, min_freq, sampling_rate,
strip_nl(label), time_spent, last_mod])
label, time_spent, last_mod, confidence, retired, counted])
except Exception as e:
label = values['value']
text = write_row(text, [original_filename, clip_length,
start, round((end-start), 4),
max_freq, min_freq,
sampling_rate, label,
time_spent, last_mod])
time_spent, last_mod, confidence, retired, counted])
csv.append([original_filename, clip_length, start,
round((end-start), 4), max_freq, min_freq,
sampling_rate, strip_nl(label), time_spent,
last_mod])
sampling_rate, label, time_spent,
last_mod, confidence, retired, counted])
return text, csv


Expand Down Expand Up @@ -176,8 +178,8 @@ def datetime_json_compare(datetime_dir):
date = datetime_dir[user]
datetime_object = datetime.strptime(date, "%m/%d/%Y, %H:%M:%S")
if (latest_date is None or datetime_object > latest_date):
latest_date = datetime_object
latest_user = user + ", " + date
latest_date = datetime_object.strftime("%m/%d/%Y-%H:%M:%S")
latest_user = user + " " + latest_date
return latest_user

def strip_nl(str):
Expand Down
4 changes: 3 additions & 1 deletion audino/backend/routes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@
from .audios import send_audio_file

from .next_clip import (
getNextReccomendedData, getNextClip, get_next_data_unknown
getNextClip, get_next_data_unknown
)

from .piha import (update_confidence_api)
15 changes: 12 additions & 3 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, retrieve_database_iou
from .logger import post_log_msg
from . import api

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

categories = ["pending", "completed", "marked_review", "all"]
data = retrieve_database(project_id, segmentations, categories)

data = {}
if(project.is_iou):
data = retrieve_database_iou(project_id, segmentations, request_user, identity["username"])
else:
data = retrieve_database(project_id, segmentations, categories, request_user)
app.logger.info(data)
paginate_data = data[active].paginate(page, 10, False)

Expand All @@ -78,7 +83,9 @@ def fetch_data_for_project(project_id):
"number_of_segmentations": len(data_point.segmentations),
"sampling_rate": data_point.sampling_rate,
"clip_length": data_point.clip_length,
"sample": data_point.sample
"sample": data_point.sample,
"confidence": data_point.confidence,
"num_users_viewed": data_point.num_reviewed
}
for data_point in paginate_data.items
]
Expand Down Expand Up @@ -152,6 +159,7 @@ def get_next_data(project_id, data_value):
"number_of_segmentations": len(data_point.segmentations),
"sampling_rate": data_point.sampling_rate,
"clip_length": data_point.clip_length,
"confidence": data_point.confidence,
}
for data_point in paginate_data.items
]
Expand Down Expand Up @@ -227,6 +235,7 @@ def get_next_data2(project_id, dv, page_data):
"number_of_segmentations": len(data_point.segmentations),
"sampling_rate": data_point.sampling_rate,
"clip_length": data_point.clip_length,
"confidence": data_point.confidence,
}
for data_point in paginate_data.items
]
Expand Down
5 changes: 3 additions & 2 deletions audino/backend/routes/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def generate_segmentation(
created_by=username,
max_freq=max_freq,
min_freq=min_freq,
counted=False,
)
else:
# segmentation updated for existing data
Expand All @@ -76,8 +77,8 @@ def generate_segmentation(
segmentation.set_max_freq(max_freq)

segmentation.append_modifers(username)
app.logger.info(segmentation.last_modified_by)

app.logger.info(segmentation.counted)
app.logger.info("LOOOOOOOOOOOOOOOOOK HERE")
values = []

for label_name, val in annotations.items():
Expand Down
92 changes: 90 additions & 2 deletions audino/backend/routes/helper_functions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from flask import jsonify, request

from backend import app, db
from backend.models import User, Data
from backend.models import User, Data, Project
from sqlalchemy.sql.expression import false, true, null
from sqlalchemy import or_
from sqlalchemy import or_, and_, not_
"""return and log an error message that is not a specific error"""


Expand Down Expand Up @@ -46,6 +46,9 @@ def check_admin_permissions(identity, json=True):

def retrieve_database(project_id, segmentations, categories, request_user=None,
big_key=None):
project = Project.query.get(project_id)
app.logger.info(project.is_iou)

data = {}
if ("pending" in categories):
if (request_user is not None):
Expand Down Expand Up @@ -109,6 +112,75 @@ def retrieve_database(project_id, segmentations, categories, request_user=None,
app.logger.info(data)
return data

def check_entry(data, big_key):
app.logger.info(data.users_reviewed)
if (data.users_reviewed[big_key] not in None):
return true()
else:
return false()

def retrieve_database_iou(project_id, segmentations, request_user, big_key):
project = Project.query.get(project_id)
THRESHOLD = project.threshold
MAX_USERS = project.max_users
app.logger.info(MAX_USERS)
#get all non annotated data
data = {}
app.logger.info(request_user.username)
app.logger.info(big_key)
data["pending"] = (
db.session.query(Data)
.filter(or_(Data.sample != true(), Data.sample == null()))
.filter(or_(request_user.id == Data.assigned_user_id[big_key], Data.assigned_user_id[big_key] == null()))
.filter(Data.project_id == project_id)
.filter(or_(Data.id.notin_(segmentations), Data.users_reviewed[big_key] == null()))
.filter(Data.confidence < THRESHOLD)
.filter(Data.num_reviewed < MAX_USERS)
.distinct()
.order_by(Data.last_modified.desc())
)

data["completed"] = (
db.session.query(Data)
.filter(or_(Data.sample != true(), Data.sample == null()))
.filter(or_(request_user.id == Data.assigned_user_id[big_key], Data.assigned_user_id[big_key] == null()))
.filter(Data.project_id == project_id)
.filter(or_(
Data.num_reviewed >= MAX_USERS,
Data.confidence >= THRESHOLD,
and_(Data.id.in_(segmentations),
Data.users_reviewed[big_key] != null(),
request_user.username == Data.users_reviewed[big_key]))
)
.distinct()
.order_by(Data.last_modified.desc())
)
data["marked_review"] = (
db.session.query(Data)
.filter(Data.project_id == project_id)
.filter(Data.is_marked_for_review == true())
.filter(or_(Data.sample != true(), Data.sample == null()))
.order_by(Data.last_modified.desc())
)

data["retired"] = (
db.session.query(Data)
.filter(or_(Data.sample != true(), Data.sample == null()))
.filter(or_(request_user.id == Data.assigned_user_id[big_key], Data.assigned_user_id[big_key] == null()))
.filter(Data.project_id == project_id)
.filter(or_(
Data.num_reviewed >= MAX_USERS,
Data.confidence >= THRESHOLD,
))
.distinct()
.order_by(Data.last_modified.desc())
)
data["all"] = Data.query.filter_by(
project_id=project_id,
sample=False
).order_by(Data.last_modified.desc())

return data

def check_login(username, password, role_id):
if not username:
Expand All @@ -128,3 +200,19 @@ def check_login(username, password, role_id):
return (jsonify(message="Please provide your role!",
type="ROLE_MISSING"), 400)
return None, None

def remove_previously_viewed_clips(data_pts, user):
new_data_pts = []
if (data_pts is not None and user is not None):
for data in data_pts:
try:
previous_users = data.users_reviewed.keys()
app.logger.info(user)
app.logger.info(previous_users)
if (len(data.users_reviewed) == 0 or not (user in previous_users)):
new_data_pts.append(data)
except:
app.logger.info("fail")
app.logger.info(data)
continue
return new_data_pts
Loading