Group items in meta by field

This commit is contained in:
Mark Veidemanis 2022-07-21 13:53:02 +01:00
parent 8710c66e05
commit 70a6221b0c
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 10 additions and 55 deletions

View File

@ -1,63 +1,19 @@
<div id="meta"> <div id="meta">
<div class="content" style="max-height: 30em; overflow: auto;"> <div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container"> <div class="table-container">
{% for item in meta %} {% for key,items in meta.items %}
<table class="table is-striped is-fullwidth is-hoverable"> <th><strong>{{ key }}</strong></th>
<table class="table is-fullwidth is-hoverable">
<tbody> <tbody>
{% if 'ts' in item %} {% for item in items %}
<tr> <tr>
<th>ts</th>
<td> <td>
<p>{{ item.date }}</p> {{ item }}
<p>{{ item.time }}</p>
</td> </td>
</tr> </tr>
{% endif %} {% endfor %}
{% if 'nick' in item %}
<tr>
<th>nick</th>
<td>{{ item.nick }}</td>
</tr>
{% endif %}
{% if 'ident' in item %}
<tr>
<th>ident</th>
<td>{{ item.ident }}</td>
</tr>
{% endif %}
{% if 'host' in item %}
<tr>
<th>host</th>
<td>{{ item.host }}</td>
</tr>
{% endif %}
{% if 'realname' in item %}
<tr>
<th>realname</th>
<td>{{ item.realname }}</td>
</tr>
{% endif %}
{% if 'status' in item %}
<tr>
<th>status</th>
<td>{{ item.status }}</td>
</tr>
{% endif %}
{% if 'server' in item %}
<tr>
<th>server</th>
<td>{{ item.server }}</td>
</tr>
{% endif %}
{% if 'channel' in item %}
<tr>
<th>channel</th>
<td>{{ item.channel }}</td>
</tr>
{% endif %}
</tbody> </tbody>
</table> </table>
<hr/>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>

View File

@ -107,16 +107,15 @@ class InsightsMeta(LoginRequiredMixin, APIView):
if k in ["ts", "time", "date", "id"]: if k in ["ts", "time", "date", "id"]:
continue continue
unique_values[nick][k].add(v) unique_values[nick][k].add(v)
meta_dedup = [] meta_dedup = {}
for x in meta: for x in meta:
nick = x["nick"] nick = x["nick"]
meta_l2 = {}
for k, v in x.items(): for k, v in x.items():
if v in unique_values[nick][k]: if v in unique_values[nick][k]:
meta_l2[k] = v if k not in meta_dedup:
meta_dedup[k] = set()
meta_dedup[k].add(v)
unique_values[nick][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, "nicks": nicks, "meta": meta_dedup} context = {"net": net, "nicks": nicks, "meta": meta_dedup}
return render(request, self.template_name, context) return render(request, self.template_name, context)