Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use const for variables #2187

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions server/fishtest/static/js/spsa.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
async function handleSPSA() {
let raw = [],
chartObject,
chartData,
const raw = [],
dataCache = [],
smoothingFactor = 0,
smoothingMax = 20,
columns = [],
viewAll = false;
smoothingMax = 20;
let chartObject,
chartData,
smoothingFactor = 0,
viewAll = false,
usePercentage = false;

const chartColors = [
"#3366cc",
Expand Down Expand Up @@ -77,9 +78,8 @@ async function handleSPSA() {
const chartTextStyle = { color: "#888" };
const gridlinesStyle = { color: "#666" };
const minorGridlinesStyle = { color: "#ccc" };
let usePercentage = false;

let chartOptions = {
const chartOptions = {
backgroundColor: {
fill: "transparent",
},
Expand Down Expand Up @@ -116,7 +116,7 @@ async function handleSPSA() {
function gaussianKernelRegression(values, bandwidth) {
if (!bandwidth) return values;

let smoothedValues = [];
const smoothedValues = [];
for (let i = 0; i < values.length; i++) {
let weightedSum = 0;
let weightTotal = 0;
Expand Down Expand Up @@ -147,21 +147,21 @@ async function handleSPSA() {
}
// cache data table to avoid recomputing the smoothed graph
if (!dataCache[smoothingFactor]) {
let dt = new google.visualization.DataTable();
const dt = new google.visualization.DataTable();
dt.addColumn("number", "Iteration");
for (let i = 0; i < spsaParams.length; i++) {
dt.addColumn("number", spsaParams[i].name);
}
// adjust the bandwidth for tests with samples != 101
const bandwidth =
smoothingFactor * ((spsaHistory.length - 1) / (spsaIterRatio * 100));
let data = [];
const data = [];
for (let j = 0; j < spsaParams.length; j++) {
data.push(gaussianKernelRegression(raw[j], bandwidth));
}
let googleFormat = [];
const googleFormat = [];
for (let i = 0; i < spsaHistory.length; i++) {
let rowData = [(i / (spsaHistory.length - 1)) * spsaIterRatio];
const rowData = [(i / (spsaHistory.length - 1)) * spsaIterRatio];
for (let j = 0; j < spsaParams.length; j++) {
rowData.push(data[j][i]);
}
Expand All @@ -173,7 +173,7 @@ async function handleSPSA() {
chartData = dataCache[smoothingFactor];
chartOptions.vAxis.format = usePercentage ? "percent" : "decimal";
if (usePercentage) {
let view = new google.visualization.DataView(chartData);
const view = new google.visualization.DataView(chartData);
view.setColumns([
0,
...spsaParams.map((_, i) => ({
Expand All @@ -195,7 +195,7 @@ async function handleSPSA() {

function redraw(animate) {
chartOptions.animation = animate ? { duration: 800, easing: "out" } : {};
let view = new google.visualization.DataView(chartData);
const view = new google.visualization.DataView(chartData);
view.setColumns(columns);
chartObject.draw(view, chartOptions);
}
Expand Down Expand Up @@ -248,9 +248,9 @@ async function handleSPSA() {

for (let i = 0; i < smoothingMax; i++) dataCache.push(false);

let googleFormat = [];
const googleFormat = [];
for (let i = 0; i < spsaHistory.length; i++) {
let rowData = [(i / (spsaHistory.length - 1)) * spsaIterRatio];
const rowData = [(i / (spsaHistory.length - 1)) * spsaIterRatio];
for (let j = 0; j < spsaParams.length; j++) {
if (usePercentage) {
rowData.push(
Expand Down Expand Up @@ -309,7 +309,7 @@ async function handleSPSA() {

// show/hide functionality
google.visualization.events.addListener(chartObject, "select", function (e) {
let sel = chartObject.getSelection();
const sel = chartObject.getSelection();
if (sel.length > 0 && sel[0].row == null) {
const col = sel[0].column;
updateColumnVisibility(col, columns[col] != col);
Expand Down
Loading