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

added plagirism highlighting

parent c2184458
Branches
No related merge requests found
{% extends "base.html" %}
{% load static %}
{% block title %}
Список отчетов
Список отчетов
{% endblock title %}
{% block style %}
<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}" />
......
......@@ -2,7 +2,7 @@
{% load crispy_forms_tags %}
{% load static %}
{% block title %}
Сравнение файлов
Сравнение файлов
{% endblock title %}
{% block style %}
<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}" />
......
......@@ -8,17 +8,11 @@
<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>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js"
integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
{% comment %}
<script
src="//cdn.jsdelivr.net/gh/TRSasasusu/highlightjs-highlight-lines.js@1.2.0/highlightjs-highlight-lines.min.js"></script>
{% endcomment %}
{% endblock style %}
{% block content %}
<script>hljs.highlightAll();</script>
<div class="mt-5 nav">
<a role="button" class="btn btn-success btn-lg" onclick="history.back()">Назад</a>
</div>
......@@ -29,15 +23,21 @@
<h4 class="text-pimped"> Процент заимствования: {{ coeff|floatformat:0 }}% </h4>
</div>
<div class="d-flex justify-content-between mt-5">
<div class="language-python" id="file1">
<div class="language-python">
<h5 class="text-center bg-success">{{ f1 }}</h5>
<pre><code>{{ file1 }}</code></pre>
<pre><code id="file1">{{ file1 }}</code></pre>
</div>
<div class="language-python" id="file2">
<div class="language-python">
<h5 class="text-center bg-success">{{ f2 }}</h5>
<pre><code>{{ file2 }}</code></pre>
<pre><code id="file2">{{ file2 }}</code></pre>
</div>
</div>
</div>
</div>
<script>
const e1 = document.getElementById("file1");
const e2 = document.getElementById("file2");
hljs.highlightLinesElement(e1, [{{ q1| safe }}]);
hljs.highlightLinesElement(e2, [{{ q2| safe }}]);
</script>
{% endblock content %}
\ No newline at end of file
from django.shortcuts import render, redirect
from django.http import HttpRequest
from pathlib import Path
from collections import deque
from clonus.forms import FileToFileForm
from clonus.models import Package
......@@ -46,37 +47,65 @@ def summary(request: HttpRequest, h: str):
p = Package.objects.get(hash=h)
except Package.DoesNotExist:
return redirect("index")
if not p.processed:
filenames = [p.file1, p.file2]
fp_builder = FingerprintMethodBuilder(filenames, p.gram_size, p.window_size)
config = MethodConfigurator(fp_builder)
method_res = config.make_method()
# method_res.print()
# p.coeff = round(method_res.clone_pct * 100,2)
p.coeff = method_res.clone_pct
p.processed = True
p.save()
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()
filenames = [p.file1, p.file2]
fp_builder = FingerprintMethodBuilder(filenames, p.gram_size, p.window_size)
config = MethodConfigurator(fp_builder)
method_res = config.make_method()
p.coeff = method_res.clone_pct
p.processed = True
p.save()
def process_file(fil: Path, l: "list[list[int]]"):
res = []
pos = 0
contents = ""
line_count = 0
offsets = deque(l)
cur = offsets[0][0]
end_of_q = False
with open(fil, "r", encoding="utf-8") as f:
for line in f:
contents += line
line_count += 1
pos += len(line)
if pos >= cur and not end_of_q:
if cur == offsets[0][0]:
cur = offsets[0][1]
res.append([line_count, line_count])
else:
offsets.popleft()
try:
cur = offsets[0][0]
except IndexError:
end_of_q = True
res[-1][-1] = line_count
# print(res)
return contents, res
file1, q1 = process_file(p.file1, method_res.clone_parts_1)
file2, q2 = process_file(p.file2, method_res.clone_parts_2)
context = {
"hash": p.hash,
"coeff": p.coeff*100,
"coeff": p.coeff * 100,
"file1": file1,
"file2": file2,
"f1": Path(p.file1).name,
"f2": Path(p.file2).name
"f2": Path(p.file2).name,
"q1": ", ".join(
"{start: " + str(i) + ", end: " + str(j) + ", color: 'yellow'}"
for i, j in q1
),
"q2": ", ".join(
"{start: " + str(i) + ", end: " + str(j) + ", color: 'yellow'}"
for i, j in q2
),
}
return render(request, "summary.html", context)
def list(request: HttpRequest):
q = Package.objects.all().order_by("-date")
context = {
"packages": ((i, Path(i.file1).name, Path(i.file2).name) for i in q)
}
context = {"packages": ((i, Path(i.file1).name, Path(i.file2).name) for i in q)}
return render(request, "list.html", context)
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