Major update

This commit is contained in:
2023-06-01 08:52:05 -05:00
parent d7c0f373f4
commit df84287eb2
264 changed files with 8614 additions and 964 deletions

View File

@@ -0,0 +1 @@
local.settings.json

View File

@@ -0,0 +1,10 @@
*.js.map
*.ts
.git*
.vscode
local.settings.json
test
getting_started.md
node_modules/@types/
node_modules/azure-functions-core-tools/
node_modules/typescript/

48
functions/season-loader/.gitignore vendored Normal file
View File

@@ -0,0 +1,48 @@
bin
obj
csx
.vs
edge
Publish
*.user
*.suo
*.cscfg
*.Cache
project.lock.json
/packages
/TestResults
/tools/NuGet.exe
/App_Data
/secrets
/data
.secrets
appsettings.json
local.settings.json
node_modules
dist
# Local python packages
.python_packages/
# Python Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# Azurite artifacts
__blobstorage__
__queuestorage__
__azurite_db*__.json

View File

@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions"
]
}

View File

@@ -0,0 +1,12 @@
# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/node:4-node16-appservice
FROM mcr.microsoft.com/azure-functions/node:4-node16
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . /home/site/wwwroot
RUN cd /home/site/wwwroot && \
npm install && \
npm run build

View File

@@ -0,0 +1,16 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.*, 4.0.0)"
},
"functionTimeout": "00:30:00"
}

View File

@@ -0,0 +1,50 @@
export interface IGame {
gamePk?: number;
link?: string;
gameType?: string;
season?: number;
gameDate?: string;
officialDate?: string;
statusAbstractGameState?: string;
statusCodedGameState?: string;
statusDetailedState?: string;
statusStatusCode?: string;
statusStartTimeTbd?: string;
statusAbstractGameCode?: string;
teamsAwayLeagueRecordWins?: number;
teamsAwayLeagueRecordLosses?: number;
teamsAwayLeagueRecordPct?: number;
teamsAwayScore?: number;
teamsAwayTeamId?: number;
teamsAwayIsWinner?: string;
teamsAwaySplitSquad?:string;
teamsAwaySeriesNumber?: number;
teamsHomeLeagueRecordWins?: number;
teamsHomeLeagueRecordLosses?: number;
teamsHomeLeagueRecordPct?: number;
teamsHomeScore?: number;
teamsHomeTeamId?: number;
teamsHomeIsWinner?: boolean;
teamsHomeSplitSquad?: string;
teamsHomeSeriesNumber?: number;
venueId?: number;
contentLink?: string;
isTie?: boolean;
gameNumber?: number;
publicFacing?: string;
doubleHeader?: string;
gamedayType?: string;
tieBreaker?: string;
calendarEventId?: string;
seasonDisplay?: number;
dayNight?: string;
scheduledInnings?: number;
reverseHomeAwayStatus?: string;
inningBreakLength?: number;
gamesInSeries?: number;
seriesGameNumber?: number;
seriesDescription?: string;
recordSource?: string;
ifNecessary?: string;
ifNecessaryDescription?: string;
}

1444
functions/season-loader/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,22 @@
{
"name": "",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"prestart": "npm run build",
"start": "func start",
"test": "echo \"No tests yet...\""
},
"dependencies": {
"@microsoft/signalr": "^7.0.3",
"axios": "^1.3.4"
},
"devDependencies": {
"@azure/functions": "^3.0.0",
"@types/node": "16.x",
"azure-functions-core-tools": "^4.x",
"typescript": "^4.0.0"
}
}

View File

@@ -0,0 +1,20 @@
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"scriptFile": "../dist/seasonLoader/index.js"
}

View File

