Skip to content

Commit

Permalink
Fixed countLines global variable bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gracexwho committed Dec 17, 2020
1 parent defe562 commit 0cc1f4f
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions source/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var dep = require("./cell_deps.js");

var args = process.argv.slice(2);
var filePath = args[0];
var countLines = 0;


class ModelCard {
Expand All @@ -31,7 +30,7 @@ class ModelCard {
datasets: {title: "Datasets", description:"", links:"", cell_ids:[]},
references: {title:"References", source:"", links:[], cell_ids:[]},
libraries:{title:"Libraries Used", lib:{}, info:{}, cell_ids:[]},
hyperparameters:{title:"Hyperparameters", cell_ids:[], lineNumbers:[], source:"", values:"", description:""},
hyperparameters:{title:"Hyperparameters", cell_ids:[], lineNumbers:[], source:"", values:[], description:""},
misc:{title:"Miscellaneous", cell_ids:[], cells:[], lineNumbers:[], source:"", markdown:"", imports:[], functions:[], figures:[], description:"", outputs:[]},
plotting:{title:"Plotting", cell_ids:[], cells:[], lineNumbers:[], source:"", markdown:"", imports:[], functions:[], figures:[], description:"", outputs:[]},
datacleaning:{title:"Data Cleaning", cell_ids:[], cells:[], lineNumbers:[], source:"", markdown:"", imports:[], functions:[], figures:[], description:"", outputs:[]},
Expand Down Expand Up @@ -80,6 +79,7 @@ function convertColorToLabel(filePath) {
// training -> purple
// evaluation -> orange
// model deployment -> pink
model_card = new ModelCard();

var color_map = dep.printLabels(filePath);

Expand Down Expand Up @@ -135,7 +135,7 @@ function readCells(filePath, new_color_map) {
let flag = true;
let programbuilder = new py.ProgramBuilder();
model_card.JSONSchema["modelname"]["Filename"] = filePath.split("/").slice(-1).toString();
console.log();
var countLines = 0;
//fs.mkdirSync("../assets/model_cards" + model_card.JSONSchema["modelname"]["Filename"], { recursive: true })

for (let cell of jsondata['cells']) {
Expand Down Expand Up @@ -215,12 +215,12 @@ function readCells(filePath, new_color_map) {
// id_count = persistentId
//let code = programbuilder.buildTo("id" + id_count.toString()).text;
model_card.markdown += notebookMarkdown;
printLineDefUse(notebookCode, model_card);
printLineDefUse(notebookCode, model_card, countLines);
return [notebookCode, notebookMarkdown, model_card];
}


function printLineDefUse(code, model_card){
function printLineDefUse(code, model_card, countLines){
let tree = py.parse(code);
let cfg = new py.ControlFlowGraph(tree);
const analyzer = new py.DataflowAnalyzer();
Expand Down Expand Up @@ -357,18 +357,13 @@ function printLineDefUse(code, model_card){

}
}

//console.log(hyperparam_descriptions);


model_card.JSONSchema["hyperparameters"]["values"] += parameters;
model_card.JSONSchema["hyperparameters"]["lineNumbers"].push(flow.fromNode.location.first_line);
model_card.JSONSchema["hyperparameters"]["cell_ids"].push(model_card.line_to_cell[flow.fromNode.location.first_line]);
model_card.JSONSchema["hyperparameters"]["source"] += fromNode[0];
model_card.JSONSchema["hyperparameters"]["source"] += fromNode[0] + "\n";
model_card.JSONSchema["hyperparameters"]["description"] = hyperparam_descriptions;
}
});

importScope[flow.fromNode.location.first_line] = -1;
model_card.JSONSchema["libraries"]["cell_ids"].push(model_card.line_to_cell[flow.fromNode.location.first_line]);

Expand Down Expand Up @@ -554,14 +549,17 @@ function bulk_run() {
console.log(fpath + file + '\n');
filePath = fpath + file;

var new_color = convertColorToLabel(filePath);
var res = readCells(filePath, new_color);
var notebookCode = res[0];
var notebookMarkdown = res[1];
var MC = res[2];

generateMarkdown(MC, "_" + file.split(".")[0]);
try {
var new_color = convertColorToLabel(filePath);
var res = readCells(filePath, new_color);
var notebookCode = res[0];
var notebookMarkdown = res[1];
var MC = res[2];

generateMarkdown(MC, "_" + file.split(".")[0]);
} catch(err) {
console.log(err);
}
}

});
Expand Down

0 comments on commit 0cc1f4f

Please sign in to comment.