This commit is contained in:
Kunal Chaudhary 2019-02-09 22:40:53 -08:00
Родитель b592b4cfdf
Коммит 189b3c937c
5 изменённых файлов: 129 добавлений и 12 удалений

Просмотреть файл

@ -27,14 +27,20 @@
"extension": true
},
"dependencies": {
"@jupyterlab/application": "^0.17.2",
"@jupyterlab/apputils": "^0.17.2",
"@jupyterlab/codemirror": "^0.17.2",
"@jupyterlab/coreutils": "^2.0.0-0",
"@jupyterlab/docmanager": "^0.17.2",
"@jupyterlab/fileeditor": "^0.17.2",
"@jupyterlab/notebook": "^0.17.2",
"@jupyterlab/application": "^0.19.1",
"@jupyterlab/apputils": "^0.19.1",
"@jupyterlab/codemirror": "^0.19.1",
"@jupyterlab/coreutils": "^2.2.1",
"@jupyterlab/cells": "^0.19.1",
"@jupyterlab/outputarea": "^0.19.1",
"@jupyterlab/docmanager": "^0.19.1",
"@jupyterlab/fileeditor": "^0.19.1",
"@jupyterlab/notebook": "^0.19.1",
"@jupyterlab/rendermime": "^0.19.1",
"@jupyterlab/codeeditor": "^0.19.1",
"@jupyterlab/docregistry": "^0.19.1",
"@phosphor/widgets": "^1.6.0",
"@types/react": "^16.8.1",
"diff-match-patch": "^1.0.1",
"jquery": "^3.3.1"
},
@ -54,8 +60,8 @@
"raw-loader": "^0.5.1",
"rimraf": "^2.6.1",
"style-loader": "^0.21.0",
"ts-node": "^7.0.0",
"typescript": "~2.4.0",
"ts-node": "8.0.2",
"typescript": "3.3.1",
"webpack": "^4.16.1",
"webpack-cli": "^3.1.0"
}

Просмотреть файл

