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

fixed speed bug for queue page #484

Open
wants to merge 2 commits into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
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
31 changes: 21 additions & 10 deletions src/main/react-front-end/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,24 @@


export function humanReadableSpeed(size) {
if (size < 1024)
return parseFloat(size.toFixed(2)) + ' Mb/s';
let i = Math.floor(Math.log(size) / Math.log(1024));
let num = (size / Math.pow(1024, i));
let round = Math.round(num);
num = round < 10 ? num.toFixed(2) : round < 100 ? num.toFixed(1) : round;
num = num*(1);
num = parseFloat(num.toFixed(4));
return `${num} ${'KMGTPEZY'[i]}b/s`
}
if (size < 1000)
return parseFloat(size.toFixed(2)) + ' bit/s';

let i = 0;
let base = 1000;
let num = size;

// Keep dividing size by 1000 until it's less than 1000
while (num >= base) {
num /= base;
i++;
}

// Round number to nearest two digits
num = num.toFixed(2);

// Units array for return to choose from
const units = ['bit/s', 'Kbit/s', 'Mbit/s', 'Gbit/s', 'Tbit/s', 'Pbit/s', 'Ebit/s', 'Zbit/s', 'Ybit/s'];

return `${num} ${units[i]}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ import moment from "moment";
import InfoRow from "./InfoRow";

export default class RowElement extends React.Component {

constructor(props) {
super(props);
this.state = {
bar: null,
actions: null,
speed: 0,
};
}

infoRow() {
return (
<InfoRow
Expand All @@ -36,6 +44,7 @@ export default class RowElement extends React.Component {
butts.push(
log[i] &&
<JobActionButton
key={jobID}
icon={icons[i]}
jobId={jobID}
onClick={events[i]}
Expand All @@ -54,47 +63,65 @@ export default class RowElement extends React.Component {
);
}

render() {
const {resp, infoVisible} = this.props
let bar = (<QueueProgressBar status={resp.status} resp={resp}/>);
let actions = (this.renderActions(resp.owner, resp.job_id, resp.status, resp.deleted));
let difference = (Date.parse(resp.endTime) - Date.parse(resp.startTime))/1000;
let speed = parseFloat((resp.jobParameters.jobSize/1000000)*8)/(difference);
if (isNaN(speed))
{
calculateState = () => {
const { resp } = this.props;

// Calculate progress bar and actions
let bar = (<QueueProgressBar status={resp.status} resp={resp} />);
let actions = this.renderActions(resp.owner, resp.job_id, resp.status, resp.deleted);

// Calculate speed
let speed = 0;
for (let element of resp.batchSteps) {
const fileInfo = JSON.parse(resp.jobParameters[element.step_name]);
let sizeWritten = element.writeCount * fileInfo.chunkSize * 8; // Convert bytes to bits
let time_difference = (Date.parse(resp.endTime) ? Date.parse(resp.endTime) : Date.now() - Date.parse(resp.startTime)) / 1000;
speed += (sizeWritten / time_difference) / resp.batchSteps.length;
}

if (isNaN(speed)) {
speed = 0;
}

// Update the state with calculated values
this.setState({ bar, actions, speed });
}

componentDidMount() {
this.calculateState();
}

componentDidUpdate(prevProps) {
if (prevProps.resp !== this.props.resp || prevProps.infoVisible !== this.props.infoVisible) {
this.calculateState();
}
}

render() {
const {resp, infoVisible} = this.props
const {bar, actions, speed} = this.state;

let time = moment(resp.startTime).fromNow();
let admin = this.props.adminPg;
return (
<React.Fragment>
<TableRow className={"QueueRow"} style={{alignSelf: "stretch"}}>
<Hidden mdDown>
{ admin &&
<TableCell className={"userCell-admin queueBodyCell"}>
<p>{resp.owner}</p>
</TableCell> }
<TableCell className={"idCell" + (admin ? "-admin" : "") + " queueBodyCell"}>
<TableCell className={"idCell" + " queueBodyCell"}>
<p>{resp.id}</p>
</TableCell>
<TableCell className={"progressCell" + (admin ? "-admin" : "") + " queueBodyCell"}>
<TableCell className={"progressCell" + " queueBodyCell"}>
{bar}
</TableCell>
<TableCell className={"speedCell" + (admin ? "-admin" : "") + " queueBodyCell"}>
<TableCell className={"speedCell" + " queueBodyCell"}>
<p>{humanReadableSpeed(speed)}</p>
</TableCell>
<TableCell className={"sourceCell" + (admin ? "-admin" : "") + " queueBodyCell"}>
<TableCell className={"sourceCell" + " queueBodyCell"}>
<p>{resp.jobParameters.sourceCredential}</p>
</TableCell>
<TableCell className={"destinationCell" + (admin ? "-admin" : "") + " queueBodyCell"}>
<TableCell className={"destinationCell" + " queueBodyCell"}>
<p>{resp.jobParameters.destCredential}</p>
</TableCell>
{ this.props.adminPg &&
<TableCell className={"startCell-admin queueBodyCell"}>
<p>{time}</p>
</TableCell>}
<TableCell className={"actionCell" + (admin ? "-admin" : "") + " queueBodyCell"}>
<TableCell className={"actionCell" + " queueBodyCell"}>
{actions}
</TableCell>
</Hidden>
Expand Down