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 # 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 = search.is_free(json)
free = True
page = page + "\n <h1>" page = page + "\n <h1>"
@ -117,16 +111,20 @@ def suggestions(page, json):
page = page + "<h1>Free Competitors:</h1>" page = page + "<h1>Free Competitors:</h1>"
found = search.suggest(json) found = search.suggest(json)
biggest = 0
for i in found:
if i[0] > biggest:
biggest = i[0]
for i in found: for i in found:
free = False free = search.is_free(i[-1])
if "licenses" in i[-1] and i[-1]["licenses"]:
free = True
if not i[0] or i[-1] == json or not free: if not i[0] or i[-1] == json or not free:
continue continue
#page = page + "<br><br>"
page = page + "<hr><br>Features match: " + str(int(i[0]/biggest*100)) + "%"
page = html(page, i[-1]) page = html(page, i[-1])
return page return page

View file

@ -48,12 +48,15 @@ def search_app(name):
if closest: if closest:
return closest, match return closest, match
match = 0
closest = {}
# Round 2. By Generic name # Round 2. By Generic name
for i in all_apps: for i in all_apps:
for n in i.get("generic_name",[]): for n in i.get("generic_name",[]):
m = similar(n.lower(), name.lower()) m = similar(n.lower(), name.lower())
if m > match: if m > match and is_free(i):
closest = i closest = i
match = m match = m
@ -97,3 +100,15 @@ def suggest(json_data):
fount = [] fount = []
return found 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 # 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 = 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) page = render.source_code_link(page)
self.send(page) self.send(page)
@ -79,7 +79,7 @@ class handler(BaseHTTPRequestHandler):
software_data, match = search.search_app(software) software_data, match = search.search_app(software)
page = render.search_widget("") 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 # Let's add the found software to the page
page = render.html(page, software_data) page = render.html(page, software_data)
page = render.suggestions(page, software_data) page = render.suggestions(page, software_data)