Skip to content

Weighted values in ideology matching (2/2) #66

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions results.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,24 @@ <h2>Closest Match: <span class="weight-300" id="ideology-label"></span></h2>
ideology = ""
ideodist = Infinity
for (var i = 0; i < ideologies.length; i++) {
//dist is the user's total distance on all axes for the current ideology
//ideodist is the final dist value for the closest ideology yet checked
dist = 0
dist += Math.pow(Math.abs(ideologies[i].stats.econ - equality), 2)
dist += Math.pow(Math.abs(ideologies[i].stats.govt - liberty), 2)
dist += Math.pow(Math.abs(ideologies[i].stats.dipl - peace), 1.73856063)
dist += Math.pow(Math.abs(ideologies[i].stats.scty - progress), 1.73856063)
//add liberty and economic distances to dist
dist += Math.pow(Math.abs(ideologies[i].stats.econ - equality), ideologies[i].stats.econWeight)
dist += Math.pow(Math.abs(ideologies[i].stats.govt - liberty), ideologies[i].stats.govtWeight)
//if diplomatic weight for current ideology is not 0, add that distance to dist
//this is done because applying a power of zero and adding that to dist would increase dist by one when the value should not change dist at all
if(ideologies[i].stats.diplWeight!=0){
dist += Math.pow(Math.abs(ideologies[i].stats.dipl - peace), ideologies[i].stats.diplWeight)
}
//if societal weight for current ideology is not 0, add that distance to dist
if(ideologies[i].stats.sctyWeight!=0){
dist += Math.pow(Math.abs(ideologies[i].stats.scty - progress), ideologies[i].stats.sctyWeight)
}
//check if this ideology is closer than the next best match
if (dist < ideodist) {
//change the ideology to the current one; set the ideodist variable to match the dist value of the new match
ideology = ideologies[i].name
ideodist = dist
}
Expand Down