Browse Source

Revert primary key change

pull/1550/head
Hironsan 2 years ago
parent
commit
5552da55ed
26 changed files with 77 additions and 96 deletions
  1. 19
      backend/api/migrations/0017_alter_example_id.py
  2. 2
      backend/api/models.py
  3. 8
      backend/api/tasks.py
  4. 18
      backend/api/urls.py
  5. 6
      backend/api/views/download/writer.py
  6. 2
      frontend/components/tasks/toolbar/ToolbarLaptop.vue
  7. 2
      frontend/components/tasks/toolbar/forms/FormComment.vue
  8. 12
      frontend/composables/useTeacherList.ts
  9. 4
      frontend/domain/models/comment/comment.ts
  10. 10
      frontend/domain/models/comment/commentRepository.ts
  11. 4
      frontend/domain/models/example/example.ts
  12. 8
      frontend/domain/models/example/exampleRepository.ts
  13. 12
      frontend/domain/models/tasks/annotationRepository.ts
  14. 8
      frontend/repositories/comment/apiCommentRepository.ts
  15. 8
      frontend/repositories/example/apiDocumentRepository.ts
  16. 4
      frontend/repositories/tasks/seq2seq/apiSeq2seq.ts
  17. 4
      frontend/repositories/tasks/sequenceLabeling/apiSequenceLabeling.ts
  18. 2
      frontend/repositories/tasks/textClassification/apiTextClassification.ts
  19. 8
      frontend/services/application/comment/commentApplicationService.ts
  20. 2
      frontend/services/application/comment/commentData.ts
  21. 6
      frontend/services/application/example/exampleApplicationService.ts
  22. 2
      frontend/services/application/example/exampleData.ts
  23. 6
      frontend/services/application/tasks/annotationApplicationService.ts
  24. 6
      frontend/services/application/tasks/seq2seq/seq2seqApplicationService.ts
  25. 6
      frontend/services/application/tasks/sequenceLabeling/sequenceLabelingApplicationService.ts
  26. 4
      frontend/services/application/tasks/textClassification/textClassificationApplicationService.ts

19
backend/api/migrations/0017_alter_example_id.py

@ -1,19 +0,0 @@
# Generated by Django 3.2.8 on 2021-11-02 05:47
from django.db import migrations, models
import uuid
class Migration(migrations.Migration):
dependencies = [
('api', '0016_auto_20211018_0556'),
]
operations = [
migrations.AlterField(
model_name='example',
name='id',
field=models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False),
),
]

2
backend/api/models.py

