Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
matejak committed Jun 7, 2024
1 parent c99eb6a commit 8e64741
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Following environmental variables are recognized and used:
- `LOGIN_PROVIDER_NAME`: one of `autologin` or `google`. Autologin logs in any user, google allows Google login when set up properly.
- `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`: When using google login, you need to obtain those from Google to have the Google login working.
- `PLUGINS`: An ordered, comma-separated list of plugin names to load. Plugins are Python packages located in the `plugins` directory of Estimagus.
- `CACHE_...`: Environment variables used by [flask-caching](https://flask-caching.readthedocs.io/en/latest/#configuring-flask-caching), e.g. `CACHE_TYPE=SimpleCache`.


## Assumptions
Expand Down
22 changes: 15 additions & 7 deletions estimage/webapp/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ def _update_tracker_and_local_point_cost(card_name, io_cls, form):
def move_consensus_estimate_to_authoritative(task_name):
form = flask.current_app.get_final_class("AuthoritativeForm")()
if form.validate_on_submit():
pollster_cons = webdata.AuthoritativePollster()
est_input = pollster_cons.ask_points(form.task_name.data)
r = routers.PollsterRouter()
est_input = r.global_pollster.ask_points(form.task_name.data)
estimate = data.Estimate.from_input(est_input)
form.point_cost.data = str(estimate.expected)
io_cls = web_utils.get_proj_loader()[1]
io_cls = routers.IORouter().get_card_io("proj")
try:
_update_tracker_and_local_point_cost(task_name, io_cls, form)
except Exception as exc:
Expand Down Expand Up @@ -409,17 +409,25 @@ def view_problems():
all_cards_by_id=r.all_cards_by_id, catforms=cat_forms)


def _solve_problem(form, classifier, all_cards_by_id):
def _solve_problem(solution, card, synchro, io_cls):
try:
solution.solve(card, synchro, io_cls)
except Exception as exc:
msg = f"Failed to solve problem of {card.name}: {exc}"
flask.flash(msg)


def _solve_problem_category(form, classifier, all_cards_by_id, io_cls):
cat_name = form.problem_category.data
problems_cat = classifier.CATEGORIES[cat_name]
if not problems_cat.solution.solvable:
flask.flash(f"Problem of kind '{cat_name}' can't be solved automatically.")
else:
synchro = flask.current_app.get_final_class("CardSynchronizer").from_form(form)
io_cls = web_utils.get_proj_loader()[1]
for name in form.problems.data:
problem = classifier.classified_problems[cat_name][name]
problems_cat.solution(problem).solve(all_cards_by_id[name], synchro, io_cls)
solution = problems_cat.solution(problem)
_solve_problem(solution, all_cards_by_id[name], synchro, io_cls)


@bp.route('/problems/fix/<category>', methods=['POST'])
Expand All @@ -430,7 +438,7 @@ def fix_problems(category):
form = flask.current_app.get_final_class("ProblemForm")(prefix=category)
form.add_problems(r.problem_detector.problems)
if form.validate_on_submit():
_solve_problem(form, r.classifier, r.all_cards_by_id)
_solve_problem_category(form, r.classifier, r.all_cards_by_id, r.cards_io)
else:
flask.flash(f"Error handing over solution: {form.errors}")
return flask.redirect(
Expand Down

0 comments on commit 8e64741

Please sign in to comment.