Skip to content

Commit

Permalink
Merge pull request #194 from CogStack/meta-task-improvements
Browse files Browse the repository at this point in the history
CU-8694ukrnk: MetaTask fixes and improvements
  • Loading branch information
tomolopolis authored Jul 19, 2024
2 parents 39d3c8f + facf485 commit e4858fc
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
18 changes: 16 additions & 2 deletions webapp/api/api/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def upload_projects_export(medcat_export: Dict):
p.dataset = ds_mod
p.save()

# create django ORM model instances that are referenced in the upload if they don't exist.
for u in unavailable_users:
logger.warning(f'Username: {u} - not present in this trainer deployment.')
for ent_lab in ent_labels:
Expand All @@ -119,6 +120,17 @@ def upload_projects_export(medcat_export: Dict):
m_task = MetaTask()
m_task.name = task
m_task.save()
# create the MetaTask Values.
for task_val in meta_tasks[task]:
if MetaTaskValue.objects.filter(name=task_val).first() is None:
mt_value = MetaTaskValue()
mt_value.name = task_val
mt_value.save()
m_task = MetaTask.objects.filter(name=task).first()
curr_vals = m_task.values.all()
task_vals = [MetaTaskValue.objects.filter(name=m_t).first() for m_t in meta_tasks[task]]
m_task.values.set(set(list(curr_vals) + task_vals))

for rel in rels:
if Relation.objects.filter(label=rel).first() is None:
r = Relation()
Expand Down Expand Up @@ -165,7 +177,8 @@ def upload_projects_export(medcat_export: Dict):
for task_name, meta_anno in anno['meta_anns'].items():
m_a = MetaAnnotation()
m_a.annotated_entity = a
m_a = MetaTask.objects.get(name=task_name)
# there will be at least one or more of these available.
m_a = MetaTask.objects.filter(name=task_name).first()
m_a.validated = meta_anno['validated']
m_a.save()
# missing acc on the model
Expand All @@ -176,7 +189,8 @@ def upload_projects_export(medcat_export: Dict):
er.user = available_users[relation['user']]
er.project = p
er.document = doc_mod
er.relation = Relation.objects.get(label=relation['relation'])
# there will be at least one or more of these available.
er.relation = Relation.objects.filter(label=relation['relation']).first()
er.validated = er.validated
# link relations with start and end anno ents
er.start_entity = anno_to_doc_ind[relation['start_entity_start_idx']]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 5.0.6 on 2024-07-10 16:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0079_merge_20240701_2259'),
]

operations = [
migrations.AlterModelOptions(
name='metatask',
options={'ordering': ['ordering', 'name']},
),
migrations.AlterModelOptions(
name='metataskvalue',
options={'ordering': ['ordering', 'name']},
),
migrations.AddField(
model_name='metatask',
name='ordering',
field=models.PositiveSmallIntegerField(default=0, help_text='the order in which the meta task will appear in the Trainer Annotation project screen'),
),
migrations.AddField(
model_name='metataskvalue',
name='ordering',
field=models.PositiveSmallIntegerField(default=0, help_text='the order in which the meta task value will appear in the Trainer Annotation project screen'),
),
]
18 changes: 18 additions & 0 deletions webapp/api/api/migrations/0081_alter_metatask_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2024-07-10 16:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0080_alter_metatask_options_alter_metataskvalue_options_and_more'),
]

operations = [
migrations.AlterField(
model_name='metatask',
name='name',
field=models.CharField(max_length=150, unique=True),
),
]
12 changes: 11 additions & 1 deletion webapp/api/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,16 +336,26 @@ def __str__(self):

class MetaTaskValue(models.Model):
name = models.CharField(max_length=150)
ordering = models.PositiveSmallIntegerField(help_text="the order in which the meta task value will appear in "
"the Trainer Annotation project screen", default=0)

class Meta:
ordering = ['ordering', 'name']

def __str__(self):
return str(self.name)


class MetaTask(models.Model):
name = models.CharField(max_length=150)
name = models.CharField(max_length=150, unique=True)
values = models.ManyToManyField(MetaTaskValue, related_name='values')
default = models.ForeignKey('MetaTaskValue', null=True, blank=True, on_delete=models.SET_NULL)
description = models.TextField(default="", blank=True)
ordering = models.PositiveSmallIntegerField(help_text="the order in which the meta task will appear in "
"the Trainer Annotation project screen", default=0)

class Meta:
ordering = ['ordering', 'name']

def __str__(self):
return str(self.name)
Expand Down

0 comments on commit e4858fc

Please sign in to comment.