-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdp_calculator.html
More file actions
217 lines (196 loc) · 9.04 KB
/
dp_calculator.html
File metadata and controls
217 lines (196 loc) · 9.04 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!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">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<!-- 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>
<![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">
<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 class='section'>
<span class='label'>Input DP JSON</span>
<div class="row">
<div class="col-xs-12">
<div class="form-group">
<textarea id="json" style="width:100%; height: 500px;"></textarea>
<div id="json-status" class="json-status json-neutral">Start typing to validate.</div>
</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">
<div class="code-shell">
<div class="code-toolbar text-right">
<button type="button" class="btn-copy-icon" id="copy-dp"
data-clipboard-target="#end-code" title="Copy to clipboard">
<svg viewBox="0 0 24 24" aria-hidden="true">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2" fill="currentColor" opacity="0.6"/>
<rect x="3" y="3" width="13" height="13" rx="2" ry="2" fill="currentColor"/>
</svg>
</button>
</div>
<pre class="code-view"><code id="end-code-highlight" class="language-json"></code></pre>
<textarea id='end-code' class="no-translate code-source" readonly></textarea>
</div>
</div>
<div class="modal-footer">
<p class='text-center'>
<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 () {
var $jsonField = $("#json");
var $jsonStatus = $("#json-status");
function setJsonStatus(state, message) {
if (!$jsonStatus.length) {
return;
}
$jsonStatus.removeClass("json-valid json-invalid json-neutral");
$jsonStatus.addClass("json-" + state);
$jsonStatus.text(message);
}
function evaluateJsonInput(value) {
var raw = (value || "").trim();
if (!raw) {
setJsonStatus("neutral", "Start typing JSON to validate.");
return { valid: false, data: null, message: "Please provide JSON input." };
}
try {
var parsed = JSON.parse(raw);
setJsonStatus("valid", "JSON looks valid.");
return { valid: true, data: parsed };
} catch (err) {
var errorMessage = err && err.message ? err.message.split("\n")[0] : "Unknown error";
setJsonStatus("invalid", "Invalid JSON: " + errorMessage);
return { valid: false, data: null, message: "Invalid JSON: " + errorMessage };
}
}
function handleJsonInputChange() {
evaluateJsonInput($jsonField.val());
}
function updateHighlight(text) {
$("#end-code-highlight").text(text || "");
if (window.hljs) {
hljs.highlightElement(document.getElementById("end-code-highlight"));
}
}
function calculate() {
var parsed = evaluateJsonInput($jsonField.val());
var data = parsed.data;
if (!parsed.valid || !data) {
alert(parsed.message || "Please enter valid JSON before calculating.");
return;
}
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);
updateHighlight(output);
$('#end-modal').modal('show');
}
else {
alert("No data");
}
}
new Clipboard('#copy-dp');
$("#gotit").click(function () {
$('#end-modal').modal('hide');
});
$("#calculate").on("click", calculate);
$('#end-modal').on('shown.bs.modal', function () {
updateHighlight($("#end-code").val());
});
$("#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);
}
});
$jsonField.on("input", handleJsonInputChange);
handleJsonInputChange();
});
</script>
</body>
</html>