# MadTownTunes calculated country rankings — methodology

These rankings are **MadTownTunes calculated**. They are not a Billboard chart, not a Billboard year-end recap, and not a reconstruction of weekly positions below number one. They are built only from facts published on English Wikipedia, fetched through the public MediaWiki API, and scored with the formula below.

Billboard.com downloads and magazine scans from earlier research were **not** read or used. This process can be rerun from Wikipedia alone.

## How to rerun (any year)

From this folder:

```bash
python3 scripts/build_rankings.py --year 1983
python3 scripts/build_rankings.py --years 1980-1983
python3 scripts/build_rankings.py --year 1994          # later eras, if the Wikipedia pages exist
```

The script is parameterized by year. It:

1. Resolves the number-ones list and `{year} in country music` page for that year (following redirects; title patterns change by era — see below).
2. Fetches wikitext for a specific revision via the MediaWiki API (polite User-Agent, `maxlag`, cached under `raw/`).
3. Parses weekly #1 issue dates, titles, and artists, plus the year-page “top hits” singles tables (US and Canadian artist sections).
4. Optionally loads the previous year’s number-ones list so a holdover #1 can keep its true first #1 date.
5. Consults linked song articles only to check peaks (same artist, Billboard country `{{singlechart}}` templates). Those checks never invent weekly ranks and are not part of the score.
6. Writes the yearly ranking, the weekly #1 race, a flags file, and a sources JSON with each page’s URL and revision id (`oldid` permalink).

Outputs for year `YYYY`:

- `madtowntunes_calculated_yearly_YYYY.csv`
- `madtowntunes_chart_race_weekly_YYYY.csv`
- `sources/flags_YYYY.csv`
- `sources/sources_YYYY.json`

## Sources (Wikipedia only)

For each year in 1980–1983 the facts come from:

1. **`List of Hot Country Singles number ones of {year}`** — every magazine issue date in that year and the song that Wikipedia lists at #1. This is the only weekly fact we treat as known.
2. **`{year} in country music`**, section “Top hits of the year” — singles tables with a **US** column that Wikipedia uses for the U.S. country peak, plus a Canadian peak column we do not score. American-artist and Canadian-artist tables are both read; a song with no US peak is omitted from the US ranking.
3. **The prior year’s number-ones list** — only to set `first_no1_date` for a holdover (for 1980, the 1979 list).
4. **Linked song articles** — optional cross-check, not a scoring input.

Every fact is stored with the article URL and the exact revision (`https://en.wikipedia.org/w/index.php?oldid=…`). Attribution and license terms are in `sources/ATTRIBUTION.md`.

## Yearly ranking formula

Name recorded in the files: **MadTownTunes calculated**.

```
score = peak_score + (5 × weeks_at_no1)

peak_score = max(0, 21 − peak)     if a US country peak is known
           = 0                     if peak is missing or worse than #20

weeks_at_no1 = number of issue dates in THIS calendar year
               that Wikipedia lists the song at #1
```

Worked values (with the 1980s peak window of 20):

| Peak | Weeks at #1 this year | Score |
|---:|---:|---:|
| 1 | 3 | 20 + 15 = **35** |
| 1 | 2 | 20 + 10 = **30** |
| 1 | 1 | 20 + 5  = **25** |
| 2 | 0 | 19 |
| 10 | 0 | 11 |
| 20 | 0 | 1 |
| 21 or lower, or unknown | 0 | 0 |

Consequences, which you can check in the CSVs:

- Any song that was #1 this year (minimum score 25) outranks any song that was not (maximum score 19).
- Among #1 songs, a longer run this year ranks higher.
- Weeks at #1 in December of the previous year do **not** count in this year’s score. The holdover still appears, with `weeks_at_no1` equal to its weeks in the new year only, and `first_no1_date` set to the earliest #1 date we have from Wikipedia (often the prior year).
- A song the year page marks as peak #1, but that does not appear on this year’s number-ones list, is usually a hit that peaked in an adjacent year. It keeps peak 1 and gets `weeks_at_no1 = 0` for this year (score 20), so it ranks below this year’s actual #1s.

Tie-break for the yearly file (after score): more weeks at #1, then better (lower) peak, then song title, then artist, case-insensitive. Ranks are unique; two songs with the same score are not given a tied rank number.

`peak_window = 20` and `no1_week_bonus = 5` are constants in `scripts/formula.py`. They can be changed for later eras if Wikipedia’s year pages are complete to a different depth. They must not be changed quietly for 1980–1983 if you want those years to stay comparable to each other.

### Why this formula, and what we refused to invent

The year pages give a US peak for a large set of notable singles (in practice, nearly every top-20 country single, plus a few deeper entries). The number-ones lists give exact #1 dates. Wikipedia does **not** publish a full weekly top 40/100 that we can reuse, and weeks-on-chart is only sometimes present on song articles, often for the wrong recording of the same title. Using sparse weeks-on-chart in the score would reward songs that happen to have a complete article. So weeks-on-chart is not in the score.

## Weekly chart-race dataset

File: `madtowntunes_chart_race_weekly_YYYY.csv`

- `chart_name` is always `MadTownTunes calculated`.
- One block of rows per Wikipedia issue date.
- `value` is the song’s **cumulative weeks at #1 in this calendar year through that issue date**.
- Only songs that have already been #1 at least once this year appear. We do **not** invent ranks 2–100 of the original Billboard chart.

Sort in a given week:

1. Cumulative #1 weeks this year, descending.
2. The song that is #1 this week, then other songs with the same count by most recent week at #1.
3. Song title, then artist.

That is a race of #1 tenure, not a stand-in for the full weekly chart. In years where almost every #1 lasts a single week (1983 is like this), the current #1 leads a large pack of songs all sitting on `value = 1`, until a song earns a second week and takes a clear lead.

## What the 1980–1983 year pages cover

The “Singles released by American artists” tables are essentially complete through peak #20 and only spotty below that. Songs peaking worse than #20 can appear, but absence below #20 is **not** evidence that a song did not chart. Those deeper rows get `peak_score = 0` so incomplete lower-chart coverage cannot rearrange the top of the list.

Canadian-artist singles are included only when Wikipedia gives a US peak.

Titles, punctuation, and artist credits follow Wikipedia (including double A-sides such as `My Heart / Silent Night (After the Fight)` and `Love in the First Degree / Ride the Train`). We match the same song across pages by folding accents and punctuation and, when needed, ignoring parentheticals (`José Cuervo` = `Jose Cuervo`; `Fancy Free` = `(I'm Settin') Fancy Free`).

## Expanding beyond 1980–1983

