This commit is contained in:
Louai Haddad 2022-06-27 15:48:56 +02:00
parent 0c92fdfb57
commit 556d1d335f
15 changed files with 6775 additions and 6707 deletions

5
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"recommendations": [
"mkaufman.HTMLHint"
]
}

View File

@ -7,7 +7,6 @@ levels = Level.objects.all().values_list('levelNumber','levelName')
standards = Standards.objects.all().values_list('standardTitle','standardTitle') standards = Standards.objects.all().values_list('standardTitle','standardTitle')
class StandardsFilter(django_filters.FilterSet): class StandardsFilter(django_filters.FilterSet):
# level = django_filters.ModelChoiceFilter(queryset = SearchResults.objects.values('level'))
level = django_filters.MultipleChoiceFilter(choices=levels) level = django_filters.MultipleChoiceFilter(choices=levels)
title = django_filters.MultipleChoiceFilter(choices=standards) title = django_filters.MultipleChoiceFilter(choices=standards)
class Meta: class Meta:

View File

@ -2,7 +2,7 @@ body,
p, p,
ul, ul,
ol { ol {
font-size: 14px !important; font-size: 16px !important;
font-family: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif; font-family: "Roboto", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #454545; color: #454545;
letter-spacing: -0.35px; letter-spacing: -0.35px;
@ -45,7 +45,7 @@ ol {
width: 30%; width: 30%;
} }
.title a { .title{
font-family: "Roboto Condensed", "Helvetica Neue", Helvetica, Arial, sans-serif; font-family: "Roboto Condensed", "Helvetica Neue", Helvetica, Arial, sans-serif;
line-height: 1; line-height: 1;
text-transform: none; text-transform: none;
@ -442,3 +442,9 @@ ol {
.dropdown-menu{ .dropdown-menu{
min-width: 25rem !important; min-width: 25rem !important;
} }
/* ############featured Qs########################## */
.fq{
width: 45%;
background-color: rgb(238, 238, 238);
}

View File

@ -36,7 +36,7 @@ anychart.onDocumentReady(function () {
.enabled(true) .enabled(true)
.useHtml(true) .useHtml(true)
.text( .text(
'Most Frequent Key-Phrases<br/>' + '<h4>Most Frequent Key-Phrases</h4><br/>' +
'<span style="color: #575e64; font-size: 12px;">' + '<span style="color: #575e64; font-size: 12px;">' +
'Click on words to get results' + 'Click on words to get results' +
'</span>' '</span>'

6
App/static/js/toggle.js Normal file
View File

@ -0,0 +1,6 @@
$(document).ready(function(){
$('#filterBtn').click(function(){
$child=$(this).children('i');
$child.toggleClass("fa-arrow-down").toggleClass("fa-arrow-up");
});
});

File diff suppressed because one or more lines are too long

View File

@ -48,9 +48,9 @@
<a href=""><img src="{% static 'img/un-logo-en.svg' %}" alt="United Nation" /></a> <a href=""><img src="{% static 'img/un-logo-en.svg' %}" alt="United Nation" /></a>
</div> </div>
<div class="title"> <div class="title">
<a href="">The Integrated Disarmament The Integrated Disarmament
Demobilization and Demobilization and
Reintegration Standards</a> Reintegration Standards
</div> </div>
<div class="search-box"> <div class="search-box">
<div class="d-flex"> <div class="d-flex">
@ -149,6 +149,7 @@
<script src="{% static 'js/swip.js' %}"></script> <script src="{% static 'js/swip.js' %}"></script>
<script src="{% static 'js/filter.js' %}"></script> <script src="{% static 'js/filter.js' %}"></script>
<script src="{% static 'js/toggle.js' %}"></script>
<script src="https://cdn.anychart.com/releases/v8/js/anychart-base.min.js"></script> <script src="https://cdn.anychart.com/releases/v8/js/anychart-base.min.js"></script>
<script src="https://cdn.anychart.com/releases/v8/js/anychart-ui.min.js"></script> <script src="https://cdn.anychart.com/releases/v8/js/anychart-ui.min.js"></script>

View File

@ -109,12 +109,12 @@
<div> <div>
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<div class=""> <div class="">
<h3>Standard: {{standard.stamdardNumber}}</h3> <h3>IDDRS {{standard.stamdardNumber}}</h3>
<h3>{{standard.standardTitle}}</h3> <h3>{{standard.standardTitle}}</h3>
</div> </div>
<div class="align-self-center"> <div class="align-self-center">
{% with 'IDDRSStandards/'|add:standard.standardPath as filePath %} {% with 'IDDRSStandards/'|add:standard.standardPath as filePath %}
<a href="{% static filePath %}" target="_blank" class="btn btn-light border rounded-3">Open Standard</a> <a href="{% static filePath %}" target="_blank" class="btn btn-light border rounded-3">Open Module</a>
{% endwith %} {% endwith %}
</div> </div>
</div> </div>

View File

@ -6,13 +6,14 @@
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-lg-8"> <div class="col-lg-8">
<form class="d-flex align-items-center" id="searchForm" method="get"> <form class="d-flex align-items-center" id="searchForm" method="get">
<input type="text" class="form-control" name ="phrase" placeholder="Seach IDDRS ..." aria-label="Seach IDDRS ..." aria-describedby="basic-addon1"> <input type="text" class="form-control" name="phrase" placeholder="Seach IDDRS ..."
aria-label="Seach IDDRS ..." aria-describedby="basic-addon1">
<button id="submitSearch" type="submit" class="btn-default">Search</button> <button id="submitSearch" type="submit" class="btn-default">Search</button>
</form> </form>
</div> </div>
</div> </div>
{% if results %}
<form id="fiterForm" method="get"> <form id="fiterForm" method="get">
<div class="d-flex justify-content-evenly mt-3"> <div class="d-flex justify-content-evenly mt-3">
{% for level in levels %} {% for level in levels %}
@ -25,10 +26,11 @@
{% for standard in standards %} {% for standard in standards %}
{% if standard.standardLevel == level.levelNumber %} {% if standard.standardLevel == level.levelNumber %}
<div class="form-check"> <div class="form-check">
<input class="form-check-input" name="title" type="checkbox" value="{{ standard.standardTitle }}" {% if standard.standardTitle in selectedChoices %} checked {% endif %} <input class="form-check-input" name="title" type="checkbox" value="{{ standard.standardTitle }}"
{% if standard.standardTitle in selectedChoices %} checked {% endif %}
id="checkbox{{ standard.id }}"> id="checkbox{{ standard.id }}">
<label class="form-check-label" for="checkbox{{ standard.id }}"> <label class="form-check-label" for="checkbox{{ standard.id }}">
{{ standard.standardTitle }} {{ standard.stamdardNumber }} {{ standard.standardTitle }}
</label> </label>
</div> </div>
{% endif %} {% endif %}
@ -37,22 +39,36 @@
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
<input type="text" class="form-control" name ="searchedPhrase" value="{{phrase}}" hidden> <input type="text" class="form-control" name="searchedPhrase" value="{{phrase}}" hidden>
</form> </form>
{% endif %}
<div class="mt-5"> <div class="mt-5">
{% if results %} {% if results %}
<h4>Results for: {{ phrase }}</h4> <h4>Results for: {{ phrase }}</h4>
{% endif %} {% endif %}
{% if selectedChoices %}
<h5>Based on the following filter/s: <a class="text-dark" id="filterBtn" href="#filterCollapse"
data-bs-toggle="collapse" role="button" aria-expanded="false" aria-controls="filterCollapse"><i
class="fa fa-arrow-down" aria-hidden="true"></i></a></h5>
<div class="ps-5 collapse" id="filterCollapse">
{% for choice in selectedChoices %}
<h6 class="text-secondary">{{choice}}</h6>
{% endfor %}
</div>
{% endif %}
{% for result in results %} {% for result in results %}
<div class="card" data-bs-toggle="modal" data-bs-target="#staticBackdrop{{result.index}}"> <div class="card" data-bs-toggle="modal" data-bs-target="#staticBackdrop{{result.index}}">
<div class="card-header card-header-test1 level-text-{{ result.level|make_list|first }}"> <div class="card-header card-header-test1 level-text-{{ result.level|make_list|first }}">
Level {{ result.level|make_list|first }}, Standard {{result.module}}, Page {{result.pageNumber}} Level {{ result.level|make_list|first }}, IDDRS {{result.module}}, <span class="float-end"> Page
{{result.pageNumber}} </span>
</div> </div>
<div class="card-body"> <div class="card-body">
<h5 class="card-title"> <h5 class="card-title">
@ -66,23 +82,53 @@
{% endfor %} {% endfor %}
</div> </div>
{% if results %} {% if results %}
<nav aria-label="Page navigation example"> <nav aria-label="Page navigation example">
<ul class="pagination"> <ul class="pagination">
{% for i in pages.page_range %} {% for i in pages.page_range %}
{% if 'title' in request.get_full_path or 'phrase' in request.get_full_path or 'searchedPhrase' in request.get_full_path %} {% if 'title' in request.get_full_path or 'phrase' in request.get_full_path or 'searchedPhrase' in request.get_full_path %}
<li class="page-item {% if i == pNumber %} active {% endif %}"><a class="page-link" href="{{ request.get_full_path }}&page={{ i }}">{{ i }}</a></li> <li class="page-item {% if i == pNumber %} active {% endif %}"><a class="page-link"
{% else %} href="{{ request.get_full_path }}&page={{ i }}">{{ i }}</a></li>
<li class="page-item {% if i == pNumber %} active {% endif %}"><a class="page-link" href="?page={{ i }}">{{ i }}</a></li> {% else %}
{% endif %} <li class="page-item {% if i == pNumber %} active {% endif %}"><a class="page-link" href="?page={{ i }}">{{ i
}}</a></li>
{% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
</nav> </nav>
{% endif %} {% endif %}
<div id="wordCloud">
<div class="d-flex justify-content-between mt-5">
<div class="border p-2 fq" >
<h4 class="text-decoration-underline">Featured Questions About IDDRS Framework</h4>
<ul>
<li class="mb-3">
<div class="fw-bold">Featured Questions About IDDRS Framework</div>
</li>
<li class="mb-3">
<div class="fw-bold">Featured Questions About IDDRS Framework</div>
</li>
<li class="mb-3">
<div class="fw-bold">Featured Questions About IDDRS Framework</div>
</li>
<li class="mb-3">
<div class="fw-bold">Featured Questions About IDDRS Framework</div>
</li>
<li class="mb-3">
<div class="fw-bold">Featured Questions About IDDRS Framework</div>
</li>
</ul>
</div>
<div class="border" style="width: 50%;">
<div id="wordCloud">
</div>
</div>
</div> </div>
@ -94,8 +140,9 @@
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<div class="" id="staticBackdropLabel{{result.index}}"> <div class="" id="staticBackdropLabel{{result.index}}">
<p class="modal-level level-text-{{ result.level|make_list|first }}">Level {{result.level}}</p> <p class="modal-level level-text-{{ result.level|make_list|first }}">Level {{result.level}} {{
<p class="modal-module">Standard {{result.module}}</p> result.levelName }}</p>
<p class="modal-module">IDDRS {{result.module}}</p>
<p class="modal-heading">{{result.heading1}}</p> <p class="modal-heading">{{result.heading1}}</p>
<p class="modal-heading modal-heading-2">{{result.heading2}}</p> <p class="modal-heading modal-heading-2">{{result.heading2}}</p>
<p class="modal-heading modal-heading-3">{{result.heading3}}</p> <p class="modal-heading modal-heading-3">{{result.heading3}}</p>
@ -108,7 +155,7 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p>{{ result.paragraph|highlight_search:result.sentence|safe }}</p> <p>{{ result.paragraph|highlight_search:result.sentence|safe|linebreaks }}</p>
<p class="text-end">Page: {{result.pageNumber}}</p> <p class="text-end">Page: {{result.pageNumber}}</p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
@ -121,3 +168,4 @@
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}

View File

@ -5,7 +5,7 @@ import os
import pandas as pd import pandas as pd
from .similarity import phrase_preprocessing, similarityCheck from .similarity import phrase_preprocessing, similarityCheck
from .tfidfSimilarity import cosine_similarity from .tfidfSimilarity import cosine_similarity
import json
from django.shortcuts import redirect from django.shortcuts import redirect
from django.core.paginator import Paginator from django.core.paginator import Paginator
@ -16,6 +16,8 @@ from .filters import StandardsFilter
import uuid import uuid
from datetime import date, timedelta from datetime import date, timedelta
from django.core import serializers
# Create your views here. # Create your views here.
@ -85,7 +87,7 @@ def tfidf(request):
else: else:
phrase = form.cleaned_data["phrase"] phrase = form.cleaned_data["phrase"]
searchResults = cosine_similarity(20, phrase) searchResults = cosine_similarity(30, phrase)
uid = str(uuid.uuid1())[:8]+phrase uid = str(uuid.uuid1())[:8]+phrase
for result in searchResults: for result in searchResults:
searchedData = SearchResults( searchedData = SearchResults(
@ -111,6 +113,7 @@ def tfidf(request):
results = SearchResults.objects.filter(uniqueID=uid) results = SearchResults.objects.filter(uniqueID=uid)
if selectedChoices: if selectedChoices:
results = SearchResults.objects.filter(uniqueID=uid) results = SearchResults.objects.filter(uniqueID=uid)
myFilter = StandardsFilter(request.GET, queryset=results) myFilter = StandardsFilter(request.GET, queryset=results)
@ -120,7 +123,7 @@ def tfidf(request):
form = searchForm() form = searchForm()
# Create pagination for results # Create pagination for results
paginator = Paginator(results, per_page=5) paginator = Paginator(results, per_page=10)
pageNumber = request.GET.get('page', 1) pageNumber = request.GET.get('page', 1)
page_obj = paginator.get_page(pageNumber) page_obj = paginator.get_page(pageNumber)

Binary file not shown.