Skip to content

Invalid Misconception Explainer #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,36 @@ def index():
# For all the keys of misconception_weights, remove the prefix MisconceptionCode. if it is present
misconception_weights = {k.replace("MisconceptionCode.", ""): v for k, v in misconception_weights.items()}

# Sort the misconception_weights dictionary by value in descending order and get the first 2 items
top_two_misconceptions = sorted(misconception_weights.items(), key=lambda item: item[1], reverse=True)[:2]

##########
## With the introduction of syntactic distractor experiments,
## we may have misconception explainers that do not have a corresponding file in the 'misconceptionexplainers' directory.
## The only one we expect is 'syntactic.html'.
## So we need to check if the file exists in the directory before joining it with the 'misconceptionexplainers' directory.

red_herring = "syntactic"

ranked_misconceptions = sorted(misconception_weights.items(), key=lambda item: item[1], reverse=True)
# And remove the red herring from ranked_misconceptions
ranked_misconceptions = [item for item in ranked_misconceptions if (item[0]).lower() != red_herring]
top_two_misconceptions = ranked_misconceptions[:2]

########

# Convert the top two misconceptions back to a dictionary
top_two_misconceptions = dict(top_two_misconceptions)
# Convert the keys to lowercase and add '.html' to the end
top_two_misconceptions = [k.lower() + '.html' for k, v in top_two_misconceptions.items()]



# Join the keys with the 'misconceptionexplainers' directory
top_two_misconceptions = [os.path.join('misconceptionexplainers', k) for k in top_two_misconceptions]





# Now choose one of the top two misconceptions randomly
max_misconception = random.choice(top_two_misconceptions)
return render_template('index.html',uid = getUserName(), misconception_weights = misconception_weights, misconception_count = misconception_count, max_misconception = max_misconception)
Expand Down
2 changes: 1 addition & 1 deletion src/templates/version.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.7
1.4.9