diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2022-05-24 17:36:08 +0100 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2022-05-24 17:36:08 +0100 |
commit | 80b5876ac8ce0322e0a5d821e51a1ce07fc95316 (patch) | |
tree | 187c2d53044276c85c87649117c4d3e5db02985f /Smarker | |
parent | f2f734194c03dfff2024cf417c502515ddb7a855 (diff) | |
download | Smarker-80b5876ac8ce0322e0a5d821e51a1ce07fc95316.tar.gz Smarker-80b5876ac8ce0322e0a5d821e51a1ce07fc95316.zip |
Fixed bug in tex template, added alternative similarity metric, updated docs
Diffstat (limited to 'Smarker')
-rw-r--r-- | Smarker/assessments.py | 16 | ||||
-rw-r--r-- | Smarker/database.py | 2 | ||||
-rw-r--r-- | Smarker/requirements.txt | 1 | ||||
-rw-r--r-- | Smarker/smarker.conf | 2 | ||||
-rw-r--r-- | Smarker/smarker.py | 2 | ||||
-rw-r--r-- | Smarker/templates/tex.jinja2 | 2 |
6 files changed, 21 insertions, 4 deletions
diff --git a/Smarker/assessments.py b/Smarker/assessments.py index cdcdcad..92bea02 100644 --- a/Smarker/assessments.py +++ b/Smarker/assessments.py @@ -1,5 +1,6 @@ from dataclasses import dataclass from matplotlib import pyplot as plt +import Levenshtein import numpy as np import misc_classes import configparser @@ -21,7 +22,7 @@ import re class SimilarityMetric: """Abstract class for getting a metric of similariry between two python objects. By default it uses pycode_similar as a metric, but this can be changed by overriding - ``get_similarity()``. There is also the additional attribute ``details`` for getting + :meth:`get_similarity()`. There is also the additional attribute ``details`` for getting a breakdown of similarity. """ code_text_1:str @@ -53,6 +54,13 @@ class SimilarityMetric: """ return float(re.findall(r"\d+\.\d+\s", self.details)[0]) +class StringSimilarity(SimilarityMetric): + """Example class inheriting from :class:`SimilarityMetric`, using the levenshtein + distance as a metric of similarity. + """ + def get_similarity(self): + return int((Levenshtein.ratio(self.code_text_1, self.code_text_2) * 100) * 10) / 10 + def visualise_matrix(dataframe:pd.DataFrame, file_name): """Visualize and draw a similarity matrix. Simply shows the figure, therefore this doesn't work in docker. @@ -85,7 +93,13 @@ def visualise_matrix(dataframe:pd.DataFrame, file_name): ax.text(x = j, y = i, s = values[i, j], va = 'center', ha = 'center') plt.title(file_name) + + out_path = os.path.realpath("%s_plagarism_report_matrix.png" % file_name) + plt.savefig(out_path) + print("Written image to %s" % out_path) + plt.show() + def generate_plagarism_report(assessment_name, db:database.SmarkerDatabase): diff --git a/Smarker/database.py b/Smarker/database.py index a3f77af..9a6f80a 100644 --- a/Smarker/database.py +++ b/Smarker/database.py @@ -72,7 +72,7 @@ class SmarkerDatabase: student_no VARCHAR(10) NOT NULL, assessment_name VARCHAR(30) NOT NULL, submission_dt DATETIME NOT NULL default CURRENT_TIMESTAMP, - report_yaml TEXT NOT NULL, + report_yaml MEDIUMTEXT NOT NULL, FOREIGN KEY (student_no) REFERENCES students(student_no), FOREIGN KEY (assessment_name) REFERENCES assessment(assessment_name) ); diff --git a/Smarker/requirements.txt b/Smarker/requirements.txt index af89c27..840891e 100644 --- a/Smarker/requirements.txt +++ b/Smarker/requirements.txt @@ -11,3 +11,4 @@ pycode_similar pandas
matplotlib
numpy
+python-Levenshtein
diff --git a/Smarker/smarker.conf b/Smarker/smarker.conf index 3416564..62915f1 100644 --- a/Smarker/smarker.conf +++ b/Smarker/smarker.conf @@ -2,7 +2,7 @@ host = vps.eda.gay
port = 3307
user = root
-passwd = ************
+passwd = *************
[tex]
columns = 1
diff --git a/Smarker/smarker.py b/Smarker/smarker.py index 39c22e6..aec04d1 100644 --- a/Smarker/smarker.py +++ b/Smarker/smarker.py @@ -57,7 +57,7 @@ def main(**kwargs): output_file = os.path.splitext(output_file)[0] + ".tex" with open(output_file, "w") as f: f.write(strout) - subprocess.run(["pdflatex", output_file]) + subprocess.run(["pdflatex", "-interaction=nonstopmode", output_file]) subprocess.run(["mv", os.path.splitext(os.path.split(output_file)[-1])[0] + ".pdf", os.path.split(output_file)[0]]) if os.path.exists(os.path.splitext(output_file)[0] + ".tex"): diff --git a/Smarker/templates/tex.jinja2 b/Smarker/templates/tex.jinja2 index 5985875..f4fac5b 100644 --- a/Smarker/templates/tex.jinja2 +++ b/Smarker/templates/tex.jinja2 @@ -203,6 +203,7 @@ breaklines=true \subsubsection{Runtime Analysis}
((* set flat_runtime = flatten_struct(files_contents["run"]) *))
+ ((* if len_(flat_runtime) > 0 *))
\begin{itemize}
((* for cmd, runtime_contents in flat_runtime.items() *))
\item Command: \texttt{((( tex_escape(cmd) )))}
@@ -231,6 +232,7 @@ breaklines=true ((*- endfor -*))
((* endfor *))
\end{itemize}
+ ((* endif *))
((* endif *))
((* else *))
|