-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexcel.html
More file actions
294 lines (285 loc) · 13.7 KB
/
Copy pathexcel.html
File metadata and controls
294 lines (285 loc) · 13.7 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Zixing Wang">
<meta name="generator" content="Hugo 0.88.1">
<title>Commutator</title>
<link rel="canonical" href="https://getbootstrap.com/docs/5.1/examples/navbar-fixed/">
<!-- Bootstrap core CSS -->
<link href="assets/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="icon" href="assets/images/logo.ico" type="image/x-icon" />
<style>
table {
border-collapse: collapse;
border-spacing: 0;
}
.productInfo tr td {
border: 1px solid #ddd;
white-space: nowrap;
padding: 5px 10px;
}
</style>
<!-- Custom styles for this template -->
<link href="assets/dist/css/navbar-top-fixed.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Commutator</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse"
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav me-auto mb-2 mb-md-0">
<li class="nav-item">
<a class="nav-link" href="./"> Home </a>
</li>
<li class="nav-item">
<a class="nav-link" href="introduction.html"> Introduction </a>
</li>
<li class="nav-item">
<a class="nav-link" href="cube.html"> Rubik's cube </a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#"> Excel </a>
</li>
<li class="nav-item">
<a class="nav-link" href="code.html"> Source code </a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/nbwzx/Commutator" target="blank"> Github
repository </a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html"> About </a>
</li>
</ul>
</div>
</div>
</nav>
<main class="container">
<br />
<h2 class="border-1">Decompose algorithms in commutator notation.</h2>
<br />
<strong>Settings:</strong>
<br />
Order: <input type="text" placeholder="4" id="order" onkeyup="changeCookie()" style="text-align:center;width:2.5em">
<i class="btn btn-default material-icons"
title="order = 4 (e.g. cube)<br />order = 5 (e.g. Megaminx)<br />order = 3 (e.g. Pyraminx)<br />order = 0 means free group"
style="font-size:16px;padding:0;vertical-align: middle;color:#17a2b8" data-toggle="popover"
data-placement="bottom" data-bs-html="true">help_outline</i>
<br />
<input class="form-check-input" type="checkbox" id="settingsOuterBracket" onclick="changeCookie()"> Outer bracket
for all commutators
<i class="btn btn-default material-icons" title="Checked [a:[b,c][d,e]]<br />Unchecked a:[[b,c]+[d,e]]"
style="font-size:16px;padding:0;vertical-align: middle;color:#17a2b8" data-toggle="popover"
data-placement="bottom" data-bs-html="true">help_outline</i>
<br />
<input class="form-check-input" type="checkbox" id="settingsInitialReplace" onclick="changeCookie()" checked>
Initial Replace
<i class="btn btn-default material-icons" title="Replace double layer turns<br />(e.g. r → R M')"
style="font-size:16px;padding:0;vertical-align: middle;color:#17a2b8" data-toggle="popover"
data-placement="bottom" data-bs-html="true">help_outline</i>
<br />
<input class="form-check-input" type="checkbox" id="settingsFinalReplace" onclick="changeCookie()" checked> Final
Replace
<i class="btn btn-default material-icons" title="Replace double layer turns<br />(e.g. R M' → r)"
style="font-size:16px;padding:0;vertical-align: middle;color:#17a2b8" data-toggle="popover"
data-placement="bottom" data-bs-html="true">help_outline</i>
<br />
<input class="form-check-input" type="checkbox" id="settingsCommute" onclick="changeCookie()" checked> Commute
<i class="btn btn-default material-icons" title="Handle commute moves<br />(e.g. R and L)"
style="font-size:16px;padding:0;vertical-align: middle;color:#17a2b8" data-toggle="popover"
data-placement="bottom" data-bs-html="true">help_outline</i>
<br />
Max Depth: <input type="text" placeholder="0" id="settingsMaxDepth" onkeyup="changeCookie()"
style="text-align:center;width:2.5em"><i class="btn btn-default material-icons"
title="Upper bound of search depth<br />0 means first solvable depth"
style="font-size:16px;padding:0;vertical-align: middle;color:#17a2b8" data-toggle="popover"
data-placement="bottom" data-bs-html="true">help_outline</i>
<br />
Sorting rules:
<br />
The score of C:[A,B] is <input type="text" placeholder="2.5" id="settingsSortScorea" onkeyup="changeCookie()"
style="text-align:center;width:2.5em"> * stm(A) + <input type="text" placeholder="5" id="settingsSortScoreb"
onkeyup="changeCookie()" style="text-align:center;width:2.5em"> *
stm(B) + stm(C) (Suppose stm(A) ≥ stm(B), stm means slice turn metric) <i class="btn btn-default material-icons"
title="Algs are sorted by score" style="font-size:16px;padding:0;vertical-align: middle;color:#17a2b8"
data-toggle="popover" data-placement="bottom" data-bs-html="true">help_outline</i>
<br />
Addition penalty: <input type="text" placeholder="1" id="settingsSortScoreAdd" onkeyup="changeCookie()"
style="text-align:center;width:2.5em"> <i class="btn btn-default material-icons"
title="Score for commutator combo" style="font-size:16px;padding:0;vertical-align: middle;color:#17a2b8"
data-toggle="popover" data-placement="bottom" data-bs-html="true">help_outline</i>
<br />
<input class="form-check-input" type="checkbox" id="settingsFast" onclick="changeCookie()">
Fast
<i class="btn btn-default material-icons" title="Show one result only"
style="font-size:16px;padding:0;vertical-align: middle;color:#17a2b8" data-toggle="popover"
data-placement="bottom" data-bs-html="true">help_outline</i>
<br /><br />
<p>Import an excel file(*.xlsx, *.xls, *.csv), decompose all the algorithms in commutator notation or expand commutator notation into regular ones.</p>
<p>You can download the excel example <a href="assets/files/test.xlsx" target="blank">here</a> first.</p>
<strong>Decompose:</strong> <input type="file" id="upfile1" accept=".xlsx, .xls, .csv" />
<br />
<br />
<strong>Expand:</strong> <input type="file" id="upfile2" accept=".xlsx, .xls, .csv" />
<br />
<br />
<div id="out">
</div>
</main>
<script src="assets/dist/js/bootstrap.bundle.min.js"></script>
<script src="assets/dist/js/commutator.min.js"></script>
<script src="assets/dist/js/cookie.js"></script>
<script src="assets/dist/js/xlsx.full.min.js"></script>
<script>
let popoverTriggerList = [].slice.call(
document.querySelectorAll('[data-toggle="popover"]')
);
const popoverList = popoverTriggerList.map(function (popoverTriggerEl) {
return new bootstrap.Popover(popoverTriggerEl);
});
</script>
<script>
function commutatorclick(alg) {
const outlist = commutator
.search({
"algorithm": alg,
"order": Number(document.getElementById("order").value !== "" ? document.getElementById("order").value : 4),
"outerBracket": document.getElementById("settingsOuterBracket").checked,
"initialReplace": document.getElementById("settingsInitialReplace").checked ? undefined : {},
"finalReplace": document.getElementById("settingsFinalReplace").checked ? undefined : {},
"abMaxScore": Number(document.getElementById("settingsSortScorea").value !== "" ? document.getElementById(
"settingsSortScorea").value : 2.5),
"abMinScore": Number(document.getElementById("settingsSortScoreb").value !== "" ? document.getElementById(
"settingsSortScoreb").value : 5),
"addScore": Number(document.getElementById("settingsSortScoreAdd").value !== "" ? document.getElementById(
"settingsSortScoreAdd").value : 1),
"commute": document.getElementById("settingsCommute").checked ? undefined : {},
"maxDepth": Number(document.getElementById("settingsMaxDepth").value !== "" ? document.getElementById(
"settingsMaxDepth").value : 0),
"fast": document.getElementById("settingsFast").checked,
});
return outlist[0];
}
function expandclick(alg) {
const outlist = commutator
.expand({
"algorithm": alg,
"order": Number(document.getElementById("order").value !== "" ? document.getElementById("order").value : 4),
"initialReplace": document.getElementById("settingsInitialReplace").checked ? undefined : {},
"finalReplace": document.getElementById("settingsFinalReplace").checked ? undefined : {},
"commute": document.getElementById("settingsCommute").checked ? undefined : {}
});
return outlist;
}
const file1 = document.getElementById("upfile1");
const file2 = document.getElementById("upfile2");
const out = document.getElementById("out");
function handleCommutator(ee) {
return handleFile(ee, 0);
}
function handleExpand(ee) {
return handleFile(ee, 1);
}
function handleFile(ee, handleType) {
const files = ee.target.files;
for (let index = 0, f = files[index]; index !== files.length; ++index) {
const reader = new FileReader();
reader.onload = function (e) {
const data = e.target.result;
const workbook = XLSX.read(data, {
"type": "binary"
});
// DO SOMETHING WITH workbook HERE
let excelResult = "";
const tmp = XLSX.utils.sheet_to_formulae(workbook.Sheets[workbook.SheetNames[0]]);
let maxRowCount = 0;
let tmpRowCount = 0;
let arrayTitle = [];
const obj = {};
const arrOut = [];
const wb = XLSX.utils.book_new();
for (let i = 0; i < tmp.length; i++) {
tmpRowCount = parseInt(tmp[i].split("=")[0].substr(1, tmp[i].split("=")[0].length - 1), 10);
if (tmpRowCount >= maxRowCount) {
maxRowCount = tmpRowCount;
}
obj[tmp[i].split("=")[0]] = tmp[i].split("=")[1];
arrayTitle.push(tmp[i].split("=")[0].charAt(0));
}
arrayTitle = Array.from(new Set(arrayTitle)); //Array deduplication
excelResult += "<table class=\"productInfo\">";
for (let i = 1; i <= maxRowCount; i++) {
excelResult += "<tr>";
arrOut.push([]);
for (let j = 0; j < arrayTitle.length; j++) {
if (obj.hasOwnProperty(arrayTitle[j] + i)) {
const algorithmResult = obj[arrayTitle[j] + i].replace("'", "")
excelResult += `<td>${algorithmResult}</td>`;
arrOut[i - 1].push(algorithmResult);
if (algorithmResult.length >= 4) {
// console.time("Time");
console.log(`${i}:${algorithmResult}`);
let commutatorResult = "";
if (handleType == 0) {
commutatorResult = commutatorclick(algorithmResult);
}
if (handleType == 1) {
commutatorResult = expandclick(algorithmResult);
}
excelResult += `<td>${commutatorResult}</td>`;
// console.timeEnd("Time");
arrOut[i - 1].push(commutatorResult);
}
} else {
excelResult += "<td></td>";
}
}
excelResult += "</tr>";
}
excelResult += "</table>";
out.innerHTML = excelResult;
const Sheet1 = XLSX.utils.aoa_to_sheet(arrOut);
XLSX.utils.book_append_sheet(wb, Sheet1, "Sheet1");
const myDate = new Date();
const year = myDate.getFullYear();
let month = myDate.getMonth() + 1;
let ddate = myDate.getDate();
let Sheet2 = "";
const monthArr = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.",
"Dec."
];
const suffix = ["st", "nd", "rd", "th"];
if (ddate % 10 < 1 || ddate % 10 > 3) {
ddate = ddate + suffix[3];
} else if (ddate % 10 === 1) {
ddate = ddate + suffix[0];
} else if (ddate % 10 === 2) {
ddate = ddate + suffix[1];
} else {
ddate = ddate + suffix[2];
}
Sheet2 = XLSX.utils.aoa_to_sheet([
["This file is post processed by https://zixingwang.com/commutator"],
[`Latest update on ${ddate} ${monthArr[month - 1]} ${year}`]
]);
XLSX.utils.book_append_sheet(wb, Sheet2, "Readme");
XLSX.writeFile(wb, `output.xlsx`);
};
reader.readAsBinaryString(f);
}
document.getElementById("upfile1").value = null;
document.getElementById("upfile2").value = null;
}
file1.addEventListener("change", handleCommutator, false);
file2.addEventListener("change", handleExpand, false);
</script>
</body>
</html>