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

Annotation result loading both cards and table #10

Open
wants to merge 2 commits 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
30 changes: 26 additions & 4 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, offset: int, 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,13 +83,36 @@ 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)

stmt = stmt.offset(offset).limit(page_size)
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_results_count(db: AsyncSession, task_id: UUID, user_id: UUID=None, from_date: datetime=None,
to_date: datetime=None) -> int:
try:
async with db.begin():
stmt = select(func.count()).select_from(model.AnnotationTaskResult).join(model.AnnotationTaskInstance)\
.where(model.AnnotationTaskInstance.annotation_task_id == task_id)
if user_id:
stmt = stmt.where(model.AnnotationTaskResult.user_id == user_id)
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)
count = result.scalar()

return count
except exc.SQLAlchemyError as e:
logging.error(str(e))
raise DBError(f'Failed fetching total count of task instance results 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:
Expand All @@ -112,5 +135,4 @@ async def get_task_instance_result_times(db: AsyncSession, task_id: UUID = None,
return [base_objects.SimplifiedAnnotationTaskResult.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.')

raise DBError(f'Failed fetching task instance result from database.')
26 changes: 24 additions & 2 deletions backend/semant_annotation/routes/task_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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,9 +115,23 @@ 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,

offset = (query.page - 1) * query.page_size
print(offset)
return await crud_task.get_task_instance_results(db, query.annotation_task_id, offset, query.page_size, query.user_id,
query.from_date, query.to_date)

@task_route.post("/results/count", response_model=int, tags=["Task"])
async def get_task_instance_results_count(query: base_objects.AnnotationTaskResultQuery,
user_token: TokenData = Depends(get_current_admin), db: AsyncSession = Depends(get_async_session)):
try:
count = await crud_task.get_task_instance_results_count(db, query.annotation_task_id, query.user_id,
query.from_date, query.to_date)
return count
except DBError as e:
raise HTTPException(status_code=500, detail=str(e))



@task_route.post("/result_times", response_model=List[base_objects.SimplifiedAnnotationTaskResult], tags=["Task"])
async def get_task_instance_result_times(query: base_objects.AnnotationTaskResultQuery,
Expand All @@ -121,6 +141,8 @@ async def get_task_instance_result_times(query: base_objects.AnnotationTaskResul
return await crud_task.get_task_instance_result_times(db, query.annotation_task_id, query.user_id,
query.from_date, query.to_date)



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))
if make_dir:
Expand All @@ -129,7 +151,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
4 changes: 3 additions & 1 deletion backend/semant_annotation/schemas/base_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ class Config:
class SimplifiedAnnotationTaskResult(BaseModel):
start_time: datetime
end_time: datetime
result_type: AnnotationResultType
user_id: UUID
subtasks: List[AnnotationSubtask] = []

class Config:
from_attributes = True
Expand All @@ -133,6 +133,8 @@ class Config:

class AnnotationTaskResultQuery(BaseModel):
annotation_task_id: UUID
page: int
page_size: int
from_date: date = None
to_date: date = None
user_id: UUID = None
Expand Down
21 changes: 8 additions & 13 deletions frontend/src/components/annotations/TaskInstance.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@
</template>

<script setup lang="ts">
import { defineComponent, defineProps, ref, onBeforeMount } from 'vue';
import { uid, Loading } from 'quasar';
import { ref, onBeforeMount, defineProps } from 'vue';
import { Loading } from 'quasar';
import { AnnotationTaskInstance } from 'src/models';
import { api, apiURL } from 'src/boot/axios';
import { useErrorStore } from 'src/stores/error';

const errorStore = useErrorStore();
interface Props {
taskInstanceId: string;
}

const props = defineProps<Props>();
const errorStore = useErrorStore();
const taskInstance = ref<AnnotationTaskInstance | null>(null);

defineComponent({
name: 'AnnotationPage',
});

onBeforeMount(async () => {
try {
// /api/task/task_instance_random/:task_id/:result_count
Loading.show();
taskInstance.value = await api
.get(`/task/task_instance/${props.taskInstanceId}/`)
.then((response) => response.data);
Expand All @@ -47,10 +48,4 @@ onBeforeMount(async () => {
Loading.hide();
}
});

interface Props {
taskInstanceId: string;
}

const props = defineProps<Props>();
</script>
Loading