UI tweaks / Match Percentages

This commit is contained in:
jyamihud 2022-04-01 22:59:32 +03:00
parent b8a2de97ee
commit 2cdaad9888
5 changed files with 30 additions and 17 deletions

View file

@ -12,15 +12,9 @@ def html(page, json):
# This function adds a rendering of the json into the page
# TODO: Add a more complex algorithm of checking if software is
# free or not. There are plenty of semi-free software like
# Unreal Engine. They have licenses but they do not give the users
# the four essential freedoms.
free = False
if "licenses" in json and json["licenses"]:
free = True
free = search.is_free(json)
page = page + "\n <h1>"
@ -117,16 +111,20 @@ def suggestions(page, json):
page = page + "<h1>Free Competitors:</h1>"
found = search.suggest(json)
biggest = 0
for i in found:
if i[0] > biggest:
biggest = i[0]
for i in found:
free = False
if "licenses" in i[-1] and i[-1]["licenses"]:
free = True
free = search.is_free(i[-1])
if not i[0] or i[-1] == json or not free:
continue
#page = page + "<br><br>"
page = page + "<hr><br>Features match: " + str(int(i[0]/biggest*100)) + "%"
page = html(page, i[-1])
return page

View file

@ -48,12 +48,15 @@ def search_app(name):
if closest:
return closest, match
match = 0
closest = {}
# Round 2. By Generic name
for i in all_apps:
for n in i.get("generic_name",[]):
m = similar(n.lower(), name.lower())
if m > match:
if m > match and is_free(i):
closest = i
match = m
@ -97,3 +100,15 @@ def suggest(json_data):
fount = []
return found
def is_free(data):
# TODO: Add a more complex algorithm of checking if software is
# free or not. There are plenty of semi-free software like
# Unreal Engine. They have licenses but they do not give the users
# the four essential freedoms.
free = False
if "licenses" in data and data["licenses"]:
free = True
return free

View file

@ -55,9 +55,9 @@ class handler(BaseHTTPRequestHandler):
# If the user is at the front page, let him get only the search bar
page = ""
page = "<center><br><br><br><h1>Free Competitors</h1>"
page = render.search_widget(page)
page = page + "<p>Please search for any software to which you would like to find a Free Software replacement.</p>"
page = page + "<p>Please search for any software to which you would like to find a Free Software replacement.</p></center>"
page = render.source_code_link(page)
self.send(page)
@ -79,7 +79,7 @@ class handler(BaseHTTPRequestHandler):
software_data, match = search.search_app(software)
page = render.search_widget("")
page = page +"Match: "+ str(match*100)+"%"
page = page +"Search match: "+ str(int(match*100))+"%"
# Let's add the found software to the page
page = render.html(page, software_data)
page = render.suggestions(page, software_data)