@@ -0,0 +1,258 @@
import { AzureFunction, Context, HttpRequest } from '@azure/functions';
import { HubConnection, HubConnectionBuilder } from '@microsoft/signalr';
import axios, { AxiosResponse } from 'axios';
import { IGame } from '../models/IGame';
const initialzeSignalRConnection = async (context: Context): Promise<HubConnection> => {
const connection: HubConnection = new HubConnectionBuilder()
.withUrl('http://localhost:5580/hubs/season')
.build();
try {
await connection.start().catch((error) => context.log(error.toString()));
context.log('connected')
return Promise.resolve<HubConnection>(connection);
} catch (error) {
return Promise.reject(error);
}
}
const createGames = async (dates: any[], context: Context): Promise<void> => {
const connection = await initialzeSignalRConnection(context);
let count = 0;
try {
for (let d = 0; d < dates.length; d++) {
const games = dates[d].games;
const gamesToAdd: IGame[] = [];
for (let g = 0; g < games.length; g++) {
const game: any = games[g];
const gameToAdd: IGame = {};
if (game.gamePk) {
gameToAdd.gamePk = game.gamePk;
}
if (game.link) {
gameToAdd.link = game.link;
}
if (game.gameType) {
gameToAdd.gameType = game.gameType;
}
if (game.season) {
gameToAdd.season = game.season;
}
if (game.gameDate) {
gameToAdd.gameDate = game.gameDate;
}
if (game.officialDate) {
gameToAdd.officialDate = game.officialDate;
}
if (game.status.abstractGameState) {
gameToAdd.statusAbstractGameState = game.status.abstractGameState;
}
if (game.status.codedGameState) {
gameToAdd.statusCodedGameState = game.status.codedGameState;
}
if (game.status.detailedState) {
gameToAdd.statusDetailedState = game.status.detailedState;
}
if (game.status.statusCode) {
gameToAdd.statusStatusCode = game.status.statusCode;
}
if (game.status.startTimeTBD) {
gameToAdd.statusStartTimeTbd = game.status.startTimeTBD;
}
if (game.status.abstractGameCode) {
gameToAdd.statusAbstractGameCode = game.status.abstractGameCode;
}
if (game.teams.away.leagueRecord.wins) {
gameToAdd.teamsAwayLeagueRecordWins = game.teams.away.leagueRecord.wins;
}
if (game.teams.away.leagueRecord.losses) {
gameToAdd.teamsAwayLeagueRecordLosses = game.teams.away.leagueRecord.losses;
}
if (game.teams.away.leagueRecord.pct) {
gameToAdd.teamsAwayLeagueRecordPct = parseFloat(game.teams.away.leagueRecord.pct);
}
if (game.teams.away.team.id) {
gameToAdd.teamsAwayTeamId = game.teams.away.team.id;
}
if (game.teams.away.splitSquad) {
gameToAdd.teamsAwaySplitSquad = game.teams.away.splitSquad;
}
if (game.teams.away.seriesNumber) {
gameToAdd.teamsAwaySeriesNumber = game.teams.away.seriesNumber;
}
if (game.teams.home.leagueRecord.wins) {
gameToAdd.teamsHomeLeagueRecordWins = game.teams.home.leagueRecord.wins;
}
if (game.teams.home.leagueRecord.losses) {
gameToAdd.teamsHomeLeagueRecordLosses = game.teams.home.leagueRecord.losses;
}
if (game.teams.home.leagueRecord.pct) {
gameToAdd.teamsHomeLeagueRecordPct = parseFloat(game.teams.home.leagueRecord.pct);
}
if (game.teams.home.team.id) {
gameToAdd.teamsHomeTeamId = game.teams.home.team.id;
}
if (game.teams.home.splitSquad) {
gameToAdd.teamsHomeSplitSquad = game.teams.home.splitSquad;
}
if (game.teams.home.seriesNumber) {
gameToAdd.teamsHomeSeriesNumber = game.teams.home.seriesNumber;
}
if (game.venue.id) {
gameToAdd.venueId = game.venue.id;
}
if (game.content.link) {
gameToAdd.contentLink = game.content.link;
}
if (game.isTie) {
gameToAdd.isTie = game.isTie;
}
if (game.gameNumber) {
gameToAdd.gameNumber = game.gameNumber;
}
if (game.publicFacing) {
gameToAdd.publicFacing = game.publicFacing;
}
if (game.doubleHeader) {
gameToAdd.doubleHeader = game.doubleHeader;
}
if (game.gamedayType) {
gameToAdd.gamedayType = game.gamedayType;
}
if (game.tieBreaker) {
gameToAdd.tieBreaker = game.tiebreaker;
}
if (game.calendarEventID) {
gameToAdd.calendarEventId = game.calendarEventID;
}
if (game.seasonDisplay) {
gameToAdd.seasonDisplay = game.seasonDisplay;
}
if (game.dayNight) {
gameToAdd.dayNight = game.dayNight;
}
if (game.scheduledInnings) {
gameToAdd.scheduledInnings = game.scheduledInnings;
}
if (game.reverseHomeAwayStatus) {
gameToAdd.reverseHomeAwayStatus = game.reverseHomeAwayStatus;
}
if (game.inningBreakLength) {
gameToAdd.inningBreakLength = game.inningBreakLength;
}
if (game.gamesInSeries) {
gameToAdd.gamesInSeries = game.gamesInSeries;
}
if (game.seriesGameNumber) {
gameToAdd.seriesGameNumber = game.seriesGameNumber;
}
if (game.seriesDescription) {
gameToAdd.seriesDescription = game.seriesDescription;
}
if (game.recordSource) {
gameToAdd.recordSource = game.recordSource;
}
if (game.ifNecessary) {
gameToAdd.ifNecessary = game.ifNecessary;
}
if (game.ifNecessaryDescription) {
gameToAdd.ifNecessaryDescription = game.ifNecessaryDescription;
}
gamesToAdd.push(gameToAdd);
}
await axios.post('http://localhost:5520/api/games', gamesToAdd);
count += 1;
context.log(`${count} of ${dates.length}`);
await connection.invoke('SendSeasonMessage', {
totalDates: dates.length,
datesCompleted: count
});
}
return Promise.resolve();
} catch (error) {
return Promise.reject(error);
}
}
const httpTrigger: AzureFunction = async (context: Context, req: HttpRequest): Promise<void> => {
const year = req.query.year;
if (!year) {
context.res = {
status: 500,
body: 'Season year required.'
}
} else {
try {
const response: AxiosResponse = await axios.get(`https://statsapi.mlb.com/api/v1/schedule?sportId=1&startDate=${year}-01-01&endDate=${year}-12-31`);
const dates = response.data.dates;
await createGames(dates, context);
context.res = {
status: 201
}
} catch (error) {
context.res = {
status: 500,
body: error
}
}
}
};
export default httpTrigger;

View File

@@ -0,0 +1,10 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "dist",
"rootDir": ".",
"sourceMap": true,
"strict": false
}
}