[tune] Use scientific notation in tune dashboard (#8782)

Co-authored-by: Kai Fricke <kai@anyscale.com>
This commit is contained in:
krfricke 2020-06-05 19:41:07 +02:00 committed by GitHub
parent 1dda659918
commit e62c1d2051
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 3 deletions

View file

@ -30,3 +30,18 @@ export const formatDuration = (durationInSeconds: number) => {
`${pad(durationSeconds)}s`, `${pad(durationSeconds)}s`,
].join(" "); ].join(" ");
}; };
export const formatValue = (rawFloat: number) => {
try {
const decimals = rawFloat.toString().split(".")[1].length || 0;
if (decimals <= 3) {
return rawFloat.toString();
} // Few decimals
if (Math.abs(rawFloat.valueOf()) >= 1.0) {
return rawFloat.toPrecision(5);
} // Values >= 1
return rawFloat.toExponential(); // Values in (-1; 1)
} catch (e) {
return rawFloat.toString();
}
};

View file

@ -21,6 +21,7 @@ import React from "react";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { TuneTrial } from "../../../api"; import { TuneTrial } from "../../../api";
import DialogWithTitle from "../../../common/DialogWithTitle"; import DialogWithTitle from "../../../common/DialogWithTitle";
import { formatValue } from "../../../common/formatUtils";
import NumberedLines from "../../../common/NumberedLines"; import NumberedLines from "../../../common/NumberedLines";
import { StoreState } from "../../../store"; import { StoreState } from "../../../store";
import { dashboardActions } from "../state"; import { dashboardActions } from "../state";
@ -387,7 +388,9 @@ class TuneTable extends React.Component<
</TableCell> </TableCell>
{viewableParams.map((value, index) => ( {viewableParams.map((value, index) => (
<TableCell className={classes.cell} key={index}> <TableCell className={classes.cell} key={index}>
{trial["params"][value]} {typeof trial["params"][value] === "number"
? formatValue(Number(trial["params"][value]))
: trial["params"][value]}
</TableCell> </TableCell>
))} ))}
<TableCell className={classes.cell}> <TableCell className={classes.cell}>
@ -396,7 +399,9 @@ class TuneTable extends React.Component<
{trial["metrics"] && {trial["metrics"] &&
viewableMetrics.map((value, index) => ( viewableMetrics.map((value, index) => (
<TableCell className={classes.cell} key={index}> <TableCell className={classes.cell} key={index}>
{trial["metrics"][value]} {typeof trial["metrics"][value] === "number"
? formatValue(Number(trial["metrics"][value]))
: trial["metrics"][value]}
</TableCell> </TableCell>
))} ))}
<TableCell className={classes.cell}> <TableCell className={classes.cell}>

View file

@ -875,7 +875,7 @@ class TuneCollector(threading.Thread):
# round all floats # round all floats
for key in float_keys: for key in float_keys:
details[key] = round(details[key], 3) details[key] = round(details[key], 12)
# group together config attributes # group together config attributes
for key in config_keys: for key in config_keys: