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 1 commit
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].*"
},
"showExecutionsPerSecond": {
"type": "boolean",
"title": "Show Executions Per Second",
"description": "Show the executions per second calculated from the last execution time.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be explicit that number of executions is always one.

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 have changed this to explicitly say Cell Executions Per Second, but I understand it might not resolve the issue completely.

I'm in favour of outputs/time or updates/time (keeping it language-agnostic).

@krassowski can it be done?

Copy link
Contributor Author

@flaviomartins flaviomartins Apr 9, 2024

Choose a reason for hiding this comment

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

@krassowski do tou know if there is a listener/hook exposed to jupyterlab extensions I can use? (for each write to stdout/output)

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a outputLengthChanged signal in output area which you should be able to access via cell.outputArea.outputLengthChanged.

"default": false
}
}
}
19 changes: 15 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;
showExecutionsPerSecond: 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,9 @@ export default class ExecuteTimeWidget extends Widget {
msg += ` at ${getTimeString(endTime, this._settings.dateFormat)}`;
}
msg += ` in ${executionTime}`;
if (this._settings.showExecutionsPerSecond) {
msg += ` (${executionsPerSecond.toFixed(2)} executions/s)`;
}
}
} else if (startTime) {
if (this._settings.showLiveExecutionTime) {
Expand Down Expand Up @@ -429,6 +435,10 @@ export default class ExecuteTimeWidget extends Widget {
);
}

this._settings.showExecutionsPerSecond = settings.get(
'showExecutionsPerSecond'
).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 +523,6 @@ export default class ExecuteTimeWidget extends Widget {
showDate: true,
historyCount: 5,
dateFormat: 'yyy-MM-dd HH:mm:ss',
showExecutionsPerSecond: false,
};
}
Loading