Skip to content

Instantly share code, notes, and snippets.

@cronco
Last active March 2, 2017 18:02
Show Gist options
  • Save cronco/cd1476b30eeb03197adfdb106ec222ab to your computer and use it in GitHub Desktop.
Save cronco/cd1476b30eeb03197adfdb106ec222ab to your computer and use it in GitHub Desktop.
JS Bin// source http://jsbin.com/satikor
Number/Months 1 2 3 4 5 6 7 8 9 10 11 12
1 5.00 5.00 4.5 4.5 4.5 4.25 4.25 4.25 4 4 4.00 3.50
2 5.00 5.00 4.5 4.5 4.5 4.25 4.25 4.25 4 4 4.00 3.50
3 5.00 5.00 4.5 4.5 4.5 4.25 4.25 4.25 4 4 4.00 3.50
4 5.00 5.00 4.5 4.5 4.5 4.25 4.25 4.25 4 4 4.00 3.50
5 4.50 4.50 4.05 4.05 4.05 3.83 3.83 3.83 3.6 3.6 3.60 3.15
6 4.50 4.50 4.05 4.05 4.05 3.83 3.83 3.83 3.6 3.6 3.60 3.15
7 4.50 4.50 4.05 4.05 4.05 3.83 3.83 3.83 3.6 3.6 3.60 3.15
8 4.50 4.50 4.05 4.05 4.05 3.83 3.83 3.83 3.6 3.6 3.60 3.15
9 4.50 4.50 4.05 4.05 4.05 3.83 3.83 3.83 3.6 3.6 3.60 3.15
10 4.25 4.25 3.83 3.83 3.83 3.61 3.61 3.61 3.4 3.4 3.40 2.98
11 4.25 4.25 3.83 3.83 3.83 3.61 3.61 3.61 3.4 3.4 3.40 2.98
12 4.25 4.25 3.83 3.83 3.83 3.61 3.61 3.61 3.4 3.4 3.40 2.98
13 4.25 4.25 3.83 3.83 3.83 3.61 3.61 3.61 3.4 3.4 3.40 2.98
14 4.25 4.25 3.83 3.83 3.83 3.61 3.61 3.61 3.4 3.4 3.40 2.98
15 4.25 4.25 3.83 3.83 3.83 3.61 3.61 3.61 3.4 3.4 3.40 2.98
16 4.25 4.25 3.83 3.83 3.83 3.61 3.61 3.61 3.4 3.4 3.40 2.98
17 4.25 4.25 3.83 3.83 3.83 3.61 3.61 3.61 3.4 3.4 3.40 2.98
18 4.25 4.25 3.83 3.83 3.83 3.61 3.61 3.61 3.4 3.4 3.40 2.98
19 4.25 4.25 3.83 3.83 3.83 3.61 3.61 3.61 3.4 3.4 3.40 2.98
20 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
21 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
22 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
23 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
24 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
25 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
26 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
27 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
28 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
29 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
30 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
31 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
32 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
33 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
34 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
35 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
36 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
37 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
38 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
39 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
40 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
41 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
42 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
43 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
44 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
45 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
46 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
47 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
48 4.00 4.00 3.6 3.6 3.6 4.25 4.25 4.25 3.2 3.2 3.20 2.80
49 4.00 4.00 3.6 3.6 3.6 3.4 3.4 3.4 3.2 3.2 3.20 2.80
50 3.50 3.50 3.15 3.15 3.15 2.98 2.98 2.98 2.8 2.8 2.8 2.45
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/4.1.4/papaparse.js"></script>
<link rel="stylesheet" href="jsbin.satikor.css">
</head>
<body>
<label for="">Box type<br><select name="" id="box-type">
<option value="box">Boxes</option>
<option value="large_box">Large Boxes</option>
<option value="wooden_crates">Wooden Crates</option>
</select></label>
<label> Months<br /><input type="number" id="months" value="1"/></label>
<label> Boxes<br /><input type="number" id="boxes" value="2"/></label>
<button id="calculate">Calculate</button>
<label> Per month<br /><input type="number" disabled="true" id="per-month"/></label>
<label> Total<br /><input type="number" disabled="true" id="total"/></label>
<script id="jsbin-javascript" src="jsbin.satikor.js"></script>
</body>
</html>
label {
display:block;
margin: 20px;
}
var boxes = [], largeBoxes = [], woodenCrates = [];
Papa.parse('/boxes.csv', {
download: true,
complete: function (result) {
boxes = result.data;
console.log(boxes);
}
});
Papa.parse('/large_boxes.csv', {
download: true,
complete: function(result) {
largeBoxes = result.data;
console.log(largeBoxes);
}
});
Papa.parse('/wooden_crates.csv', {
download: true,
complete: function (result) {
woodenCrates = result.data;
console.log(woodenCrates);
}
})
$('#calculate').click(function(e) {
var monthsVal = parseInt($('#months').val(), 10);
var boxesVal = parseInt($('#boxes').val(), 10);
var boxType = $('#box-type').val();
var priceMatrix;
if (boxType === 'box') {
priceMatrix = boxes;
} else if (boxType === 'large_box') {
priceMatrix = largeBoxes;
} else if (boxType === 'wooden_crates') {
priceMatrix = woodenCrates;
}
if (monthsVal && boxesVal) {
var monthIndex = 1, boxIndex = 1, totalValue;
if (boxesVal < priceMatrix.length) {
boxIndex = boxesVal;
} else {
boxIndex = priceMatrix.length - 1;
}
if (monthsVal < priceMatrix[boxIndex].length) {
monthIndex = monthsVal
} else {
monthIndex = priceMatrix[boxIndex].length - 1
}
$('#per-month').val(priceMatrix[boxIndex][monthIndex]);
totalValue = priceMatrix[boxIndex][monthIndex] * monthsVal * boxesVal
$('#total').val(totalValue);
}
});
Number/Months 1 2 3 4 5 6 7 8 9 10 11 12
1 6.5 6.5 5.85 5.85 5.85 5.53 5.53 5.53 5.2 5.2 5.2 4.55
2 6.5 6.5 5.85 5.85 5.85 5.53 5.53 5.53 5.2 5.2 5.2 4.55
3 6.5 6.5 5.85 5.85 5.85 5.53 5.53 5.53 5.2 5.2 5.2 4.55
4 6.5 6.5 5.85 5.85 5.85 5.53 5.53 5.53 5.2 5.2 5.2 4.55
5 5.85 5.85 5.27 5.27 5.27 4.97 4.97 4.97 4.68 4.68 4.68 4.1
6 5.85 5.85 5.27 5.27 5.27 4.97 4.97 4.97 4.68 4.68 4.68 4.1
7 5.85 5.85 5.27 5.27 5.27 4.97 4.97 4.97 4.68 4.68 4.68 4.1
8 5.85 5.85 5.27 5.27 5.27 4.97 4.97 4.97 4.68 4.68 4.68 4.1
9 5.85 5.85 5.27 5.27 5.27 4.97 4.97 4.97 4.68 4.68 4.68 4.1
10 5.53 5.53 4.97 4.97 4.97 4.7 4.7 4.7 4.42 4.42 4.42 3.87
11 5.53 5.53 4.97 4.97 4.97 4.7 4.7 4.7 4.42 4.42 4.42 3.87
12 5.53 5.53 4.97 4.97 4.97 4.7 4.7 4.7 4.42 4.42 4.42 3.87
13 5.53 5.53 4.97 4.97 4.97 4.7 4.7 4.7 4.42 4.42 4.42 3.87
14 5.53 5.53 4.97 4.97 4.97 4.7 4.7 4.7 4.42 4.42 4.42 3.87
15 5.53 5.53 4.97 4.97 4.97 4.7 4.7 4.7 4.42 4.42 4.42 3.87
16 5.53 5.53 4.97 4.97 4.97 4.7 4.7 4.7 4.42 4.42 4.42 3.87
17 5.53 5.53 4.97 4.97 4.97 4.7 4.7 4.7 4.42 4.42 4.42 3.87
18 5.53 5.53 4.97 4.97 4.97 4.7 4.7 4.7 4.42 4.42 4.42 3.87
19 5.53 5.53 4.97 4.97 4.97 4.7 4.7 4.7 4.42 4.42 4.42 3.87
20 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
21 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
22 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
23 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
24 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
25 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
26 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
27 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
28 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
29 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
30 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
31 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
32 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
33 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
34 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
35 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
36 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
37 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
38 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
39 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
40 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
41 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
42 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
43 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
44 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
45 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
46 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
47 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
48 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
49 5.2 5.2 4.68 4.68 4.68 4.42 4.42 4.42 4.16 4.16 4.16 3.64
50 4.55 4.55 4.1 4.1 4.1 3.87 3.87 3.87 3.64 3.64 3.64 3.19
Number/Weeks 1 2 3 4 5 6 7 8 9 10 11 12 13
1 22 22 22 22 21 21 21 21 21 21 21 21 19.5
2 21 21 21 21 20 20 20 20 20 20 20 20 18.5
3 21 21 21 21 20 20 20 20 20 20 20 20 18.5
4 19.5 19.5 19.5 19.5 18.5 18.5 18.5 18.5 18.5 18.5 18.5 18.5 17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment