import { fmt_pct, rate, fmt_surname, AP } from "./utils.js"
d3 = require("d3")
d_sum = FileAttachment("summary.json").json()
d_history = FileAttachment("history.csv").csv({typed: true})
DARK_BLUE = "#0063B1"
DARK_RED = "#A0442C"
BLUE = "#3D77BB"
RED = "#B25D4C"
w_BODY = 796;
SMALL = width < 600;
color = {
let midpt = "#fafffa";
let color_dem = d3.scaleLinear()
.domain([0.5, 1.0])
.range([midpt, DARK_BLUE]);
let color_gop = d3.scaleLinear()
.domain([0.0, 0.5])
.range([DARK_RED, midpt]);
return x => x <= 0.5 ? color_gop(x) : color_dem(x);
}
2022 Midterms Forecast
Author
Cory McCartan
dem_lead = d_sum.sen_prob > 0.5
{
let win_party = dem_lead ? "Democrats" : "Republicans"
let win_class = dem_lead ? "dem" : "rep"
let phrase = dem_lead ? "maintaining" : "flipping"
let prob = dem_lead ? d_sum.sen_prob : 1 - d_sum.sen_prob
let timestamp = d_history[d_history.length-1].timestamp;
let date_fmt = timestamp.toLocaleString("en-US", {
weekday: "long",
month: "long",
day: "numeric",
})
return md`
As of ${date_fmt}, there is a:
**${fmt_pct(d_sum.pr_DsRh)} chance** of a <b class="dem">Democratic</b> Senate and <b class="rep">Republican</b> House.
**${fmt_pct(d_sum.pr_RsRh)} chance** of a <b class="rep">Republican</b> Senate and <b class="rep">Republican</b> House.
**${fmt_pct(d_sum.pr_DsDh)} chance** of a <b class="dem">Democratic</b> Senate and <b class="dem">Democratic</b> House.
**${fmt_pct(d_sum.pr_RsDh)} chance** of a <b class="rep">Republican</b> Senate and <b class="dem">Democratic</b> House.
`;
}