-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
234 lines (189 loc) · 5.54 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<meta name=viewport content="width=device-width">
<link rel=icon
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2280%22>🏉</text></svg>"
type="image/svg+xml">
<title>Inner Melbourne Football League</title>
<!-- <link rel="stylesheet" href="https://fonts.xz.style/serve/inter.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@exampledev/[email protected]/new.min.css">
<link rel="stylesheet" href="https://newcss.net/theme/terminal.css"> -->
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.css">
<style>
label {
display: unset;
}
* {
font-variant: no-common-ligatures;
font-variant-numeric: tabular-nums
}
th.right,
td.right {
text-align: right;
}
tr:nth-child(5) th,
tr:nth-child(5) td {
border-bottom: 3px solid ;
}
@media (prefers-color-scheme: dark) {
tr:nth-child(5) th,
tr:nth-child(5) td {
border-bottom: 3px ;
}
}
th[scope=row] {
background-color: unset;
}
.bold {
font-weight: bold;
}
.italic {
font-style: italic;
}
</style>
</head>
<body>
<header>
<h1>Inner Melbourne Football League 🏉</h1>
</header>
<main id=app>
<p>
<label for=yearSelect>Year</label> 
<select v-model="currentYear" title="choose year" id=yearSelect>
<option v-for="year in years" :value="year">{{ year }}</option>
</select>
</p>
<Season :season="season"></Season>
<p>
<input type=checkbox id=southCheck v-model="south" /> 
<label for=southCheck>Show South Melbourne and Fitzroy</label>
</p>
</main>
<footer>
made with ❤️ by W. David Porter
</footer>
<!-- <script type=importmap>
{
"imports": {
"vue": "https://unpkg.com/vue@3/dist/vue.esm-browser.js",
"season": "./components/season.js",
"csv": "https://cdn.jsdelivr.net/npm/[email protected]/dist/esm/index.js"
}
}
</script> -->
<script type="module">
import { createApp, ref, watch } from "https://unpkg.com/vue@3/dist/vue.esm-browser.js" //"vue"
import Season from "./components/season.js" // "season"
import { parse } from "https://cdn.jsdelivr.net/npm/[email protected]/dist/esm/index.js" //"csv"
createApp({
components: {
Season
},
setup() {
const season = ref({
year: 2022,
rounds: [],
finals: []
})
const currentYear = ref("")
let years = ref([])
const south = ref(false)
async function getLatestYear() {
const response = await fetch("/data/latest.txt")
currentYear.value = await response.text()
years.value = Array.from({ length: parseInt(currentYear.value) - 1982 + 1 }, (x, i) => i + 1982).reverse()
}
getLatestYear()
async function changeSeason() {
//const vue = this
//const response = await fetch(`./data/${currentYear.value}.csv`)
// const params = new URLSearchParams()
// params.set("apikey", "2OtiWzDGnMCaD5ZbFSuRRsnIMYQ")
// params.set("dbowner", "wdporter")
// params.set("dbname", "imfl.db")
// params.set("sql", btoa(`SELECT * FROM imfl WHERE year=${currentYear.value}`))
const response = await fetch(`http://api.wdporter.id.au/v2?year=${currentYear.value}`)
console.log(response)
const raw = JSON.parse(await response.text())
let data = []
//convert raw data to manageable objects
raw.forEach(r => {
data.push({
year: r[0].Value,
roundType: r[1].Value,
roundNumber: parseInt(r[2].Value),
homeTeam: r[3].Value,
homeGoals: parseInt(r[4].Value),
homeBehinds: parseInt(r[5].Value),
awayTeam: r[6].Value,
awayGoals: parseInt(r[7].Value),
awayBehinds: parseInt(r[8].Value),
})
})
// filter out irrelevant teams
data = data.filter(d => {
if (!south.value) {
if ((d.homeTeam == "South Melbourne" || d.awayTeam == "South Melbourne"))
return false
if ((d.homeTeam == "Fitzroy" || d.awayTeam == "Fitzroy") && currentYear.value > 1996)
return false
}
return true
})
// set up a new season
season.value = {
year: currentYear,
rounds: []
}
// add matches to rounds of the season
let currentRoundNumber = 0, previousRoundNumber = 0
data.forEach(d => {
if (d.roundType != "round")
return;
if (d.roundNumber != previousRoundNumber) {
previousRoundNumber = d.roundNumber
++currentRoundNumber
season.value.rounds.push({
roundNumber: currentRoundNumber,
matches: [d]
})
}
else {
season.value.rounds.at(-1).matches.push(d)
}
})
// add finals matches to season
season.value.finals = []
let roundNumber = 0
data.forEach(d => {
if (d.roundType != "finals")
return;
if (d.roundNumber != previousRoundNumber) {
if (d.roundNumber != roundNumber) {
++roundNumber
season.value.finals[roundNumber - 1] = {
roundNumber: d.roundNumber,
matches: [d]
}
}
else {
season.value.finals[roundNumber - 1].matches.push(d)
}
}
})
}
watch(currentYear, changeSeason)
watch(south, changeSeason)
return {
season,
years,
currentYear,
south,
}
},
}).mount('#app')
</script>
</body>
</html>