vsoch / freegenes

FreeGenes BioNode with Django
https://vsoch.github.io/freegenes/
Mozilla Public License 2.0
2 stars 4 forks source link

Production Board "Complete" or "Failed" does not check for FactoryOrder #100

Open Koeng101 opened 5 years ago

Koeng101 commented 5 years ago

Describe the bug The Production Board does not check for if parts are associated with that FactoryOrder https://github.com/vsoch/freegenes/issues/91#issuecomment-542304633

Samples should only be considered if they were present within the FactoryOrder. For example, the first link in https://freegenes.dev/f/factoryorder/parts/completed/12ec1419-6e31-4399-b152-583acc4e6d1f leads to a sample that has no status and is not part of the FactoryOrder

To Reproduce https://freegenes.dev/f/factoryorder/parts/completed/12ec1419-6e31-4399-b152-583acc4e6d1f

Expected behavior System checks for if a Sample exists that is associated with that FactoryOrder.

If applicable, add versions and screenshots to help explain your problem.

vsoch commented 5 years ago

I'm not sure how this is possible - for example, when we derive the list of completed or failed parts, we do so directly from the factory order object:

    def count_parts_completed(self):
        '''determine parts completed based on having (or not having) a sample.
        '''
        count = 0
        for part in self.parts.all():
            if part.sample_set.count() > 0:
                count+=1

        return count

    def count_parts_failed(self):
        '''parts failed is total minus parts completed
        '''
        return self.parts.count() - self.count_parts_completed()

    # Get filtered parts

    def get_completed_parts(self):
        '''return completed parts'''
        parts = []
        for part in self.parts.all():
            if part.sample_set.count() > 0:
                parts.append(part)
        return parts

    def get_failed_parts(self):
        '''return completed parts'''
        parts = []
        for part in self.parts.all():
            if part.sample_set.count() == 0:
                parts.append(part)
        return parts

This is used in the view as follows:

    try:
        order = FactoryOrder.objects.get(uuid=uuid)
    except FactoryOrder.DoesNotExist:
        messages.info(request, "This factory order does not exist.")
        return redirect('factory')

    # Custom filtering of parts
    if subset == "completed":
        parts = order.get_completed_parts()
    elif subset == "failed":
        parts = order.get_failed_parts()
    else:
        parts = order.parts.all()

    context = {
        "order": order,
        "parts": parts,
        "subset": subset
    }

And then the context provides the variable "parts" that is rendered into the table for the respective pages.

Per your example, we can look up the part that you mention, the first in the table:

from fg.apps.main.models import *                                       
part = Part.objects.get(uuid="5471c835-4dc6-48e4-b633-77f6bc6d1e10")    

And then the factory order's page that it shows up as completed:

from fg.apps.factory.models import *                                    
order = FactoryOrder.objects.get(uuid="12ec1419-6e31-4399-b152-583acc4e6d1f")                                                                   

And test if the part is in the order's parts:

part in order.parts.all()                                               
True

And it is. So that link is correct. I would review the import logic for plates and samples, as I suspect the issue is there. I (still) don't understand this logic, so I'll ask that you take a look - I do not feel empowered to know how to fix this for you.

vsoch commented 4 years ago

@Koeng101 is this resolved?

Koeng101 commented 4 years ago

I'll have to reupload all previous plates into the system again. Will take a little bit to test, so I'll do after checking the local plate import

vsoch commented 4 years ago

okay sounds good.