Skip to content
Snippets Groups Projects
Commit 8d26a8a8 authored by Andrey's avatar Andrey
Browse files

added simple report doc

parent 21fd5d81
No related merge requests found
......@@ -24,7 +24,7 @@ from clonus import views
urlpatterns = [
path("admin/", admin.site.urls),
path("", views.index, name="index"),
path("compare/file_to_file/", views.f2f, name="f2f"),
path("compare/file_to_file/summary/<str:h>", views.f2f_summary, name="f2f_summary"),
path("compare/file_to_database/", views.f2db, name="f2db"),
path("compare/", views.compare, name="compare"),
path("summary/<str:h>", views.summary, name="summary"),
path("list/", views.list, name="list")
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
from .method_builder import MethodBuilder
from .fp_method import FpMethodResult
class MethodConfigurator():
builder: MethodBuilder
......@@ -13,7 +13,7 @@ class MethodConfigurator():
def change_builder(self, new_builder: MethodBuilder):
self.builder = new_builder
def make_method(self):
def make_method(self)-> FpMethodResult:
self.builder.pre_processing_step()
self.builder.processing_step()
return self.builder.post_processing_step()
......@@ -15,8 +15,8 @@ clonus
<p class="text-white h4 landing">
Веб-сервис для поиска заимствований в решениях задач по программированию
</p>
<a role="button" class="btn btn-success btn-xl" href={% url 'f2f' %}>Сравнить два файла</a>
<a role="button" class="btn btn-success btn-xl" href={% url 'f2db' %}>Сравнить файл с базой данных</a>
<a role="button" class="btn btn-success btn-xl" href={% url 'compare' %}>Сравнить два файла</a>
<a role="button" class="btn btn-success btn-xl" href={% url 'list' %}>Список отчетов</a>
</div>
</div>
{% endblock content %}
......
......@@ -2,23 +2,23 @@
{% load crispy_forms_tags %}
{% load static %}
{% block title %}
{{ title }}
Сравнение двух файлов
{% endblock title %}
{% block style %}
<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}" />
{% endblock style %}
{% block content %}
<div class="mt-5 nav">
<a role="button" class="btn btn-success btn-lg" href="{% url 'index' %}">На главную</a>
</div>
<div class="d-flex align-items-center justify-content-center">
<div class="container text-white">
<div class="text-center">
<h2 class="lab"> {{ title }} </h2>
<form method="post" enctype="multipart/form-data" class="form">
{% csrf_token %}
{% crispy form %}
</form>
<div class="mt-5 nav">
<a role="button" class="btn btn-success btn-lg" href="{% url 'index' %}">На главную</a>
</div>
<div class="d-flex align-items-center justify-content-center">
<div class="container text-white">
<div class="text-center">
<h2 class="lab"> {{ title }} </h2>
<form method="post" enctype="multipart/form-data" class="form">
{% csrf_token %}
{% crispy form %}
</form>
</div>
</div>
{% endblock content %}
\ No newline at end of file
{% endblock content %}
\ No newline at end of file
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% load static %}
{% block title %}
Просмотр отчета
{% endblock title %}
{% block style %}
<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
{% endblock style %}
{% block content %}
<script>hljs.highlightAll();</script>
<div class="mt-5 nav">
<a role="button" class="btn btn-success btn-lg" href="{% url 'index' %}">На главную</a>
</div>
<div class="d-flex align-items-center justify-content-center">
<div class="container text-white">
<div class="text-center">
<h2 class="lab"> Отчет {{ hash }} </h2>
<h4> Процент оригинальности {{ coeff }}% </h4>
</div>
<div class="d-flex justify-content-between">
<div class="language-python">
<pre><code>{{ file1 }}</code></pre>
</div>
<div>
<pre><code>{{ file2 }}</code></pre>
</div>
</div>
</div>
</div>
{% endblock content %}
\ No newline at end of file
......@@ -14,7 +14,7 @@ def index(request: HttpRequest):
return render(request, "index.html")
def f2f(request: HttpRequest):
def compare(request: HttpRequest):
if request.method == "POST":
form = FileToFileForm(request.POST, request.FILES)
if form.is_valid():
......@@ -32,15 +32,15 @@ def f2f(request: HttpRequest):
p.file2 = p.path / request.FILES["file2"].name
p.gen_hash()
p.save()
return redirect("f2f_summary", h=p.hash)
return redirect("summary", h=p.hash)
else:
form = FileToFileForm()
context = {"title": "Сравнение двух файлов", "form": form}
context = {"form": form}
return render(request, "send.html", context)
def f2f_summary(request: HttpRequest, h: str):
def summary(request: HttpRequest, h: str):
try:
p = Package.objects.get(hash=h)
except Package.DoesNotExist:
......@@ -49,12 +49,31 @@ def f2f_summary(request: HttpRequest, h: str):
filenames = [p.file1, p.file2]
fp_builder = FingerprintMethodBuilder(filenames, p.gram_size, p.window_size)
config = MethodConfigurator(fp_builder)
res = config.make_method()
res.print()
method_res = config.make_method()
# method_res.print()
p.coeff = round(method_res.clone_pct * 100,2)
p.processed = True
p.save()
return render(request, "f2f_summary.html")
# TODO:
# 1). save shit to db
# 2). interpolate files with html tags
# 3). write view for summary
# 4). think of a way to implement f2db
with open(p.file1, 'r', encoding='utf-8') as f:
file1 = f.read()
with open(p.file2, 'r', encoding='utf-8') as f:
file2 = f.read()
context = {
"hash": p.hash,
"coeff": p.coeff,
"file1": file1,
"file2": file2
}
return render(request, "summary.html", context)
def f2db(request: HttpRequest):
def list(request: HttpRequest):
pass
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment