Skip to content

Commit 0b1c61f

Browse files
Merge pull request #219 from lambda-feedback/tr124-restructuring
Some minor updates after checking compatibility with SymbolicEqual
2 parents 1593985 + c4392ec commit 0b1c61f

9 files changed

+161
-16
lines changed

app/context/symbolic.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,12 @@ def equality_equivalence(unused_input):
316316

317317
# TODO: Remove when criteria for checking proportionality is implemented
318318
if isinstance(res, Equality) and isinstance(ans, Equality):
319-
symbols_in_equality_ratio = ((res.args[0]-res.args[1])/(ans.args[0]-ans.args[1])).simplify().free_symbols
319+
if (res.args[0]-res.args[1]).simplify() == 0:
320+
symbols_in_equality_ratio = (ans.args[0]-ans.args[1]).simplify().free_symbols
321+
elif (ans.args[0]-ans.args[1]).simplify() == 0:
322+
symbols_in_equality_ratio = (res.args[0]-res.args[1]).simplify().free_symbols
323+
else:
324+
symbols_in_equality_ratio = ((res.args[0]-res.args[1])/(ans.args[0]-ans.args[1])).simplify().free_symbols
320325
result = {str(s) for s in symbols_in_equality_ratio}.issubset(parameters_dict["parsing_parameters"]["constants"])
321326
if result is True:
322327
return {

app/tests/example_tests.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
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 enumerate(result["criteria_graphs_vis"].values()):
9+
with open(filename+"_"+str(index)+".md", "w") as f:
10+
#f.write(r'<!DOCTYPE html><html lang="en"><body><style>.mermaid {display: inline-flex;}</style>'+'\n')
11+
f.write("```mermaid\n")
12+
for g in result["criteria_graphs_vis"].values():
13+
print(g)
14+
#f.write('<pre class="mermaid">\n'+g+'\n</pre>\n')
15+
f.write(g+"\n")
16+
#f.write('<script type="module"> import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";</script></body></html>')
17+
f.write("```\n")
718

819
class TestEvaluationFunction():
920
"""
@@ -143,6 +154,18 @@ def test_checking_the_value_of_a_physical_quantity(self, response, answer, respo
143154
assert tags == set(result["tags"])
144155
assert result["is_correct"] == value
145156

157+
def test_checking_the_value_of_a_physical_quantity_and_create_diagram_for_docs(self):
158+
params = {
159+
"strict_syntax": False,
160+
"elementary_functions": True,
161+
"physical_quantity": True,
162+
}
163+
response = "2.00 kilometre/hour"
164+
answer = "2.00 km/h"
165+
result = evaluation_function(response, answer, params, include_test_data=True)
166+
create_diagram_for_documentation("physical_quantity", result)
167+
assert result["is_correct"] == True
168+
146169
@pytest.mark.parametrize(
147170
"res,ans,convention,value",
148171
[
@@ -573,6 +596,13 @@ def test_custom_comparison_with_criteria_order(self, response, value, tags):
573596
}
574597
answer = "2*x^2"
575598
result = evaluation_function(response, answer, params, include_test_data=True)
599+
create_diagram_for_documentation("custom_comparison_with_criteria_order", result)
600+
# with open("diagrams.html", "w") as f:
601+
# f.write(r'<!DOCTYPE html><html lang="en"><body><style>.mermaid {display: inline-flex;}</style>'+'\n')
602+
# for g in result["criteria_graphs_vis"].values():
603+
# print(g)
604+
# f.write('<pre class="mermaid">\n'+g+'\n</pre>\n')
605+
# f.write('<script type="module"> import mermaid from "https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs";</script></body></html>')
576606
assert result["is_correct"] is value
577607
assert set(tags) == set(result["tags"])
578608

app/tests/physical_quantity_evaluation_tests.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,18 +349,6 @@ def test_physical_quantity_with_atol(self):
349349
result = evaluation_function(res, ans, params, include_test_data=True)
350350
assert result["is_correct"] is True
351351

352-
# def test_rad_vs_Hz(self):
353-
# ans = "28.53 rad/s"
354-
# res = "4.5405 H"
355-
# params = {
356-
# 'rtol': 0.03,
357-
# 'strict_syntax': False,
358-
# 'physical_quantity': True,
359-
# 'elementary_functions': True,
360-
# }
361-
# result = evaluation_function(res, ans, params, include_test_data=True)
362-
# assert result["is_correct"] is True
363-
364352
def test_tolerance_given_as_string(self):
365353
ans = "4.52 kg"
366354
res = "13.74 kg"

app/tests/symbolic_evaluation_tests.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,25 @@ def test_input_symbols_takes_priority_when_containing_elementary_function_names_
19701970
result = evaluation_function(response, answer, params)
19711971
assert result["is_correct"] is True
19721972

1973+
def test_equality_with_both_sides_equal_in_response(self):
1974+
response = "(1/3)^(1/4)= (1/3)^(1/4)"
1975+
answer = "Vbar=(1/3)^(1/4)"
1976+
params = {
1977+
'atol': 0,
1978+
'rtol': 0,
1979+
'strict_syntax': False,
1980+
'elementary_functions': True,
1981+
'symbols': {
1982+
'LtDmax': {'aliases': [''], 'latex': '$(L/D)_{max}$'},
1983+
'etap': {'aliases': [''], 'latex': '$\\eta_p$'},
1984+
'sigma': {'aliases': [''], 'latex': '$\\sigma$'},
1985+
'Vbar': {'aliases': [''], 'latex': '$\\overline{V}$'},
1986+
'Pbar': {'aliases': [''], 'latex': '$\\overline{P}$'},
1987+
},
1988+
}
1989+
result = evaluation_function(response, answer, params)
1990+
assert result["is_correct"] is False
1991+
19731992
def test_integral(self):
19741993
response = "6y"
19751994
answer = "int(3*x*y, (x, 0, 2))"

app/utility/criteria_graph_utilities.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,23 @@ def json(self):
180180
return str(json.dumps(graph))
181181

182182
def mermaid(self):
183-
output = ["graph TD"]
183+
output = ["flowchart TD"]
184+
linebreak = '<br/>---<br/>'
184185
edges = set()
185186
sufficiencies = set()
186187
node_sets = [self.evaluations, self.criteria, self.outputs]
187188
node_styles = [evaluation_style, criterion_style, output_style]
189+
node_keys = {}
190+
for set_index, nodes in enumerate(node_sets):
191+
index = 0
192+
for (label, node) in nodes.items():
193+
node_keys.update({label: "N_"+str(set_index)+"_"+str(index)})
194+
index += 1
188195
for set_index, nodes in enumerate(node_sets):
189196
style = node_styles[set_index]
190197
for (label, node) in nodes.items():
191-
output.append(label+style[0]+'"'+node.summary+'"'+style[1])
192-
edges.update([(edge.source.label, edge.target.label) for edge in node.outgoing+node.incoming])
198+
output.append(node_keys[label]+style[0]+'"'+label+linebreak+node.details+'"'+style[1])
199+
edges.update([(node_keys[edge.source.label], node_keys[edge.target.label]) for edge in node.outgoing+node.incoming])
193200
if self.sufficiencies.get(label, None) is not None:
194201
sufficiencies.update([(label, sufficiency) for sufficiency in self.sufficiencies.get(label, None)])
195202
for edge in edges:

app/utility/evaluation_result_utilities.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def __init__(self):
55
self._feedback = [] # A list that will hold all feedback items
66
self._feedback_tags = {} # A dictionary that holds a list with indices to all feedback items with the same tag
77
self._criteria_graphs = {}
8+
self._criteria_graphs_vis = {}
89
self.latex = ""
910
self.simplified = ""
1011

@@ -41,6 +42,7 @@ def add_feedback_from_tags(self, tags, graph, custom_feedback=None):
4142

4243
def add_criteria_graph(self, name, graph):
4344
self._criteria_graphs.update({name: graph.json()})
45+
self._criteria_graphs_vis.update({name: graph.mermaid()})
4446

4547
def _serialise_feedback(self) -> str:
4648
feedback = []
@@ -56,6 +58,7 @@ def serialise(self, include_test_data=False) -> dict:
5658
out.update(dict(tags=list(self._feedback_tags.keys())))
5759
if include_test_data is True:
5860
out.update(dict(criteria_graphs=self._criteria_graphs))
61+
out.update(dict(criteria_graphs_vis=self._criteria_graphs_vis))
5962
if self.latex is not None:
6063
out.update(dict(response_latex=self.latex))
6164
if self.simplified is not None:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
```mermaid
2+
flowchart TD
3+
N_0_0(["answer <= response<br/>---<br/>Checks if answer <= response is true."])
4+
N_1_0["answer <= response_TRUE<br/>---<br/>answer <= response is true."]
5+
N_1_1["answer <= response_FALSE<br/>---<br/>answer <= response is false."]
6+
N_1_2["answer <= response_UNKNOWN<br/>---<br/>answer <= response is false."]
7+
N_2_0{{"END<br/>---<br/>Evaluation completed."}}
8+
N_0_0 --> N_1_2
9+
N_1_0 --> N_2_0
10+
N_1_1 --> N_2_0
11+
N_0_0 --> N_1_0
12+
N_0_0 --> N_1_1
13+
N_1_2 --> N_2_0
14+
flowchart TD
15+
N_0_0(["2+answer > response<br/>---<br/>Checks if 2+answer > response is true."])
16+
N_1_0["2+answer > response_TRUE<br/>---<br/>2+answer > response is true."]
17+
N_1_1["2+answer > response_FALSE<br/>---<br/>2+answer > response is false."]
18+
N_1_2["2+answer > response_UNKNOWN<br/>---<br/>2+answer > response is false."]
19+
N_2_0{{"END<br/>---<br/>Evaluation completed."}}
20+
N_0_0 --> N_1_2
21+
N_1_0 --> N_2_0
22+
N_1_1 --> N_2_0
23+
N_0_0 --> N_1_0
24+
N_0_0 --> N_1_1
25+
N_1_2 --> N_2_0
26+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
```mermaid
2+
flowchart TD
3+
N_0_0(["answer <= response<br/>---<br/>Checks if answer <= response is true."])
4+
N_1_0["answer <= response_TRUE<br/>---<br/>answer <= response is true."]
5+
N_1_1["answer <= response_FALSE<br/>---<br/>answer <= response is false."]
6+
N_1_2["answer <= response_UNKNOWN<br/>---<br/>answer <= response is false."]
7+
N_2_0{{"END<br/>---<br/>Evaluation completed."}}
8+
N_0_0 --> N_1_2
9+
N_1_0 --> N_2_0
10+
N_1_1 --> N_2_0
11+
N_0_0 --> N_1_0
12+
N_0_0 --> N_1_1
13+
N_1_2 --> N_2_0
14+
flowchart TD
15+
N_0_0(["2+answer > response<br/>---<br/>Checks if 2+answer > response is true."])
16+
N_1_0["2+answer > response_TRUE<br/>---<br/>2+answer > response is true."]
17+
N_1_1["2+answer > response_FALSE<br/>---<br/>2+answer > response is false."]
18+
N_1_2["2+answer > response_UNKNOWN<br/>---<br/>2+answer > response is false."]
19+
N_2_0{{"END<br/>---<br/>Evaluation completed."}}
20+
N_0_0 --> N_1_2
21+
N_1_0 --> N_2_0
22+
N_1_1 --> N_2_0
23+
N_0_0 --> N_1_0
24+
N_0_0 --> N_1_1
25+
N_1_2 --> N_2_0
26+
```

physical_quantity_0.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
```mermaid
2+
flowchart TD
3+
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."])
4+
N_0_1(["response matches answer_DIMENSION_MATCH<br/>---<br/>Do the dimensions of QUANTITY: response tags: {} and QUANTITY: answer tags: {} match?"])
5+
N_0_2(["response matches answer_UNIT_COMPARISON<br/>---<br/>Compares how similar the units of QUANTITY: response tags: {} and QUANTITY: answer tags: {} are."])
6+
N_1_0["response matches answer_TRUE<br/>---<br/>The quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} match."]
7+
N_1_1["response matches answer_FALSE<br/>---<br/>The quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} does not match."]
8+
N_1_2["response matches answer_MISSING_VALUE<br/>---<br/>The response is missing a value."]
9+
N_1_3["response matches answer_UNEXPECTED_VALUE<br/>---<br/>The response is expected only have unit(s), no value."]
10+
N_1_4["response matches answer_MISSING_UNIT<br/>---<br/>The response is missing unit(s)."]
11+
N_1_5["response matches answer_UNEXPECTED_UNIT<br/>---<br/>The response is expected to be a value without unit(s)."]
12+
N_1_6["response matches answer_DIMENSION_MATCH_TRUE<br/>---<br/>The quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} have the same dimensions."]
13+
N_1_7["response matches answer_DIMENSION_MATCH_FALSE<br/>---<br/>The quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} have different dimensions."]
14+
N_1_8["response matches answer_UNIT_COMPARISON_IDENTICAL<br/>---<br/>The units of quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} are identical."]
15+
N_1_9["response matches answer_UNIT_COMPARISON_SIMILAR<br/>---<br/>The units of quantities QUANTITY: response tags: {} and QUANTITY: answer tags: {} are similar."]
16+
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: {}."]
17+
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: {}."]
18+
N_2_0{{"END<br/>---<br/>Evaluation completed."}}
19+
N_0_1 --> N_1_7
20+
N_0_2 --> N_1_9
21+
N_0_2 --> N_1_11
22+
N_1_10 --> N_2_0
23+
N_1_1 --> N_0_1
24+
N_1_6 --> N_2_0
25+
N_0_0 --> N_1_5
26+
N_1_11 --> N_2_0
27+
N_1_0 --> N_0_2
28+
N_0_1 --> N_1_6
29+
N_0_2 --> N_1_8
30+
N_1_7 --> N_2_0
31+
N_0_2 --> N_1_10
32+
N_0_0 --> N_1_3
33+
N_0_0 --> N_1_1
34+
N_1_4 --> N_2_0
35+
N_0_0 --> N_1_4
36+
N_0_0 --> N_1_0
37+
N_1_2 --> N_2_0
38+
N_1_5 --> N_2_0
39+
N_1_3 --> N_2_0
40+
N_0_0 --> N_1_2
41+
```

0 commit comments

Comments
 (0)