@datagrok/api-samples 1.0.12 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/README.md +2 -2
- package/dist/package-test.js +1848 -2
- package/dist/package.js +30 -2
- package/package.json +18 -17
- package/scripts/dapi/admin.js +5 -5
- package/scripts/dapi/applicable-layouts.js +3 -1
- package/scripts/dapi/fetch.js +8 -6
- package/scripts/dapi/files.js +7 -2
- package/scripts/dapi/projects-list.js +3 -3
- package/scripts/dapi/projects-open.js +4 -4
- package/scripts/dapi/who-am-i.js +10 -10
- package/scripts/data-access/db/ad-hoc-query.js +16 -0
- package/scripts/data-access/db/db-edit.js +6 -9
- package/scripts/data-access/{parameterized-query.js → db/parameterized-query.js} +3 -2
- package/scripts/data-access/db/query_builder_join.js +15 -0
- package/scripts/data-access/db/query_builder_simple.js +15 -0
- package/scripts/data-access/db-master-details-manual.js +9 -12
- package/scripts/data-access/external/stock-prices.js +2 -2
- package/scripts/data-access/files/file-exists.js +10 -0
- package/scripts/data-access/files/read-file.js +19 -0
- package/scripts/data-access/load-csv.js +2 -2
- package/scripts/data-access/save-and-load-df.js +6 -5
- package/scripts/data-frame/column-access.js +5 -1
- package/scripts/data-frame/columns-ordering.js +4 -0
- package/scripts/data-frame/construction/add-new-column.js +13 -0
- package/scripts/data-frame/construction/create-from-columns.js +4 -4
- package/scripts/data-frame/construction/date-time.js +24 -0
- package/scripts/data-frame/join-link/link-tables-dynamic.js +10 -9
- package/scripts/data-frame/join-link/link-tables.js +12 -8
- package/scripts/demo/med-chem.js +103 -0
- package/scripts/demo/stock-broker.js +1 -1
- package/scripts/domains/chem/chem-benchmark.js +0 -5
- package/scripts/domains/chem/descriptors.js +2 -4
- package/scripts/domains/chem/diversity-search.js +2 -4
- package/scripts/domains/chem/mcs.js +3 -3
- package/scripts/domains/chem/r-group.js +3 -3
- package/scripts/domains/chem/similarity-scoring-scores.js +3 -5
- package/scripts/domains/chem/similarity-scoring-sorted.js +3 -5
- package/scripts/domains/chem/substructure-search-smarts-molfile-als.js +11 -12
- package/scripts/domains/chem/substructure-search-smarts.js +4 -7
- package/scripts/domains/chem/substructure-search.js +5 -6
- package/scripts/domains/data-science/cluster.js +8 -10
- package/scripts/domains/data-science/missing-values-imputation.js +3 -3
- package/scripts/domains/data-science/pca.js +3 -3
- package/scripts/domains/data-science/predictive-model.js +4 -4
- package/scripts/domains/data-science/random-data.js +5 -6
- package/scripts/events/function-events.js +1 -1
- package/scripts/functions/caching-results.js +8 -9
- package/scripts/functions/calling.js +7 -10
- package/scripts/functions/func-call.js +4 -2
- package/scripts/functions/param-editor.js +1 -1
- package/scripts/functions/progress.js +2 -5
- package/scripts/functions/register-function.js +1 -1
- package/scripts/grid/advanced/column-groups.js +8 -0
- package/scripts/grid/advanced/dynamic-value-retrieval.js +12 -0
- package/scripts/grid/cell-types/tags-multi-cell.js +18 -0
- package/scripts/grid/color-coding/color-coding-conditional.js +1 -1
- package/scripts/grid/color-coding/color-coding.js +7 -4
- package/scripts/misc/audit/errors-summary.js +2 -2
- package/scripts/misc/audit/test-tracking.js +2 -2
- package/scripts/misc/audit/users-today.js +3 -5
- package/scripts/misc/package-credentials.js +2 -1
- package/scripts/performance/all-chembl-structures.js +2 -1
- package/scripts/scripting/grok-scripting.js +2 -3
- package/scripts/scripting/package-scripting.js +4 -2
- package/scripts/shell/windows/browse/customize-tree.js +1 -1
- package/scripts/statistics/pearson-correlation.js +39 -0
- package/scripts/ui/components/drop-down.js +9 -7
- package/scripts/ui/components/icons.js +7 -7
- package/scripts/ui/components/menu-advanced.js +85 -0
- package/scripts/ui/components/popup-menu.js +6 -5
- package/scripts/ui/components/summary-card.js +4 -3
- package/scripts/ui/containers/splitters.js +9 -17
- package/scripts/ui/handlers/markup-handlers.js +2 -3
- package/scripts/ui/inputs/advanced/all-input-types.js +21 -16
- package/scripts/ui/inputs/advanced/for-properties.js +1 -1
- package/scripts/ui/inputs/advanced/input-api.js +4 -5
- package/scripts/ui/inputs/advanced/input-form.js +5 -5
- package/scripts/ui/inputs/forms.js +5 -6
- package/scripts/ui/inputs/inputs.js +2 -2
- package/scripts/ui/inputs/validation/{visible-enabled.js → parameter-expressions.js} +1 -1
- package/scripts/ui/inputs/validation/{script-param-validation.js → parameter-validation.js} +2 -2
- package/scripts/ui/rendering/render-items.js +9 -9
- package/scripts/ui/tooltips/tooltip-events.js +2 -1
- package/scripts/ui/tooltips/tooltips.js +5 -0
- package/scripts/ui/viewers/advanced/descriptors.js +14 -0
- package/scripts/ui/viewers/filters/custom-filters.js +6 -5
- package/scripts/ui/viewers/js viewers/globe-viewer.js +7 -7
- package/scripts/ui/viewers/js viewers/surface-plot.js +19 -1
- package/scripts/ui/viewers/types/globe.js +2 -3
- package/scripts/ui/viewers/types/markup-advanced.js +1 -1
- package/scripts/ui/viewers/types/markup-eeg.js +5 -5
- package/scripts/ui/viewers/types/shape-map.js +4 -4
- package/scripts/ui/viewers/viewer-tooltips.js +1 -1
- package/scripts/ui/views/default-views.js +8 -7
- package/scripts/ui/widgets/widgets-tree.js +32 -0
- package/src/package-api.ts +8 -0
- package/src/package-test.ts +44 -31
- package/src/tests/owners.ts +8 -0
- package/test-console-output-1.log +6957 -0
- package/test-console-output-2.log +363 -0
- package/test-console-output-3.log +810 -0
- package/test-console-output-4.log +120 -0
- package/test-console-output-5.log +1069 -0
- package/test-console-output-6.log +972 -0
- package/test-console-output-7.log +7 -0
- package/test-record-1.mp4 +0 -0
- package/test-record-2.mp4 +0 -0
- package/test-record-3.mp4 +0 -0
- package/test-record-4.mp4 +0 -0
- package/test-record-5.mp4 +0 -0
- package/test-record-6.mp4 +0 -0
- package/test-record-7.mp4 +0 -0
- package/to fix/dynamic-loading.js +6 -6
- package/tsconfig.json +1 -1
- package/scripts/misc/audit/activity-today.js +0 -4
- package/src/global.d.ts +0 -13
- /package/scripts/data-access/{dynamic-query.js → db/dynamic-query.js} +0 -0
- /package/scripts/grid/{cell-bounds.js → advanced/cell-bounds.js} +0 -0
- /package/scripts/grid/{hit-test.js → advanced/hit-test.js} +0 -0
- /package/scripts/grid/{category-colors.js → color-coding/category-colors.js} +0 -0
- /package/scripts/grid/{custom-cell-prepare.js → events/custom-cell-prepare.js} +0 -0
- /package/scripts/grid/{custom-cell-rendering-indexes.js → events/custom-cell-rendering-indexes.js} +0 -0
- /package/scripts/grid/{custom-cell-rendering.js → events/custom-cell-rendering.js} +0 -0
- /package/scripts/grid/{custom-cell-tooltip.js → events/custom-cell-tooltip.js} +0 -0
- /package/scripts/grid/{scroll-bars.js → navigate/scroll-bars.js} +0 -0
- /package/scripts/grid/{scroll-to-cell.js → navigate/scroll-to-cell.js} +0 -0
- /package/scripts/grid/{scroll-to-pixels.js → navigate/scroll-to-pixels.js} +0 -0
- /package/scripts/grid/{order-columns.js → order/order-columns.js} +0 -0
- /package/scripts/grid/{order-rows-by-comparer.js → order/order-rows-by-comparer.js} +0 -0
- /package/scripts/grid/{order-rows.js → order/order-rows.js} +0 -0
- /package/scripts/grid/{hide-columns.js → resize/hide-columns.js} +0 -0
- /package/scripts/grid/{resize-columns.js → resize/resize-columns.js} +0 -0
- /package/scripts/grid/{resize-events.js → resize/resize-events.js} +0 -0
- /package/scripts/grid/{column-cell-styles.js → styles/column-cell-styles.js} +0 -0
- /package/scripts/grid/{column-controlled-values.js → styles/column-controlled-values.js} +0 -0
- /package/scripts/grid/{data-format.js → styles/data-format.js} +0 -0
package/dist/package.js
CHANGED
|
@@ -1,2 +1,30 @@
|
|
|
1
|
-
var apisamples;
|
|
2
|
-
|
|
1
|
+
var apisamples;
|
|
2
|
+
/******/ (() => { // webpackBootstrap
|
|
3
|
+
/******/ "use strict";
|
|
4
|
+
/******/ // The require scope
|
|
5
|
+
/******/ var __webpack_require__ = {};
|
|
6
|
+
/******/
|
|
7
|
+
/************************************************************************/
|
|
8
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
9
|
+
/******/ (() => {
|
|
10
|
+
/******/ // define __esModule on exports
|
|
11
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
12
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
13
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
14
|
+
/******/ }
|
|
15
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
16
|
+
/******/ };
|
|
17
|
+
/******/ })();
|
|
18
|
+
/******/
|
|
19
|
+
/************************************************************************/
|
|
20
|
+
var __webpack_exports__ = {};
|
|
21
|
+
/*!************************!*\
|
|
22
|
+
!*** ./src/package.ts ***!
|
|
23
|
+
\************************/
|
|
24
|
+
__webpack_require__.r(__webpack_exports__);
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGFja2FnZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInBhY2thZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZXNDb250ZW50IjpbIi8qIERvIG5vdCBjaGFuZ2UgdGhlc2UgaW1wb3J0IGxpbmVzLiBEYXRhZ3JvayB3aWxsIGltcG9ydCBBUEkgbGlicmFyeSBpbiBleGFjdGx5IHRoZSBzYW1lIG1hbm5lciAqL1xuaW1wb3J0ICogYXMgZ3JvayBmcm9tICdkYXRhZ3Jvay1hcGkvZ3Jvayc7XG5pbXBvcnQgKiBhcyB1aSBmcm9tICdkYXRhZ3Jvay1hcGkvdWknO1xuaW1wb3J0ICogYXMgREcgZnJvbSAnZGF0YWdyb2stYXBpL2RnJztcbiJdfQ==
|
|
27
|
+
apisamples = __webpack_exports__;
|
|
28
|
+
/******/ })()
|
|
29
|
+
;
|
|
30
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGFja2FnZS5qcyIsIm1hcHBpbmdzIjoiOzs7VUFBQTtVQUNBOzs7OztXQ0RBO1dBQ0E7V0FDQTtXQUNBLHVEQUF1RCxpQkFBaUI7V0FDeEU7V0FDQSxnREFBZ0QsYUFBYTtXQUM3RDs7Ozs7Ozs7O0FDTlU7QUFDViwyQ0FBMkMsdWQiLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9hcGlzYW1wbGVzL3dlYnBhY2svYm9vdHN0cmFwIiwid2VicGFjazovL2FwaXNhbXBsZXMvd2VicGFjay9ydW50aW1lL21ha2UgbmFtZXNwYWNlIG9iamVjdCIsIndlYnBhY2s6Ly9hcGlzYW1wbGVzLy4vc3JjL3BhY2thZ2UudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLy8gVGhlIHJlcXVpcmUgc2NvcGVcbnZhciBfX3dlYnBhY2tfcmVxdWlyZV9fID0ge307XG5cbiIsIi8vIGRlZmluZSBfX2VzTW9kdWxlIG9uIGV4cG9ydHNcbl9fd2VicGFja19yZXF1aXJlX18uciA9IChleHBvcnRzKSA9PiB7XG5cdGlmKHR5cGVvZiBTeW1ib2wgIT09ICd1bmRlZmluZWQnICYmIFN5bWJvbC50b1N0cmluZ1RhZykge1xuXHRcdE9iamVjdC5kZWZpbmVQcm9wZXJ0eShleHBvcnRzLCBTeW1ib2wudG9TdHJpbmdUYWcsIHsgdmFsdWU6ICdNb2R1bGUnIH0pO1xuXHR9XG5cdE9iamVjdC5kZWZpbmVQcm9wZXJ0eShleHBvcnRzLCAnX19lc01vZHVsZScsIHsgdmFsdWU6IHRydWUgfSk7XG59OyIsImV4cG9ydCB7fTtcbi8vIyBzb3VyY2VNYXBwaW5nVVJMPWRhdGE6YXBwbGljYXRpb24vanNvbjtiYXNlNjQsZXlKMlpYSnphVzl1SWpvekxDSm1hV3hsSWpvaWNHRmphMkZuWlM1cWN5SXNJbk52ZFhKalpWSnZiM1FpT2lJaUxDSnpiM1Z5WTJWeklqcGJJbkJoWTJ0aFoyVXVkSE1pWFN3aWJtRnRaWE1pT2x0ZExDSnRZWEJ3YVc1bmN5STZJaUlzSW5OdmRYSmpaWE5EYjI1MFpXNTBJanBiSWk4cUlFUnZJRzV2ZENCamFHRnVaMlVnZEdobGMyVWdhVzF3YjNKMElHeHBibVZ6TGlCRVlYUmhaM0p2YXlCM2FXeHNJR2x0Y0c5eWRDQkJVRWtnYkdsaWNtRnllU0JwYmlCbGVHRmpkR3g1SUhSb1pTQnpZVzFsSUcxaGJtNWxjaUFxTDF4dWFXMXdiM0owSUNvZ1lYTWdaM0p2YXlCbWNtOXRJQ2RrWVhSaFozSnZheTFoY0drdlozSnZheWM3WEc1cGJYQnZjblFnS2lCaGN5QjFhU0JtY205dElDZGtZWFJoWjNKdmF5MWhjR2t2ZFdrbk8xeHVhVzF3YjNKMElDb2dZWE1nUkVjZ1puSnZiU0FuWkdGMFlXZHliMnN0WVhCcEwyUm5KenRjYmlKZGZRPT0iXSwibmFtZXMiOltdLCJzb3VyY2VSb290IjoiIn0=
|
package/package.json
CHANGED
|
@@ -1,39 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/api-samples",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Savenko Stanislav",
|
|
6
6
|
"email": "ssavenko@datagrok.ai"
|
|
7
7
|
},
|
|
8
8
|
"servicePackage": true,
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@datagrok-libraries/utils": "^4.
|
|
10
|
+
"@datagrok-libraries/utils": "^4.6.5",
|
|
11
11
|
"cash-dom": "^8.1.1",
|
|
12
|
-
"datagrok-api": "^1.
|
|
12
|
+
"datagrok-api": "^1.25.0",
|
|
13
13
|
"dayjs": "^1.11.13",
|
|
14
14
|
"rxjs": "^6.6.7",
|
|
15
15
|
"wu": "^2.1.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
+
"@datagrok/bio": "^2.18.0",
|
|
19
|
+
"@datagrok/charts": "^1.4.0",
|
|
20
|
+
"@datagrok/chem": "^1.13.0",
|
|
21
|
+
"@datagrok/chembl": "^1.2.0",
|
|
22
|
+
"@datagrok/clinical-case": "^1.1.0",
|
|
23
|
+
"@datagrok/helm": "^2.7.0",
|
|
24
|
+
"@datagrok/power-grid": "^1.5.0",
|
|
25
|
+
"@datagrok/samples": "^1.0.4",
|
|
26
|
+
"@datagrok/usage-analysis": "^2.2.1",
|
|
18
27
|
"@types/wu": "^2.1.42",
|
|
19
28
|
"@typescript-eslint/eslint-plugin": "^5.26.0",
|
|
20
29
|
"@typescript-eslint/parser": "^5.26.0",
|
|
30
|
+
"datagrok-tools": "^4.14.55",
|
|
21
31
|
"eslint": "^8.16.0",
|
|
22
32
|
"eslint-config-google": "^0.14.0",
|
|
23
33
|
"root-require": "^0.3.1",
|
|
24
34
|
"ts-loader": "^9.2.6",
|
|
25
35
|
"typescript": "^4.4.4",
|
|
26
36
|
"webpack": "^5.59.1",
|
|
27
|
-
"webpack-cli": "^4.9.1"
|
|
28
|
-
"@datagrok/bio": "^2.15.0",
|
|
29
|
-
"@datagrok/chem": "^1.12.0",
|
|
30
|
-
"@datagrok/helm": "^2.5.0",
|
|
31
|
-
"@datagrok/clinical-case": "^1.1.0",
|
|
32
|
-
"@datagrok/power-grid": "^1.4.0",
|
|
33
|
-
"@datagrok/usage-analysis": "^2.1.0",
|
|
34
|
-
"@datagrok/charts": "^1.4.0",
|
|
35
|
-
"@datagrok/chembl": "^1.1.4",
|
|
36
|
-
"@datagrok/samples": "^1.0.4"
|
|
37
|
+
"webpack-cli": "^4.9.1"
|
|
37
38
|
},
|
|
38
39
|
"friendlyName": "API Samples",
|
|
39
40
|
"description": "API Samples",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"scripts": {
|
|
47
48
|
"publish samples local": "grok publish local",
|
|
48
49
|
"publish samples localhost": "grok publish localhost",
|
|
49
|
-
"build": "webpack",
|
|
50
|
+
"build": "grok api && grok check --soft && webpack",
|
|
50
51
|
"test": "grok test",
|
|
51
52
|
"test-dev": "grok test --host dev",
|
|
52
53
|
"test-local": "grok test --host localhost",
|
|
@@ -54,10 +55,10 @@
|
|
|
54
55
|
"build-all": "npm --prefix ./../../js-api run build && npm --prefix ./../../libraries/utils run build && npm run build"
|
|
55
56
|
},
|
|
56
57
|
"canEdit": [
|
|
57
|
-
"
|
|
58
|
+
"Administrators"
|
|
58
59
|
],
|
|
59
60
|
"canView": [
|
|
60
|
-
"
|
|
61
|
+
"Administrators"
|
|
61
62
|
],
|
|
62
63
|
"category": "Development"
|
|
63
|
-
}
|
|
64
|
+
}
|
package/scripts/dapi/admin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
grok.dapi.admin.getServiceInfos()
|
|
2
|
-
|
|
1
|
+
let result = await grok.dapi.admin.getServiceInfos();
|
|
2
|
+
let v = grok.shell.newView("list");
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
v.root.appendChild(
|
|
5
|
+
ui.table(result, (item, idx) => [`${item.key}:`, item.status])
|
|
6
|
+
);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
//tags: ViewLayout, Dataframe
|
|
2
2
|
let df = grok.data.demo.demog();
|
|
3
3
|
let view = grok.shell.addTableView(df);
|
|
4
|
-
grok.dapi.layouts.getApplicable(df)
|
|
4
|
+
let layouts = await grok.dapi.layouts.getApplicable(df);
|
|
5
|
+
if (layouts.length > 0)
|
|
6
|
+
view.loadLayout(layouts[0]);
|
package/scripts/dapi/fetch.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
// Proxy a request via Datagrok's server with the same interface as "fetch"
|
|
2
2
|
|
|
3
3
|
const url = 'https://jsonplaceholder.typicode.com/posts';
|
|
4
|
-
|
|
4
|
+
let data = { name: 'username', password: 'password' };
|
|
5
5
|
|
|
6
6
|
// POST
|
|
7
|
-
grok.dapi.fetchProxy(url, {
|
|
7
|
+
let response = await grok.dapi.fetchProxy(url, {
|
|
8
8
|
method: 'POST',
|
|
9
9
|
headers: { 'Content-Type': 'application/json' },
|
|
10
10
|
body: JSON.stringify(data)
|
|
11
|
-
})
|
|
11
|
+
});
|
|
12
|
+
grok.shell.info(response.ok)
|
|
12
13
|
|
|
13
14
|
// GET
|
|
14
|
-
grok.dapi.fetchProxy('https://
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
response = await grok.dapi.fetchProxy('https://dev.datagrok.ai/demo/demog.csv');
|
|
16
|
+
data = await response.text();
|
|
17
|
+
console.log(data);
|
|
18
|
+
grok.shell.addTableView(DG.DataFrame.fromCsv(data))
|
package/scripts/dapi/files.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//tags: FileInfo
|
|
2
1
|
//help-url: https://datagrok.ai/help/develop/how-to/access-data
|
|
3
2
|
// JS API methods for working with files
|
|
4
3
|
|
|
@@ -28,11 +27,17 @@
|
|
|
28
27
|
res = await grok.dapi.files.list('System:AppData/Samples/', recursive, searchPattern);
|
|
29
28
|
console.log(`list: ${res}`);
|
|
30
29
|
|
|
31
|
-
//
|
|
30
|
+
//Create Directory
|
|
31
|
+
await grok.dapi.files.createDirectory('System:AppData/Samples/geo')
|
|
32
|
+
|
|
33
|
+
// Move files
|
|
32
34
|
await grok.dapi.files.move(['System:AppData/Samples/testFile.txt'], 'Samples/geo');
|
|
33
35
|
res = await grok.dapi.files.exists('System:AppData/Samples/geo/testFile.txt');
|
|
34
36
|
console.log(`testFile.txt was moved to geo: ${res}`);
|
|
35
37
|
|
|
38
|
+
//Remove Directory
|
|
39
|
+
await grok.dapi.files.delete('System:AppData/Samples/geo')
|
|
40
|
+
|
|
36
41
|
// Delete files
|
|
37
42
|
await grok.dapi.files.delete('System:AppData/Samples/geo/testFile.txt');
|
|
38
43
|
await grok.dapi.files.delete('System:AppData/Samples/testFile.dat');
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// gets #demo project list and shows them in the view
|
|
4
4
|
|
|
5
5
|
let view = grok.shell.newView('projects');
|
|
6
|
-
grok.dapi.projects
|
|
6
|
+
let projects = await grok.dapi.projects
|
|
7
7
|
.filter('#demo')
|
|
8
|
-
.list()
|
|
9
|
-
|
|
8
|
+
.list();
|
|
9
|
+
view.append(ui.div(projects.map((p) => ui.renderCard(p)), 'grok-gallery-grid'));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// find project, open it and close everything else
|
|
2
|
-
grok.dapi.projects
|
|
2
|
+
let project = await grok.dapi.projects
|
|
3
3
|
.filter('demog')
|
|
4
|
-
.first()
|
|
5
|
-
|
|
4
|
+
.first();
|
|
5
|
+
project.open({closeAll: true})
|
|
6
6
|
|
|
7
7
|
// a shortcut method
|
|
8
|
-
grok.dapi.projects.open('
|
|
8
|
+
grok.dapi.projects.open('demog');
|
package/scripts/dapi/who-am-i.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
// Prints the current user name and picture
|
|
4
4
|
|
|
5
5
|
let view = grok.shell.newView('User', []);
|
|
6
|
-
grok.dapi.users.current()
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
let user = await grok.dapi.users.current();
|
|
7
|
+
|
|
8
|
+
let p = user.picture;
|
|
9
|
+
let d = ui.div([ui.h1(user.firstName + ' ' + user.lastName), p]);
|
|
10
|
+
d.style.width = '300px';
|
|
11
|
+
d.style.textAlign = 'center';
|
|
12
|
+
p.style.width = '300px';
|
|
13
|
+
p.style.height = '300px';
|
|
14
|
+
p.style.fontSize = '150px';
|
|
15
|
+
view.root.appendChild(d);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//tags: query, ad-hoc query
|
|
2
|
+
// All queries execution are saved by default for the history. If you don't want this behaviour use special ad-hoc flag
|
|
3
|
+
|
|
4
|
+
// Get a connection
|
|
5
|
+
let connection = await grok.functions.eval('System:Datagrok')
|
|
6
|
+
|
|
7
|
+
// Create a query
|
|
8
|
+
let q = connection.query('query name', 'select 1 as hello_world');
|
|
9
|
+
|
|
10
|
+
// Create FuncCall and set adHoc flag
|
|
11
|
+
let call = q.prepare();
|
|
12
|
+
call.adHoc = true;
|
|
13
|
+
|
|
14
|
+
// Execute call
|
|
15
|
+
await call.call();
|
|
16
|
+
grok.shell.addTableView(call.getOutputParamValue());
|
|
@@ -5,7 +5,7 @@ const dbEdit = (t) => {
|
|
|
5
5
|
const dbIdColumnName = 'id';
|
|
6
6
|
|
|
7
7
|
let v = grok.shell.addTableView(t);
|
|
8
|
-
v.grid.onCellValueEdited.subscribe((c) => {
|
|
8
|
+
v.grid.onCellValueEdited.subscribe(async (c) => {
|
|
9
9
|
const idColumnName = 'id'
|
|
10
10
|
const dbColumnName = c.cell.column.tags['DbColumn'];
|
|
11
11
|
const sql =
|
|
@@ -14,14 +14,11 @@ const dbEdit = (t) => {
|
|
|
14
14
|
' where ' + dbIdColumnName + " = '" + c.cell.row.get(idColumnName) + "'";
|
|
15
15
|
|
|
16
16
|
grok.shell.info('Executing ' + sql);
|
|
17
|
-
|
|
18
|
-
grok.data.db
|
|
19
|
-
|
|
20
|
-
.then(r => grok.shell.info('Success!'))
|
|
21
|
-
.catch(e => grok.shell.error(e));
|
|
17
|
+
|
|
18
|
+
await grok.data.db.query('System:Datagrok', sql);
|
|
19
|
+
grok.shell.info('Success!');
|
|
22
20
|
});
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
grok.data.db
|
|
26
|
-
|
|
27
|
-
.then(dbEdit);
|
|
23
|
+
let result = await grok.data.db.query('System:Datagrok', 'select * from models');
|
|
24
|
+
dbEdit(result);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
|
|
1
2
|
//tags: DataQuery
|
|
2
3
|
//help-url: https://datagrok.ai/help/access/databases#parameterized-queries
|
|
3
4
|
// An example of using parameterized query
|
|
4
5
|
|
|
5
|
-
grok.data.query(
|
|
6
|
-
|
|
6
|
+
let t = await grok.data.query("Samples:MSSQLByInt", { orderid: 10 })
|
|
7
|
+
grok.shell.info("Number of orders: " + t.rowCount);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//tags: TableQueryBuilder, TableQuery, query
|
|
2
|
+
try {
|
|
3
|
+
let df = await grok.data.db
|
|
4
|
+
.buildQuery("Samples:PostgresNorthwind", "products")
|
|
5
|
+
.leftJoin("categories", ["categoryid"], ["categoryid"])
|
|
6
|
+
.innerJoin("suppliers", ["supplierid"], ["supplierid"])
|
|
7
|
+
.groupBy(["companyname", "products.supplierid", "country"])
|
|
8
|
+
.having("country", "in (USA, UK)")
|
|
9
|
+
.limit(5)
|
|
10
|
+
.build()
|
|
11
|
+
.executeTable();
|
|
12
|
+
grok.shell.addTableView(df);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
grok.shell.error(e);
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//tags: TableQueryBuilder, TableQuery, query
|
|
2
|
+
|
|
3
|
+
try {
|
|
4
|
+
let df = await grok.data.db
|
|
5
|
+
.buildQuery("Samples:PostgresNorthwind", "orders")
|
|
6
|
+
.select(["shipcity", "shipcountry", "orderdate"])
|
|
7
|
+
.where("orderdate", "before 1996-08-26", DG.TYPE.DATE_TIME)
|
|
8
|
+
.sortBy("orderdate", false)
|
|
9
|
+
.limit(10)
|
|
10
|
+
.build()
|
|
11
|
+
.executeTable()
|
|
12
|
+
grok.shell.addTableView(df);
|
|
13
|
+
} catch (e) {
|
|
14
|
+
grok.shell.error(e);
|
|
15
|
+
}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
//tags: DataQuery
|
|
2
2
|
//help-url: https://datagrok.ai/help/access/databases#parameterized-queries
|
|
3
3
|
// Manual master-details linking of tables that are dynamically retrieved from the database
|
|
4
|
-
grok.data.query('Samples:Countries', {})
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//grok.shell.addTableView(t);
|
|
14
|
-
})
|
|
15
|
-
});
|
|
4
|
+
let countries = await grok.data.query('Samples:Countries', {})
|
|
5
|
+
let customersView = null;
|
|
6
|
+
|
|
7
|
+
grok.shell.addTableView(countries);
|
|
8
|
+
countries.onCurrentRowChanged.subscribe(async (_) => {
|
|
9
|
+
let t = await grok.data.query('Samples:CustomersInCountry', {country: countries.currentRow['country']})
|
|
10
|
+
customersView = grok.shell.addTableView(t);
|
|
11
|
+
customersView.dataFrame = t;
|
|
12
|
+
})
|
|
16
13
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
grok.data.loadTable('https://calmcode.io/static/data/bigmac.csv')
|
|
2
|
-
|
|
1
|
+
let t = await grok.data.loadTable('https://calmcode.io/static/data/bigmac.csv');
|
|
2
|
+
grok.shell.addTableView(t);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//tags: Files, exists
|
|
2
|
+
//See more examples in dapi/files
|
|
3
|
+
|
|
4
|
+
(async () => {
|
|
5
|
+
// Using System:DemoFiles connection
|
|
6
|
+
let filePath = 'System:DemoFiles/cars.csv';
|
|
7
|
+
|
|
8
|
+
let exists = await grok.dapi.files.exists(filePath);
|
|
9
|
+
grok.shell.info(`File ${filePath} ${exists ? 'exists' : 'doesn\'t exist'}`);
|
|
10
|
+
})();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//tags: Files, read
|
|
2
|
+
//See more examples in dapi/files
|
|
3
|
+
|
|
4
|
+
(async () => {
|
|
5
|
+
// Using System:DemoFiles connection
|
|
6
|
+
let filePath = 'System:DemoFiles/cars.csv';
|
|
7
|
+
|
|
8
|
+
// Read file as bytes
|
|
9
|
+
let bytes = await grok.dapi.files.readAsBytes(filePath);
|
|
10
|
+
grok.shell.info(`Read file cars.csv as bytes: length ${bytes.length}`);
|
|
11
|
+
|
|
12
|
+
// Read file as string. File content should be UTF-8 decodable or error will be thrown
|
|
13
|
+
let text = await grok.dapi.files.readAsText(filePath);
|
|
14
|
+
grok.shell.info(`Read file cars.csv as string: length ${text.length}`);
|
|
15
|
+
|
|
16
|
+
// Read csv file and convert it to DG.DataFrame automatically. File content should be valid csv or error will be thrown
|
|
17
|
+
let dataFrame = await grok.dapi.files.readCsv(filePath);
|
|
18
|
+
grok.shell.info(`Read file cars.csv as DataFrame: rows ${dataFrame.rowCount}`);
|
|
19
|
+
})();
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Loading a csv file from the specified URL
|
|
2
|
-
grok.data.loadTable('https://public.datagrok.ai/demo/demog.csv')
|
|
3
|
-
|
|
2
|
+
let t = await grok.data.loadTable('https://public.datagrok.ai/demo/demog.csv')
|
|
3
|
+
grok.shell.addTableView(t);
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
let df = DG.DataFrame.fromColumns([DG.Column.fromStrings('myColumn', ['first row', 'second row', 'third row'])]);
|
|
4
4
|
df.name = 'my data frame';
|
|
5
|
-
grok.dapi.tables.uploadDataFrame(df)
|
|
6
|
-
grok.shell.info('Data frame id: ' + id);
|
|
7
|
-
grok.dapi.tables.getTable(id).then((loadedDf) => grok.shell.addTableView(loadedDf));
|
|
5
|
+
let id = await grok.dapi.tables.uploadDataFrame(df);
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
grok.shell.info('Data frame id: ' + id);
|
|
8
|
+
let loadedDf = await grok.dapi.tables.getTable(id);
|
|
9
|
+
grok.shell.addTableView(loadedDf);
|
|
10
|
+
let meta = await grok.dapi.tables.find(id);
|
|
11
|
+
grok.shell.info('Data frame name: ' + meta.name);
|
|
@@ -5,4 +5,8 @@ let d = grok.data.demo.demog();
|
|
|
5
5
|
|
|
6
6
|
let ageColumn = d.getCol('age');
|
|
7
7
|
ageColumn = d.columns.byName('age');
|
|
8
|
-
|
|
8
|
+
console.log('Column by name:');
|
|
9
|
+
console.log(ageColumn);
|
|
10
|
+
ageColumn = d.columns.byIndex(3);
|
|
11
|
+
console.log('Column by index:');
|
|
12
|
+
console.log(ageColumn);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Create dataframe by adding and initializing columns
|
|
2
|
+
//tags: DataFrame, Column, construction
|
|
3
|
+
|
|
4
|
+
let t = DG.DataFrame.create(10)
|
|
5
|
+
t.columns.addNewInt('int').init((i) => i);
|
|
6
|
+
t.columns.addNewFloat('float').init((i) => i / 10);
|
|
7
|
+
t.columns.addNewQnum('qnum').init((i) => DG.Qnum.create(i / 10, DG.QNUM_LESS));
|
|
8
|
+
t.columns.addNewString('string').init((i) => 'str ' + i);
|
|
9
|
+
t.columns.addNewBool('bool').init((i) => i % 2 === 0);
|
|
10
|
+
t.columns.addNewDateTime('datetime').init((i) => dayjs());
|
|
11
|
+
t.columns.addNewBytes('bytes').init((i) => new Uint8Array(42));
|
|
12
|
+
|
|
13
|
+
grok.shell.addTableView(t);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
//tags: DataFrame, Column, construction
|
|
2
2
|
// API References:
|
|
3
3
|
//
|
|
4
|
-
// https://datagrok.ai/js-api/classes/
|
|
5
|
-
// https://datagrok.ai/js-api/classes/
|
|
6
|
-
// https://datagrok.ai/js-api/classes/
|
|
7
|
-
// https://datagrok.ai/js-api/classes/
|
|
4
|
+
// https://datagrok.ai/js-api/dg/classes/ColumnList
|
|
5
|
+
// https://datagrok.ai/js-api/dg/classes/DataFrame
|
|
6
|
+
// https://datagrok.ai/js-api/dg/classes/Column#fromList
|
|
7
|
+
// https://datagrok.ai/js-api/dg/classes/Column#qnum
|
|
8
8
|
//
|
|
9
9
|
// Note that the "population" data type becomes int
|
|
10
10
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Datetime columns return [Dayjs object](https://github.com/iamkun/dayjs/) but accept multiple types:
|
|
2
|
+
|
|
3
|
+
let t = DG.DataFrame.create(10)
|
|
4
|
+
|
|
5
|
+
// Batch initialization using functions
|
|
6
|
+
t.columns.addNewDateTime('fun dayJs').init((i) => dayjs());
|
|
7
|
+
t.columns.addNewDateTime('fun Date').init((i) => Date.now());
|
|
8
|
+
t.columns.addNewDateTime('fun ms since epoch').init((i) => 42);
|
|
9
|
+
t.columns.addNewDateTime('fun string').init((i) => '2024/10/30');
|
|
10
|
+
|
|
11
|
+
// Batch initialization with the same value
|
|
12
|
+
t.columns.addNewDateTime('dayJs').init(dayjs());
|
|
13
|
+
t.columns.addNewDateTime('Date').init(Date.now());
|
|
14
|
+
t.columns.addNewDateTime('ms since epoch').init(42);
|
|
15
|
+
t.columns.addNewDateTime('string').init('2024/10/30');
|
|
16
|
+
|
|
17
|
+
// Index-based initialization
|
|
18
|
+
let dc = t.columns.addNewDateTime('new');
|
|
19
|
+
dc.set(0, dayjs());
|
|
20
|
+
dc.set(1, Date.now());
|
|
21
|
+
dc.set(2, 42);
|
|
22
|
+
dc.set(3, '2024/10/30');
|
|
23
|
+
|
|
24
|
+
grok.shell.addTableView(t);
|
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
let tickers = DG.DataFrame.fromCsv(
|
|
4
4
|
`chickweight
|
|
5
|
-
fish`
|
|
5
|
+
fish`
|
|
6
|
+
);
|
|
6
7
|
grok.shell.addTableView(tickers);
|
|
7
8
|
|
|
8
9
|
let detailsView = null;
|
|
9
10
|
|
|
10
|
-
tickers.onCurrentRowChanged.subscribe((_) => {
|
|
11
|
-
grok.data.loadTable(
|
|
12
|
-
.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
});
|
|
11
|
+
tickers.onCurrentRowChanged.subscribe(async (_) => {
|
|
12
|
+
let t = await grok.data.loadTable(
|
|
13
|
+
`https://calmcode.io/static/data/${tickers.currentRow.chickWeight}.csv`
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
if (detailsView === null) detailsView = grok.shell.addTableView(t);
|
|
17
|
+
else detailsView.dataFrame = t;
|
|
18
18
|
});
|
|
19
|
+
|
|
@@ -12,14 +12,18 @@
|
|
|
12
12
|
//
|
|
13
13
|
// https://datagrok.ai/help/explore/link-tables
|
|
14
14
|
|
|
15
|
-
grok.data.loadTable(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
let demog = await grok.data.loadTable("https://public.datagrok.ai/demo/demog.csv");
|
|
16
|
+
let demogTypes = await grok.data.loadTable("https://public.datagrok.ai/demo/demog-types.csv");
|
|
17
|
+
|
|
18
|
+
grok.shell.addTableView(demog);
|
|
19
|
+
grok.shell.addTableView(demogTypes);
|
|
20
|
+
grok.data.linkTables(
|
|
21
|
+
demogTypes,
|
|
22
|
+
demog,
|
|
23
|
+
["sex", "race"],
|
|
24
|
+
["sex", "race"],
|
|
25
|
+
[DG.SYNC_TYPE.CURRENT_ROW_TO_FILTER, DG.SYNC_TYPE.MOUSE_OVER_ROW_TO_SELECTION]
|
|
26
|
+
);
|
|
23
27
|
|
|
24
28
|
// Link types:
|
|
25
29
|
// From SYNC_TYPE enum:
|