import mockData from './mockdata'; // function calculateBusinessDay(player: any) { // let lineItems = []; // for (let i in player.vendingMachines) { // let machine = player.vendingMachines[i]; // // } // } function personPassesByVendingMachine(person: Person, machine): EventLog { let isThursty: boolean = Math.random() < person.thirst; let availableSelections = machine.selections.filter((selection) => { return !!selection.current; }); if (isThursty) { if (!availableSelections.length) { return wontBuy('NoneAvailable'); } // pick a drink let options = availableSelections.filter((selection) => { return selection.price <= person.highestPrice; }); if (!options.length) { return wontBuy('HighPrice'); } let acceptableOptions = options.filter((option) => { return person.preferences.indexOf(option.drink) !== -1; }); if (!acceptableOptions.length) { return wontBuy('NoPreferredDrinks'); } let picked = pick(acceptableOptions); let selectionTypeData = getSelectionType(picked.type); return { eventName: 'bought', data: { reason: 'Thirsty', amount: picked.price, drink: picked.drink, selection: picked.id, selectionType: picked.type, oz: selectionTypeData ? selectionTypeData.oz : 12, person: person.id, offer: machine.id, } }; } else { return wontBuy('NotThirsty'); } function wontBuy(reason): EventLog { return { eventName: 'wontBuy', data: { reason: reason, amount: 0, drink: 'none', selection: 'none', selectionType: 'none', oz: 0, person: person.id, offer: machine.id, } }; } } function generatePerson(location: Location): Person { return { id: genId('person'), name: string; preferences: string[]; highestPrice: number; money: number; thirst: number; } } function genId(prefix: string): string { return `${prefix}-${}`; } function getSelectionType(typeName: string) { return mockData.selectionTypes.find((type) => { return type.type === typeName; }); } function pick(arr: any[]) { return arr[Math.floor(Math.random() * arr.length)]; } interface Location { } interface Person { id: string; name: string; preferences: string[]; highestPrice: number; money: number; thirst: number; } interface EventLog { eventName: string; data: any; } interface PersonEvent { reason: string; amount: number; drink: string; selection: string; selectionType: string; oz: number; person: string; // person involved in the event offer: string; // id of deal or vending machine }