Parsing data more fully
This commit is contained in:
parent
99d5f41140
commit
0a3a8ecb2e
2389
data/1952.html
2389
data/1952.html
File diff suppressed because one or more lines are too long
2356
data/1953.html
2356
data/1953.html
File diff suppressed because one or more lines are too long
2390
data/1954.html
2390
data/1954.html
File diff suppressed because one or more lines are too long
2356
data/1955.html
2356
data/1955.html
File diff suppressed because one or more lines are too long
2390
data/1956.html
2390
data/1956.html
File diff suppressed because one or more lines are too long
2403
data/1957.html
2403
data/1957.html
File diff suppressed because one or more lines are too long
2403
data/1958.html
2403
data/1958.html
File diff suppressed because one or more lines are too long
2356
data/1959.html
2356
data/1959.html
File diff suppressed because one or more lines are too long
3689
data/1960.html
3689
data/1960.html
File diff suppressed because one or more lines are too long
3985
data/1961.html
3985
data/1961.html
File diff suppressed because one or more lines are too long
3985
data/1962.html
3985
data/1962.html
File diff suppressed because one or more lines are too long
4044
data/1963.html
4044
data/1963.html
File diff suppressed because one or more lines are too long
3985
data/1964.html
3985
data/1964.html
File diff suppressed because one or more lines are too long
4020
data/1965.html
4020
data/1965.html
File diff suppressed because one or more lines are too long
4311
data/1966.html
4311
data/1966.html
File diff suppressed because one or more lines are too long
4407
data/1967.html
4407
data/1967.html
File diff suppressed because one or more lines are too long
4457
data/1968.html
4457
data/1968.html
File diff suppressed because one or more lines are too long
4436
data/1969.html
4436
data/1969.html
File diff suppressed because one or more lines are too long
4128
data/1970.html
4128
data/1970.html
File diff suppressed because one or more lines are too long
4128
data/1971.html
4128
data/1971.html
File diff suppressed because one or more lines are too long
4128
data/1972.html
4128
data/1972.html
File diff suppressed because one or more lines are too long
4128
data/1973.html
4128
data/1973.html
File diff suppressed because one or more lines are too long
4128
data/1974.html
4128
data/1974.html
File diff suppressed because one or more lines are too long
4128
data/1975.html
4128
data/1975.html
File diff suppressed because one or more lines are too long
4338
data/1976.html
4338
data/1976.html
File diff suppressed because one or more lines are too long
4338
data/1977.html
4338
data/1977.html
File diff suppressed because one or more lines are too long
4796
data/1978.html
4796
data/1978.html
File diff suppressed because one or more lines are too long
4796
data/1979.html
4796
data/1979.html
File diff suppressed because one or more lines are too long
4796
data/1980.html
4796
data/1980.html
File diff suppressed because one or more lines are too long
4796
data/1981.html
4796
data/1981.html
File diff suppressed because one or more lines are too long
3362
data/1982.html
3362
data/1982.html
File diff suppressed because one or more lines are too long
4796
data/1983.html
4796
data/1983.html
File diff suppressed because one or more lines are too long
4796
data/1984.html
4796
data/1984.html
File diff suppressed because one or more lines are too long
4796
data/1985.html
4796
data/1985.html
File diff suppressed because one or more lines are too long
4796
data/1986.html
4796
data/1986.html
File diff suppressed because one or more lines are too long
4580
data/1987.html
4580
data/1987.html
File diff suppressed because one or more lines are too long
4796
data/1988.html
4796
data/1988.html
File diff suppressed because one or more lines are too long
4796
data/1989.html
4796
data/1989.html
File diff suppressed because one or more lines are too long
4856
data/1990.html
4856
data/1990.html
File diff suppressed because one or more lines are too long
4856
data/1991.html
4856
data/1991.html
File diff suppressed because one or more lines are too long
4856
data/1992.html
4856
data/1992.html
File diff suppressed because one or more lines are too long
4890
data/1993.html
4890
data/1993.html
File diff suppressed because one or more lines are too long
4856
data/1994.html
4856
data/1994.html
File diff suppressed because one or more lines are too long
5092
data/1995.html
5092
data/1995.html
File diff suppressed because one or more lines are too long
5092
data/1996.html
5092
data/1996.html
File diff suppressed because one or more lines are too long
5092
data/1997.html
5092
data/1997.html
File diff suppressed because one or more lines are too long
5092
data/1998.html
5092
data/1998.html
File diff suppressed because one or more lines are too long
5210
data/1999.html
5210
data/1999.html
File diff suppressed because one or more lines are too long
5210
data/2000.html
5210
data/2000.html
File diff suppressed because one or more lines are too long
5210
data/2001.html
5210
data/2001.html
File diff suppressed because one or more lines are too long
5328
data/2002.html
5328
data/2002.html
File diff suppressed because one or more lines are too long
5328
data/2003.html
5328
data/2003.html
File diff suppressed because one or more lines are too long
5328
data/2004.html
5328
data/2004.html
File diff suppressed because one or more lines are too long
5328
data/2005.html
5328
data/2005.html
File diff suppressed because one or more lines are too long
5328
data/2006.html
5328
data/2006.html
File diff suppressed because one or more lines are too long
5328
data/2007.html
5328
data/2007.html
File diff suppressed because one or more lines are too long
5328
data/2008.html
5328
data/2008.html
File diff suppressed because one or more lines are too long
5328
data/2009.html
5328
data/2009.html
File diff suppressed because one or more lines are too long
5328
data/2010.html
5328
data/2010.html
File diff suppressed because one or more lines are too long
5328
data/2011.html
5328
data/2011.html
File diff suppressed because one or more lines are too long
5328
data/2012.html
5328
data/2012.html
File diff suppressed because one or more lines are too long
5328
data/2013.html
5328
data/2013.html
File diff suppressed because one or more lines are too long
5328
data/2014.html
5328
data/2014.html
File diff suppressed because one or more lines are too long
5328
data/2015.html
5328
data/2015.html
File diff suppressed because one or more lines are too long
5328
data/2016.html
5328
data/2016.html
File diff suppressed because one or more lines are too long
5328
data/2017.html
5328
data/2017.html
File diff suppressed because one or more lines are too long
5328
data/2018.html
5328
data/2018.html
File diff suppressed because one or more lines are too long
5328
data/2019.html
5328
data/2019.html
File diff suppressed because one or more lines are too long
5354
data/2020.html
5354
data/2020.html
File diff suppressed because one or more lines are too long
5596
data/2021.html
5596
data/2021.html
File diff suppressed because one or more lines are too long
5583
data/2022.html
5583
data/2022.html
File diff suppressed because one or more lines are too long
5596
data/2023.html
5596
data/2023.html
File diff suppressed because one or more lines are too long
5557
data/2024.html
5557
data/2024.html
File diff suppressed because one or more lines are too long
@ -1,6 +1,7 @@
|
||||
from bs4 import BeautifulSoup
|
||||
from dateutil.parser import parse
|
||||
import json
|
||||
from tqdm import tqdm
|
||||
import re
|
||||
|
||||
def calcPredictedScore(sF,sU,S,O):
|
||||
@ -9,24 +10,17 @@ def calcPredictedScore(sF,sU,S,O):
|
||||
scoreObj["sF"] = int(O) - ((int(O)-int(S))/2)
|
||||
return scoreObj
|
||||
|
||||
fullObj = {
|
||||
"years":[]
|
||||
}
|
||||
fullObj = []
|
||||
|
||||
|
||||
start_year = 1952
|
||||
|
||||
for year in range(start_year, 2025):
|
||||
for year in tqdm(range(start_year, 1954)):
|
||||
|
||||
with open("data/"+str(year)+".html") as fp:
|
||||
with open("src/data/"+str(year)+".html") as fp:
|
||||
soup = BeautifulSoup(fp, 'html.parser')
|
||||
|
||||
start_pos = soup.find(string=str(year)+" Regular Season - Week 1");
|
||||
|
||||
gamesObj = {
|
||||
"year":year,
|
||||
"games":[]
|
||||
}
|
||||
start_pos = soup.find(string=re.compile(".*Regular Season - Week 1"))
|
||||
|
||||
try:
|
||||
for table in start_pos.find_all_next(class_="soh1"):
|
||||
@ -68,15 +62,16 @@ for year in range(start_year, 2025):
|
||||
if spreadVal != -1 and ouVal != -1:
|
||||
game["pScore"] = calcPredictedScore(game["sF"],game["sU"],spreadVal,ouVal)
|
||||
|
||||
gamesObj["games"].append(game)
|
||||
fullObj.append(game)
|
||||
except:
|
||||
print("Error parsing " + str(year))
|
||||
|
||||
fullObj["years"].append(gamesObj)
|
||||
objson = json.dumps(fullObj, indent=4)
|
||||
|
||||
objson = json.dumps(fullObj)
|
||||
|
||||
print(objson)
|
||||
with open("src/data/odds_data_abbr.json", "w") as odds_file:
|
||||
odds_file.write(
|
||||
objson
|
||||
)
|
||||
|
||||
'''
|
||||
|
||||
|
72
src/index.md
72
src/index.md
@ -1,5 +1,71 @@
|
||||
# .\NFLOddsVis
|
||||
```js
|
||||
const parseTime = d3.timeParse("%b %d, %Y");
|
||||
const coerceGameData = (d,i) => ({date: parseTime(d.date), spread: Number(d.spread)});
|
||||
const oddsfile = FileAttachment("./data/odds_data_abbr.json").json().then((D) => D.map(coerceGameData));
|
||||
```
|
||||
|
||||
This is the home page of your new Observable Framework app.
|
||||
```js
|
||||
Inputs.table(oddsfile);
|
||||
```
|
||||
|
||||
For more, see <https://observablehq.com/framework/getting-started>.
|
||||
```js
|
||||
function oddsPlot(data, {width} = {}) {
|
||||
// Declare the chart dimensions and margins.
|
||||
const height = 500;
|
||||
const marginTop = 20;
|
||||
const marginRight = 30;
|
||||
const marginBottom = 30;
|
||||
const marginLeft = 40;
|
||||
|
||||
// Declare the x (horizontal position) scale.
|
||||
const x = d3.scaleUtc(d3.extent(data, d => d.date), [marginLeft, width - marginRight]);
|
||||
|
||||
// Declare the y (vertical position) scale.
|
||||
const y = d3.scaleLinear([0, d3.max(data, d => d.spread)], [height - marginBottom, marginTop]);
|
||||
|
||||
// Declare the line generator.
|
||||
const line = d3.line()
|
||||
.x(d => x(d.date))
|
||||
.y(d => y(d.spread));
|
||||
|
||||
// Create the SVG container.
|
||||
const svg = d3.create("svg")
|
||||
.attr("width", width)
|
||||
.attr("height", height)
|
||||
.attr("viewBox", [0, 0, width, height])
|
||||
.attr("style", "max-width: 100%; height: auto; height: intrinsic;");
|
||||
|
||||
// Add the x-axis.
|
||||
svg.append("g")
|
||||
.attr("transform", `translate(0,${height - marginBottom})`)
|
||||
.call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0));
|
||||
|
||||
// Add the y-axis, remove the domain line, add grid lines and a label.
|
||||
svg.append("g")
|
||||
.attr("transform", `translate(${marginLeft},0)`)
|
||||
.call(d3.axisLeft(y).ticks(height / 40))
|
||||
.call(g => g.select(".domain").remove())
|
||||
.call(g => g.selectAll(".tick line").clone()
|
||||
.attr("x2", width - marginLeft - marginRight)
|
||||
.attr("stroke-opacity", 0.1))
|
||||
.call(g => g.append("text")
|
||||
.attr("x", -marginLeft)
|
||||
.attr("y", 10)
|
||||
.attr("fill", "currentColor")
|
||||
.attr("text-anchor", "start")
|
||||
.text("↑ Daily close ($)"));
|
||||
|
||||
// Append a path for the line.
|
||||
svg.append("path")
|
||||
.attr("fill", "none")
|
||||
.attr("stroke", "steelblue")
|
||||
.attr("stroke-width", 1.5)
|
||||
.attr("d", line(data));
|
||||
|
||||
return svg.node();
|
||||
}
|
||||
```
|
||||
|
||||
<div class="grid grid-cols-1">
|
||||
<div class="card">${resize((width) => oddsPlot(oddsfile, {width}))}</div>
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user