@vizabi/reader-ddfcsv 4.5.2 → 4.5.3

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/README.md CHANGED
@@ -1,112 +1,122 @@
1
1
  # Vizabi DDFcsv reader
2
+ This package implements [DDF model](https://open-numbers.github.io/ddf.html) for datasets made of csv files and a datapackage.json.
3
+ Once initialised, this reader can receive DDFQL queries, perform data searching, filtering, joinery etc and output an tidy data array for data visualisation.
2
4
 
5
+ See live example here https://observablehq.com/@vizabi/ddfcsv-reader
3
6
  ## Install
4
-
5
- ```
7
+ ```bash
6
8
  npm i @vizabi/reader-ddfcsv
7
9
  ```
8
-
9
10
  ## Usage
10
-
11
- ```
12
- const Vizabi = require('vizabi');
13
- const ddfCsvReader = require('reader-ddfcsv');
14
- const readerObject = ddfCsvReader.getDDFCsvReaderObject();
15
- Vizabi.Reader.extend('ddf-csv-reader', readerObject);
16
- // ...
11
+ There are two implementations: for frontend and backend. Additionally, you can customise file reading plugin, so that for example backend implementation would fetch files online instead of reading locally.
12
+
13
+ * Backend implementation is at `lib/src/index.js`, also usable via es6 import `import DDFCsvReader from "@vizabi/reader-ddfcsv"`, as aliased by "main" field in package.json
14
+
15
+ * Frontend implementation is at `lib-web/src/index-web.js`, also bundled and minified to `dist/reader-ddfcsv.js`
16
+ ### On Backend
17
+ ```js
18
+ //this will import "lib/src/index.js", aliased by "main" in package.json
19
+ import DDFCsvReader from "@vizabi/reader-ddfcsv";
20
+
21
+ //init
22
+ const readerInstance = new DDFCsvReader.getDDFCsvReaderObject();
23
+ readerInstance.init({path: "path/to/local/dataset/root"});
24
+
25
+ //test reading some concepts
26
+ const concepts = await readerInstance.read({
27
+ from: "concepts",
28
+ language: "en",
29
+ select: {key: ["concept"], value: ["concept_type", "name"]},
30
+ where: {}
31
+ })
17
32
  ```
18
-
19
- ## Build
33
+ ### On Frontend
34
+ On a plain webpage use
35
+ ```js
36
+ import "@vizabi/reader-ddfcsv/dist/reader-ddfcsv.js";
37
+
38
+ //init
39
+ const ddfReader = new DDFCsvReader.getDDFCsvReaderObject();
40
+ reader.init({
41
+ path: "https://github.com/open-numbers/ddf--gapminder--fasttrack.git"
42
+ })
43
+
44
+ const data = await readerInstance.read({
45
+ from: "datapoints",
46
+ language: "en",
47
+ select: {key: ["country", "time"], value: ["gdp_pcap", "lex", "pop"]},
48
+ where: {}
49
+ })
20
50
 
21
51
  ```
22
- git clone https://github.com/vizabi/reader-ddfcsv.git
23
- cd reader-ddfcsv
24
- npm i
25
- npm run build
26
- ```
27
-
28
- ### Run tests
29
-
52
+
53
+ In Observable notebooks use
30
54
  ```
31
- npm test
55
+ DDFCsvReader = require('https://unpkg.com/@vizabi/reader-ddfcsv@4.5.2')
32
56
  ```
33
57
 
34
- And after this you can see `dist` folder that contains two sets:
35
-
36
- * `bundle.js` and `bundle.js.map`
37
- * `bundle.web.js` and `bundle.web.js.map`
38
-
39
- First one is for using with electron app or tests. Second one is only for using in browser.
58
+ which will redirect to https://unpkg.com/@vizabi/reader-ddfcsv@4.5.1/dist/reader-ddfcsv.js
40
59
 
41
- ## File readers
60
+ See the [Live demo](https://observablehq.com/@vizabi/ddfcsv-reader)
61
+ ## Custom file readers
62
+ Each implementation has its own default file readers built-in:
63
+ * FrontendFileReader is a part of `lib-web/src/index-web.js` version, also usable from `dist/reader-ddfcsv.js`
64
+ * BackendFileReader is a part of `lib/src/index.js` version.
42
65
 
43
- `Vizabi DDFcsv reader` has 2 file readers:
44
-
45
- * FrontendFileReader is a part of `bundle.js` version.
46
- * BackendFileReader is a part of `bundle.web.js` version.
47
-
66
+ You can find in the source code and import them readers separately
67
+ ```js
68
+ import { FrontendFileReader } from "@vizabi/reader-ddfcsv/lib-web/src/index-web.js";
69
+ ```
70
+ ### FrontendFileReader
71
+ This reader is designed for file reading via HTTP protocol. It uses `fetch`, which since v4.5.2 is no longer polyfilled
48
72
  ### BackendFileReader
73
+ This reader is designed for file reading via OS file system. It uses `fs` and `path`
74
+ ### Frankensteining: Using FrontendFileReader in a Backend instance
75
+ The backend version of `DDFCsvReader` defaults to `fs` for local files.
76
+ To fetch data from GitHub (or any remote source), inject the `FrontendFileReader`:
49
77
 
50
- This reader is designed for file reading via OS file system.
51
-
52
- ### FrontendFileReader
78
+ ```js
53
79
 
54
- This reader is designed for file reading via HTTP protocol.
80
+ import DDFCsvReader from "@vizabi/reader-ddfcsv";
81
+ import { FrontendFileReader } from "@vizabi/reader-ddfcsv/lib-web/src/index-web.js";
55
82
 
56
- ## DDFcsv reader usage for DDF data reading examples:
83
+ //init
84
+ const readerInstance = new DDFCsvReader.prepareDDFCsvReaderObject(new FrontendFileReader)();
85
+ readerInstance.init({ path: "https://github.com/open-numbers/ddf--gapminder--ai_worldview_benchmark.git" });
57
86
 
58
- ```
59
- import {BackendFileReader, Ddf} from 'reader-ddfcsv';
60
-
61
- const backendFileReader = new BackendFileReader();
62
- const ddf = new Ddf('your-ddf-folder', backendFileReader);
63
-
64
- ddf.getIndex(indexErr => {
65
- // process indexErr here ...
66
-
67
- ddf.getConcepts((conceptsErr, conceptsData) => {
68
- // process conceptsErr here ...
69
-
70
- // process conceptsData here ...
71
-
72
- ddf.getAllDataPointsContent(
73
- (dataPointsFileErr, dataPointsData) => {
74
- // process dataPointsFileErr here ...
75
-
76
- // process dataPointsData here ...
77
- },
78
- dataPointsAllErr => {
79
- // process dataPointsAllErr here ...
80
-
81
- // data reading finish
82
- });
83
- });
84
- });
85
- ```
87
+ //usage example
88
+ const concepts = await readerInstance.read({
89
+ from: "concepts",
90
+ language: "en",
91
+ select: {key: ["concept"], value: ["concept_type", "name"]},
92
+ where: {}
93
+ })
86
94
 
87
- or
95
+ ```
88
96
 
97
+ ## Data reading examples:
98
+ Once you can access concepts of a dataset you can run any other DDFQL query, see [DDFQL specs](https://open-numbers.github.io/ddf.html)
99
+
100
+ ```js
101
+ //typical datapoint query
102
+ data = readerInstance.read({
103
+ from: "datapoints",
104
+ language: "en",
105
+ select: {key: ["country", "time"], value: ["gdp_pcap", "lex", "pop"]},
106
+ where: {}
107
+ })
89
108
  ```
90
- import {BackendFileReader, Ddf} from 'reader-ddfcsv';
91
-
92
- const backendFileReader = new BackendFileReader();
93
- const ddf = new Ddf('your-ddf-folder', backendFileReader);
94
- // for example, :
95
- const query = {
96
- from: 'entities',
97
- animatable: 'time',
98
- select: {
99
- key: ['geo'],
100
- value: ['geo.name', '_default', 'geo.world_4region']
101
- },
102
- where: {'geo.is--country': true},
103
- grouping: {},
104
- orderBy: null
105
- };
106
-
107
- ddf.processRequest(query, (err, data) => {
108
- // process err here ...
109
109
 
110
- // process expected data here ...
111
- };
110
+ interactive example: https://observablehq.com/@vizabi/ddfcsv-reader
111
+
112
+ ## Build
113
+ ```bash
114
+ git clone https://github.com/vizabi/reader-ddfcsv.git
115
+ cd reader-ddfcsv
116
+ npm i
117
+ npm run build
112
118
  ```
119
+ ## Run tests
120
+ ```bash
121
+ npm test
122
+ ```