LCOGT / mop

Microlensing Observation Portal
GNU General Public License v3.0
0 stars 7 forks source link

Priority Target view shows Alive=False events #176

Closed KKruszynska closed 1 month ago

KKruszynska commented 2 months ago

Targets that are not Alive seem to be appearing in the Priority Target view. See: https://mop.lco.global/targets/3700/ And: image

rachel3834 commented 1 month ago

Reviewing the query code that selects events for this view, I think the exclude was implemented wrong.

Previously the query was doing:

ts = Target.objects.filter(
tap_priority__gt=threshold,
sky_location__icontains='Outside HCZ',
classification__icontains='Microlensing)
.exclude(
YSO=True,
QSO=True,
galaxy=True,
alive=False
)

But this chaining of filters is interpreted as an AND, but in practice we actually want an OR for the exclude filters. So I've updated this code to use the Q operator:

ts = Target.objects.filter(
            Q(tap_priority__gt=priority_threshold)
            & Q(sky_location__icontains='Outside HCZ')
            & Q(classification__icontains='Microlensing')
        ).exclude(
            Q(YSO=True) | Q(QSO=True) | Q(galaxy=True) | Q(alive=False)
        )