Skip to content

Commit

Permalink
update Instance Completion task + update admin
Browse files Browse the repository at this point in the history
  • Loading branch information
rw-bsi committed Nov 24, 2024
1 parent d6a407c commit 5b6bb4d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
4 changes: 2 additions & 2 deletions backend/apps/ifc_validation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,9 @@ def size_text(self, obj):

class ModelInstanceAdmin(BaseAdmin, NonAdminAddable):

list_display = ["id", "public_id", "stepfile_id", "model", "ifc_type", "created", "updated"]

list_display = ["id", "public_id", "model", "model_id", "stepfile_id", "ifc_type", "created", "updated"]
search_fields = ('stepfile_id', 'model__file_name', 'ifc_type')
list_filter = ["ifc_type", "model_id", "created", "updated"]


class CompanyAdmin(BaseAdmin):
Expand Down
42 changes: 33 additions & 9 deletions backend/apps/ifc_validation/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,51 @@ def ifc_file_validation_task(self, id, file_name, *args, **kwargs):
@requires_django_user_context
def instance_completion_subtask(self, prev_result, id, file_name, *args, **kwargs):

# fetch request info
request = ValidationRequest.objects.get(pk=id)
file_path = get_absolute_file_path(request.file.name)

# increment overall progress
PROGRESS_INCREMENT = 5
request.progress += PROGRESS_INCREMENT
request.save()

# add task
task = ValidationTask.objects.create(request=request, type=ValidationTask.Type.INSTANCE_COMPLETION)

prev_result_succeeded = prev_result is not None and prev_result[0]['is_valid'] is True
if prev_result_succeeded:

request = ValidationRequest.objects.get(pk=id)
file_path = get_absolute_file_path(request.file.name)

task.mark_as_initiated()

try:
ifc_file = ifcopenshell.open(file_path)
except:
logger.warning(f'Failed to open {file_path}. Likely previous tasks also failed.')
ifc_file = None
except:
reason = f'Failed to open {file_path}. Likely previous tasks also failed.'
task.mark_as_completed(reason)
return {'is_valid': False, 'reason': reason}

if ifc_file:

# fetch and update ModelInstance records without ifc_type
with transaction.atomic():
for inst in request.model.instances.iterator():
model_id = request.model.id
model_instances = ModelInstance.objects.filter(model_id=model_id, ifc_type__in=[None, ''])
instance_count = model_instances.count()
logger.info(f'Retrieved {instance_count:,} ModelInstance record(s)')

for inst in model_instances.iterator():
inst.ifc_type = ifc_file[inst.stepfile_id].is_a()
inst.save()

# update Task info and return
reason = f'Updated {instance_count:,} ModelInstance record(s)'
task.mark_as_completed(reason)
return {'is_valid': True, 'reason': reason}

else:
reason = f'Skipped as prev_result = {prev_result}.'
#task.mark_as_skipped(reason)
task.mark_as_skipped(reason)
return {'is_valid': None, 'reason': reason}


Expand Down Expand Up @@ -468,7 +492,7 @@ def prerequisites_subtask(self, prev_result, id, file_name, *args, **kwargs):
file_path = get_absolute_file_path(request.file.name)

# increment overall progress
PROGRESS_INCREMENT = 15
PROGRESS_INCREMENT = 10
request.progress += PROGRESS_INCREMENT
request.save()

Expand Down

0 comments on commit 5b6bb4d

Please sign in to comment.