From 870094048c2e60870e4a2afea90041cfc4407676 Mon Sep 17 00:00:00 2001 From: Nikita Manovich Date: Fri, 25 Jan 2019 12:18:30 +0300 Subject: [PATCH] Added segment_size field to Task model. --- .../migrations/0015_task_segment_size.py | 32 +++++++++++++++++++ cvat/apps/engine/models.py | 1 + cvat/apps/engine/task.py | 1 + 3 files changed, 34 insertions(+) create mode 100644 cvat/apps/engine/migrations/0015_task_segment_size.py diff --git a/cvat/apps/engine/migrations/0015_task_segment_size.py b/cvat/apps/engine/migrations/0015_task_segment_size.py new file mode 100644 index 000000000000..a71c1bd139f1 --- /dev/null +++ b/cvat/apps/engine/migrations/0015_task_segment_size.py @@ -0,0 +1,32 @@ +# Generated by Django 2.1.5 on 2019-01-25 08:35 + +from django.db import migrations, models + +def set_segment_size(apps, schema_editor): + Task = apps.get_model('engine', 'Task') + for task in Task.objects.all(): + segment = task.segment_set.first() + task.segment_size = segment.stop_frame - segment.start_frame + 1 + task.save() + +class Migration(migrations.Migration): + + dependencies = [ + ('engine', '0014_job_max_shape_id'), + ] + + operations = [ + migrations.AddField( + model_name='task', + name='segment_size', + field=models.PositiveIntegerField(null=True), + ), + migrations.RunPython(code=set_segment_size, + reverse_code=migrations.RunPython.noop), + + migrations.AlterField( + model_name='task', + name='segment_size', + field=models.PositiveIntegerField(), + ), + ] diff --git a/cvat/apps/engine/models.py b/cvat/apps/engine/models.py index 1d62f02da38d..566ffa27259e 100644 --- a/cvat/apps/engine/models.py +++ b/cvat/apps/engine/models.py @@ -47,6 +47,7 @@ class Task(models.Model): created_date = models.DateTimeField(auto_now_add=True) updated_date = models.DateTimeField(auto_now_add=True) overlap = models.PositiveIntegerField(default=0) + segment_size = models.PositiveIntegerField() z_order = models.BooleanField(default=False) flipped = models.BooleanField(default=False) source = SafeCharField(max_length=256, default="unknown") diff --git a/cvat/apps/engine/task.py b/cvat/apps/engine/task.py index e1b2b1ffd268..6e7c388fe05e 100644 --- a/cvat/apps/engine/task.py +++ b/cvat/apps/engine/task.py @@ -606,6 +606,7 @@ def _save_task_to_db(db_task, task_params): db_task.z_order = task_params['z_order'] db_task.flipped = task_params['flip'] db_task.source = task_params['data'] + db_task.segment_size = min(db_task.size, task_params['segment']) segment_step = task_params['segment'] - db_task.overlap for x in range(0, db_task.size, segment_step):