jupyter-ijavascript-utils 1.1.0 → 1.2.0
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/DOCS.md +6 -0
- package/README.md +4 -0
- package/package.json +4 -4
- package/tutorials/exampleWalkthrough.markdown +108 -108
package/DOCS.md
CHANGED
package/README.md
CHANGED
|
@@ -16,6 +16,10 @@ Simple library for working with Jupyter - through IJavaScript kernel.
|
|
|
16
16
|
|
|
17
17
|
See documentation at: [https://jupyter-ijavascript-utils.onrender.com/](https://jupyter-ijavascript-utils.onrender.com/)
|
|
18
18
|
|
|
19
|
+
# What's New
|
|
20
|
+
|
|
21
|
+
5.2 - bumped vega-lite to latest
|
|
22
|
+
|
|
19
23
|
# For Example
|
|
20
24
|
|
|
21
25
|
## Get Sample Data
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jupyter-ijavascript-utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Utilities for working with iJavaScript - a Jupyter Kernel",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"pino-pretty": "^5.1.2",
|
|
46
46
|
"plantuml-encoder": "^1.4.0",
|
|
47
47
|
"promise-sequential": "^1.1.1",
|
|
48
|
-
"vega": "^5.
|
|
49
|
-
"vega-datasets": "^2.
|
|
50
|
-
"vega-lite": "^5.
|
|
48
|
+
"vega": "^5.22.0",
|
|
49
|
+
"vega-datasets": "^2.3.0",
|
|
50
|
+
"vega-lite": "^5.2.0",
|
|
51
51
|
"vega-lite-api": "^5.0.0"
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -113,22 +113,22 @@ We can see the list of the datasets available:
|
|
|
113
113
|
```
|
|
114
114
|
utils.datasets.list();
|
|
115
115
|
|
|
116
|
-
[
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
]
|
|
116
|
+
// [
|
|
117
|
+
// 'annual-precip.json',
|
|
118
|
+
// 'anscombe.json',
|
|
119
|
+
// 'barley.json',
|
|
120
|
+
// 'budget.json',
|
|
121
|
+
// 'budgets.json',
|
|
122
|
+
// 'burtin.json',
|
|
123
|
+
// ...
|
|
124
|
+
// ]
|
|
125
125
|
```
|
|
126
126
|
|
|
127
127
|
The DataSet we want is the [facinating GapMinder Life Expectancy study](https://www.gapminder.org/answers/how-does-income-relate-to-life-expectancy/)
|
|
128
128
|
|
|
129
129
|
```
|
|
130
130
|
$$.async()
|
|
131
|
-
utils.datasets.
|
|
131
|
+
utils.datasets.fetch('gapminder.json')
|
|
132
132
|
.then(data => {
|
|
133
133
|
gapMinder = data;
|
|
134
134
|
$$.sendResult(gapMinder);
|
|
@@ -141,7 +141,7 @@ As we called `$$.async()` - the cell knows that it should pause execution for th
|
|
|
141
141
|
|
|
142
142
|
```
|
|
143
143
|
utils.ijs.await(async ($$, console) => {
|
|
144
|
-
gapMinder = await utils.datasets.
|
|
144
|
+
gapMinder = await utils.datasets.fetch('gapminder.json');
|
|
145
145
|
});
|
|
146
146
|
```
|
|
147
147
|
|
|
@@ -154,15 +154,15 @@ One option to understand the kinds of data is to always look at the first record
|
|
|
154
154
|
```
|
|
155
155
|
gapMinder[0];
|
|
156
156
|
|
|
157
|
-
gives:
|
|
158
|
-
{
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
157
|
+
// gives:
|
|
158
|
+
// {
|
|
159
|
+
// year: 1955,
|
|
160
|
+
// country: 'Afghanistan',
|
|
161
|
+
// cluster: 0,
|
|
162
|
+
// pop: 8891209,
|
|
163
|
+
// life_expect: 30.332,
|
|
164
|
+
// fertility: 7.7
|
|
165
|
+
// }
|
|
166
166
|
```
|
|
167
167
|
|
|
168
168
|
The Utilities also include two additional methods that can help:
|
|
@@ -177,22 +177,22 @@ It tells us that there are no objects further down with additional fields, and a
|
|
|
177
177
|
But this can leave a bit to be desired for the types of properties.
|
|
178
178
|
|
|
179
179
|
```
|
|
180
|
-
{
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
180
|
+
// {
|
|
181
|
+
// '$schema': 'http://json-schema.org/draft-04/schema#',
|
|
182
|
+
// type: 'array',
|
|
183
|
+
// items: {
|
|
184
|
+
// type: 'object',
|
|
185
|
+
// properties: {
|
|
186
|
+
// year: [Object],
|
|
187
|
+
// country: [Object],
|
|
188
|
+
// cluster: [Object],
|
|
189
|
+
// pop: [Object],
|
|
190
|
+
// life_expect: [Object],
|
|
191
|
+
// fertility: [Object]
|
|
192
|
+
// },
|
|
193
|
+
// required: [ 'year', 'country', 'cluster', 'pop', 'life_expect', 'fertility' ]
|
|
194
|
+
// }
|
|
195
|
+
// }
|
|
196
196
|
```
|
|
197
197
|
|
|
198
198
|
{@link module:object.getObjectPropertyTypes|object.getObjectPropertyTypes(object / array)}
|
|
@@ -203,11 +203,11 @@ but only of the objects in the collection (shallow introspection).
|
|
|
203
203
|
```
|
|
204
204
|
utils.object.getObjectPropertyTypes(gapMinder)
|
|
205
205
|
|
|
206
|
-
returns
|
|
207
|
-
Map(2) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
206
|
+
// returns
|
|
207
|
+
// Map(2) {
|
|
208
|
+
// 'number' => Set(5) { 'year', 'cluster', 'pop', 'life_expect','fertility' },
|
|
209
|
+
// 'string' => Set(1) { 'country' }
|
|
210
|
+
// }
|
|
211
211
|
```
|
|
212
212
|
|
|
213
213
|
# Simple Aggregation
|
|
@@ -232,11 +232,11 @@ or which countries are covered:
|
|
|
232
232
|
|
|
233
233
|
```
|
|
234
234
|
utils.aggregate.unique(gapMinder, 'country')
|
|
235
|
-
[
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
]
|
|
235
|
+
// [
|
|
236
|
+
// 'Afghanistan', 'Argentina', 'Aruba',
|
|
237
|
+
// 'Australia', 'Austria', 'Bahamas',
|
|
238
|
+
// ...
|
|
239
|
+
// ]
|
|
240
240
|
```
|
|
241
241
|
|
|
242
242
|
how many countries:
|
|
@@ -256,15 +256,15 @@ Or maybe I would like to know the extents for multiple fields:
|
|
|
256
256
|
year_range: utils.agg.extent(gapMinder, 'year'),
|
|
257
257
|
pop_range: utils.agg.extent(gapMinder, 'pop'),
|
|
258
258
|
life_expect: utils.agg.extent(gapMinder, 'life_expect'),
|
|
259
|
-
fertility: utils.agg.
|
|
259
|
+
fertility: utils.agg.extent(gapMinder, 'fertility')
|
|
260
260
|
});
|
|
261
|
-
returns
|
|
262
|
-
{
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
261
|
+
// returns
|
|
262
|
+
// {
|
|
263
|
+
// year_range: { min: 1955, max: 2005 },
|
|
264
|
+
// pop_range: { min: 53865, max: 1303182268 },
|
|
265
|
+
// life_expect: { min: 23.599, max: 82.603 },
|
|
266
|
+
// fertility: { min: 0.94, max: 8.5 }
|
|
267
|
+
// }
|
|
268
268
|
```
|
|
269
269
|
|
|
270
270
|
# Group Transformations
|
|
@@ -285,29 +285,29 @@ utils.group.by(gapMinder, 'cluster')
|
|
|
285
285
|
it looks like they are geography regions:
|
|
286
286
|
|
|
287
287
|
```
|
|
288
|
-
[
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
]
|
|
288
|
+
// [
|
|
289
|
+
// {
|
|
290
|
+
// cluster: 0,
|
|
291
|
+
// countries: [ 'Afghanistan', 'Bangladesh', 'India', 'Pakistan' ]
|
|
292
|
+
// },
|
|
293
|
+
// {
|
|
294
|
+
// cluster: 3,
|
|
295
|
+
// countries: [
|
|
296
|
+
// 'Argentina', 'Aruba', 'Bahamas', 'Barbados', 'Bolivia',
|
|
297
|
+
// 'Brazil', 'Canada', 'Chile', 'Colombia', 'Costa Rica',
|
|
298
|
+
// 'Cuba', 'Dominican Republic', 'Ecuador', 'El Salvador',
|
|
299
|
+
// 'Grenada', 'Haiti', 'Jamaica', 'Mexico', 'Peru', 'United States', 'Venezuela'
|
|
300
|
+
// ]
|
|
301
|
+
// },
|
|
302
|
+
// {
|
|
303
|
+
// cluster: 4,
|
|
304
|
+
// countries: [
|
|
305
|
+
// 'Australia', 'China', 'Hong Kong', 'Indonesia', 'Japan',
|
|
306
|
+
// 'South Korea', 'North Korea', 'New Zealand', 'Philippines'
|
|
307
|
+
// ]
|
|
308
|
+
// },
|
|
309
|
+
// ...
|
|
310
|
+
// ]
|
|
311
311
|
```
|
|
312
312
|
|
|
313
313
|
How many entries are there per country?
|
|
@@ -323,14 +323,14 @@ utils.group.by(gapMinder, 'country')
|
|
|
323
323
|
.sort(utils.array.createSort('-count'));
|
|
324
324
|
|
|
325
325
|
// provides
|
|
326
|
-
[
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
]
|
|
326
|
+
// [
|
|
327
|
+
// { country: 'Afghanistan', count: 11 },
|
|
328
|
+
// { country: 'Argentina', count: 11 },
|
|
329
|
+
// { country: 'Aruba', count: 11 },
|
|
330
|
+
// { country: 'Australia', count: 11 },
|
|
331
|
+
// { country: 'Austria', count: 11 },
|
|
332
|
+
// ...
|
|
333
|
+
// ]
|
|
334
334
|
```
|
|
335
335
|
|
|
336
336
|
Looks like they are 11 records all the way down.
|
|
@@ -365,29 +365,29 @@ utils.group.by(gapMinder, 'country', 'year')
|
|
|
365
365
|
.get('Afghanistan');
|
|
366
366
|
|
|
367
367
|
//-- returns
|
|
368
|
-
SourceMap(11) [Map] {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
}
|
|
368
|
+
// SourceMap(11) [Map] {
|
|
369
|
+
// 1955 => [
|
|
370
|
+
// {
|
|
371
|
+
// year: 1955,
|
|
372
|
+
// country: 'Afghanistan',
|
|
373
|
+
// cluster: 0,
|
|
374
|
+
// pop: 8891209,
|
|
375
|
+
// life_expect: 30.332,
|
|
376
|
+
// fertility: 7.7
|
|
377
|
+
// }
|
|
378
|
+
// ],
|
|
379
|
+
// 1960 => [
|
|
380
|
+
// {
|
|
381
|
+
// year: 1960,
|
|
382
|
+
// country: 'Afghanistan',
|
|
383
|
+
// cluster: 0,
|
|
384
|
+
// pop: 9829450,
|
|
385
|
+
// life_expect: 31.997,
|
|
386
|
+
// fertility: 7.7
|
|
387
|
+
// }
|
|
388
|
+
// ],
|
|
389
|
+
// ...
|
|
390
|
+
// }
|
|
391
391
|
```
|
|
392
392
|
|
|
393
393
|
# Table
|