From 032d5fab87d7860884ee02730258988f6ba4bca6 Mon Sep 17 00:00:00 2001 From: Kasia Krasnowska <kasia.krasnowska@gmail.com> Date: Wed, 7 Jul 2021 16:57:17 +0200 Subject: [PATCH] stub stats page; css/html/translation fixes --- common/static/common/js/init.js | 2 +- common/templates/base.html | 12 ++- common/templates/dash.html | 2 +- .../templates/dictionary_statistics.html | 74 ++++++++++++++++++- dictionary_statistics/views.py | 37 +++++++++- entries/polish_strings.py | 18 ++++- entries/static/entries/css/entries.css | 26 +++---- entries/templates/entries.html | 6 +- 8 files changed, 151 insertions(+), 26 deletions(-) diff --git a/common/static/common/js/init.js b/common/static/common/js/init.js index a3f1469..1e3acdf 100644 --- a/common/static/common/js/init.js +++ b/common/static/common/js/init.js @@ -4,7 +4,7 @@ var lang; $(document).ready(function() { - $('.nav-item > a[href$="' + window.location.pathname + '"]').addClass('active'); + $('.nav-item > a[href$="' + window.location.pathname + '"]').removeClass('text-light active').addClass('disabled'); lang = $('html').attr('lang'); diff --git a/common/templates/base.html b/common/templates/base.html index b516abc..0be482d 100644 --- a/common/templates/base.html +++ b/common/templates/base.html @@ -35,7 +35,8 @@ <div class="container-fluid h-100 d-flex flex-column p-0"> - <nav class="navbar navbar-expand-lg sticky-top navbar-dark bg-dark font-weight-bold p-2"> + <!--z-index 2 above sticky-top--> + <nav class="navbar navbar-expand-lg sticky-top navbar-dark bg-dark font-weight-bold p-2" style="z-index: 1022;"> <a class="navbar-brand" href="{% url 'dash' %}">Walenty [beta]</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> @@ -44,16 +45,21 @@ <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav mr-auto"> <li class="nav-item" id="nav-entries"> - <a class="nav-link" href="{% url 'entries:entries' %}"> + <a class="nav-link text-light" href="{% url 'entries:entries' %}"> {% trans "Hasła" %} </a> </li> {% block additional-nav-items %}{% endblock %} <li class="nav-item" id="nav-phrases"> - <a class="nav-link" href="{% url 'phrase_expansions:phrase_expansions' %}"> + <a class="nav-link text-light" href="{% url 'phrase_expansions:phrase_expansions' %}"> {% trans "Typy fraz" %} </a> </li> + <li class="nav-item" id="nav-statistics"> + <a class="nav-link text-light" href="{% url 'dictionary_statistics:dictionary_statistics' %}"> + {% trans "Statystyki" %} + </a> + </li> </ul> </div> <span id="import-status" class="navbar-text text-warning mr-3"></span> diff --git a/common/templates/dash.html b/common/templates/dash.html index 739b8a9..91fb42d 100644 --- a/common/templates/dash.html +++ b/common/templates/dash.html @@ -49,7 +49,7 @@ </div> </div> -<div class="card mt-3"> +<div class="card my-3"> <h5 class="card-header">{% trans "Pozostałe publikacje" %}</h5> <div class="card-body"> diff --git a/dictionary_statistics/templates/dictionary_statistics.html b/dictionary_statistics/templates/dictionary_statistics.html index 1f86b82..0b9d366 100644 --- a/dictionary_statistics/templates/dictionary_statistics.html +++ b/dictionary_statistics/templates/dictionary_statistics.html @@ -4,6 +4,8 @@ {% load static %} +{% load custom_templatetags %} + {% block title %}{% trans "Statystyki" %}{% endblock %} {% block scripts %} @@ -12,10 +14,76 @@ {% block content2 %} <div class="card mt-3"> + <h5 class="card-header">{% trans "Liczba haseł" %}</h5> + <div class="card-body"> + <table class="table table-sm table-striped mb-0"> + <thead> + <tr> + <th style="width: 13em;">{% trans "Status / część mowy" %}</th> + {% for pos in all_pos %} + <th style="width: 10em;" scope="col">{{ pos }}</th> + {% endfor %} + </tr> + </thead> + <tbody> + {% for status in all_statuses %} + <tr> + <th scope="row">{{ status }}</th> + {% for num in entry_stats|get_item:status %} + <td>{{ num }}</td> + {% endfor %} + </tr> + {% endfor %} + <tbody> + </table> + </div> +</div> + +<div class="card mt-3"> + <h5 class="card-header">{% trans "Liczba schematów" %}</h5> + <div class="card-body"> + <table class="table table-sm table-striped mb-0"> + <thead> + <tr> + {% for opinion, opinion_key, n in schema_stats %} + <th style="width: 10em;" scope="col"> + {% if opinion_key != "all" %}<img src="/static/entries/img/{{ opinion_key }}.svg" width="12" height="12" alt="{{ opinion }}"> {% endif %}{{ opinion }} + </th> + {% endfor %} + </tr> + </thead> + <tbody> + <tr> + {% for opinion, opinion_key, n in schema_stats %} + <td>{{ n }}</td> + {% endfor %} + </tr> + <tbody> + </table> + </div> +</div> + +<div class="card my-3"> + <h5 class="card-header">{% trans "Liczba ram" %}</h5> <div class="card-body"> - <p> - Tutaj będą statystyki słownika. - </p> + <table class="table table-sm table-striped mb-0"> + <thead> + <tr> + {% for opinion, opinion_key, n in frame_stats %} + <th scope="col"> + {% if opinion_key != "all" %}<img src="/static/entries/img/{{ opinion_key }}.svg" width="12" height="12" alt="{{ opinion }}"> {% endif %}{{ opinion }} + </th> + {% endfor %} + </tr> + </thead> + <tbody> + <tr> + {% for opinion, opinion_key, n in frame_stats %} + <td>{{ n }}</td> + {% endfor %} + </tr> + <tbody> + </table> </div> </div> diff --git a/dictionary_statistics/views.py b/dictionary_statistics/views.py index 106c950..e91161a 100644 --- a/dictionary_statistics/views.py +++ b/dictionary_statistics/views.py @@ -1,4 +1,39 @@ from django.shortcuts import render +from django.utils.translation import gettext as _ + +from connections.models import Entry, POS, Status +from syntax.models import Schema, SchemaOpinion +from semantics.models import Frame, FrameOpinion + +from entries.polish_strings import POS as POS_names, STATUS, SCHEMA_OPINION, FRAME_OPINION def dictionary_statistics(request): - return render(request, 'dictionary_statistics.html', { }) + ALL = _('wszystkie') + + # ENTRIES + entries = Entry.objects.filter(import_error=False) + pos_names = POS_names() + status_names = STATUS() + entry_statuses = list(Status.objects.all()) + all_pos = ['verb', 'noun', 'adj', 'adv'] + entry_stats = { ALL : [entries.count()] + [entries.filter(pos__tag=pos).count() for pos in all_pos] } + used_statuses = set() + for status in entry_statuses: + c = entries.filter(status=status).count() + if c: + used_statuses.add(status) + entry_stats[status_names[status.key]] = [entries.filter(status=status).count()] + [entries.filter(status=status, pos__tag=pos).count() for pos in all_pos] + all_statuses = [ALL] + [status_names[status.key] for status in entry_statuses if status in used_statuses] + all_pos = [ALL] + [pos_names[pos] for pos in all_pos] + + # SCHEMATA + schemata = Schema.objects.filter(subentries__entry__import_error=False) + schema_opinions = SCHEMA_OPINION() + schema_stats = [(ALL, 'all', schemata.count())] + [(schema_opinions[opinion.key], opinion.key, schemata.filter(opinion=opinion).count()) for opinion in SchemaOpinion.objects.all()] + + # FRAMES + frames = Frame.objects.all() #filter(arguments__argument_connections__schema_connections__subentry__entry__import_error=False) + frame_opinions = FRAME_OPINION() + frame_stats = [(ALL, 'all', frames.count())] + [(frame_opinions[opinion.key], opinion.key, frames.filter(opinion=opinion).count()) for opinion in FrameOpinion.objects.all()] + + return render(request, 'dictionary_statistics.html', { 'all_statuses' : all_statuses, 'all_pos' : all_pos, 'entry_stats' : entry_stats, 'schema_stats' : schema_stats, 'frame_stats' : frame_stats }) diff --git a/entries/polish_strings.py b/entries/polish_strings.py index 4519d10..bdb37ce 100644 --- a/entries/polish_strings.py +++ b/entries/polish_strings.py @@ -1,6 +1,22 @@ from django.utils.text import format_lazy from django.utils.translation import gettext_lazy as _ +def STATUS(): + return { + 'do obróbki' : _('do obróbki'), + 'w obróbce' : _('w obróbce'), + 'do usunięcia' : _('do usunięcia'), + 'gotowe' : _('gotowe'), + 'zalążkowe' : _('zalążkowe'), + 'sprawdzone' : _('sprawdzone'), + '(F) w obróbce' : _('(F) w obróbce'), + '(F) gotowe' : _('(F) gotowe'), + '(F) sprawdzone' : _('(F) sprawdzone'), + '(S) w obróbce' : _('(S) w obróbce'), + '(S) gotowe' : _('(S) gotowe'), + '(S) sprawdzone' : _('(S) sprawdzone'), + } + def POS(): return { 'adj' : _('przymiotnik'), @@ -40,7 +56,7 @@ def FRAME_OPINION(): 'col' : _('potoczna'), 'dat' : _('archaiczna'), 'bad' : _('zła'), - 'unc' : _('niepewna'), + 'unc' : _('wątpliwa'), 'cer' : _('pewna'), 'rar' : _('sporadyczna'), 'dom' : _('dziedzinowa'), diff --git a/entries/static/entries/css/entries.css b/entries/static/entries/css/entries.css index 1ba8fe8..17b7bea 100644 --- a/entries/static/entries/css/entries.css +++ b/entries/static/entries/css/entries.css @@ -90,55 +90,55 @@ legend { } .form-depth-1 { - background-color: #fefefe; - border-color: #f3f4f5; -} - -.form-depth-2 { background-color: #f3f4f5; border-color: #e8ebed; } -.form-depth-3 { +.form-depth-2 { background-color: #e8ebed; border-color: #dee1e4; } -.form-depth-4 { +.form-depth-3 { background-color: #dee1e4; border-color: #d3d7db; } -.form-depth-5 { +.form-depth-4 { background-color: #d3d7db; border-color: #c8cdd2; } -.form-depth-6 { +.form-depth-5 { background-color: #c8cdd2; border-color: #bdc3c9; } -.form-depth-7 { +.form-depth-6 { background-color: #bdc3c9; border-color: #b2bac1; } -.form-depth-8 { +.form-depth-7 { background-color: #b2bac1; border-color: #a7b0b8; } -.form-depth-9 { +.form-depth-8 { background-color: #a7b0b8; border-color: #9da6af; } -.form-depth-10 { +.form-depth-9 { background-color: #9da6af; border-color: #929ca6; } +.form-depth-10 { + background-color: #929ca6; + border-color: #87929e; +} + .to-remove { background-color: #f0b9b8; } diff --git a/entries/templates/entries.html b/entries/templates/entries.html index 8ede0a2..5e0efa5 100644 --- a/entries/templates/entries.html +++ b/entries/templates/entries.html @@ -30,7 +30,7 @@ {% block additional-nav-items %} <li class="nav-item dropdown"> - <a class="nav-link dropdown-toggle" href="#" id="nav-filters" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> + <a class="nav-link dropdown-toggle text-light" href="#" id="nav-filters" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> {% trans "Filtrowanie" %} </a> <div class="dropdown-menu" id="filters-visited-dropdown" aria-labelledby="nav-filters"> @@ -46,7 +46,7 @@ </div> </li> <li class="nav-item dropdown"> - <a class="nav-link dropdown-toggle" href="#" id="nav-last" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> + <a class="nav-link dropdown-toggle text-light" href="#" id="nav-last" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> {% trans "Ostatnio oglądane" %} </a> <div class="dropdown-menu" id="last-visited-dropdown" aria-labelledby="nav-last"> @@ -56,7 +56,7 @@ </div> </li> <li class="nav-item dropdown"> - <a class="nav-link dropdown-toggle" href="#" id="nav-options" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> + <a class="nav-link dropdown-toggle text-light" href="#" id="nav-options" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> {% trans "Opcje" %} </a> <div class="dropdown-menu px-1" id="options-dropdown" aria-labelledby="nav-options"> -- GitLab