Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statistics table … #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
90 changes: 45 additions & 45 deletions backend/scripts/stats.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

import requests
#import requests
import argparse
import json
import sys
Expand Down Expand Up @@ -182,47 +182,47 @@ def get_final_list(users, tasks, start_date, end_date, keypress_time, task_resul

return list


def main():
args = parse_args()
keypress_time = int(args.keypress_time)

login_url = urljoin(args.api_url, 'token')
user_url = urljoin(args.api_url, 'user/')
task_url = urljoin(args.api_url, 'task/task')
task_result_url = urljoin(args.api_url, 'task/results')
time_tracking_url = urljoin(args.api_url, 'time_tracking/time_tracking')

session = requests.Session()

session = get_session(login_url, session, args.login, args.password)

users = query_api(user_url, session, None)

tasks = query_api(task_url, session, None)
tasks = [item for item in tasks if item['active']]

final_list = get_final_list(users, tasks, args.start_date, args.end_date, keypress_time, task_result_url, time_tracking_url, session)
field_names = []
field_names_dict = max(final_list, key=len)
for key in field_names_dict:
field_names.append(key)

with open(args.output + '.jsonl', 'w') as csvfile:
for item in final_list:
csvfile.write(json.dumps(item) + '\n')

with open(args.output + '.csv', 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=field_names)
writer.writeheader()
writer.writerows(final_list)

if args.export_blocks:
time_blocks_list = get_time_blocks_list(session, users, time_tracking_url, args.start_date, args.end_date)
with open(args.output + '_time_blocks.jsonl', 'w') as jsonfile:
for item in time_blocks_list:
jsonfile.write(json.dumps(item) + '\n')

if __name__ == '__main__':
main()
#def main():
# args = parse_args()
# keypress_time = int(args.keypress_time)
#
# login_url = urljoin(args.api_url, 'token')
# user_url = urljoin(args.api_url, 'user/')
# task_url = urljoin(args.api_url, 'task/task')
# task_result_url = urljoin(args.api_url, 'task/results')
# time_tracking_url = urljoin(args.api_url, 'time_tracking/time_tracking')
#
# session = requests.Session()
#
# session = get_session(login_url, session, args.login, args.password)
#
# users = query_api(user_url, session, None)
#
# tasks = query_api(task_url, session, None)
# tasks = [item for item in tasks if item['active']]
#
# final_list = get_final_list(users, tasks, args.start_date, args.end_date, keypress_time, task_result_url, time_tracking_url, session)
# field_names = []
# field_names_dict = max(final_list, key=len)
# for key in field_names_dict:
# field_names.append(key)
#
# with open(args.output + '.jsonl', 'w') as csvfile:
# for item in final_list:
# csvfile.write(json.dumps(item) + '\n')
#
# with open(args.output + '.csv', 'w') as csvfile:
# writer = csv.DictWriter(csvfile, fieldnames=field_names)
# writer.writeheader()
# writer.writerows(final_list)
#
# if args.export_blocks:
# time_blocks_list = get_time_blocks_list(session, users, time_tracking_url, args.start_date, args.end_date)
# with open(args.output + '_time_blocks.jsonl', 'w') as jsonfile:
# for item in time_blocks_list:
# jsonfile.write(json.dumps(item) + '\n')
#
#
#if __name__ == '__main__':
# main()
#
20 changes: 15 additions & 5 deletions backend/semant_annotation/db/crud_task.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy import exc, select, or_, update
from sqlalchemy import exc, select, or_, update, func
from .database import DBError
from . import model
from semant_annotation.schemas import base_objects
Expand Down Expand Up @@ -71,7 +71,7 @@ async def get_task_instance_random(db: AsyncSession, task_id: UUID, result_count
raise DBError(f'Failed fetching task instance from database.')


async def get_task_instance_results(db: AsyncSession, task_id: UUID, user_id: UUID=None, from_date: datetime=None,
async def get_task_instance_results(db: AsyncSession, task_id: UUID, page_size: int, user_id: UUID=None, from_date: datetime=None,
to_date: datetime=None) -> base_objects.AnnotationTaskResult:
try:
async with db.begin():
Expand All @@ -83,30 +83,40 @@ async def get_task_instance_results(db: AsyncSession, task_id: UUID, user_id: UU
stmt = stmt.where(model.AnnotationTaskResult.created_date >= from_date)
if to_date:
stmt = stmt.where(model.AnnotationTaskResult.created_date <= to_date)

result = await db.execute(stmt)
db_task_instance_result = result.scalars().all()

return [base_objects.AnnotationTaskResult.model_validate(db_task_instance_result) for db_task_instance_result in db_task_instance_result]
except exc.SQLAlchemyError as e:
logging.error(str(e))
raise DBError(f'Failed fetching task instance result from database.')


async def get_task_instance_result_times(db: AsyncSession, task_id: UUID = None, user_id: UUID=None, from_date: datetime=None,
to_date: datetime=None) -> base_objects.SimplifiedAnnotationTaskResult:
to_date: datetime=None, result_type: base_objects.AnnotationResultType=None) -> base_objects.SimplifiedAnnotationTaskResult:
try:
async with db.begin():
stmt = select(model.AnnotationTaskResult.start_time,
stmt = select(model.AnnotationTaskInstance.annotation_task_id, # Include annotation_task_id in the select clause
model.AnnotationTaskResult.start_time,
model.AnnotationTaskResult.end_time,
model.AnnotationTaskResult.result_type,
model.AnnotationTaskResult.user_id)


if task_id:
stmt = stmt.join(model.AnnotationTaskInstance).where(model.AnnotationTaskInstance.annotation_task_id == task_id)
else:
stmt = stmt.join(model.AnnotationTaskInstance)

if user_id:
stmt = stmt.where(model.AnnotationTaskResult.user_id == user_id)
if result_type:
stmt = stmt.where(model.AnnotationTaskResult.result_type == result_type)
if from_date:
stmt = stmt.where(model.AnnotationTaskResult.created_date >= from_date)
if to_date:
stmt = stmt.where(model.AnnotationTaskResult.created_date <= to_date)

result = await db.execute(stmt.distinct())
db_task_instance_result = result.all()
return [base_objects.SimplifiedAnnotationTaskResult.model_validate(db_task_instance_result) for db_task_instance_result in db_task_instance_result]
Expand Down
24 changes: 18 additions & 6 deletions backend/semant_annotation/routes/task_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from fastapi.responses import FileResponse

from sqlalchemy.ext.asyncio import AsyncSession
from scripts.stats import get_final_list

from . import task_route

Expand Down Expand Up @@ -53,6 +54,12 @@ async def delete_task(task_id: UUID,
await crud_general.delete_obj(db, task_id, model.AnnotationTask)


@task_route.get("/types/", response_model=List[base_objects.AnnotationResultType], tags=["Task"])
async def get_types(
user_token: TokenData = Depends(get_current_user), db: AsyncSession = Depends(get_async_session)):
return [type_.value for type_ in base_objects.AnnotationResultType]


@task_route.post("/subtask", tags=["Task"])
async def new_subtask(subtask: base_objects.AnnotationSubtaskUpdate,
user_token: TokenData = Depends(get_current_admin), db: AsyncSession = Depends(get_async_session)):
Expand Down Expand Up @@ -109,17 +116,22 @@ async def update_task_instance_result(task_instance_result: base_objects.Annotat
@task_route.post("/results", response_model=List[base_objects.AnnotationTaskResult], tags=["Task"])
async def get_task_instance_result(query: base_objects.AnnotationTaskResultQuery,
user_token: TokenData = Depends(get_current_admin), db: AsyncSession = Depends(get_async_session)):
return await crud_task.get_task_instance_results(db, query.annotation_task_id, query.user_id,

return await crud_task.get_task_instance_results(db, query.annotation_task_id, query.page_size, query.user_id,
query.from_date, query.to_date)


@task_route.post("/result_times", response_model=List[base_objects.SimplifiedAnnotationTaskResult], tags=["Task"])
async def get_task_instance_result_times(query: base_objects.AnnotationTaskResultQuery,
async def get_task_instance_result_times(query: base_objects.AnnotationTaskResultQueryStats,
user_token: TokenData = Depends(get_current_user), db: AsyncSession = Depends(get_async_session)):

if not user_token.trusted_user and user_token.user_id != query.user_id:
raise HTTPException(status_code=403, detail="You can only access your own statistics.")
return await crud_task.get_task_instance_result_times(db, query.annotation_task_id, query.user_id,
query.from_date, query.to_date)

result = await crud_task.get_task_instance_result_times(db, query.annotation_task_id, query.user_id,
query.from_date, query.to_date, query.result_type)
return result



async def get_image_path(image_id: UUID, task_id: UUID, make_dir: bool = True):
path = os.path.join(config.UPLOADED_IMAGES_FOLDER, str(task_id))
Expand All @@ -129,7 +141,7 @@ async def get_image_path(image_id: UUID, task_id: UUID, make_dir: bool = True):


@task_route.get("/image/{task_id}/{image_id}", tags=["Task"])
async def get_image(task_id: UUID, image_id: UUID,
async def get_image(task_id: UUID, image_id: UUID,
user_token: TokenData = Depends(get_current_user)):
path = await get_image_path(image_id=image_id, task_id=task_id, make_dir=False)
if not os.path.exists(path):
Expand Down
9 changes: 9 additions & 0 deletions backend/semant_annotation/schemas/base_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class SimplifiedAnnotationTaskResult(BaseModel):
end_time: datetime
result_type: AnnotationResultType
user_id: UUID
annotation_task_id: UUID

class Config:
from_attributes = True
Expand Down Expand Up @@ -138,6 +139,14 @@ class AnnotationTaskResultQuery(BaseModel):
user_id: UUID = None


class AnnotationTaskResultQueryStats(BaseModel):
annotation_task_id: UUID = None
from_date: date = None
to_date: date = None
user_id: UUID = None
result_type: AnnotationResultType = None


class TimeTrackingItemNew(BaseModel):
id: UUID
user_id: UUID
Expand Down
43 changes: 43 additions & 0 deletions frontend/src/css/app.scss
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
// app global css in SCSS form

.my-sticky-header-column-table {
height: 500px;
overflow: auto;

td:first-child {
background-color: $primary;
color: white;
z-index: 1;
position: sticky;
left: 0;
}

tr th {
position: sticky;
z-index: 2;
background: $primary;
color: white;
top: 0;
}

tr:first-child th:first-child {
z-index: 3;
}

th:first-child {
position: sticky;
left: 0;
z-index: 3;
}

tr:nth-child(2) th {
top: 48px;
}

tr:first-child {
background-color: #d3d3d3;
}
}

.q-page {
overflow: auto;
}
2 changes: 1 addition & 1 deletion frontend/src/layouts/MainLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
:class="{ 'drawer-item-selected': currentRoute.startsWith('/annotation_statistics') }"
v-ripple clickable>
<q-item-section avatar>
<q-icon name="fa-solid fa-book" />
<q-icon name="fa-solid fa-chart-simple"></q-icon>
</q-item-section>
<q-item-section>
<q-item-label>Annotation statistics</q-item-label>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export interface User {
disabled: boolean
}


export enum AnnotationResultType {
NEW = 'new',
CORRECTION = 'correction',
REJECTED = 'rejected'
}

export interface UserWithPassword extends User {
password: string
}
Expand Down Expand Up @@ -83,6 +90,7 @@ export class SimplifiedAnnotationTaskResult{
result_type = ''
start_time = ''
end_time = ''
annotation_task_id = ''
}


Expand Down
Loading