1

steam_small.json aangemaakt met de eerste 5 entries, dit is om te testen.

README.md aangepast met de datastructuur die we bij het sorteren gaan gebruiken.
in sorting.py is de sorteer algoritme uitgewerkt echter is deze extreem traag. dit moet sneller gemaakt worder. Maar de omzet van json naar geneste tuple werkt
This commit is contained in:
Ventilaar 2021-01-02 13:21:04 +01:00
parent fbf559d5b5
commit 350b039d4a
3 changed files with 190 additions and 0 deletions

View File

@ -27,3 +27,38 @@ De applicatie is simpel uit te voeren door de python script uit te voeren.
python poc.py
## Data formaat geheugen tabel
Om het sorteren makkelijker te maken gaan we de json in een tuple/list opslaan in het geheugen. Het formaat is een tabel
achtige structuur. Als voorbeeld de eerste json entry in een tuple.
{
"appid":10,
"name":"Counter-Strike",
"release_date":"2000-11-01",
"english":1,
"developer":"Valve",
"publisher":"Valve",
"platforms":"windows;mac;linux",
"required_age":0,
"categories":"Multi-player;Online Multi-Player;Local Multi-Player;Valve Anti-Cheat enabled",
"genres":"Action",
"steamspy_tags":"Action;FPS;Multiplayer",
"achievements":0,
"positive_ratings":124534,
"negative_ratings":3339,
"average_playtime":17612,
"median_playtime":317,
"owners":"10000000-20000000",
"price":7.19
}
(10, "Counter-Strike", "2000-11-01", 1, "Valve", "windows;mac;linux", 0,
"Multi-player;Online Multi-Player;Local Multi-Player;Valve Anti-Cheat enabled", "Action", "Action;FPS;Multiplayer",
0, 124534, 3339, 17612, 317, "10000000-20000000", 7.19)
En om meerdere entries op te slaan maken we het genest zoals alsvolgd.
(
(10, "Counter-Strike", "2000-11-01", 1, "Valve", "windows;mac;linux", 0, "Multi-player;Online Multi-Player;Local Multi-Player;Valve Anti-Cheat enabled", "Action", "Action;FPS;Multiplayer", 0, 124534, 3339, 17612, 317, "10000000-20000000", 7.19),
(20, "Team Fortress Classic", "1999-04-01", 1, "Valve", "Valve", "windows;mac;linux", 0, "Multi-player;Online Multi-Player;Local Multi-Player;Valve Anti-Cheat enabled", "Action", "Action;FPS;Multiplayer", 0, 3318, 633, 277, 62, "5000000-10000000", 3.99)
)

53
sorting.py Normal file
View File

@ -0,0 +1,53 @@
import json
# lees json bestand en maak de tabel structuur aan, data_tpl
with open('steam.json') as file:
# laad de json in een list
blob = json.load(file)
# lege lijst aanmaken
temp_biglst = []
# voor elke item in de list
for i in blob:
# voeg elke regel in de item toe aan een tijdelijke list
temp_lst = [i['appid'], i['name'], i['release_date'], i['english'], i['developer'], i['publisher'],
i['platforms'], i['required_age'], i['categories'], i['genres'], i['steamspy_tags'],
i['achievements'], i['positive_ratings'], i['negative_ratings'], i['average_playtime'],
i['median_playtime'], i['owners'], i['price']]
# zet de tijdelijke lijst om in een tuple
temp_tpl = tuple(temp_lst)
# voeg de tijdelijke list toe in de datalijst
temp_biglst.append(temp_tpl)
# datalijst omzetten in tuple, dit is de globale variabele die opgeroepen mag worden
data_tpl = tuple(temp_biglst)
def sorteer(tpl_in, colnum, reverse=False):
"""
:param tpl_in: geneste tuple in
:param colnum: sorteren op basis van colom nummer vanaf 0
:param reverse: True of False, niet verplicht, standaard False
:return: een gesorteerde tuple
"""
lst_to_sort = list(tpl_in)
# dubbel for loop yay
for _ in range(len(lst_to_sort) - 1):
for x in range(len(lst_to_sort) - 1):
if reverse:
# als tuple+1 hoger dan x, swap plaatsen
if lst_to_sort[x][colnum] < lst_to_sort[x + 1][colnum]:
lst_to_sort[x + 1], lst_to_sort[x] = lst_to_sort[x], lst_to_sort[x + 1]
else:
# zelfde als hierboven maar dan andersom
if lst_to_sort[x][colnum] > lst_to_sort[x + 1][colnum]:
lst_to_sort[x], lst_to_sort[x + 1] = lst_to_sort[x + 1], lst_to_sort[x]
# return een tuple terug
return tuple(lst_to_sort)
sorteer(data_tpl, 0)

