|
|
|
@ -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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|