Skip to content

Instantly share code, notes, and snippets.

View mattmazzola's full-sized avatar

Matt Mazzola mattmazzola

View GitHub Profile
npx create-react-app@latest client --template=typescript
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
md Service
cd Service
dotnet new sln
dotnet new gitignore
dotnet new webapi -n Articles.Api
dotnet sln add Articles.Api
git add -A
git commit -m "Initial Commit"
@mattmazzola
mattmazzola / setup.ps1
Created February 20, 2022 20:28
Creating the monorepo
md dotnet-openapi-node
cd dotnet-openapi-node
git init
@mattmazzola
mattmazzola / playerOutcome.ts
Created November 23, 2020 03:53
Compute player outcome
const [playerProbability, questionProbability] = ratingSystem.getPlayerProbabilities(player.rating, question.rating)
const expectedOutcome = playerProbability > 0.5 ? 1 : 0
const playerOutcome = Math.random() < playerProbability ? 1 : 0
@mattmazzola
mattmazzola / matching.ts
Created November 23, 2020 03:51
Get question within range
const minRating = player.rating - ratingRange
const maxRating = player.rating + ratingRange
const isRatingWithinRange = (question: Question) => minRating <= question.rating && question.rating <= maxRating
const question = getRandomWhichMeetsConstraints(questions, isRatingWithinRange)
@mattmazzola
mattmazzola / createCsvFromObjects.ts
Created November 23, 2020 03:30
Create CSV from Objects
export function createCsvFromObjects<T extends Record<string, unknown>>(os: T[]): string {
if (os.length == 0) {
throw new Error(`Cannon create CSV from empty list. Given list must not be empty.`)
}
const firstResult = os[0]
const keys = Object.keys(firstResult)
const headers = keys.join(',')
const rows = os.map(result => Object.values(result).join(','))
@mattmazzola
mattmazzola / executeGames.ts
Created November 23, 2020 03:11
Execute Games
// Execute simulation
const numQuestionsPerPlayer = 100
// The maximum difference that a question's rating will be from the player's rating
// Simulates a queuing system the pairs likely candidates
const ratingRange = 250
const symmetricResults = simulateGames(symmetricRatingSystem, players, questions, numQuestionsPerPlayer, ratingRange)
const asymmetricResults = simulateGames(asymmetricRatingSystem, players2, questions2, numQuestionsPerPlayer, ratingRange)
@mattmazzola
mattmazzola / simulateGame.ts
Created November 23, 2020 03:04
Simulate Games
// For each player simulate the player answering series of questions and observe rating changes
export default function simulateGames(
ratingSystem: RatingSystem,
players: Player[],
questions: Question[],
numQuestionsPerPlayer: number,
ratingRange: number
): Result[] {
const results: Result[] = []
@mattmazzola
mattmazzola / createPlayers.ts
Created November 23, 2020 02:23
Create Players
// Create players
const initialRating = 1000
const numPlayers = 10
const playerTiers = 5
const playerRatingRange = 6000 - initialRating
const playerSegmentSize = Math.floor(numPlayers / playerTiers)
const playerIncrementAmount = Math.floor(playerRatingRange / playerTiers)
const playerGeneration = {
total: numPlayers,