summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Smarker/assessments.py16
-rw-r--r--Smarker/database.py2
-rw-r--r--Smarker/requirements.txt1
-rw-r--r--Smarker/smarker.conf2
-rw-r--r--Smarker/smarker.py2
-rw-r--r--Smarker/templates/tex.jinja22
-rw-r--r--docs/requirements.txt3
-rw-r--r--docs/source/assessments.rst4
-rw-r--r--docs/source/docker.rst7
-rw-r--r--docs/source/quickstart.rst16
-rw-r--r--plagarism_report_matrix.pngbin0 -> 16646 bytes
11 files changed, 48 insertions, 7 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 *))
diff --git a/docs/requirements.txt b/docs/requirements.txt
new file mode 100644
index 0000000..bced0aa
--- /dev/null
+++ b/docs/requirements.txt
@@ -0,0 +1,3 @@
+Sphinx
+sphinx_mdinclude
+sphinx-argparse \ No newline at end of file
diff --git a/docs/source/assessments.rst b/docs/source/assessments.rst
index a8d7311..cd92fe1 100644
--- a/docs/source/assessments.rst
+++ b/docs/source/assessments.rst
@@ -16,6 +16,10 @@ Classes
.. autoclass:: assessments.SimilarityMetric
:members:
+.. autoclass:: assessments.StringSimilarity
+ :inherited-members:
+ :members:
+
Functions
*********
diff --git a/docs/source/docker.rst b/docs/source/docker.rst
index 232c7f4..6332dae 100644
--- a/docs/source/docker.rst
+++ b/docs/source/docker.rst
@@ -11,6 +11,13 @@ Running the system in docker has many advantages:
* Makes the system be able to be used in Windows- Smarker has been tested in docker for windows using WSL for the backend
+.. warning::
+
+ If using windows, I recommend using the mingw shell since powershell is bad at dealing with relative file paths. With mingw you can simply use ``$(pwd)``.
+
+ However, if you do, be sure to **escape file paths properly**; since, for example, ``/tmp/`` will automatically be expanded to ``C:/Users/<user>/AppData/Local/Temp/``. This causes issues when
+ setting up docker volumes. You can prefix your commands with ``MSYS_NO_PATHCONV=1`` (`see the documentation <https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion>`_).
+
Using docker
------------
diff --git a/docs/source/quickstart.rst b/docs/source/quickstart.rst
index 08f3cec..b851823 100644
--- a/docs/source/quickstart.rst
+++ b/docs/source/quickstart.rst
@@ -21,7 +21,12 @@ Then add it to the database:
docker run -v "$(pwd)/docs/source/_static/QuickStart/simple_assessment.yml":/tmp/assessment.yml -it --entrypoint python --rm smarker assessments.py -c /tmp/assessment.yml
-If using windows, I recommend using the mingw shell since powershell is bad at dealing with relative file paths in docker.
+.. warning::
+
+ If using windows, I recommend using the mingw shell since powershell is bad at dealing with relative file paths. With mingw you can simply use ``$(pwd)``.
+
+ However, if you do, be sure to **escape file paths properly**; since, for example, ``/tmp/`` will automatically be expanded to ``C:/Users/<user>/AppData/Local/Temp/``. This causes issues when
+ setting up docker volumes. You can prefix your commands with ``MSYS_NO_PATHCONV=1`` (`see the documentation <https://web.archive.org/web/20201112005258/http://www.mingw.org/wiki/Posix_path_conversion>`_).
Then add some students:
@@ -76,7 +81,11 @@ Now we can generate a plagarism report:
.. code-block:: bash
- touch out/report.pickle && sudo docker run -v "$(pwd)/out/report.pickle":/Smarker/plagarism_report_details.pickle -it --entrypoint python --rm smarker assessments.py --plagarism_report simple_assessment
+ touch out/report.pickle && touch out/matrix.png && docker run \
+ -v "$(pwd)/out/report.pickle":/Smarker/plagarism_report_details.pickle \
+ -v "$(pwd)/out/matrix.png":/Smarker/plagarism_report_matrix.png \
+ -it --entrypoint python --rm smarker \
+ assessments.py --plagarism_report simple_assessment
Which produces a pickled report matrix, and prints out to stdout:
@@ -87,9 +96,10 @@ Which produces a pickled report matrix, and prints out to stdout:
3 100.00 100.00 42.86 94.74
4 63.16 63.16 100.00 57.89
1 94.74 94.74 39.29 100.00
+ Written image to /Smarker/plagarism_report_matrix.png
Written report to /Smarker/plagarism_report_details.pickle
-If we run it outside of docker, we can also get it rendered nicely in matplotlib:
+If we run it outside of docker, we can also get it rendered nicely in matplotlib figure GUI, which enables us to resize the produced matrix:
.. image:: _static/readme_matrix.png
diff --git a/plagarism_report_matrix.png b/plagarism_report_matrix.png
new file mode 100644
index 0000000..6f65b06
--- /dev/null
+++ b/plagarism_report_matrix.png
Binary files differ