-
Notifications
You must be signed in to change notification settings - Fork 13
/
dp_calculator.html
160 lines (146 loc) · 6.23 KB
/
dp_calculator.html
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="images/favicon.png">
<title>Countly Code Generator</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/style.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="jumbotron top">
<div class="container">
<div id="logo">
<span class="image"></span>
<span class="text">DP calculator</span>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-12">
<p><a href="index.html" id="back" class="btn btn-default">← Back</a></p>
<h2 class="text-center">Calculate Monthly DP from JSON</h2>
</div>
</div>
<div class='section'>
<span class='label'>Input DP JSON</span>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<textarea id="json" style="width:100%; height: 500px;"></textarea>
</div>
<p class='text-right'><button type="button" class="btn btn-default"
id="calculate">Calculate</button></p>
</div><!-- /.col-lg-6 -->
</div>
</div>
<footer>
<p><a href='http://count.ly'>Count.ly</a></p>
</footer>
</div> <!-- /container -->
<div class="modal fade" id="end-modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4 class="modal-title text-center">DP calculated per month</h4>
</div>
<div class="modal-body">
<p><textarea id='end-code' class="no-translate" readonly onclick="this.select();"></textarea></p>
</div>
<div class="modal-footer">
<p class='text-center'>
<button type="button" class="btn btn-success" id="copy"
data-clipboard-target="#end-code">Copy</button>
<button type="button" class="btn btn-success" id="download">Download</button>
<button type="button" class="btn btn-primary" id="gotit">Close</button>
</p>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')</script>
<script src="https://global.localizecdn.com/localize.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="js/ie10-viewport-bug-workaround.js"></script>
<script src="js/sdks.js"></script>
<script src="js/common.js"></script>
<script src="js/Blob.js"></script>
<script src="js/FileSaver.min.js"></script>
<script src="js/clipboard.min.js"></script>
<script>
$(document).ready(function () {
function calculate() {
var data;
try {
data = JSON.parse(document.getElementById("json").value);
}
catch (ex) {
alert("Error: " + ex);
}
if (data) {
var ob = {};
for (var i = 0; i < data.length; i++) {
if (data[i].m) {
if (!ob[data[i].m]) {
ob[data[i].m] = 0;
}
ob[data[i].m] += (data[i].e || 0) + (data[i].s || 0)
}
}
var output = "";
var keys = Object.keys(ob);
keys = keys.sort(function (a, b) {
a = a.split(":");
b = b.split(":")
return new Date(b[0], b[1], 1) - new Date(a[0], a[1], 1);
});
for (var i = 0; i < keys.length; i++) {
output += keys[i] + " - " + ob[keys[i]] + "\n";
}
$("#end-code").val(output);
$('#end-modal').modal();
}
else {
alert("No data");
}
}
new Clipboard('#copy');
$("#gotit").click(function () {
$('#end-modal').modal('hide');
});
$("#calculate").on("click", calculate);
$("#download").click(function () {
var data = $("#end-code").val();
try {
var blob = new Blob([data], { type: "text/plain;charset=utf-8" });
saveAs(blob, "dp-monthly.txt");
} catch (e) {
alert(data);
}
});
});
</script>
</body>
</html>