Skip to content

Commit

Permalink
Replaced giant schedule.json file with individual season files (#22)
Browse files Browse the repository at this point in the history
* Replaced giant schedule.json with individual season files

* Ran Prettier on all JSON files

* Fixed default logo flashing before team logo

* Disable matchup history for now

* Fixed lint
  • Loading branch information
jwngr authored Jul 9, 2024
1 parent c8e8610 commit 7391e49
Show file tree
Hide file tree
Showing 187 changed files with 2,408 additions and 59,496 deletions.
173 changes: 0 additions & 173 deletions data/ndSchedules/2020-original.json

This file was deleted.

4 changes: 2 additions & 2 deletions scripts/archive/fetchUniqueLocations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const logger = require('../lib/logger');
const ndSchedules = require('../lib/ndSchedules');

const ndSchedules = require('../../website/src/resources/schedules');
logger.info('Fetching unique locations...');

let gamesCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion scripts/archive/generateDecadeCsvs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path');
const format = require('date-fns/format');

const logger = require('../lib/logger');
const ndSchedules = require('../lib/ndSchedules');
const ndSchedules = require('../../website/src/resources/schedules');
const {CURRENT_SEASON} = require('../lib/constants');

const OUTPUT_DATA_DIRECTORY = path.resolve(__dirname, '../../data/decadeCsvs');
Expand Down
2 changes: 1 addition & 1 deletion scripts/archive/scrapeGameIdsAndApRankings_SR.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const cheerio = require('cheerio');
const request = require('request-promise');

const {CURRENT_SEASON, AP_POLL_SEASONS} = require('../lib/constants');
const INPUT_DATA_DIRECTORY = path.resolve(__dirname, '../../data/ndSchedules');
const INPUT_DATA_DIRECTORY = path.resolve(__dirname, '../../website/src/resources/schedules');

const SPORTS_REFERENCE_GAME_STATS_START_YEAR = 2000;

Expand Down
2 changes: 1 addition & 1 deletion scripts/archive/scrapeGameStats_SR.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {CURRENT_SEASON} = require('../lib/constants');
const red = chalk.bold.red;
const green = chalk.bold.green;

const INPUT_DATA_DIRECTORY = path.resolve(__dirname, '../../data/ndSchedules');
const INPUT_DATA_DIRECTORY = path.resolve(__dirname, '../../website/src/resources/schedules');

process.setMaxListeners(Infinity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const _ = require('lodash');

const polls = require('../../../lib/polls');
const logger = require('../../../lib/logger');
const ndSchedules = require('../../../lib/ndSchedules');
const ndSchedules = require('../../../../website/src/resources/schedules');

let numSeasonsPlayed = 0;
let firstLossOfSeasonsIndexTotal = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const _ = require('lodash');

const logger = require('../../../lib/logger');
const ndSchedules = require('../../../lib/ndSchedules');
const ndSchedules = require('../../../../website/src/resources/schedules');
const {ALL_SEASONS} = require('../../../lib/constants');

const _getResultString = (result) => (result === 'W' ? 'wins' : result === 'L' ? 'losses' : 'ties');

Expand Down Expand Up @@ -53,9 +54,10 @@ const stats = {
},
};

_.forEach(ndSchedules.getForAllSeasons(), (seasonScheduleData) => {
ALL_SEASONS.forEach((season) => {
const currentYearStats = _getInitialStats();


const seasonScheduleData = ndSchedules.getForSeason(season);
seasonScheduleData.forEach((gameData) => {
if (gameData.result) {
const resultString = _getResultString(gameData.result);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const _ = require('lodash');

const logger = require('../../../lib/logger');
const ndSchedules = require('../../../lib/ndSchedules');
const ndSchedules = require('../../../../website/src/resources/schedules');
const {ALL_SEASONS} = require('../../../lib/constants');

// TODO: Analyze record based on location of opponent's campus, not just where the game was played.

Expand Down Expand Up @@ -47,7 +48,8 @@ let stats = {
country: {},
};

_.forEach(ndSchedules.getForAllSeasons(), (seasonScheduleData, season) => {
ALL_SEASONS.forEach((season) => {
const seasonScheduleData = ndSchedules.getForSeason(season);
seasonScheduleData.forEach((gameData) => {
if (gameData.location !== 'TBD') {
const stateOrCountryKey =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const _ = require('lodash');

const logger = require('../../../lib/logger');
const ndSchedules = require('../../../lib/ndSchedules');
const ndSchedules = require('../../../../website/src/resources/schedules');
const {ALL_SEASONS} = require('../../../lib/constants');

let pollRankings = {
ap: Array(25).fill(0),
Expand All @@ -10,7 +11,8 @@ let pollRankings = {
cfbPlayoff: Array(25).fill(0),
};

_.forEach(ndSchedules.getForAllSeasons(), (seasonScheduleData) => {
ALL_SEASONS.forEach((season) => {
const seasonScheduleData = ndSchedules.getForSeason(season);
seasonScheduleData
.filter(({result}) => typeof result !== 'undefined')
.forEach((gameData) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ const fs = require('fs');
const path = require('path');

const logger = require('../../../lib/logger');
const ndSchedules = require('../../../lib/ndSchedules');
const ndSchedules = require('../../../../website/src/resources/schedules');
const {ALL_SEASONS} = require('../../../lib/constants');

const OUTPUT_DATA_DIRECTORY = path.resolve(__dirname, './data');

let gamesPlayedCount = 0;
const scorigamiMatrix = [];

_.forEach(ndSchedules.getForAllSeasons(), (seasonScheduleData) => {
ALL_SEASONS.forEach((season) => {
const seasonScheduleData = ndSchedules.getForSeason(season);
seasonScheduleData.forEach((gameData) => {
if (gameData.result) {
gamesPlayedCount++;
Expand Down
23 changes: 2 additions & 21 deletions scripts/lib/ndSchedules.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ const path = require('path');

const {ALL_SEASONS, CURRENT_SEASON} = require('./constants');

const ND_SCHEDULES_DATA_DIRECTORY = path.resolve(__dirname, '../../data/ndSchedules');
const COMBINED_SCHEDULE_FILENAME = path.resolve(
__dirname,
'../../website/src/resources/schedule.json'
);
const ND_SCHEDULES_DATA_DIRECTORY = path.resolve(__dirname, '../../website/src/resources/schedules');

const getForSeason = (season) => {
try {
Expand All @@ -25,33 +21,18 @@ module.exports.getForCurrentSeason = () => {
return getForSeason(CURRENT_SEASON);
};

const getForAllSeasons = () => {
return require(COMBINED_SCHEDULE_FILENAME);
};
module.exports.getForAllSeasons = getForAllSeasons;

const updateForSeason = (season, seasonScheduleData) => {
fs.writeFileSync(
`${ND_SCHEDULES_DATA_DIRECTORY}/${season}.json`,
JSON.stringify(seasonScheduleData, null, 2)
);

updateForAllSeasons({
...getForAllSeasons(),
[season]: seasonScheduleData,
});
};
module.exports.updateForSeason = updateForSeason;

module.exports.updateForCurrentSeason = (seasonScheduleData) => {
return updateForSeason(CURRENT_SEASON, seasonScheduleData);
};

const updateForAllSeasons = (allSeasonsScheduleData) => {
fs.writeFileSync(COMBINED_SCHEDULE_FILENAME, JSON.stringify(allSeasonsScheduleData, null, 2));
};
module.exports.updateForAllSeasons = updateForAllSeasons;

module.exports.transformForAllSeasons = async (transform) => {
const allSeasonsScheduleData = {};

Expand All @@ -68,5 +49,5 @@ module.exports.transformForAllSeasons = async (transform) => {
updateForSeasonPromises.push(updateForSeason(season, seasonScheduleData));
});

await Promise.all([...updateForSeasonPromises, updateForAllSeasons(allSeasonsScheduleData)]);
await Promise.all(updateForSeasonPromises);
};
7 changes: 5 additions & 2 deletions scripts/miscellaneous/generateSitemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const fs = require('fs');
const path = require('path');

const logger = require('../lib/logger');
const ndSchedules = require('../lib/ndSchedules');
const ndSchedules = require('../../website/src/resources/schedules');
const {ALL_SEASONS} = require('../lib/constants');

const SITEMAP_FILENAME = path.resolve(__dirname, '../../website/public/sitemap.xml');

Expand All @@ -14,7 +15,9 @@ const paths = [
'/explorables/s1e2-chasing-perfection',
];

_.forEach(ndSchedules.getForAllSeasons(), (seasonScheduleData, season) => {

ALL_SEASONS.forEach((season) => {
const seasonScheduleData = ndSchedules.getForSeason(season);
paths.push(`/${season}/`);

seasonScheduleData.forEach((gameData, i) => {
Expand Down
2 changes: 1 addition & 1 deletion scripts/ndSchedules/auditFutureSchedules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const _ = require('lodash');
const teams = require('../lib/teams');
const logger = require('../lib/logger');
const sentry = require('../lib/sentry');
const ndSchedules = require('../lib/ndSchedules');
const ndSchedules = require('../../website/src/resources/schedules');
const futureSchedules = require('../lib/futureSchedules');

sentry.initialize();
Expand Down
2 changes: 1 addition & 1 deletion scripts/ndSchedules/transform.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const logger = require('../lib/logger');
const ndSchedules = require('../lib/ndSchedules');
const ndSchedules = require('../../website/src/resources/schedules');

logger.info('Transforming schedule data...');

Expand Down
Loading

0 comments on commit 7391e49

Please sign in to comment.