@ -28,6 +28,8 @@ import { nbformat } from '@jupyterlab/coreutils';
import { log } from '../utils/log';
import { INotebookOpener, IScriptOpener } from '../packages/gather/opener';
//import { UUID } from '@phosphor/coreutils';
/**
* Try to only write Jupyter Lab-specific implementation code in this file.
* If there is any program analysis / text processing, widgets that could be shared with Jupyter
@ -140,6 +142,9 @@ class ExecutionLoggerExtension implements DocumentRegistry.IWidgetExtension<Note
const cell = new LabCell(cellClone);
this._executionSlicer.logExecution(cell);
this._gatherModel.lastExecutedCell = cell;
}
});
}
@ -337,6 +342,7 @@ class NotebookOpener implements INotebookOpener {
// TODO put more safety checks on this
const widget = this._documentManager.open(model.path, undefined, this._notebooks.currentWidget.session.kernel.model) as NotebookPanel;
setTimeout(() => {
const notebookModel = widget.content.model;
let notebookJson = notebookModel.toJSON() as nbformat.INotebookContent;
notebookJson.cells = []
@ -419,6 +425,15 @@ function activateExtension(app: JupyterLab, palette: ICommandPalette, notebooks:
console.log('Activating code gathering tools');
docManager.activateRequested.connect(
(docMan, msg) => {
notebooks.forEach((widget: NotebookPanel) => print(widget))
});
let gatherModel = new GatherModel();
const notificationExtension = new NotifactionExtension();
@ -426,6 +441,99 @@ function activateExtension(app: JupyterLab, palette: ICommandPalette, notebooks:
let executionSlicer = new ExecutionLogSlicer(new DataflowAnalyzer());
let historyLoaded = 0;
let previousSaveLogLength = executionSlicer._executionLog.length
function print(notebook: NotebookPanel){
//deserializes execution history on load of the notebook metadata
if (executionSlicer._executionLog.length == 0 && historyLoaded == 0) {
var seconds = 0;
var intervalId = setInterval(function(){
seconds+=1
if(seconds == 10) {
console.log("history is empty")
clearInterval(intervalId);
historyLoaded = 1;
} else {
if (notebook.model.metadata.get("executionHistory")) {
let history = notebook.model.metadata.get("executionHistory");
console.log("History Loading...")
console.log("Loading Before", executionSlicer._executionLog);
console.log("Notebook Stored Execution History", notebook.model.metadata.get("executionHistory"));
for (let x in (<any>history)){
let cell =(<ICell>(<any>history)[x.toString()]);
executionSlicer.logExecution(cell)
}
//notebook.model.metadata.set("executionHistory","")
historyLoaded = 1;
previousSaveLogLength = executionSlicer._executionLog.length
console.log("Loading After", executionSlicer._executionLog);
clearInterval(intervalId);
} else {
console.log(notebook.model.metadata.get("executionHistory"));
console.log("still waiting!", seconds);
}
}
}, 1000);
}
//Notebook listener serializes execution log to metadata on save
notebook.context.saveState.connect((context, msg) => {
let currentSaveLogLength = executionSlicer._programBuilder._cellPrograms.length
if (msg == "started" && currentSaveLogLength != previousSaveLogLength){
console.log("Saving File and Updating Execution History...");
console.log("before", notebook.model.metadata.get("executionHistory"));
let cellPrograms = executionSlicer._programBuilder._cellPrograms;
let tempCellGroup: any = [];
for (var i = previousSaveLogLength; i < cellPrograms.length; i++) {
let cell = cellPrograms[i].cell;
let tempCell: any = {};
tempCell["id"] = cell.id;
tempCell["is_cell"] = cell.is_cell;
tempCell["executionCount"] = cell.executionCount;
tempCell["hasError"] = cell.hasError;
tempCell["isCode"] = cell.isCode;
tempCell["text"] = cell.text;
tempCell["gathered"] = cell.gathered;
tempCellGroup.push(tempCell);
}
let history = notebook.model.metadata.get("executionHistory");
let tempHistory: any = {};
let counter = 0
for (let x in (<any>history)){
tempHistory[counter.toString()] = (<any>history)[x.toString()];
counter += 1;
}
for (var i = 0; i<tempCellGroup.length; i++) {
tempHistory[counter.toString()] = tempCellGroup[i];
counter+=1;
}
previousSaveLogLength = currentSaveLogLength;
notebook.model.metadata.set("executionHistory",tempHistory)
console.log("after", notebook.model.metadata.get("executionHistory"));
}
});
}
let notebookOpener = new NotebookOpener(docManager, notebooks);
let scriptOpener = new ScriptOpener(docManager, notebooks);
@ -449,6 +557,8 @@ function activateExtension(app: JupyterLab, palette: ICommandPalette, notebooks:
const executionLogger = new ExecutionLoggerExtension(executionSlicer, gatherModel, app.commands, markerManager);
app.docRegistry.addWidgetExtension('Notebook', executionLogger);
function addCommand(command: string, label: string, execute: (options?: JSONObject) => void) {
app.commands.addCommand(command, { label, execute });
palette.addItem({ command, category: 'Clean Up' });

Просмотреть файл

@ -77,4 +77,5 @@ export class LabCell extends AbstractOutputterCell<IOutputModel[]> {
is_cell: boolean = true;
is_outputter_cell: boolean = true;
private _model: ICodeCellModel;
}

Просмотреть файл

@ -52,8 +52,8 @@ export class SlicedExecution {
*/
export class ExecutionLogSlicer {
private _executionLog = new Array<CellExecution>();
private _programBuilder: ProgramBuilder;
public _executionLog = new Array<CellExecution>();
public _programBuilder: ProgramBuilder;
private _dataflowAnalyzer: DataflowAnalyzer;
/**

Просмотреть файл

@ -217,7 +217,7 @@ export class ProgramBuilder {
return null;
}
private _cellPrograms: CellProgram[];
public _cellPrograms: CellProgram[];
private _dataflowAnalyzer: DataflowAnalyzer;
private _magicsRewriter: MagicsRewriter = new MagicsRewriter();
}