-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"env": { | ||
"worker": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
self.datasets = { | ||
default: [ | ||
// Data used in README’s examples | ||
{r: 10.0, e: 0}, | ||
{r: 9.5, e: -0.00065673}, | ||
{r: 9.0, e: -0.00173718}, | ||
{r: 8.5, e: -0.00346348}, | ||
{r: 8.0, e: -0.00612669}, | ||
{r: 7.5, e: -0.01005967}, | ||
{r: 7.0, e: -0.01554171}, | ||
{r: 6.5, e: -0.02256036}, | ||
{r: 6.0, e: -0.03028974}, | ||
{r: 5.5, e: -0.03598181}, | ||
{r: 5.0, e: -0.03234259}, | ||
{r: 4.5, e: 0.00189849} | ||
], | ||
|
||
morse: [ | ||
// Good Morse data | ||
{r: 8.0, e: -0.012978}, | ||
{r: 7.9, e: -0.014204}, | ||
{r: 7.8, e: -0.015505}, | ||
{r: 7.7, e: -0.016882}, | ||
{r: 7.6, e: -0.018339}, | ||
{r: 7.5, e: -0.019875}, | ||
{r: 7.4, e: -0.021494}, | ||
{r: 7.3, e: -0.023194}, | ||
{r: 7.2, e: -0.024977}, | ||
{r: 7.1, e: -0.026840}, | ||
{r: 7.0, e: -0.028782}, | ||
{r: 6.9, e: -0.030799}, | ||
{r: 6.8, e: -0.032886}, | ||
{r: 6.7, e: -0.035035}, | ||
{r: 6.6, e: -0.037237}, | ||
{r: 6.5, e: -0.039479}, | ||
{r: 6.4, e: -0.041746}, | ||
{r: 6.3, e: -0.044015}, | ||
{r: 6.2, e: -0.046262}, | ||
{r: 6.1, e: -0.048454}, | ||
{r: 6.0, e: -0.050553}, | ||
{r: 5.9, e: -0.052509}, | ||
{r: 5.8, e: -0.054264}, | ||
{r: 5.7, e: -0.055746}, | ||
{r: 5.6, e: -0.056870}, | ||
{r: 5.5, e: -0.057529}, | ||
{r: 5.4, e: -0.057599}, | ||
{r: 5.3, e: -0.056928}, | ||
{r: 5.2, e: -0.055333}, | ||
{r: 5.1, e: -0.052595}, | ||
{r: 5.0, e: -0.048450}, | ||
{r: 4.9, e: -0.042581}, | ||
{r: 4.8, e: -0.034606}, | ||
{r: 4.7, e: -0.024064}, | ||
{r: 4.6, e: -0.010401}, | ||
{r: 4.5, e: 0.0070517} | ||
], | ||
|
||
dft1: [ | ||
// Not so good Morse data (#1) | ||
{r: 2.4, e: 0.0011065975400015300}, | ||
{r: 2.7, e: -0.0005154566702003650}, | ||
{r: 2.8, e: -0.0005886383598609250}, | ||
{r: 2.9, e: -0.0006901650199324650}, | ||
{r: 3.0, e: -0.0007013264298620920}, | ||
{r: 3.1, e: -0.0006627122002100800}, | ||
{r: 3.2, e: -0.0005815557201458430}, | ||
{r: 3.3, e: -0.0005038423500991480}, | ||
{r: 3.6, e: -0.0003942354501305090}, | ||
{r: 3.9, e: -0.0003059441601180880}, | ||
{r: 4.2, e: -0.0002946622598756220}, | ||
{r: 4.5, e: -0.0002702452502489900}, | ||
{r: 4.8, e: -0.0002602356198622150}, | ||
{r: 5.1, e: -0.0002354620100959440}, | ||
{r: 5.4, e: -0.0002172725398850160}, | ||
{r: 8.0, e: -0.0001106484301089950}, | ||
{r: 10.0, e: -0.0000510502900397114}, | ||
{r: 12.0, e: -0.0000181051000254229}, | ||
{r: 14.0, e: 0.0000000000000000000} | ||
], | ||
|
||
dft2: [ | ||
// Not so good Morse data (#2) | ||
{r: 3, e: 0.001742320280300190}, | ||
{r: 3.3, e: -0.000076646359957522}, | ||
{r: 3.4, e: -0.000272204209977644}, | ||
{r: 3.5, e: -0.000339631269980600}, | ||
{r: 3.6, e: -0.000360947829904035}, | ||
{r: 3.7, e: -0.000330864899751759}, | ||
{r: 3.8, e: -0.000267280129719438}, | ||
{r: 3.9, e: -0.000276979209957062}, | ||
{r: 4.2, e: -0.000075809799909621}, | ||
{r: 4.5, e: 0.000056670869980735}, | ||
{r: 4.8, e: 0.000040003249978327}, | ||
{r: 5.1, e: 0.000052195689931978}, | ||
{r: 5.4, e: 0.000032915210340434}, | ||
{r: 8, e: 0.000010500670214242}, | ||
{r: 10, e: 0.000003441470198595}, | ||
{r: 12, e: 0.000001319030161540}, | ||
{r: 14, e: 0.000000000000000000} | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Test potprox as a global object</title> | ||
</head> | ||
<body> | ||
|
||
<form id="datasets" action="#"></form> | ||
<pre id="result"></pre> | ||
|
||
<script src="../../dist/potprox.min.js"></script> | ||
<script src="datasets.js"></script> | ||
<script src="ui.js"></script> | ||
<script> | ||
window.addEventListener("message", ({data = {}}) => { | ||
if (data.type !== "recalc") { | ||
return; | ||
} | ||
let dataset = window.datasets[data.datasetType || "default"]; | ||
let result = {}; | ||
Object.keys(potprox).forEach(name => { | ||
let potential = potprox[name].from(dataset, {d0Conv: 0.0001, r0Conv: 0.0001, aConv: 0.0001, bConv: 0.0001}); | ||
result[name] = { | ||
potential: potential.toJSON(), | ||
rSqr: potprox.utils.rSqr(dataset, potential) | ||
}; | ||
}); | ||
window.postMessage({type: "recalcDone", result}, "*"); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Test potprox as an ES module</title> | ||
</head> | ||
<body> | ||
|
||
<form id="datasets" action="#"></form> | ||
<pre id="result"></pre> | ||
|
||
<script src="datasets.js"></script> | ||
<script src="ui.js"></script> | ||
<script type="module"> | ||
import potprox from "../../src/potprox.mjs"; | ||
|
||
window.addEventListener("message", ({data = {}}) => { | ||
if (data.type !== "recalc") { | ||
return; | ||
} | ||
let dataset = window.datasets[data.datasetType || "default"]; | ||
let result = {}; | ||
Object.keys(potprox).forEach(name => { | ||
let potential = potprox[name].from(dataset, {d0Conv: 0.0001, r0Conv: 0.0001, aConv: 0.0001, bConv: 0.0001}); | ||
result[name] = { | ||
potential: potential.toJSON(), | ||
rSqr: potprox.utils.rSqr(dataset, potential) | ||
}; | ||
}); | ||
window.postMessage({type: "recalcDone", result}, "*"); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" | ||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Test potprox within a WebWorker</title> | ||
</head> | ||
<body> | ||
|
||
<form id="datasets" action="#"></form> | ||
<pre id="result"></pre> | ||
|
||
<script src="datasets.js"></script> | ||
<script src="ui.js"></script> | ||
<script> | ||
let worker = new Worker("./worker.js"); | ||
worker.addEventListener("message", ({data}) => window.postMessage(data, "*")); | ||
window.addEventListener("message", ({data = {}}) => { | ||
if (data.type === "recalc") { | ||
worker.postMessage(data); | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(function () { | ||
"use strict"; | ||
|
||
let switcher = document.getElementById("datasets"); | ||
switcher.innerHTML = Object.keys(window.datasets) | ||
.map(key => `<label><input type="radio" name="datasetType" value="${key}"> ${key}</label>`) | ||
.join(" \u2502 "); | ||
switcher.datasetType[0].checked = true; | ||
switcher.addEventListener("change", () => { | ||
window.postMessage({type: "recalc", datasetType: switcher.datasetType.value}, "*"); | ||
}); | ||
|
||
window.addEventListener("load", () => { | ||
window.postMessage({type: "recalc", datasetType: switcher.datasetType.value}, "*"); | ||
}); | ||
|
||
window.addEventListener("message", ({data = {}}) => { | ||
if (data.type !== "recalcDone") { | ||
return; | ||
} | ||
let output = ""; | ||
Object.entries(data.result).forEach(([name, result]) => { | ||
output += `================== ${name} ==================\n`; | ||
output += JSON.stringify(result.potential, null, 4); | ||
output += `\nR² = ${result.rSqr}\n\n`; | ||
}); | ||
document.getElementById("result").textContent = output; | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
importScripts("../../dist/potprox.min.js"); | ||
importScripts("./datasets.js"); | ||
|
||
self.addEventListener("message", ({data = {}}) => { | ||
if (data.type !== "recalc") { | ||
return; | ||
} | ||
let dataset = self.datasets[data.datasetType || "default"]; | ||
let result = {}; | ||
Object.keys(self.potprox).forEach(name => { | ||
let potential = self.potprox[name].from(dataset, {d0Conv: 0.0001, r0Conv: 0.0001, aConv: 0.0001, bConv: 0.0001}); | ||
result[name] = { | ||
potential: potential.toJSON(), | ||
rSqr: self.potprox.utils.rSqr(dataset, potential) | ||
}; | ||
}); | ||
self.postMessage({type: "recalcDone", result}); | ||
}); |