diff --git a/core/lib/meta.py b/core/lib/meta.py index 76e50de..231518e 100644 --- a/core/lib/meta.py +++ b/core/lib/meta.py @@ -37,17 +37,20 @@ def get_meta(request, net, nicks, iter=True): """ # Split query into chunks - split_nicks = array_split( - nicks, ceil(len(nicks) / settings.META_MAX_CHUNK_SIZE) - ) + split_nicks = array_split(nicks, ceil(len(nicks) / settings.META_MAX_CHUNK_SIZE)) meta = [] for nicks_chunked in split_nicks: if len(nicks_chunked) == 0: break meta_tmp = [] query = construct_query(net, nicks_chunked) - results = run_main_query(client, request.user, query, - custom_query=True, index=settings.OPENSEARCH_INDEX_META) + results = run_main_query( + client, + request.user, + query, + custom_query=True, + index=settings.OPENSEARCH_INDEX_META, + ) if "hits" in results.keys(): if "hits" in results["hits"]: for item in results["hits"]["hits"]: diff --git a/core/lib/opensearch.py b/core/lib/opensearch.py index bd9e9d5..ec37647 100644 --- a/core/lib/opensearch.py +++ b/core/lib/opensearch.py @@ -169,10 +169,9 @@ def query_results(request, size=None): def query_single_result(request): context = query_results(request, 1) dedup_set = {item["nick"] for item in context["results"]} - if len(dedup_set) == 1: + if dedup_set: context["item"] = context["results"][0] - else: - return (len(dedup_set), context) + return (1, context) diff --git a/core/templates/ui/insights/info.html b/core/templates/ui/insights/info.html index 9a9d84c..535b515 100644 --- a/core/templates/ui/insights/info.html +++ b/core/templates/ui/insights/info.html @@ -18,15 +18,6 @@ hx-target="#nicks" hx-swap="outerHTML"> -
-
{% if item is not None %}
diff --git a/core/templates/ui/insights/nicks.html b/core/templates/ui/insights/nicks.html index 8d8c4ab..3e3bdfd 100644 --- a/core/templates/ui/insights/nicks.html +++ b/core/templates/ui/insights/nicks.html @@ -1,5 +1,13 @@ {% load index %} - +
+
diff --git a/core/views/dynamic/insights.py b/core/views/dynamic/insights.py index ce5e9b3..972d74d 100644 --- a/core/views/dynamic/insights.py +++ b/core/views/dynamic/insights.py @@ -1,3 +1,5 @@ +from ast import literal_eval + from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpResponse, HttpResponseForbidden, JsonResponse from django.shortcuts import render @@ -87,28 +89,36 @@ class InsightsMeta(LoginRequiredMixin, APIView): return HttpResponseForbidden() if "net" not in request.data: return HttpResponse("No net") - if "nick" not in request.data: - return HttpResponse("No nick") + if "nicks" not in request.data: + return HttpResponse("No nicks") net = request.data["net"] - nick = request.data["nick"] - meta = get_meta(request, net, [nick]) + nicks = request.data["nicks"] + nicks = literal_eval(nicks) + meta = get_meta(request, net, nicks) unique_values = {} + # Create a map of unique values for each key for each nick for x in meta: + nick = x["nick"] + if nick not in unique_values: + unique_values[nick] = {} for k, v in x.items(): - if k not in unique_values: - unique_values[k] = set() - unique_values[k].add(v) + if k not in unique_values[nick]: + unique_values[nick][k] = set() + if k in ["ts", "time", "date", "id"]: + continue + unique_values[nick][k].add(v) meta_dedup = [] for x in meta: + nick = x["nick"] meta_l2 = {} for k, v in x.items(): - if v in unique_values[k]: + if v in unique_values[nick][k]: meta_l2[k] = v - unique_values[k].remove(v) + unique_values[nick][k].remove(v) if not set(meta_l2.keys()).issubset(set(["ts", "time", "date", "id"])): meta_dedup.append(meta_l2) - context = {"net": net, "nick": nick, "meta": meta_dedup} + context = {"net": net, "nicks": nicks, "meta": meta_dedup} return render(request, self.template_name, context)