The same command works for other years if Wikipedia has the pages. `scripts/page_titles.py` maps eras and title candidates from the Wikipedia article [Hot Country Songs](https://en.wikipedia.org/wiki/Hot_Country_Songs) (revision used for this note: [oldid=1389064983](https://en.wikipedia.org/w/index.php?oldid=1389064983)).

### Pre-1958 — more than one Billboard country chart

Billboard’s first country-style chart, “Most Played Juke Box Folk Records,” starts in the January 8, 1944 issue. From 1948 to 1958 there were often **three** charts at once (jukebox, retail best sellers from May 15, 1948, and a disc-jockey/airplay chart from December 10, 1949). The jukebox chart ended in June 1957.

For these years Wikipedia may have one list with a chart column, or more than one list. **Do not merge those charts into a single MadTownTunes ranking** without labeling each source chart. A defensible approach is a separate yearly ranking (and a separate weekly #1 race) per named chart, or a clearly marked “combined #1 mentions” list that is not presented as one official peak.

The `{year} in country music` peak column, if it exists that early, must be checked to see which chart the “US” figure refers to.

### October 20, 1958 – 1989 — one sales-and-airplay singles chart

On October 20, 1958 Billboard combined sales and airplay into **Hot C&W Sides**. The title **Hot Country Singles** is used from the November 3, 1962 era (after the October 27, 1962 issue still said Hot C&W Sides) through 1989. This is the era of the 1980–1983 build. Typical Wikipedia title: `List of Hot Country Singles number ones of {year}`.

### January 20, 1990 – October 13, 2012 — airplay only

On January 20, 1990 the chart was cut from 100 to 75 positions and compiled from Nielsen BDS radio airplay only (retitled **Hot Country Singles & Tracks** on February 17, 1990; cut to 60 positions on January 13, 2001, with weeks-on-chart retallied; renamed **Hot Country Songs** on April 30, 2005). Audience vs. spins methodology also flipped during this stretch (audience, then spins in 1992, then back to audience in January 2005 because of spin programs).

Peaks and #1 runs from this era are **not on the same scale** as pre-1990 sales-and-airplay or post-2012 sales-streaming-airplay lists. The formula can still be run, but:

- Keep the era label in `sources/sources_YYYY.json` and in any public copy.
- Do not stitch a cross-era “all-time” ranking from raw scores without an era flag.
- Wikipedia titles are often `List of Hot Country Singles & Tracks number ones of {year}` or `List of Hot Country Songs number ones of {year}`. The script tries both and follows redirects.
- Year-page completeness may not stop at #20; reset `peak_window` only after checking the tables, and document the change.

### From the October 20, 2012 issue — Hot Country Songs vs Country Airplay

Starting with the October 20, 2012 issue, **Hot Country Songs** uses the Hot 100 method (sales + streaming + airplay from all radio formats). **Country Airplay** is a separate, country-radio-only chart created at the same time. Wikipedia may list both.

Rules for this era:

- Pick **one** chart per ranking and name it in `chart_name` / the methodology line (for example “MadTownTunes calculated (Hot Country Songs facts)” vs “MadTownTunes calculated (Country Airplay facts)”).
- Do not mix the two peaks in one score.
- Do not treat a post-2012 Hot Country Songs #1 run as comparable to a 1980s Hot Country Singles #1 run without a note. Long cross-format runs became common after the change.

### If a year has no Wikipedia number-ones list

The script exits with an error for that year rather than guessing. A later fallback could be individual song articles only, but that set is incomplete and must not be labeled as a full-year ranking.

## Limitations and uncertainties

- Wikipedia can be wrong or incomplete. We record the revision we used so a later editor can compare.
- The year-page US column is treated as the U.S. country peak. The pages do not always spell out “Billboard Hot Country Singles” in the table header.
- Peaks are the song’s listed peak, which may have occurred in an adjacent year.
- 1983: the number-ones **article intro** says 52 issues and 50 different releases. The **table** has 53 issue dates (January 1 through December 31, 1983 — both were Saturdays) and 51 releases, including the holdover “Wild and Blue.” This build follows the table. 50 new #1s + 1 holdover = 51, which matches the intro’s “50” if the holdover was excluded.
- Song articles often list several recordings of the same title. A peak is only compared when a `{{singlechart}}` / `{{single chart}}` Billboard country entry names the same artist. One remaining disagreement is flagged: Eddy Raven, “A Little Bit Crazy,” 1982 year page peak 12 vs song article peak 14 (we keep the year-page peak of 12 in the ranking).
- “Run for the Roses” by Dan Fogelberg appears on the 1982 year page with no US peak (Canadian peak only) and is omitted as unrankable.
- Double A-sides are kept as one Wikipedia credit (`Title A / Title B`).
- The weekly race is only as complete as Wikipedia’s #1 list. It is not a full chart race of every song on the radio that week.

## License

Wikipedia text is available under CC BY-SA 4.0 (and, unless otherwise marked, the GFDL). See `sources/ATTRIBUTION.md`. The numeric score and the rank order are MadTownTunes’ own calculation from those facts. If you publish the compiled tables, include the attribution file and the `oldid` permalinks.
