Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • arkindex/backend
1 result
Show changes
Commits on Source (5)
0.10.4-rc1
0.10.4-rc2
......@@ -122,6 +122,11 @@ class DataImport(IndexableModel):
if elements:
command = ' '.join([command, '--dataimport-id {}'.format(str(self.id))])
# Do not retrieve elements children in case there of thumbnails generation only
thumbnails = self.payload.get('thumbnails')
if thumbnails and len(self.ml_tools) == 0:
command = ' '.join([command, '--skip-children'.format(str(self.id))])
tasks = {
import_task_name: {
'image': settings.ARKINDEX_TASKS_IMAGE,
......
......@@ -499,3 +499,31 @@ class TestWorkflows(FixtureAPITestCase):
'python -m arkindex_tasks.init_elements --corpus-id {} --chunks-number 1 --dataimport-id {}'
.format(str(self.corpus.id), str(dataimport.id))
)
def test_thumbnails_generation_only(self, ml_get_mock):
"""
Generating thumbnails without any workflow must generate an import task
which do not to retrieve filtered elements children
"""
self.client.force_login(self.user)
corpus_type = self.corpus.types.first()
response = self.client.post(
reverse('api:corpus-workflow'),
{
'ml_tools': [],
'corpus': str(self.corpus.id),
'chunks': 3,
'type': corpus_type.slug,
'thumbnails': True
},
format='json'
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
data = response.json()
dataimport = DataImport.objects.get(id=data['id'])
workflow = dataimport.workflow
self.assertEqual(
workflow.recipes['initialisation'].command,
'python -m arkindex_tasks.init_elements --corpus-id {} --chunks-number 3 --type {} --skip-children'
.format(str(self.corpus.id), corpus_type.slug)
)
......@@ -38,6 +38,7 @@ class Command(BaseCommand):
'--update-batch-size',
help='Batch size used to update zones. Updates are run with each retrieval batch.',
type=int,
default=1000,
)
parser.add_argument(
'--dry-run',
......@@ -51,7 +52,15 @@ class Command(BaseCommand):
default=True,
)
def handle(self, *args, offset=0, limit=0, batch_size=1000, update_batch_size=None, remove=True, **kwargs):
def handle(self,
*args,
offset=0,
limit=0,
batch_size=1000,
update_batch_size=1000,
dry_run=False,
remove=True,
**kwargs):
assert batch_size > 0, 'Batch size must be positive.'
assert update_batch_size > 0, 'Update batch size must be positive.'
......@@ -77,10 +86,14 @@ class Command(BaseCommand):
zone.polygon.reorder()
except Exception as e:
if old_polygon.width < 1 or old_polygon.height < 1 and remove:
logger.info('Removing incoherent zone {}…'.format(zone.id))
zone.transcriptions.all().delete()
zone.elements.all().delete()
zone.delete()
if dry_run:
logger.info('Would remove incoherent zone {}'.format(zone.id))
else:
logger.info('Removing incoherent zone {}…'.format(zone.id))
zone.transcriptions.all().delete()
zone.elements.all().delete()
zone.regions.all().delete()
zone.delete()
removed += 1
total -= 1
else:
......@@ -90,9 +103,29 @@ class Command(BaseCommand):
continue
if zone.polygon != old_polygon:
reordered_zones.append(zone)
# Check if a zone already exists and either reorder or deduplicate
existing_zone = Zone.objects \
.filter(image_id=zone.image_id, polygon=zone.polygon) \
.exclude(id=zone.id) \
.first()
if not existing_zone:
reordered_zones.append(zone)
continue
if dry_run:
logger.info('Would remove zone {} and reassign to zone {}'.format(zone.id, existing_zone.id))
continue
logger.info('Removing zone {} and reassigning to zone {}…'.format(zone.id, existing_zone.id))
zone.transcriptions.all().update(zone_id=existing_zone.id)
zone.elements.all().update(zone_id=existing_zone.id)
zone.regions.all().update(zone_id=existing_zone.id)
zone.delete()
removed += 1
total -= 1
Zone.objects.bulk_update(reordered_zones, ['polygon'], batch_size=update_batch_size)
if not dry_run:
Zone.objects.bulk_update(reordered_zones, ['polygon'], batch_size=update_batch_size)
reordered += len(reordered_zones)
completed += batch.count()
......