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

Add an option to show the cell outputs per second #116

Merged
merged 12 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions schema/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
"description": "Show the formatted date string in the given format. For example \"yyy-MM-dd HH:mm:ss\" results in \"2023-02-28 14:25:57 \", \"dd/MM/YYY HH:mm:ss (O)\" results in \"28/02/2023 14:25:57 (GMT +3)\". Find out more on unicode date field symbols on this link [https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table]",
"default": "yyy-MM-dd HH:mm:ss",
"pattern": "[yGuqQMLwdeEcabBhHkKmsSzOxX\\W].*"
},
"showOutputsPerSecond": {
"type": "boolean",
"title": "Show Outputs Per Second (outputs/s)",
"description": "Show the outputs per second calculated from the last cell execution time and number of outputs.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear from the name if this is in real time. How about: "After a cell has finished running, show the outputs per second calculated from the last cell execution time and number of outputs."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Updated the description with your copy.

"default": false
}
}
}
22 changes: 18 additions & 4 deletions src/ExecuteTimeWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface IExecuteTimeSettings {
showDate: boolean;
historyCount: number;
dateFormat: string;
showOutputsPerSecond: boolean;
}

export default class ExecuteTimeWidget extends Widget {
Expand Down Expand Up @@ -290,11 +291,13 @@ export default class ExecuteTimeWidget extends Widget {
if (isLikelyAborted) {
msg = '';
} else if (endTime) {
if (
this._settings.minTime <=
differenceInMilliseconds(endTime, startTime) / 1000.0
) {
const executionTimeMillis = differenceInMilliseconds(
endTime,
startTime
);
if (this._settings.minTime <= executionTimeMillis) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a bug here - minTime is in s and now this is compared in ms

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the conversion back in a new commit. Thanks!

const executionTime = getTimeDiff(endTime, startTime);
const executionsPerSecond = 1000.0 / executionTimeMillis;
const lastExecutionTime = executionTimeNode.getAttribute(
PREV_DATA_EXECUTION_TIME_ATTR
);
Expand Down Expand Up @@ -324,6 +327,13 @@ export default class ExecuteTimeWidget extends Widget {
msg += ` at ${getTimeString(endTime, this._settings.dateFormat)}`;
}
msg += ` in ${executionTime}`;

const numberOfOutputs = cell.model.outputs.length;
if (this._settings.showOutputsPerSecond && numberOfOutputs > 0) {
const outputsPerSecond = executionsPerSecond / numberOfOutputs;
msg += ` and generated ${numberOfOutputs} output(s)`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting a bit long:

image

Can you modify this line to only append "s" when the number of outputs is >1? This will also remove the parentheses making it shorter in both cases.

additional idea: "and generated" could be replaced by shorter "displaying"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. It looks like this now. Much shorter 👍

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krassowski I am not familiar with ui-tests. How can we get something like last-executed.png?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be auto-generated when running the test for the first time: https://github.com/deshaw/jupyterlab-execute-time/tree/master/ui-tests#run-the-tests

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But in general I would just push the code and download the artifacts from CI

msg += ` (${outputsPerSecond.toFixed(2)} outputs/s)`;
}
}
} else if (startTime) {
if (this._settings.showLiveExecutionTime) {
Expand Down Expand Up @@ -429,6 +439,9 @@ export default class ExecuteTimeWidget extends Widget {
);
}

this._settings.showOutputsPerSecond = settings.get('showOutputsPerSecond')
.composite as boolean;

const cells = this._panel.context.model.cells;
if (this._settings.enabled) {
cells.changed.connect(this.updateConnectedCell);
Expand Down Expand Up @@ -513,5 +526,6 @@ export default class ExecuteTimeWidget extends Widget {
showDate: true,
historyCount: 5,
dateFormat: 'yyy-MM-dd HH:mm:ss',
showOutputsPerSecond: false,
};
}
Loading