copy cli files to help with processing
This commit is contained in:
123
mockProcess.ts
Normal file
123
mockProcess.ts
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
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
|
||||||
|
}
|
219
mockdata.ts
Normal file
219
mockdata.ts
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
let dataDefinition: any = {
|
||||||
|
players: [
|
||||||
|
{
|
||||||
|
id: 'player-01',
|
||||||
|
name: 'payne8',
|
||||||
|
balance: 4000.00,
|
||||||
|
vendingMachines: [
|
||||||
|
{
|
||||||
|
id: 'vend-01',
|
||||||
|
name: "First One!",
|
||||||
|
location: 'loc-01',
|
||||||
|
placement: 'plac-01',
|
||||||
|
compatibleSelectionTypes: ['can', 'bottle'],
|
||||||
|
selections: [
|
||||||
|
{
|
||||||
|
id: 'sel-01',
|
||||||
|
name: 'Diet Mtn. Dew',
|
||||||
|
drink: 'drink-01',
|
||||||
|
max: 56,
|
||||||
|
current: 24,
|
||||||
|
price: 1.00,
|
||||||
|
type: 'can'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'sel-02',
|
||||||
|
name: 'Mtn. Dew',
|
||||||
|
drink: 'drink-02',
|
||||||
|
max: 56,
|
||||||
|
current: 24,
|
||||||
|
price: 1.00,
|
||||||
|
type: 'can'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'sel-03',
|
||||||
|
name: 'Dr. Pepper',
|
||||||
|
drink: 'drink-03',
|
||||||
|
max: 56,
|
||||||
|
current: 24,
|
||||||
|
price: 1.00,
|
||||||
|
type: 'can'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'sel-04',
|
||||||
|
name: 'Sprite',
|
||||||
|
drink: 'drink-04',
|
||||||
|
max: 56,
|
||||||
|
current: 24,
|
||||||
|
price: 1.00,
|
||||||
|
type: 'can'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'sel-05',
|
||||||
|
name: 'Coke',
|
||||||
|
drink: 'drink-05',
|
||||||
|
max: 56,
|
||||||
|
current: 24,
|
||||||
|
price: 1.00,
|
||||||
|
type: 'can'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'sel-06',
|
||||||
|
name: 'Diet Coke',
|
||||||
|
drink: 'drink-06',
|
||||||
|
max: 56,
|
||||||
|
current: 24,
|
||||||
|
price: 1.00,
|
||||||
|
type: 'can'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'sel-07',
|
||||||
|
name: 'Orange Soda',
|
||||||
|
drink: 'drink-07',
|
||||||
|
max: 56,
|
||||||
|
current: 24,
|
||||||
|
price: 1.00,
|
||||||
|
type: 'can'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'sel-08',
|
||||||
|
name: 'Grape Soda',
|
||||||
|
drink: 'drink-08',
|
||||||
|
max: 56,
|
||||||
|
current: 24,
|
||||||
|
price: 1.00,
|
||||||
|
type: 'can'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
agreement: 0.0, // revenue share
|
||||||
|
}
|
||||||
|
],
|
||||||
|
deals: [
|
||||||
|
{
|
||||||
|
id: 'deal-01',
|
||||||
|
location: 'loc-01',
|
||||||
|
selections: [
|
||||||
|
{
|
||||||
|
id: 'sel-09',
|
||||||
|
name: 'Diet Mtn. Dew - Dozen Cans',
|
||||||
|
drink: 'drink-01',
|
||||||
|
max: 56,
|
||||||
|
current: 24,
|
||||||
|
price: 7.00,
|
||||||
|
type: 'dozen-box'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
agreement: 0.4, // revenue share
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
selectionTypes: [
|
||||||
|
{
|
||||||
|
type: 'can',
|
||||||
|
oz: 12,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'dozen-box',
|
||||||
|
os: 144
|
||||||
|
}
|
||||||
|
],
|
||||||
|
drinks: [
|
||||||
|
{
|
||||||
|
id: 'drink-01',
|
||||||
|
name: 'Diet Mtn. Dew',
|
||||||
|
costPerOz: 0.005,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'drink-02',
|
||||||
|
name: 'Mtn. Dew',
|
||||||
|
costPerOz: 0.005,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'drink-03',
|
||||||
|
name: 'Dr. Pepper',
|
||||||
|
costPerOz: 0.005,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'drink-04',
|
||||||
|
name: 'Sprite',
|
||||||
|
costPerOz: 0.005,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'drink-05',
|
||||||
|
name: 'Coke',
|
||||||
|
costPerOz: 0.005,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'drink-06',
|
||||||
|
name: 'Diet Coke',
|
||||||
|
costPerOz: 0.005,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'drink-07',
|
||||||
|
name: 'Orange Soda',
|
||||||
|
costPerOz: 0.005,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'drink-08',
|
||||||
|
name: 'Grape Soda',
|
||||||
|
costPerOz: 0.005,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
locations: [
|
||||||
|
{
|
||||||
|
id: 'loc-01',
|
||||||
|
name: 'General Store',
|
||||||
|
city: 'city-01',
|
||||||
|
dailyTraffic: {
|
||||||
|
max: 2000,
|
||||||
|
min: 400,
|
||||||
|
thirstBonus: 0.2,
|
||||||
|
},
|
||||||
|
deals: {
|
||||||
|
count: 2,
|
||||||
|
traffic: 0.4,
|
||||||
|
list: [
|
||||||
|
'deal-01'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
placements: [
|
||||||
|
{
|
||||||
|
id: 'plac-01',
|
||||||
|
traffic: 0.5,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'plac-02',
|
||||||
|
traffic: 0.6,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
cities: [
|
||||||
|
{
|
||||||
|
id: 'city-01',
|
||||||
|
name: 'Hometown',
|
||||||
|
population: 15000
|
||||||
|
}
|
||||||
|
],
|
||||||
|
people: [
|
||||||
|
{
|
||||||
|
id: 'person-01',
|
||||||
|
name: 'Steve Klemm',
|
||||||
|
preferences: [
|
||||||
|
'drink-01',
|
||||||
|
'drink-04',
|
||||||
|
'drink-08',
|
||||||
|
],
|
||||||
|
highestPrice: 2.00,
|
||||||
|
wallet: {
|
||||||
|
cc: 500.00,
|
||||||
|
cash: 10.00,
|
||||||
|
coins: 1.25,
|
||||||
|
},
|
||||||
|
thirst: 0.8,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
export default dataDefinition;
|
@ -9,6 +9,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"core-js": "^3.6.4",
|
"core-js": "^3.6.4",
|
||||||
|
"crypto-random-string": "^3.2.0",
|
||||||
"register-service-worker": "^1.7.1",
|
"register-service-worker": "^1.7.1",
|
||||||
"vue": "^2.6.11",
|
"vue": "^2.6.11",
|
||||||
"vue-class-component": "^7.2.3",
|
"vue-class-component": "^7.2.3",
|
||||||
|
@ -2654,6 +2654,13 @@ crypto-browserify@^3.11.0:
|
|||||||
randombytes "^2.0.0"
|
randombytes "^2.0.0"
|
||||||
randomfill "^1.0.3"
|
randomfill "^1.0.3"
|
||||||
|
|
||||||
|
crypto-random-string@^3.2.0:
|
||||||
|
version "3.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/crypto-random-string/-/crypto-random-string-3.2.0.tgz#d513ef0c2ac6ff7cad5769de585d9bf2ad5a2b4d"
|
||||||
|
integrity sha512-8vPu5bsKaq2uKRy3OL7h1Oo7RayAWB8sYexLKAqvCXVib8SxgbmoF1IN4QMKjBv8uI8mp5gPPMbiRah25GMrVQ==
|
||||||
|
dependencies:
|
||||||
|
type-fest "^0.8.1"
|
||||||
|
|
||||||
css-color-names@0.0.4, css-color-names@^0.0.4:
|
css-color-names@0.0.4, css-color-names@^0.0.4:
|
||||||
version "0.0.4"
|
version "0.0.4"
|
||||||
resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-0.0.4.tgz#808adc2e79cf84738069b646cb20ec27beb629e0"
|
resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-0.0.4.tgz#808adc2e79cf84738069b646cb20ec27beb629e0"
|
||||||
|
Reference in New Issue
Block a user