-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
84 lines (78 loc) · 1.89 KB
/
main.js
File metadata and controls
84 lines (78 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const queue = require('./core');
const yargs = require('yargs')
// Mapping Operations code to functions
const operations = {
'ti': {
name: 'Traffic intensity',
fn: 'findTrafficIntensity'
},
'aiis': {
name: 'Average number of items in the system',
fn: 'avgNumOfItemInSys'
},
'aeqi': {
name: 'Average number of elements with no queue',
fn: 'avgNumOfElementsQueueExists'
},
'aenq': {
name: 'Average number of elements with queue',
fn: 'avgNumOfElementsQueueNotExist'
},
'atiq': {
name: 'Average time in queue',
fn: 'avgTimeInQueue'
},
'atis': {
name: 'Average time in the system',
fn: 'avgTimeInSys'
},
'pqoa': {
name: 'Probability of queueing on arrival',
fn: 'probOfQueueingOnArrival'
},
'pnqa': {
name: 'Probability of not queueing on arrival',
fn: 'probOfNotQueueingOnArrival'
},
'pnsat': {
name: 'Probability of n elements in the system at any time',
fn: 'findProbOfNEelementsInSysAnyTime'
},
'pnoms': {
name: 'Probability of n or more items in the system ',
fn: 'findProbOfNOrMoreElementsInSys'
}
}
const argv = yargs
.option('ar', {
alias: 'arrival_rate',
demandOption: true,
type: 'number',
describe: 'the arrival rate parameter used for calculations'
})
.option('sr', {
alias: 'service_rate',
demandOption: true,
type: 'number',
describe: 'the service rate parameter used for calculations'
})
.option('cl', {
alias: 'calculate',
demandOption: true,
choices: Object.keys(operations).concat('all'),
hidden: false,
describe: 'What calculation to perform on parameters'
})
.array("calculate")
.argv
// Compute
var queueInstance = new queue(argv.ar, argv.sr);
var command = argv.cl;
function compute(code) {
let op = operations[code];
process.stdout.write(`${op.name} = ${queueInstance[op.fn]()} \n`);
}
if(command.length == 1 && command[0] === "all") {
command = Object.keys(operations)
}
command.forEach(compute)