Skip to content

Commit

Permalink
Updates vis data and README
Browse files Browse the repository at this point in the history
  • Loading branch information
zenlan committed Apr 11, 2024
1 parent a0548bd commit c13ccbb
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 83 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ It is compiled and published by the [Open Repair Alliance (ORA)](https://openrep
* Tests
* Data visualisation
* Document all the things
* Clean up poor quality code

## Licences & acknowledgments

Expand Down
124 changes: 62 additions & 62 deletions vis/ords_coffee_v_tea.json
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
{
"BEL": [
{
"product": "Coffee maker",
"records": 1123
},
{
"product": "Kettle",
"records": 216
}
],
"DEU": [
{
"product": "Coffee maker",
"records": 714
},
{
"product": "Kettle",
"records": 291
}
],
"DNK": [
{
"product": "Coffee maker",
"records": 164
},
{
"product": "Kettle",
"records": 75
}
],
"FRA": [
{
"product": "Coffee maker",
"records": 328
},
{
"product": "Kettle",
"records": 70
}
],
"GBR": [
{
"product": "Coffee maker",
"records": 330
},
{
"product": "Kettle",
"records": 719
}
],
"NLD": [
{
"product": "Coffee maker",
"records": 3443
},
{
"product": "Kettle",
"records": 640
}
]
}
[
{
"product": "Coffee maker",
"records": 1436
},
{
"product": "Kettle",
"records": 257
},
{
"product": "Kettle",
"records": 56
},
{
"product": "Coffee maker",
"records": 911
},
{
"product": "Kettle",
"records": 349
},
{
"product": "Coffee maker",
"records": 361
},
{
"product": "Kettle",
"records": 157
},
{
"product": "Coffee maker",
"records": 460
},
{
"product": "Kettle",
"records": 118
},
{
"product": "Coffee maker",
"records": 474
},
{
"product": "Kettle",
"records": 930
},
{
"product": "Coffee maker",
"records": 51
},
{
"product": "Coffee maker",
"records": 4297
},
{
"product": "Kettle",
"records": 764
},
{
"product": "Kettle",
"records": 64
}
]
51 changes: 30 additions & 21 deletions vis/ords_coffee_v_tea.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/usr/bin/env python3


# Standalone script to dump a JSON dataset for use in data visualisation.

import mysql.connector
import os
import json
import pandas as pd
from dotenv import load_dotenv
load_dotenv()

# Standalong script to dump a JSON dataset for use in data visualisation.

def query_fetchall(sql):
result = False
try:
dbh = mysql.connector.connect(
host=os.environ['ORDS_DB_HOST'],
database=os.environ['ORDS_DB_DATABASE'],
user=os.environ['ORDS_DB_USER'],
password=os.environ['ORDS_DB_PWD']
host=os.environ["ORDS_DB_HOST"],
database=os.environ["ORDS_DB_DATABASE"],
user=os.environ["ORDS_DB_USER"],
password=os.environ["ORDS_DB_PWD"],
)
cursor = dbh.cursor(dictionary=True)
cursor.execute(sql)
Expand All @@ -31,18 +32,26 @@ def query_fetchall(sql):
return result


sql = """
SELECT
country,
product_category as product,
COUNT(*) as records
FROM `{}`
WHERE product_category IN ('Kettle', 'Coffee Maker')
GROUP BY product_category, country
HAVING records > 50
ORDER BY country, product_category, records DESC;
"""
dfsub = pd.DataFrame(query_fetchall(sql.format(os.environ['ORDS_DATA'])))
with open('ords_coffee_v_tea.json', 'w') as f:
json.dump(dfsub.set_index('country').to_dict(
'records'), f, indent=4, ensure_ascii=False)
if __name__ == "__main__":

load_dotenv()

sql = """
SELECT
country,
product_category as product,
COUNT(*) as records
FROM `{}`
WHERE product_category IN ('Kettle', 'Coffee Maker')
GROUP BY product_category, country
HAVING records > 50
ORDER BY country, product_category, records DESC;
"""
dfsub = pd.DataFrame(query_fetchall(sql.format(os.environ["ORDS_DATA"])))
with open("vis/ords_coffee_v_tea.json", "w") as f:
json.dump(
dfsub.set_index("country").to_dict("records"),
f,
indent=4,
ensure_ascii=False,
)

0 comments on commit c13ccbb

Please sign in to comment.