Skip to content

Commit

Permalink
cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
louisd13 committed May 30, 2024
1 parent c25c7c2 commit d3d2d6f
Show file tree
Hide file tree
Showing 15 changed files with 19 additions and 488,949 deletions.
18 changes: 0 additions & 18 deletions data/athletics/outdoor_senior_men_world_records.csv

This file was deleted.

4 changes: 0 additions & 4 deletions data/athletics/outdoor_u20_men_world_records.csv

This file was deleted.

488,644 changes: 0 additions & 488,644 deletions data/athletics/world-athletics_all-time-top-lists.csv

This file was deleted.

201 changes: 0 additions & 201 deletions data/swimming/Men 50m Freestyle Rankings.csv

This file was deleted.

30 changes: 0 additions & 30 deletions data/swimming/Men50mFreestyle.csv

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,16 @@
"result_ids_path = os.path.join(dataroot, '_distinct_result_id.csv')\n",
"csv_save_path = os.path.join(dataroot, 'olympedia_all_results.csv')\n",
"\n",
"# Function to identify if a row is part of the final round based on specific columns\n",
"def is_final_round(row, headers):\n",
" final_columns = [\"Final\", \"Final Round\"]\n",
" for col in final_columns:\n",
" if col in headers and row.get(col, \"\").strip() and row.get(col).strip() != \"\":\n",
" return True\n",
" return False\n",
"\n",
"# Function to parse the event results and filter for final rounds\n",
"def parse_results_table(table) -> Tuple[List[str], List[Dict[str, str]]]:\n",
" headers = [th.get_text().strip() for th in table.find_all('th')]\n",
" rows = table.find_all('tr')[1:] # skip the header row\n",
" rows = table.find_all('tr')[1:] \n",
" results = []\n",
"\n",
" has_final_column = any(col in headers for col in [\"Final\", \"Final Round\"])\n",
Expand All @@ -369,7 +367,6 @@
" if cols:\n",
" result = {}\n",
" for i, col in enumerate(cols):\n",
" # Handle edge cases for cells containing spans or being empty\n",
" if i < len(headers):\n",
" text = col.get_text().strip()\n",
" if not text:\n",
Expand Down Expand Up @@ -431,7 +428,6 @@
" 'sport': sport,\n",
" }\n",
"\n",
" # Parsing the event bio table\n",
" try:\n",
" event_bio_table = result_soup.select('body > div.container > table.biodata')[0]\n",
" event_bio_header = [item.get_text() for item in event_bio_table.select('table > tr > th')]\n",
Expand All @@ -450,8 +446,6 @@
" print(f\"Error parsing event bio table for result ID {result_id}: {e}\")\n",
" for key in ['result_date', 'result_location', 'result_participants', 'result_format', 'result_detail']:\n",
" event_info[key] = 'na'\n",
"\n",
" # Parsing the results table\n",
" results_table = result_soup.find('table', class_='table table-striped')\n",
" if results_table:\n",
" try:\n",
Expand Down Expand Up @@ -509,7 +503,6 @@
" result_ids = [row[0] for row in reader]\n",
" return result_ids\n",
"\n",
"# Run the script\n",
"if __name__ == \"__main__\":\n",
" result_ids = load_result_ids(result_ids_path)\n",
" asyncio.run(main(result_ids))\n"
Expand Down
2 changes: 1 addition & 1 deletion pages/athletics.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- Include D3.js library -->
<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/papaparse.min.js"></script>
<script src="../scripts/running.js" defer></script>
<script src="../scripts/olympics/running.js" defer></script>
<style>
body {
font-family: Arial, sans-serif;
Expand Down
4 changes: 2 additions & 2 deletions pages/olympics.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/papaparse.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="../scripts/medals.js"></script>
<script src="../scripts/olympics/medals.js"></script>
<script src="https://d3js.org/d3.v6.min.js"></script>
<script src="../scripts/podium.js"></script>
<script src="../scripts/olympics/podium.js"></script>
<style>
body {
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion pages/podium.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title>Olympic Podium Visualization</title>
<script src="https://d3js.org/d3.v6.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"></script>
<script src="../scripts/podium.js"></script>
<script src="../scripts/olympics/podium.js"></script>
<style>
body {
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion pages/swimming.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- Include D3.js library -->
<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/papaparse.min.js"></script>
<script src="../scripts/swimming.js" defer></script>
<script src="../scripts/olympics/swimming.js" defer></script>
<style>
body {
font-family: Arial, sans-serif;
Expand Down
52 changes: 13 additions & 39 deletions scripts/medals.js → scripts/olympics/medals.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
// Sample data format
/*
const data = [
{ Country: "France", NOC: "FRA", Season: "Summer", Year: "1896", Gold: "0.0", Silver: "1.0", Bronze: "0.0", None: "3.0" },
{ Country: "USA", NOC: "USA", Season: "Summer", Year: "1896", Gold: "1.0", Silver: "1.0", Bronze: "1.0", None: "3.0" },
// Add more data here
];
*/

let data = [];

// Function to populate year options based on data
/* function populateYears() {
const yearSelect = document.getElementById('yearSelect');
const years = [...new Set(data.map(item => item.Year))];
console.log("pop data", data);
years.forEach(year => {
const option = document.createElement('option');
option.value = year;
option.text = year;
yearSelect.appendChild(option);
});
} */
let data = [];


function populateYears() {
Expand All @@ -36,18 +16,17 @@ function populateYears() {


function updateChart() {
//const selectedYear = document.getElementById('yearSelect').value;

const selectedYearSeason = document.getElementById('yearSeasonSelect').value;
const [selectedYear, selectedSeason] = selectedYearSeason.split(" - ");
//const selectedSeason = document.getElementById('seasonSelect').value;
console.log("chart data", data);

//let filteredData = data.filter(item => item.Year === selectedYear && item.Season === selectedSeason);

let filteredData = data.filter(item => String(item.Year) === selectedYear && item.Season === selectedSeason);

console.log(filteredData);

// Aggregate medals by country

const medalCounts = filteredData.reduce((acc, item) => {
const country = item.Country;
acc[country] = acc[country] || { Gold: 0, Silver: 0, Bronze: 0 };
Expand All @@ -65,10 +44,10 @@ function updateChart() {

const ctx = document.getElementById('medalChart').getContext('2d');
if (window.myChart) {
window.myChart.destroy(); // Destroy existing chart instance if exists
window.myChart.destroy();
}
window.myChart = new Chart(ctx, {
type: 'bar', // Correct chart type for horizontal bars in Chart.js 3.x
type: 'bar',
data: {
labels: sortedMedals.map(item => item.Country),
datasets: [{
Expand All @@ -92,21 +71,21 @@ function updateChart() {
}]
},
options: {
indexAxis: 'y', // Ensures the bar chart is horizontal
indexAxis: 'y',
responsive: false,
scales: {
x: {
stacked: true,
beginAtZero: true,
title: {
display: true, // Ensure the title is displayed
display: true,
text: 'Number of Medals'
},
ticks: {
stepSize: 1, // Forces the ticks to increment by 1
precision: 0, // Ensures no decimal places
stepSize: 1,
precision: 0,
callback: function(value) {
if (value % 1 === 0) { // Only display integer values
if (value % 1 === 0) {
return value;
}
}
Expand All @@ -120,11 +99,6 @@ function updateChart() {
});
}

/* window.onload = function() {
populateYears();
updateChart(); // Initial chart display
console.log(data);
}; */


window.onload = function() {
Expand All @@ -136,8 +110,8 @@ window.onload = function() {
data = results.data;
console.log(data);
populateYears();
updateChart(); // Initialize the chart after data is loaded and processed
updateChart();
}
})
//console.log("Global Data Check:", data);
//console.log(" Data Check:", data);
};
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d3d2d6f

Please sign in to comment.