forked from visualpython/visualpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernelApi.js
More file actions
102 lines (93 loc) · 3.53 KB
/
Copy pathkernelApi.js
File metadata and controls
102 lines (93 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
define([
'require'
, 'jquery'
, 'nbextensions/visualpython/src/common/constant'
, 'nbextensions/visualpython/src/common/StringBuilder'
, 'nbextensions/visualpython/src/common/vpCommon'
], function (requirejs, $, vpConst, sb, vpCommon) {
/**
* Execute python kernel
* @param {*} command
* @param {*} callback
* @param {*} isSilent
*/
var executePython = function (command, callback, isSilent = false) {
Jupyter.notebook.kernel.execute(
command,
{
iopub: {
output: function (msg) {
if (msg.content) {
if (msg.content['name'] == 'stderr') {
;
} else {
var result = '';
var type = '';
if (msg.content['text']) {
result = String(msg.content['text']);
type = 'text';
} else if (msg.content.data) {
if (msg.content.data['text/plain']) {
result = String(msg.content.data['text/plain']);
type = 'text/plain';
} else if (msg.content.data['text/html']) {
result = String(msg.content.data['text/html']);
type = 'text/html';
}
}
callback(result, type);
}
}
}
}
},
{ silent: isSilent }
);
};
var searchVarList = function(types, callback) {
// types에 맞는 변수목록 조회하는 명령문 구성
var cmdSB = new sb.StringBuilder();
if (types && types.length > 0) {
cmdSB.appendFormat('_vp_print(_vp_get_variables_list({0}))', JSON.stringify(types));
} else {
cmdSB.appendFormat('_vp_print(_vp_get_variables_list({0}))', 'None');
}
executePython(cmdSB.toString(), function(result) {
callback(result);
});
}
var getColumnList = function(dataframe, callback) {
executePython(
vpCommon.formatString('_vp_print(_vp_get_columns_list({0}))', dataframe)
, function(result) {
callback(result);
});
}
var getCommonColumnList = function(dataframeList, callback) {
executePython(
vpCommon.formatString('_vp_print(_vp_get_multi_columns_list([{0}]))', dataframeList.join(','))
, function(result) {
callback(result);
});
}
var getRowList = function(dataframe, callback) {
executePython(
vpCommon.formatString('_vp_print(_vp_get_rows_list({0}))', dataframe)
, function(result) {
callback(result);
});
}
var getProfilingList = function(callback) {
executePython('_vp_print(_vp_get_profiling_list())', function(result) {
callback(result);
});
}
return {
executePython: executePython,
searchVarList: searchVarList,
getColumnList: getColumnList,
getCommonColumnList: getCommonColumnList,
getRowList: getRowList,
getProfilingList: getProfilingList
}
});