@ -150,7 +150,7 @@ class Label(models.Model):
class Example(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, db_index=True)
uuid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True, unique=True)
meta = models.JSONField(default=dict)
filename = models.FileField(default='.', max_length=1024)
project = models.ForeignKey(

8
backend/api/tasks.py

@ -63,12 +63,12 @@ class DataFactory:
def create_data(self, examples, project):
uuids = sorted(uuid.uuid4() for _ in range(len(examples)))
dataset = [
self.data_class(id=uid, project=project, **example.data)
self.data_class(uuid=uid, project=project, **example.data)
for uid, example in zip(uuids, examples)
]
data = self.data_class.objects.bulk_create(dataset)
data.sort(key=lambda example: example.id)
return data
self.data_class.objects.bulk_create(dataset)
data = self.data_class.objects.in_bulk(uuids, field_name='uuid')
return [data[uid] for uid in uuids]
def create_annotation(self, examples, ids, user, project):
mapping = {label.text: label.id for label in project.labels.all()}

18
backend/api/urls.py

@ -51,7 +51,7 @@ urlpatterns_project = [
name='example_list'
),
path(
route='examples/<uuid:example_id>',
route='examples/<int:example_id>',
view=example.ExampleDetail.as_view(),
name='example_detail'
),
@ -92,23 +92,23 @@ urlpatterns_project = [
name='doc_list'
),
path(
route='docs/<uuid:doc_id>',
route='docs/<int:doc_id>',
view=example.DocumentDetail.as_view(),
name='doc_detail'
),
path(
route='approval/<uuid:example_id>',
route='approval/<int:example_id>',
view=annotation.ApprovalAPI.as_view(),
name='approve_labels'
),
# Todo: change.
path(
route='docs/<uuid:doc_id>/annotations',
route='docs/<int:doc_id>/annotations',
view=annotation.AnnotationList.as_view(),
name='annotation_list'
),
path(
route='docs/<uuid:doc_id>/annotations/<int:annotation_id>',
route='docs/<int:doc_id>/annotations/<int:annotation_id>',
view=annotation.AnnotationDetail.as_view(),
name='annotation_detail'
),
@ -123,7 +123,7 @@ urlpatterns_project = [
name='tag_detail'
),
path(
route='examples/<uuid:example_id>/comments',
route='examples/<int:example_id>/comments',
view=comment.CommentListDoc.as_view(),
name='comment_list_doc'
),
@ -133,12 +133,12 @@ urlpatterns_project = [
name='comment_list_project'
),
path(
route='examples/<uuid:example_id>/comments/<int:comment_id>',
route='examples/<int:example_id>/comments/<int:comment_id>',
view=comment.CommentDetail.as_view(),
name='comment_detail'
),
path(
route='examples/<uuid:example_id>/states',
route='examples/<int:example_id>/states',
view=example_state.ExampleStateList.as_view(),
name='example_state_list'
),
@ -178,7 +178,7 @@ urlpatterns_project = [
name='auto_labeling_config_test'
),
path(
route='examples/<uuid:example_id>/auto-labeling',
route='examples/<int:example_id>/auto-labeling',
view=auto_labeling.AutoLabelingAnnotation.as_view(),
name='auto_labeling_annotation'
),

6
backend/api/views/download/writer.py

@ -82,7 +82,7 @@ class CsvWriter(BaseWriter):
def create_line(self, record) -> Dict:
return {
'id': str(record.id),
'id': record.id,
'data': record.data,
'label': '#'.join(record.label),
**record.metadata
@ -120,7 +120,7 @@ class JSONWriter(BaseWriter):
def create_line(self, record) -> Dict:
return {
'id': str(record.id),
'id': record.id,
'data': record.data,
'label': record.label,
**record.metadata
@ -132,7 +132,7 @@ class JSONLWriter(LineWriter):
def create_line(self, record):
return json.dumps({
'id': str(record.id),
'id': record.id,
'data': record.data,
'label': record.label,
**record.metadata

2
frontend/components/tasks/toolbar/ToolbarLaptop.vue

@ -104,7 +104,7 @@ export default Vue.extend({
props: {
docId: {
type: String,
type: Number,
required: true
},
enableAutoLabeling: {

2
frontend/components/tasks/toolbar/forms/FormComment.vue

@ -36,7 +36,7 @@ export default Vue.extend({
props: {
docId: {
type: String,
type: Number,
required: true
}
},

12
frontend/composables/useTeacherList.ts

@ -7,14 +7,14 @@ export const useTeacherList = (service: any) => {
const getTeacherList = async(
projectId: string,
exampleId: string
exampleId: number
) => {
state.teacherList = await service.list(projectId, exampleId)
}
const removeTeacher = async(
projectId: string,
exampleId: string,
exampleId: number,
teacherId: number
) => {
await service.delete(projectId, exampleId, teacherId)
@ -23,7 +23,7 @@ export const useTeacherList = (service: any) => {
const annotateLabel = async(
projectId: string,
exampleId: string,
exampleId: number,
labelId: number
) => {
await service.create(projectId, exampleId, labelId)
@ -32,7 +32,7 @@ export const useTeacherList = (service: any) => {
const clearTeacherList = async(
projectId: string,
exampleId: string
exampleId: number
) => {
await service.clear(projectId, exampleId)
await getTeacherList(projectId, exampleId)
@ -40,7 +40,7 @@ export const useTeacherList = (service: any) => {
const autoLabel = async(
projectId: string,
exampleId: string
exampleId: number
) => {
await service.autoLabel(projectId, exampleId)
await getTeacherList(projectId, exampleId)
@ -48,7 +48,7 @@ export const useTeacherList = (service: any) => {
const annotateOrRemoveLabel = async(
projectId: string,
exampleId: string,
exampleId: number,
srcKey: string
) => {
const labelId = parseInt(srcKey, 10)

4
frontend/domain/models/comment/comment.ts

@ -41,14 +41,14 @@ export class CommentItem {
public id: number,
public user: number,
public username: string,
public example: string,
public example: number,
public text: string,
public createdAt: string
) {}
static valueOf(
{ id, user, username, example, text, created_at }:
{ id: number, user: number, username: string, example: string,
{ id: number, user: number, username: string, example: number,
text: string, created_at: string }
): CommentItem {
return new CommentItem(id, user, username, example, text, created_at)

10
frontend/domain/models/comment/commentRepository.ts

@ -4,7 +4,7 @@ export interface CommentItemResponse {
id: number,
user: number,
username: string,
example: string,
example: number,
text: string,
created_at: string
}
@ -12,13 +12,13 @@ export interface CommentItemResponse {
export interface CommentRepository {
listAll(projectId: string, q: string): Promise<CommentItem[]>
list(projectId: string, docId: string): Promise<CommentItem[]>
list(projectId: string, docId: number): Promise<CommentItem[]>
create(projectId: string, docId: string, text: string): Promise<CommentItem>
create(projectId: string, docId: number, text: string): Promise<CommentItem>
update(projectId: string, docId: string, item: CommentItem): Promise<CommentItem>
update(projectId: string, docId: number, item: CommentItem): Promise<CommentItem>
delete(projectId: string, docId: string, commentId: number): Promise<void>
delete(projectId: string, docId: number, commentId: number): Promise<void>
deleteBulk(projectId: string, items: number[]): Promise<void>
}

4
frontend/domain/models/example/example.ts

@ -43,7 +43,7 @@ export class ExampleItemList {
export class ExampleItem {
constructor(
public id: string,
public id: number,
public text: string,
public meta: object,
public annotationApprover: boolean | null,
@ -55,7 +55,7 @@ export class ExampleItem {
static valueOf(
{ id, text, meta, annotation_approver, comment_count, filename, is_confirmed }:
{
id: string,
id: number,
text: string,
meta: object,
annotation_approver: boolean | null,

8
frontend/domain/models/example/exampleRepository.ts

@ -9,13 +9,13 @@ export interface ExampleRepository {
update(projectId: string, item: ExampleItem): Promise<ExampleItem>
bulkDelete(projectId: string, ids: string[]): Promise<void>
bulkDelete(projectId: string, ids: number[]): Promise<void>
deleteAll(projectId: string): Promise<void>
findById(projectId: string, exampleId: string): Promise<ExampleItem>
findById(projectId: string, exampleId: number): Promise<ExampleItem>
approve(projectId: string, docId: string, approved: boolean): Promise<void>
approve(projectId: string, docId: number, approved: boolean): Promise<void>
confirm(projectId: string, exampleId: string): Promise<void>
confirm(projectId: string, exampleId: number): Promise<void>
}

12
frontend/domain/models/tasks/annotationRepository.ts

@ -8,34 +8,34 @@ export abstract class AnnotationRepository<T extends AnnotationModel> {
readonly request = ApiService
) {}
public async list(projectId: string, docId: string): Promise<T[]> {
public async list(projectId: string, docId: number): Promise<T[]> {
const url = this.baseUrl(projectId, docId)
const response = await this.request.get(url)
const items: T[] = response.data
return items.map(item => this.model.valueOf(item))
}
public async create(projectId: string, docId: string, item: T): Promise<void> {
public async create(projectId: string, docId: number, item: T): Promise<void> {
const url = this.baseUrl(projectId, docId)
await this.request.post(url, item.toObject())
}
public async delete(projectId: string, docId: string, annotationId: number): Promise<void> {
public async delete(projectId: string, docId: number, annotationId: number): Promise<void> {
const url = this.baseUrl(projectId, docId) + `/${annotationId}`
await this.request.delete(url)
}
public async clear(projectId: string, docId: string): Promise<void> {
public async clear(projectId: string, docId: number): Promise<void> {
const url = this.baseUrl(projectId, docId)
await this.request.delete(url)
}
public async autoLabel(projectId: string, docId: string): Promise<void> {
public async autoLabel(projectId: string, docId: number): Promise<void> {
const url = `/projects/${projectId}/examples/${docId}/auto-labeling`
await this.request.post(url, {})
}
protected baseUrl(projectId: string, docId: string): string {
protected baseUrl(projectId: string, docId: number): string {
return `/projects/${projectId}/examples/${docId}/annotations`
}
}

8
frontend/repositories/comment/apiCommentRepository.ts

@ -14,28 +14,28 @@ export class APICommentRepository implements CommentRepository {
return items.map(item => CommentItem.valueOf(item))
}
async list(projectId: string, exampleId: string): Promise<CommentItem[]> {
async list(projectId: string, exampleId: number): Promise<CommentItem[]> {
const url = `/projects/${projectId}/examples/${exampleId}/comments`
const response = await this.request.get(url)
const items: CommentItemResponse[] = response.data
return items.map(item => CommentItem.valueOf(item))
}
async create(projectId: string, exampleId: string, text: string): Promise<CommentItem> {
async create(projectId: string, exampleId: number, text: string): Promise<CommentItem> {
const url = `/projects/${projectId}/examples/${exampleId}/comments`
const response = await this.request.post(url, { projectId, exampleId, text })
const responseItem: CommentItemResponse = response.data
return CommentItem.valueOf(responseItem)
}
async update(projectId: string, exampleId: string, item: CommentItem): Promise<CommentItem> {
async update(projectId: string, exampleId: number, item: CommentItem): Promise<CommentItem> {
const url = `/projects/${projectId}/examples/${exampleId}/comments/${item.id}`
const response = await this.request.put(url, item.toObject())
const responseItem: CommentItemResponse = response.data
return CommentItem.valueOf(responseItem)
}
async delete(projectId: string, exampleId: string, commentId: number): Promise<void> {
async delete(projectId: string, exampleId: number, commentId: number): Promise<void> {
const url = `/projects/${projectId}/examples/${exampleId}/comments/${commentId}`
const response = await this.request.delete(url)
}

8
frontend/repositories/example/apiDocumentRepository.ts

@ -26,7 +26,7 @@ export class APIExampleRepository implements ExampleRepository {
return ExampleItem.valueOf(response.data)
}
async bulkDelete(projectId: string, ids: string[]): Promise<void> {
async bulkDelete(projectId: string, ids: number[]): Promise<void> {
const url = `/projects/${projectId}/examples`
await this.request.delete(url, { ids })
}
@ -36,18 +36,18 @@ export class APIExampleRepository implements ExampleRepository {
await this.request.delete(url)
}
async findById(projectId: string, exampleId: string): Promise<ExampleItem> {
async findById(projectId: string, exampleId: number): Promise<ExampleItem> {
const url = `/projects/${projectId}/examples/${exampleId}`
const response = await this.request.get(url)
return ExampleItem.valueOf(response.data)
}
async approve(projectId: string, exampleId: string, approved: boolean): Promise<void> {
async approve(projectId: string, exampleId: number, approved: boolean): Promise<void> {
const url = `/projects/${projectId}/approval/${exampleId}`
await this.request.post(url, { approved })
}
async confirm(projectId: string, exampleId: string): Promise<void> {
async confirm(projectId: string, exampleId: number): Promise<void> {
const url = `/projects/${projectId}/examples/${exampleId}/states`
await this.request.post(url, {})
}

4
frontend/repositories/tasks/seq2seq/apiSeq2seq.ts

@ -7,13 +7,13 @@ export class APISeq2seqRepository extends AnnotationRepository<Seq2seqLabel> {
super(Seq2seqLabel)
}
public async update(projectId: string, docId: string, annotationId: number, text: string) {
public async update(projectId: string, docId: number, annotationId: number, text: string) {
const url = this.baseUrl(projectId, docId) + `/${annotationId}`
const payload = { text }
await this.request.patch(url, payload)
}
protected baseUrl(projectId: string, docId: string): string {
protected baseUrl(projectId: string, docId: number): string {
return `/projects/${projectId}/docs/${docId}/annotations`
}
}

4
frontend/repositories/tasks/sequenceLabeling/apiSequenceLabeling.ts

@ -7,13 +7,13 @@ export class APISequenceLabelingRepository extends AnnotationRepository<Sequence
super(SequenceLabelingLabel)
}
public async update(projectId: string, docId: string, annotationId: number, labelId: number) {
public async update(projectId: string, docId: number, annotationId: number, labelId: number) {
const url = this.baseUrl(projectId, docId) + `/${annotationId}`
const payload = { label: labelId }
await this.request.patch(url, payload)
}
protected baseUrl(projectId: string, docId: string): string {
protected baseUrl(projectId: string, docId: number): string {
return `/projects/${projectId}/docs/${docId}/annotations`
}
}

2
frontend/repositories/tasks/textClassification/apiTextClassification.ts

@ -7,7 +7,7 @@ export class APITextClassificationRepository extends AnnotationRepository<TextCl
super(TextClassificationItem)
}
protected baseUrl(projectId: string, docId: string): string {
protected baseUrl(projectId: string, docId: number): string {
return `/projects/${projectId}/docs/${docId}/annotations`
}
}

8
frontend/services/application/comment/commentApplicationService.ts

@ -12,23 +12,23 @@ export class CommentApplicationService {
return items.map(item => new CommentReadDTO(item))
}
public async list(projectId: string, docId: string): Promise<CommentReadDTO[]> {
public async list(projectId: string, docId: number): Promise<CommentReadDTO[]> {
const items = await this.repository.list(projectId, docId)
return items.map(item => new CommentReadDTO(item))
}
public create(projectId: string, docId: string, text: string): Promise<CommentItem> {
public create(projectId: string, docId: number, text: string): Promise<CommentItem> {
return this.repository.create(projectId, docId, text)
}
public update(projectId: string, docId: string, item: CommentReadDTO): Promise<CommentItem> {
public update(projectId: string, docId: number, item: CommentReadDTO): Promise<CommentItem> {
const comment = new CommentItem(
item.id, item.user, item.username, docId, item.text, item.createdAt
)
return this.repository.update(projectId, docId, comment)
}
public delete(projectId: string, docId: string, item: CommentReadDTO): Promise<void> {
public delete(projectId: string, docId: number, item: CommentReadDTO): Promise<void> {
return this.repository.delete(projectId, docId, item.id)
}

2
frontend/services/application/comment/commentData.ts

@ -5,7 +5,7 @@ export class CommentReadDTO {
id: number;
user: number;
username: string;
example: string;
example: number;
text: string;
createdAt: string;

6
frontend/services/application/example/exampleApplicationService.ts

@ -52,16 +52,16 @@ export class ExampleApplicationService {
return this.repository.bulkDelete(projectId, ids)
}
public async findById(projectId: string, exampleId: string): Promise<ExampleDTO> {
public async findById(projectId: string, exampleId: number): Promise<ExampleDTO> {
const response = await this.repository.findById(projectId, exampleId)
return new ExampleDTO(response)
}
public async approve(projectId: string, docId: string, approved: boolean): Promise<void> {
public async approve(projectId: string, docId: number, approved: boolean): Promise<void> {
await this.repository.approve(projectId, docId, approved)
}
public async confirm(projectId: string, exampleId: string): Promise<void> {
public async confirm(projectId: string, exampleId: number): Promise<void> {
await this.repository.confirm(projectId, exampleId)
}

2
frontend/services/application/example/exampleData.ts

@ -2,7 +2,7 @@ import { ExampleItem, ExampleItemList } from '~/domain/models/example/example'
export class ExampleDTO {
id: string;
id: number;
text: string;
meta: object;
annotationApprover: boolean | null;

6
frontend/services/application/tasks/annotationApplicationService.ts

@ -7,15 +7,15 @@ export class AnnotationApplicationService<T extends AnnotationModel> {
readonly repository: AnnotationRepository<T>
) {}
public async delete(projectId: string, docId: string, annotationId: number): Promise<void> {
public async delete(projectId: string, docId: number, annotationId: number): Promise<void> {
await this.repository.delete(projectId, docId, annotationId)
}
public async clear(projectId: string, docId: string): Promise<void> {
public async clear(projectId: string, docId: number): Promise<void> {
await this.repository.clear(projectId, docId)
}
public async autoLabel(projectId: string, docId: string): Promise<void> {
public async autoLabel(projectId: string, docId: number): Promise<void> {
await this.repository.autoLabel(projectId, docId)
}
}

6
frontend/services/application/tasks/seq2seq/seq2seqApplicationService.ts

@ -10,17 +10,17 @@ export class Seq2seqApplicationService extends AnnotationApplicationService<Seq2
super(new APISeq2seqRepository())
}
public async list(projectId: string, docId: string): Promise<Seq2seqDTO[]> {
public async list(projectId: string, docId: number): Promise<Seq2seqDTO[]> {
const items = await this.repository.list(projectId, docId)
return items.map(item => new Seq2seqDTO(item))
}
public async create(projectId: string, docId: string, text: string): Promise<void> {
public async create(projectId: string, docId: number, text: string): Promise<void> {
const item = new Seq2seqLabel(0, text, 0)
await this.repository.create(projectId, docId, item)
}
public async changeText(projectId: string, docId: string, annotationId: number, text: string): Promise<void> {
public async changeText(projectId: string, docId: number, annotationId: number, text: string): Promise<void> {
await this.repository.update(projectId, docId, annotationId, text)
}
}

6
frontend/services/application/tasks/sequenceLabeling/sequenceLabelingApplicationService.ts

@ -13,17 +13,17 @@ export class SequenceLabelingApplicationService extends AnnotationApplicationSer
super(new APISequenceLabelingRepository())
}
public async list(projectId: string, docId: string): Promise<SequenceLabelingDTO[]> {
public async list(projectId: string, docId: number): Promise<SequenceLabelingDTO[]> {
const items = await this.repository.list(projectId, docId)
return items.map(item => new SequenceLabelingDTO(item))
}
public async create(projectId: string, docId: string, labelId: number, startOffset: number, endOffset: number): Promise<void> {
public async create(projectId: string, docId: number, labelId: number, startOffset: number, endOffset: number): Promise<void> {
const item = new SequenceLabelingLabel(0, labelId, 0, startOffset, endOffset)
await this.repository.create(projectId, docId, item)
}
public async changeLabel(projectId: string, docId: string, annotationId: number, labelId: number): Promise<void> {
public async changeLabel(projectId: string, docId: number, annotationId: number, labelId: number): Promise<void> {
await this.repository.update(projectId, docId, annotationId, labelId)
}

4
frontend/services/application/tasks/textClassification/textClassificationApplicationService.ts

@ -4,12 +4,12 @@ import { TextClassificationItem } from '~/domain/models/tasks/textClassification
export class TextClassificationApplicationService extends AnnotationApplicationService<TextClassificationItem> {
public async list(projectId: string, docId: string): Promise<TextClassificationDTO[]> {
public async list(projectId: string, docId: number): Promise<TextClassificationDTO[]> {
const items = await this.repository.list(projectId, docId)
return items.map(item => new TextClassificationDTO(item))
}
public async create(projectId: string, docId: string, labelId: number): Promise<void> {
public async create(projectId: string, docId: number, labelId: number): Promise<void> {
const item = new TextClassificationItem(0, labelId, 0)
await this.repository.create(projectId, docId, item)
}

Loading…
Cancel
Save