Skip to content

Commit

Permalink
started new derivation; added AST to step_review
Browse files Browse the repository at this point in the history
  • Loading branch information
bhpayne committed May 6, 2020
1 parent ea9e5f7 commit 32f12ad
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 57 deletions.
2 changes: 2 additions & 0 deletions flask/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2797,6 +2797,7 @@ def add_symbol(
category: str,
latex: str,
name: str,
dimension: str,
reference: str,
value: str,
units: str,
Expand All @@ -2813,6 +2814,7 @@ def add_symbol(
symbol_dict["category"] = category
symbol_dict["latex"] = latex
symbol_dict["name"] = name
symbol_dict["measure"] = dimension
symbol_dict["scope"] = scope
symbol_dict["references"] = [reference]
if category == "constant" and len(value) > 0:
Expand Down
34 changes: 23 additions & 11 deletions flask/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ class NewSymbolForm(FlaskForm):

symbol_latex = StringField("latex", validators=[validators.InputRequired()])
symbol_name = StringField("name", validators=[validators.InputRequired()])
symbol_measure = StringField("dimensions", validators=[validators.InputRequired()])
symbol_reference = StringField("reference")
symbol_value = StringField("value")
symbol_units = StringField("units")
Expand Down Expand Up @@ -1204,6 +1205,7 @@ def list_all_symbols():
request.form["symbol_category"],
request.form["symbol_latex"],
request.form["symbol_name"],
request.form["symbol_measure"],
request.form["symbol_reference"],
value,
units,
Expand Down Expand Up @@ -1973,12 +1975,12 @@ def step_review(deriv_id: str, local_step_id: str):
logger.error(str(err))
flash(str(err))
derivation_validity_dict[step_id] = "failed"
try:
step_dict = dat["derivations"][deriv_id]["steps"]
except Exception as err:
logger.error(str(err))
flash(str(err))
step_dict = {}
#try:
# step_dict = dat["derivations"][deriv_id]["steps"]
#except Exception as err:
# logger.error(str(err))
# flash(str(err))
# step_dict = {}
else:
logger.debug(deriv_id + "does not exist in derivations")
derivation_validity_dict = {}
Expand All @@ -2002,20 +2004,30 @@ def step_review(deriv_id: str, local_step_id: str):
flash(str(err))
list_of_symbols = []

try:
expr_dict_with_symbol_list = compute.generate_expr_dict_with_symbol_list(
path_to_db
)
except Exception as err:
logger.error(str(err))
flash(str(err))
expr_dict_with_symbol_list = {}

return render_template(
"step_review.html",
webform=webform,
name_of_graphviz_png=step_graphviz_png,
deriv_id=deriv_id,
dat=dat,
expression_popularity_dict=expression_popularity_dict,
step_dict=step_dict,
expr_dict_with_symbol_list=expr_dict_with_symbol_list,
#step_dict=step_dict,
list_of_symbols=list_of_symbols,
symbols=dat["symbols"],
expr_dict=dat["expressions"],
expressions_dict=dat["expressions"],
#symbols=dat["symbols"],
#expr_dict=dat["expressions"],
#expressions_dict=dat["expressions"],
derivation_validity_dict=derivation_validity_dict,
expr_local_to_global=dat["expr local to global"],
#expr_local_to_global=dat["expr local to global"],
title="step review",
)

Expand Down
92 changes: 91 additions & 1 deletion flask/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -4126,6 +4126,43 @@
"creation date": "2020-04-23"
}
}
},
"387954": {
"name": "speed of Earth around Sun",
"author": "Ben",
"notes": "from Tipler and Llewellyn, third edition, page 9",
"creation date": "2020-05-06",
"steps": {
"9784411": {
"inf rule": "declare initial expr",
"inputs": [],
"feeds": [],
"outputs": [
"1131405"
],
"linear index": 1,
"notes": "",
"author": "Ben",
"creation date": "2020-05-06"
},
"5700345": {
"inf rule": "substitute X for Y",
"inputs": [
"1131405"
],
"feeds": [
"1022830",
"8635770"
],
"outputs": [
"7360652"
],
"linear index": 2,
"notes": "",
"author": "Ben",
"creation date": "2020-05-06"
}
}
}
},
"expr local to global": {
Expand Down Expand Up @@ -4495,7 +4532,11 @@
"4277577": "9040079362",
"2414344": "2131616531",
"8147899": "9565166889",
"5564581": "2113211456"
"5564581": "2113211456",
"1131405": "5426308937",
"1022830": "7476820482",
"8635770": "1277713901",
"7360652": "6946088325"
},
"expressions": {
"0000040490": {
Expand Down Expand Up @@ -8391,6 +8432,42 @@
"notes": "",
"author": "Ben",
"creation date": "2020-04-23"
},
"5426308937": {
"latex": "v = \\frac{d}{t}",
"AST": [
"1467",
"1357",
"1943"
],
"name": "",
"notes": "",
"author": "Ben",
"creation date": "2020-05-06"
},
"7476820482": {
"latex": "C",
"AST": [],
"name": "",
"notes": "",
"author": "Ben",
"creation date": "2020-05-06"
},
"1277713901": {
"latex": "d",
"AST": [],
"name": "",
"notes": "",
"author": "Ben",
"creation date": "2020-05-06"
},
"6946088325": {
"latex": "v = \\frac{C}{t}",
"AST": [],
"name": "",
"notes": "",
"author": "Ben",
"creation date": "2020-05-06"
}
},
"inference rules": {
Expand Down Expand Up @@ -9846,6 +9923,19 @@
],
"author": "Ben",
"creation date": "2020-05-03"
},
"1943": {
"category": "variable",
"latex": "d",
"name": "displacement",
"scope": [
"real"
],
"references": [
"https://en.wikipedia.org/wiki/Displacement_(geometry)"
],
"author": "Ben",
"creation date": "2020-05-06"
}
},
"units": {
Expand Down
1 change: 1 addition & 0 deletions flask/templates/list_all_symbols.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ <h2>

{{ new_symbol_form.symbol_latex.label }}(<small><B>Required</B></small>): {{ new_symbol_form.symbol_latex }}<BR>
{{ new_symbol_form.symbol_name.label }}(<small><B>Required</B></small>): {{ new_symbol_form.symbol_name }}<BR>
{{ new_symbol_form.symbol_measure.label }}(<small><B>Required</B></small>): {{ new_symbol_form.symbol_measure }}<BR>
{{ new_symbol_form.symbol_scope_real.label }}: {{ new_symbol_form.symbol_scope_real }}<BR>
{{ new_symbol_form.symbol_scope_complex.label }}: {{ new_symbol_form.symbol_scope_complex }}<BR>
{{ new_symbol_form.symbol_reference.label }}(<small><i>optional</i></small>): {{ new_symbol_form.symbol_reference }}<BR>
Expand Down
84 changes: 39 additions & 45 deletions flask/templates/step_review.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,47 @@
<!-- https://stackoverflow.com/questions/28207761/where-does-flask-look-for-image-files -->
<P><img src="{{ url_for('static', filename=name_of_graphviz_png) }}">

<P>
<fieldset>
<legend>
<a id="define symbol">
<H2>Define Symbols used</h2>
</a>
</legend>
<a href="https://github.com/allofphysicsgraph/proofofconcept/issues/124">https://github.com/allofphysicsgraph/proofofconcept/issues/124</a><BR>
This feature is in progress and is not yet working
{% if not current_user.is_anonymous %}
<form method="post" action="">
<!-- https://flask-wtf.readthedocs.io/en/v0.12/csrf.html -->
{{ webform.csrf_token }}
<div class="form-group">

{% for this_symbol in list_of_symbols %}

<P>{{ this_symbol }}
<table border="1">
{% for subfield in webform.symbol_radio %}
<tr>
<td>{{ subfield }}</td>
<td>{{ subfield.label }}</td>
{% if loop.index0 == 0 %}
<td>select existing symbol ID</td>
{% elif loop.index0 == 1 %}
<td>
<div class="input-group">
<P>{{ webform.symbol_latex.label }}: {{ webform.symbol_latex(size=50, maxlength=300) }}
<P>{{ webform.symbol_name.label }}: {{ webform.symbol_name(size=50, maxlength=300) }}
<P>{{ webform.symbol_reference.label }}: {{ webform.symbol_reference(size=50, maxlength=500) }}
</div>
<button type="submit" class="btn btn-default">Add</button>
</td>
{% endif %}
</tr>
{% endfor %}
</table>

<h2>AST for each expression in step</h2>
<P>From Sympy's parsing of the Latex
{% for ast_png_and_id in list_of_expression_AST_dicts %}
<P>
<a href="{{ url_for('list_all_expressions') }}?referrer=modify_step#{{ ast_png_and_id['expr global id'] }}">{{ ast_png_and_id['expr global id'] }}</a>: \({{ dat['expressions'][ast_png_and_id['expr global id']]['latex'] }}\)<BR>
symbols from Sympy: {{ ast_png_and_id['symbols from sympy'] }}<BR>
symbols from PDG AST:
{% for symbol_id in ast_png_and_id['symbols from PDG AST'] %}
(<a href="{{ url_for('list_all_symbols') }}?referrer=modify_step#{{ symbol_id }}">{{ symbol_id }}</a>:
{{ dat['symbols'][symbol_id]['latex'] }}),
{% endfor %}
<BR>
{% if ast_png_and_id["sympy symbols without PDG AST ID"]|length > 0 %}
Sympy symbols lacking PDG AST ID: {{ ast_png_and_id["sympy symbols without PDG AST ID"] }}<BR>
{% else %}
all Sympy symbols have corresponding PDG AST IDs<BR>
{% endif %}
<img src="{{ url_for('static', filename=ast_png_and_id['ast png filename']) }}">
{% endfor %}
</div>
</form>
</fieldset>
{% else %}
This action requires you to be <a href="{{ url_for('login') }}">signed in</a>
{% endif %}
</P>
</p>

<H2>Symbols in use in this step according to Sympy</h2>
<P>From Sympy's parsing of the Latex
<UL>
{% for symbol_latex in list_of_symbols_from_sympy %}
<LI> {{ symbol_latex }} </LI>
{% endfor %}
</UL>
</P>

<h2>Symbols in PDG AST for this step</h2>
<UL>
{% for symbol_id in list_of_symbols_from_PDG_AST %}
<LI> <a href="{{ url_for('list_all_symbols') }}?referrer=modify_step#{{ symbol_id }}">{{ symbol_id }}</a>:
{{ dat['symbols'][symbol_id]['latex'] }}
{% endfor %}
</UL>




<P>
{% include '_table_of_derivation_steps.html' %}
Expand Down

0 comments on commit 32f12ad

Please sign in to comment.