I am learning python and I am looking for a library or a solution that allows me to rank json data by matching criteria/condition and that will return each json object with its matching score.
For example if we have the following example of data set :
{ "name": "Ronaldo", country: "Brazil", "world cups title": 1, UCL : 0, Ballon d'Or : 2 },
{ "name": "Maradona", country: "Argentina", "world cups title": 1, UCL : 0, Ballon d'Or : 0 },
{ "name": "Cristiano Ronaldo", country: "Portugal", "world cups title": 0, UCL : 5, Ballon d'Or : 5 },
{ "name": "Zidane", country: "France", "world cups title": 1, UCL : 1, Ballon d'Or : 1 },
{ "name": "Pele", country: "Brazil", "world cups title": 3, UCL : 0, Ballon d'Or : 0 },
{ "name": "Toni Kroos", country: "Germany", "world cups title": 1, UCL : 5, Ballon d'Or : 0 },
{ "name": "Messi", country: "Argentina", "world cups title": 1, UCL : 4, Ballon d'Or : 8 },
<code>{
"Best soccer players": [
{ "name": "Ronaldo", country: "Brazil", "world cups title": 1, UCL : 0, Ballon d'Or : 2 },
{ "name": "Maradona", country: "Argentina", "world cups title": 1, UCL : 0, Ballon d'Or : 0 },
{ "name": "Cristiano Ronaldo", country: "Portugal", "world cups title": 0, UCL : 5, Ballon d'Or : 5 },
{ "name": "Zidane", country: "France", "world cups title": 1, UCL : 1, Ballon d'Or : 1 },
{ "name": "Pele", country: "Brazil", "world cups title": 3, UCL : 0, Ballon d'Or : 0 },
{ "name": "Toni Kroos", country: "Germany", "world cups title": 1, UCL : 5, Ballon d'Or : 0 },
{ "name": "Messi", country: "Argentina", "world cups title": 1, UCL : 4, Ballon d'Or : 8 },
]
}
</code>
{
"Best soccer players": [
{ "name": "Ronaldo", country: "Brazil", "world cups title": 1, UCL : 0, Ballon d'Or : 2 },
{ "name": "Maradona", country: "Argentina", "world cups title": 1, UCL : 0, Ballon d'Or : 0 },
{ "name": "Cristiano Ronaldo", country: "Portugal", "world cups title": 0, UCL : 5, Ballon d'Or : 5 },
{ "name": "Zidane", country: "France", "world cups title": 1, UCL : 1, Ballon d'Or : 1 },
{ "name": "Pele", country: "Brazil", "world cups title": 3, UCL : 0, Ballon d'Or : 0 },
{ "name": "Toni Kroos", country: "Germany", "world cups title": 1, UCL : 5, Ballon d'Or : 0 },
{ "name": "Messi", country: "Argentina", "world cups title": 1, UCL : 4, Ballon d'Or : 8 },
]
}
Now I want to rank this list by the best soccer player regarding the following conditions :
- 1 : Player has at least 1
world cups title
AND 1 UCL
AND 1 Ballon d'Or
- 2 : Player has more than 1
Ballon d'Or
- 3 : Player has more than 1
UCL
So for this example, I need to obtain something like this :
<code>// return ranked data with the matching score attribute
{ "name": "Messi", country: "Argentina",
"world cups title": 1, "UCL" : 4,
"Ballon d'Or" : 8, Matching Score : 100 },
{ "name": "Cristiano Ronaldo",
country: "Portugal", "world cups title": 0, UCL : 5,
Ballon d'Or : Matching Score : 66.7 },
<code>// return ranked data with the matching score attribute
{
"Best soccer players": [
{ "name": "Messi", country: "Argentina",
"world cups title": 1, "UCL" : 4,
"Ballon d'Or" : 8, Matching Score : 100 },
{ "name": "Cristiano Ronaldo",
country: "Portugal", "world cups title": 0, UCL : 5,
Ballon d'Or : Matching Score : 66.7 },
//etc.
]
}
</code>
// return ranked data with the matching score attribute
{
"Best soccer players": [
{ "name": "Messi", country: "Argentina",
"world cups title": 1, "UCL" : 4,
"Ballon d'Or" : 8, Matching Score : 100 },
{ "name": "Cristiano Ronaldo",
country: "Portugal", "world cups title": 0, UCL : 5,
Ballon d'Or : Matching Score : 66.7 },
//etc.
]
}
I think what I am looking for is a way to indexing my json data and retrieve them maybe by using some kind of query language. I am not sure if this is possible to do this with vanilla python.
Any help will be very appreciated