Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IVS-235 - update Instance Completion task + update admin #131

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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