102
steam_small.json Normal file
View File

@ -0,0 +1,102 @@
[
{
"appid":10,
"name":"Counter-Strike",
"release_date":"2000-11-01",
"english":1,
"developer":"Valve",
"publisher":"Valve",
"platforms":"windows;mac;linux",
"required_age":0,
"categories":"Multi-player;Online Multi-Player;Local Multi-Player;Valve Anti-Cheat enabled",
"genres":"Action",
"steamspy_tags":"Action;FPS;Multiplayer",
"achievements":0,
"positive_ratings":124534,
"negative_ratings":3339,
"average_playtime":17612,
"median_playtime":317,
"owners":"10000000-20000000",
"price":7.19
},
{
"appid":20,
"name":"Team Fortress Classic",
"release_date":"1999-04-01",
"english":1,
"developer":"Valve",
"publisher":"Valve",
"platforms":"windows;mac;linux",
"required_age":0,
"categories":"Multi-player;Online Multi-Player;Local Multi-Player;Valve Anti-Cheat enabled",
"genres":"Action",
"steamspy_tags":"Action;FPS;Multiplayer",
"achievements":0,
"positive_ratings":3318,
"negative_ratings":633,
"average_playtime":277,
"median_playtime":62,
"owners":"5000000-10000000",
"price":3.99
},
{
"appid":30,
"name":"Day of Defeat",
"release_date":"2003-05-01",
"english":1,
"developer":"Valve",
"publisher":"Valve",
"platforms":"windows;mac;linux",
"required_age":0,
"categories":"Multi-player;Valve Anti-Cheat enabled",
"genres":"Action",
"steamspy_tags":"FPS;World War II;Multiplayer",
"achievements":0,
"positive_ratings":3416,
"negative_ratings":398,
"average_playtime":187,
"median_playtime":34,
"owners":"5000000-10000000",
"price":3.99
},
{
"appid":40,
"name":"Deathmatch Classic",
"release_date":"2001-06-01",
"english":1,
"developer":"Valve",
"publisher":"Valve",
"platforms":"windows;mac;linux",
"required_age":0,
"categories":"Multi-player;Online Multi-Player;Local Multi-Player;Valve Anti-Cheat enabled",
"genres":"Action",
"steamspy_tags":"Action;FPS;Multiplayer",
"achievements":0,
"positive_ratings":1273,
"negative_ratings":267,
"average_playtime":258,
"median_playtime":184,
"owners":"5000000-10000000",
"price":3.99
},
{
"appid":50,
"name":"Half-Life: Opposing Force",
"release_date":"1999-11-01",
"english":1,
"developer":"Gearbox Software",
"publisher":"Valve",
"platforms":"windows;mac;linux",
"required_age":0,
"categories":"Single-player;Multi-player;Valve Anti-Cheat enabled",
"genres":"Action",
"steamspy_tags":"FPS;Action;Sci-fi",
"achievements":0,
"positive_ratings":5250,
"negative_ratings":288,
"average_playtime":624,
"median_playtime":415,
"owners":"5000000-10000000",
"price":3.99
}
]