Skip to content

Commit f2a6a36

Browse files
More experiments with generating diagrams
1 parent 1d6972d commit f2a6a36

File tree

6 files changed

+104
-52
lines changed

6 files changed

+104
-52
lines changed

app/evaluation_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ class TestEvaluationFunction():
2323
"""
2424

2525
# Import tests that makes sure that mathematical expression comparison works as expected
26-
from .tests.symbolic_evaluation_tests import TestEvaluationFunction as TestSymbolicComparison
26+
#from .tests.symbolic_evaluation_tests import TestEvaluationFunction as TestSymbolicComparison
2727

2828
# Import tests that makes sure that physical quantities are handled as expected
29-
from .tests.physical_quantity_evaluation_tests import TestEvaluationFunction as TestQuantities
29+
#from .tests.physical_quantity_evaluation_tests import TestEvaluationFunction as TestQuantities
3030

3131
# Import tests that corresponds to examples in documentation and examples module
3232
from .tests.example_tests import TestEvaluationFunction as TestExamples

app/tests/example_tests.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
from ..evaluation import evaluation_function
55
from ..preview import preview_function
66

7+
def create_diagram_for_documentation(filename, result):
8+
for (index, graph) in result["criteria_graphs_vis"].values():
9+
with open(filename+"_"+str(index)+"_"+".mmd", "w") as f:
10+
#f.write(r'<!DOCTYPE html><html lang="en"><body><style>.mermaid {display: inline-flex;}</style>'+'\n')
11+
for g in result["criteria_graphs_vis"].values():
12+
print(g)
13+
f.write('<pre class="mermaid">\n'+g+'\n</pre>\n')
14+
#f.write('<script type="module"> import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";</script></body></html>')
715

816
class TestEvaluationFunction():
917
"""
@@ -143,6 +151,18 @@ def test_checking_the_value_of_a_physical_quantity(self, response, answer, respo
143151
assert tags == set(result["tags"])
144152
assert result["is_correct"] == value
145153

154+
def test_checking_the_value_of_a_physical_quantity_and_create_diagram_for_docs(self):
155+
params = {
156+
"strict_syntax": False,
157+
"elementary_functions": True,
158+
"physical_quantity": True,
159+
}
160+
response = "2.00 kilometre/hour"
161+
answer = "2.00 km/h"
162+
result = evaluation_function(response, answer, params, include_test_data=True)
163+
create_diagram_for_documentation("physical_quantity.html", result)
164+
assert result["is_correct"] == True
165+
146166
@pytest.mark.parametrize(
147167
"res,ans,convention,value",
148168
[
@@ -573,12 +593,13 @@ def test_custom_comparison_with_criteria_order(self, response, value, tags):
573593
}
574594
answer = "2*x^2"
575595
result = evaluation_function(response, answer, params, include_test_data=True)
576-
with open("diagrams.html", "a") as f:
577-
f.write(r'<!DOCTYPE html><html lang="en"><body><style>.mermaid {display: inline-flex;}</style>\n')
578-
for g in result["criteria_graphs_vis"].values():
579-
print(g)
580-
f.write('<pre class="mermaid">\n'+g+'\n</pre>\n')
581-
f.write('<script type="module"> import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";</script></body></html>')
596+
create_diagram_for_documentation("custom_comparison_with_criteria_order.html", result)
597+
# with open("diagrams.html", "w") as f:
598+
# f.write(r'<!DOCTYPE html><html lang="en"><body><style>.mermaid {display: inline-flex;}</style>'+'\n')
599+
# for g in result["criteria_graphs_vis"].values():
600+
# print(g)
601+
# f.write('<pre class="mermaid">\n'+g+'\n</pre>\n')
602+
# f.write('<script type="module"> import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";</script></body></html>')
582603
assert result["is_correct"] is value
583604
assert set(tags) == set(result["tags"])
584605

app/utility/criteria_graph_utilities.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,11 @@ def mermaid(self):
191191
index = 0
192192
for (label, node) in nodes.items():
193193
node_keys.update({label: "N_"+str(set_index)+"_"+str(index)})
194+
index += 1
194195
for set_index, nodes in enumerate(node_sets):
195196
style = node_styles[set_index]
196197
for (label, node) in nodes.items():
197-
output.append(node_keys[label]+style[0]+'"'+label+linebreak+node.summary+'"'+style[1])
198+
output.append(node_keys[label]+style[0]+'"'+label+linebreak+node.details+'"'+style[1])
198199
edges.update([(node_keys[edge.source.label], node_keys[edge.target.label]) for edge in node.outgoing+node.incoming])
199200
if self.sufficiencies.get(label, None) is not None:
200201
sufficiencies.update([(label, sufficiency) for sufficiency in self.sufficiencies.get(label, None)])
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html><html lang="en"><body><style>.mermaid {display: inline-flex;}</style>
2+
<pre class="mermaid">
3+
flowchart TD
4+
N_0_0(["2+answer > response<br/>---<br/>Checks if 2+answer > response is true."])
5+
N_1_0["2+answer > response_TRUE<br/>---<br/>2+answer > response is true."]
6+
N_1_1["2+answer > response_FALSE<br/>---<br/>2+answer > response is false."]
7+
N_1_2["2+answer > response_UNKNOWN<br/>---<br/>2+answer > response is false."]
8+
N_2_0{{"END<br/>---<br/>Evaluation completed."}}
9+
N_0_0 --> N_1_1
10+
N_1_0 --> N_2_0
11+
N_0_0 --> N_1_2
12+
N_1_1 --> N_2_0
13+
N_1_2 --> N_2_0
14+
N_0_0 --> N_1_0
15+
</pre>
16+
<pre class="mermaid">
17+
flowchart TD
18+
N_0_0(["answer <= response<br/>---<br/>Checks if answer <= response is true."])
19+
N_1_0["answer <= response_TRUE<br/>---<br/>answer <= response is true."]
20+
N_1_1["answer <= response_FALSE<br/>---<br/>answer <= response is false."]
21+
N_1_2["answer <= response_UNKNOWN<br/>---<br/>answer <= response is false."]
22+
N_2_0{{"END<br/>---<br/>Evaluation completed."}}
23+
N_0_0 --> N_1_1
24+
N_1_0 --> N_2_0
25+
N_0_0 --> N_1_2
26+
N_1_1 --> N_2_0
27+
N_1_2 --> N_2_0
28+
N_0_0 --> N_1_0
29+
</pre>
30+
<script type="module"> import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";</script></body></html>

diagrams.html

Lines changed: 0 additions & 43 deletions
This file was deleted.

physical_quantity.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html><html lang="en"><body><style>.mermaid {display: inline-flex;}</style>
2+
<pre class="mermaid">
3+
flowchart TD
4+
N_0_0(["response matches answer<br/>---<br/>Converts QUANTITY: response tags: {} and QUANTITY: answer tags: {} match to a common set of base units and compares their values."])
5+
N_0_1(["response matches answer_DIMENSION_MATCH<br/>---<br/>Do the dimensions of QUANTITY: response tags: {} and QUANTITY: answer tags: {} match?"])
6+
N_0_2(["response matches answer_UNIT_COMPARISON<br/>---<br/>Compares how similar the units of QUANTITY: response tags: {} and QUANTITY: answer tags: {} are."])
7+
N_1_0["response matches answer_TRUE<br/>---<br/>The quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} match."]
8+
N_1_1["response matches answer_FALSE<br/>---<br/>The quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} does not match."]
9+
N_1_2["response matches answer_MISSING_VALUE<br/>---<br/>The response is missing a value."]
10+
N_1_3["response matches answer_UNEXPECTED_VALUE<br/>---<br/>The response is expected only have unit(s), no value."]
11+
N_1_4["response matches answer_MISSING_UNIT<br/>---<br/>The response is missing unit(s)."]
12+
N_1_5["response matches answer_UNEXPECTED_UNIT<br/>---<br/>The response is expected to be a value without unit(s)."]
13+
N_1_6["response matches answer_DIMENSION_MATCH_TRUE<br/>---<br/>The quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} have the same dimensions."]
14+
N_1_7["response matches answer_DIMENSION_MATCH_FALSE<br/>---<br/>The quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} have different dimensions."]
15+
N_1_8["response matches answer_UNIT_COMPARISON_IDENTICAL<br/>---<br/>The units of quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} are identical."]
16+
N_1_9["response matches answer_UNIT_COMPARISON_SIMILAR<br/>---<br/>The units of quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} are similar."]
17+
N_1_10["response matches answer_UNIT_COMPARISON_PREFIX_IS_LARGE<br/>---<br/>The units of QUANTITY: response tags: {} are at least 1000 times greater than the units of QUANTITY: answer tags: {}."]
18+
N_1_11["response matches answer_UNIT_COMPARISON_PREFIX_IS_SMALL<br/>---<br/>The units of QUANTITY: response tags: {} are at least 1000 times smaller than the units of QUANTITY: answer tags: {}."]
19+
N_2_0{{"END<br/>---<br/>Evaluation completed."}}
20+
N_0_0 --> N_1_1
21+
N_1_2 --> N_2_0
22+
N_0_0 --> N_1_3
23+
N_0_0 --> N_1_4
24+
N_0_0 --> N_1_5
25+
N_1_7 --> N_2_0
26+
N_1_0 --> N_0_2
27+
N_1_1 --> N_0_1
28+
N_1_10 --> N_2_0
29+
N_0_2 --> N_1_11
30+
N_0_1 --> N_1_6
31+
N_1_5 --> N_2_0
32+
N_1_3 --> N_2_0
33+
N_0_2 --> N_1_8
34+
N_0_0 --> N_1_2
35+
N_0_1 --> N_1_7
36+
N_1_4 --> N_2_0
37+
N_1_6 --> N_2_0
38+
N_0_0 --> N_1_0
39+
N_0_2 --> N_1_9
40+
N_1_11 --> N_2_0
41+
N_0_2 --> N_1_10
42+
</pre>
43+
<script type="module"> import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";</script></body></html>

0 commit comments

Comments
 (0)