Skip to content
Merged
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
30 changes: 15 additions & 15 deletions Campaign/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,15 @@ def campaign_status_esa(campaign) -> str:
"""
out_str += f"<h1>{campaign.campaignName}</h1>\n"
out_str += "<table>\n"
out_str += "<tr>" + "".join(
f"<th>{x}</th>" for x in ["Username", "Progress", "First Modified", "Last Modified", "Time (Last-First)", "Time (Real)"]
) + "</tr>\n"

out_str += """<tr>
<th>Username</th>
<th>Progress</th>
<th>First Modified</th>
<th>Last Modified</th>
<th style="cursor: pointer" title="Very coarse upper bound estimate between the last and the first interaction with the system.">Time (Coarse ❔)</th>
<th style="cursor: pointer" title="Sum of times between any two interactions that are not longer than 10 minutes.">Time (Real ❔)</th>
</tr>\n
"""
for team in campaign.teams.all():
for user in team.members.all():
if user.is_staff:
Expand Down Expand Up @@ -298,6 +303,7 @@ def campaign_status_esa(campaign) -> str:
_data = DirectAssessmentDocumentResult.objects.filter(
createdBy=user, completed=True, task__campaign=campaign.id
)
_data_uniq_len = len({item.id for item in _data})

# If no data, show 0 progress or show that no task is assigned
if not _data:
Expand Down Expand Up @@ -331,11 +337,11 @@ def campaign_status_esa(campaign) -> str:
continue

total_count = task.items.count()
if total_count == len(_data):
if total_count == _data_uniq_len:
out_str += f"<td>{user.username} ✅</td>"
else:
out_str += f"<td>{user.username} 🛠️</td>"
out_str += f"<td>{len(_data)}/{total_count} ({len(_data) / total_count:.0%})</td>"
out_str += f"<td>{_data_uniq_len}/{total_count} ({_data_uniq_len / total_count:.0%})</td>"
first_modified = min([x.start_time for x in _data])
last_modified = max([x.end_time for x in _data])

Expand All @@ -351,15 +357,9 @@ def campaign_status_esa(campaign) -> str:
annotation_time_upper = f'{int(floor(annotation_time_upper / 3600)):0>2d}h {int(floor((annotation_time_upper % 3600) / 60)):0>2d}m'
out_str += f"<td>{annotation_time_upper}</td>"

times = collections.defaultdict(list)
for item in _data:
times[(item.item.documentID, item.item.targetID)].append((item.start_time, item.end_time))
times = [
(min([x[0] for x in doc_v]), max([x[1] for x in doc_v]))
for doc, doc_v in times.items()
]

annotation_time = sum([b-a for a, b in times])
# consider time that's in any action within 10 minutes
times = sorted([item.start_time for item in _data] + [item.end_time for item in _data])
annotation_time = sum([b-a for a, b in zip(times, times[1:]) if (b-a) < 10*60])
annotation_time = f'{int(floor(annotation_time / 3600)):0>2d}h {int(floor((annotation_time % 3600) / 60)):0>2d}m'

out_str += f"<td>{annotation_time}</td>"
Expand Down
24 changes: 7 additions & 17 deletions EvalData/models/direct_assessment_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,35 +599,25 @@ def get_hit_status_for_user(cls, user):
@classmethod
def get_time_for_user(cls, user):
results = cls.objects.filter(createdBy=user, activated=False, completed=True)
campaign_opts = result.task.campaign.campaignOptions.lower().split(";")
is_esa_or_mqm = any(
[
"esa" in result.task.campaign.campaignOptions.lower().split(";")
or "mqm" in result.task.campaign.campaignOptions.lower().split(";")
"esa" in campaign_opts or "mqm" in campaign_opts
for result in results
]
)

if is_esa_or_mqm:
# for ESA or MQM, do minimum and maximum from each doc
import collections

timestamps = collections.defaultdict(list)
for result in results:
timestamps[
result.item.documentID + " ||| " + result.item.targetID
].append((result.start_time, result.end_time))

# timestamps are document-level now, but that does not change anything later on
timestamps = [
(min([x[0] for x in doc_v]), max([x[1] for x in doc_v]))
for doc, doc_v in timestamps.items()
]
# consider time that's in any action within 10 minutes
times = sorted([item.start_time for item in results] + [item.end_time for item in results])
annotation_time = sum([b-a for a, b in zip(times, times[1:]) if (b-a) < 10*60])
return seconds_to_timedelta(annotation_time)
else:
timestamps = []
for result in results:
timestamps.append((result.start_time, result.end_time))

return seconds_to_timedelta(_compute_user_total_annotation_time(timestamps))
return seconds_to_timedelta(_compute_user_total_annotation_time(timestamps))

@classmethod
def get_system_annotations(cls):
Expand Down
Loading