Skip to content

Commit

Permalink
The last of us 2 (#900)
Browse files Browse the repository at this point in the history
* Dashboard Parent Ticket (#896)

* Adding free-text-search to related barriers (#845)

* Adding free-text-search to related barriers

* Rebase

* Update and working search endpoint

* Excluding archived barriers from inactive notification alerts (#858)

Co-authored-by: santinomolinaro <santino.molinaro@mail>

* Deleting cached barrier when creating and updating next steps items so they are reflected instantly on frontend (#861)

Co-authored-by: santinomolinaro <santino.molinaro@mail>

* TSS-1995: Move set_to_allowed_on into public barrier serializer (#862)

* tss-1995: set_to_allowed expected on public_barrier serializer

---------

Co-authored-by: abarolo <[email protected]>

* using the full text search on the search page

---------

Co-authored-by: santinomolinaro <santino.molinaro@mail>
Co-authored-by: abarolo <[email protected]>
Co-authored-by: abarolo <[email protected]>
Co-authored-by: Uka Osim <[email protected]>
Co-authored-by: Uka Osim <[email protected]>

* feat: lint fix

* raise search limit

* test fix

* TSS 1966 dashboard summary with filters (#885)

* hotfix: Reduce Dataworkspace pagination size (#877)

* hotfix: Reduce Dataworkspace pagination size

---------

Co-authored-by: abarolo <[email protected]>

* Basic summary info

Basic summary stats exposed with filter set implemented

* Fix filtering

* Remove comments

* Add financial year

---------

Co-authored-by: abarolo <[email protected]>
Co-authored-by: abarolo <[email protected]>

* Tss 1965 dashboard tasks merge branch (#888)

* Adding Dashboard Task list view to calculate outstanding tasks for display on new dashboard

* Unit tests and edge case fixes

* Limiting initial query to 1000 results, and order by last modified on date

---------

Co-authored-by: santinomolinaro <santino.molinaro@mail>

* Dashboard chart data (#898)

* Fix PB100 filter (#890)

---------

Co-authored-by: santinomolinaro <santino.molinaro@mail>
Co-authored-by: abarolo <[email protected]>
Co-authored-by: abarolo <[email protected]>
Co-authored-by: Uka Osim <[email protected]>
Co-authored-by: Uka Osim <[email protected]>
Co-authored-by: Feroze Rub <[email protected]>

* Delete barrier detail cache (#899)

Co-authored-by: abarolo <[email protected]>

* Remove test command (#901)

Co-authored-by: abarolo <[email protected]>

---------

Co-authored-by: Santino Molinaro <[email protected]>
Co-authored-by: santinomolinaro <santino.molinaro@mail>
Co-authored-by: abarolo <[email protected]>
Co-authored-by: Uka Osim <[email protected]>
Co-authored-by: Uka Osim <[email protected]>
Co-authored-by: Feroze Rub <[email protected]>
  • Loading branch information
7 people authored Sep 17, 2024
1 parent 601679b commit a1bf346
Show file tree
Hide file tree
Showing 19 changed files with 2,483 additions and 254 deletions.
15 changes: 0 additions & 15 deletions api/barriers/barrier_cache.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from django.core.management import BaseCommand

from api.barriers import barrier_cache
from api.barriers.models import Barrier


Expand Down Expand Up @@ -49,6 +48,5 @@ def handle(self, *args, **options):
if dryrun:
print(f"{barrier_id}: {policy_team_ids}")
else:
barrier_cache.delete(barrier_id)
for pid in policy_team_ids:
barrier.policy_teams.add(pid)
52 changes: 48 additions & 4 deletions api/barriers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from django.core.cache import cache
from django.core.validators import int_list_validator
from django.db import models
from django.db.models import CASCADE, Q, QuerySet
from django.db.models import CASCADE, CharField, Q, QuerySet
from django.db.models.functions import Cast
from django.shortcuts import get_object_or_404
from django.utils import timezone
from django_filters.widgets import BooleanWidget
Expand Down Expand Up @@ -706,7 +707,7 @@ def current_economic_assessment(self):
@property
def current_valuation_assessment(self):
"""
Get the current valuration assessment
Get the current valuation assessment
Filter in python to avoid another db call if prefetch_related has been used.
"""
Expand Down Expand Up @@ -1298,8 +1299,8 @@ class BarrierFilterSet(django_filters.FilterSet):
combined_priority = django_filters.BaseInFilter(method="combined_priority_filter")
location = django_filters.BaseInFilter(method="location_filter")
admin_areas = django_filters.BaseInFilter(method="admin_areas_filter")
search = django_filters.Filter(method="text_search")
text = django_filters.Filter(method="text_search")
search = django_filters.Filter(method="vector_search")
text = django_filters.Filter(method="vector_search")

user = django_filters.Filter(method="my_barriers")
has_action_plan = django_filters.Filter(method="has_action_plan_filter")
Expand Down Expand Up @@ -1611,6 +1612,49 @@ def text_search(self, queryset, name, value):
| Q(combined_company_related_organisation_query)
)

def vector_search(self, queryset, name, value):
"""
full text search on multiple fields
Args:
queryset the queryset to filter
name the name of the filter
value the value of the filter
Returns:
_type_: the resust is a queryset with a free text search applied to the barrier model
"""

from api.related_barriers import manager as handler_manager
from api.related_barriers.constants import (
SIMILAR_BARRIERS_LIMIT,
SIMILARITY_THRESHOLD,
)

if handler_manager.manager is None:
handler_manager.init()

barrier_scores = handler_manager.manager.get_similar_barriers_searched(
search_term=value,
similarity_threshold=SIMILARITY_THRESHOLD,
quantity=SIMILAR_BARRIERS_LIMIT,
)

if not barrier_scores:
# If no similar barriers are found, return the queryset with the text search applied
# we do this to compensate for the fact that the related barriers handler may not have
# emededings and barrier ids to return
# this can happend when running the CI tests
# or when the related barriers handler is not running
return self.text_search(queryset, name, value)

barrier_ids = [b[0] for b in barrier_scores]

queryset = queryset.filter(id__in=barrier_ids).annotate(
barrier_id=Cast("id", output_field=CharField())
)

return queryset

def my_barriers(self, queryset, name, value):
if value:
current_user = self.get_user()
Expand Down
2 changes: 1 addition & 1 deletion api/barriers/signals/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def related_barrier_update_embeddings(sender, instance, *args, **kwargs):
manager.manager.update_barrier(
BarrierEntry(
id=str(current_barrier_object.id),
barrier_corpus=manager.barrier_to_corpus(current_barrier_object),
barrier_corpus=manager.barrier_to_corpus(instance),
)
)
except Exception as e:
Expand Down
4 changes: 4 additions & 0 deletions api/barriers/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from api.barriers.views import (
BarrierActivity,
BarrierDashboardSummary,
BarrierDetail,
BarrierFullHistory,
BarrierHibernate,
Expand Down Expand Up @@ -170,6 +171,9 @@
name="unknown-barrier",
),
path("counts", barrier_count, name="barrier-count"),
path(
"dashboard-summary", BarrierDashboardSummary.as_view(), name="barrier-summary"
),
path("reports", BarrierReportList.as_view(), name="list-reports"),
path("reports/<uuid:pk>", BarrierReportDetail.as_view(), name="get-report"),
path(
Expand Down
Loading

0 comments on commit a1bf346

Please sign in to comment.