@nshiab/simple-data-analysis 5.20.0 → 5.20.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.
Files changed (2) hide show
  1. package/README.md +130 -101
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -273,12 +273,12 @@ const chart = (data: unknown[]) =>
273
273
  }),
274
274
  ],
275
275
  });
276
- await firesInsideProvinces.writeChart(chart, "./chart.png");
276
+ await firesInsideProvinces.writeChart(chart, "sda/output/chart.png");
277
277
 
278
278
  // And we can write the data to a parquet, json or csv file.
279
279
  // For geospatial data, you can use writeGeoData to
280
280
  // write geojson or geoparquet files.
281
- await firesInsideProvinces.writeData("./firesInsideProvinces.parquet");
281
+ await firesInsideProvinces.writeData("sda/output/firesInsideProvinces.parquet");
282
282
 
283
283
  // We close everything.
284
284
  await sdb.done();
@@ -347,7 +347,7 @@ const chart = (data: unknown[]) =>
347
347
  ],
348
348
  });
349
349
 
350
- const path = "./chart.png";
350
+ const path = "sda/output/chart.png";
351
351
 
352
352
  await table.writeChart(chart, path);
353
353
 
@@ -443,7 +443,7 @@ const map = (geoData: {
443
443
  };
444
444
 
445
445
  // This is the path where the map will be saved.
446
- const path = "./map.png";
446
+ const path = "sda/output/map.png";
447
447
 
448
448
  // Now we can call writeMap.
449
449
  await provincesAndFires.writeMap(map, path);
@@ -461,15 +461,15 @@ computationally expensive operations.
461
461
 
462
462
  Here's the previous example adapted to cache data. For more information, check
463
463
  the
464
- [cache method documentation](https://nshiab.github.io/simple-data-analysis/classes/SimpleTable.html#cache).
464
+ [cache method documentation](https://jsr.io/@nshiab/simple-data-analysis-core/doc/~/SimpleTable#method_cache_0).
465
465
 
466
466
  The data is cached in the hidden folder `.sda-cache` at the root of your code
467
467
  repository. Make sure to add it to your `.gitignore`. If you want to clean your
468
468
  cache, just delete the folder.
469
469
 
470
- If you set up with `setup-sda` (see _Quick setup_ at the top), `.sda-cache` is
471
- automatically added to your `.gitignore` and you can use `npm run clean` or
472
- `bun run clean` or `deno task clean` to clear the cache.
470
+ If you set up with `@nshiab/setup-data-project` (see _Quick setup_ at the top),
471
+ `.sda-cache` is automatically added to your `.gitignore` and you can use
472
+ `npm run clean` or `bun run clean` or `deno task clean` to clear the cache.
473
473
 
474
474
  ```ts
475
475
  import { SimpleDB } from "@nshiab/simple-data-analysis";
@@ -528,9 +528,8 @@ const firesInsideProvinces = sdb.newTable("firesInsideProvinces");
528
528
  // up-to-date data.
529
529
  await firesInsideProvinces.cache(
530
530
  async () => {
531
- await fires.joinGeo(provinces, "inside", {
532
- outputTable: "firesInsideProvinces",
533
- });
531
+ await firesInsideProvinces.insertTables(fires);
532
+ await firesInsideProvinces.joinGeo(provinces, "inside");
534
533
  await firesInsideProvinces.removeMissing();
535
534
  await firesInsideProvinces.summarize({
536
535
  values: "hectares",
@@ -563,116 +562,146 @@ After the first run, here's what you'll see in your terminal. For each
563
562
  The whole script took around a second to complete.
564
563
 
565
564
  ```
565
+ cache() for fires
566
566
  Nothing in cache. Running and storing in cache.
567
- Duration: 311 ms. Wrote ./.sda-cache/fires.ff...68f.geojson.
567
+ Computations done in 350 ms.
568
+ Wrote in cache in 3 ms.
569
+
568
570
 
571
+ cache() for provinces
569
572
  Nothing in cache. Running and storing in cache.
570
- Duration: 397 ms. Wrote ./.sda-cache/provinces.42...55.geojson.
573
+ Computations done in 247 ms.
574
+ Wrote in cache in 1 ms.
571
575
 
576
+
577
+ cache() for firesInsideProvinces
572
578
  Nothing in cache. Running and storing in cache.
573
- Duration: 49 ms. Wrote ./.sda-cache/firesInsideProvinces.71...a8.parquet.
574
-
575
- table firesInsideProvinces:
576
- ┌─────────┬────────────┬─────────────────────────────┬─────────┬───────────┐
577
- (index) │ value │ nameEnglish │ nbFires │ burntArea │
578
- ├─────────┼────────────┼─────────────────────────────┼─────────┼───────────┤
579
- 0 'hectares' 'Quebec' 706 5024737 │
580
- 1 'hectares' 'Northwest Territories' 314 │ 4253907
581
- │ 2 │ 'hectares' │ 'Alberta' │ 1208 │ 3214444 │
582
- 3'hectares' 'British Columbia' 2496 2856625 │
583
- 4'hectares''Saskatchewan' 560 1801903 │
584
- 5'hectares' │ 'Ontario'741 441581
585
- 6'hectares''Yukon' 227 395461 │
586
- 7'hectares' 'Manitoba' 301 199200 │
587
- 8'hectares' 'Nova Scotia' 208 25017 │
588
- 9'hectares' 'Newfoundland and Labrador' 85 21833 │
589
- 10 │ 'hectares' 'Nunavut' 1 2700
590
- 11 │ 'hectares' 'New Brunswick' 202 854
591
- 12 'hectares' null 124 258
592
- └─────────┴────────────┴─────────────────────────────┴─────────┴───────────┘
593
- 13 rows in total (nbRowsToLog: 13)
594
-
595
- SimpleDB - Done in 891 ms
579
+ Computations done in 68 ms.
580
+ Wrote in cache in 0 ms.
581
+
582
+
583
+ Table firesInsideProvinces:
584
+ ┌────────────────┬───────────────────────────┬────────────────┬───────────────┐
585
+ value nameEnglish nbFires burntArea
586
+ VARCHAR/string VARCHAR/string INTEGER/numberDOUBLE/number
587
+ ├────────────────┼───────────────────────────┼────────────────┼───────────────┤
588
+ hectaresQuebec 706 5024737
589
+ hectaresNorthwest Territories 314 4253907
590
+ hectaresAlberta1208 3214444
591
+ hectaresBritish Columbia 2496 2856625
592
+ hectaresSaskatchewan 560 1801903
593
+ hectaresOntario 741 441581
594
+ hectaresYukon 227 395461
595
+ │ hectares Manitoba 301 199200
596
+ │ hectares Nova Scotia 208 25017
597
+ hectares Newfoundland and Labrador 85 21833
598
+ │ hectares │ Nunavut │ 1 │ 2700 │
599
+ hectares │ New Brunswick │ 202 │ 854 │
600
+ └────────────────┴───────────────────────────┴────────────────┴───────────────┘
601
+ 12 rows in total (nbRowsToLog: 13)
602
+
603
+ Bar chart of "burntArea" per "nameEnglish":
604
+
605
+ Quebec ┤████████████████████████████████████████ 5,024,737
606
+
607
+ Northwest Territories ┤██████████████████████████████████ 4,253,907
608
+
609
+ Alberta ┤██████████████████████████ 3,214,444
610
+
611
+ British Columbia ┤███████████████████████ 2,856,625
612
+
613
+ Saskatchewan ┤██████████████ 1,801,903
614
+
615
+ Ontario ┤████ 441,581
616
+
617
+ Yukon ┤███ 395,461
618
+
619
+ Manitoba ┤██ 199,200
620
+
621
+ Nova Scotia ┤ 25,017
622
+
623
+ Newfoundland and Labrador ┤ 21,833
624
+
625
+ Nunavut ┤ 2,700
626
+
627
+ New Brunswick ┤ 854
628
+
629
+
630
+
631
+ SimpleDB - Done in 681 ms / 4 ms spent writing the cache
596
632
  ```
597
633
 
598
634
  If you run the script less than 60 seconds after the first run, here's what
599
635
  you'll see.
600
636
 
601
- Thanks to caching, the script ran five times faster!
637
+ Thanks to caching, the script ran 25 times faster!
602
638
 
603
639
  ```
604
- Found ./.sda-cache/fires.ff...8f.geojson in cache.
605
- ttl of 60 sec has not expired. The creation date is July 5, 2024, at 4:25 p.m.. There are 11 sec, 491 ms left.
606
- Data loaded in 151 ms. Running the computations took 311 ms last time. You saved 160 ms.
607
-
608
- Found ./.sda-cache/provinces.42...55.geojson in cache.
609
- Data loaded in 8 ms. Running the computations took 397 ms last time. You saved 389 ms.
610
-
611
- Found ./.sda-cache/firesInsideProvinces.71...a8.parquet in cache.
612
- ttl of 60 sec has not expired. The creation date is July 5, 2024, at 4:25 p.m.. There are 11 sec, 792 ms left.
613
- Data loaded in 1 ms. Running the computations took 49 ms last time. You saved 48 ms.
614
-
615
- table firesInsideProvinces:
616
- ┌─────────┬────────────┬─────────────────────────────┬─────────┬───────────┐
617
- (index) value │ nameEnglish │ nbFires │ burntArea │
618
- ├─────────┼────────────┼─────────────────────────────┼─────────┼───────────┤
619
- │ 0 │ 'hectares' │ 'Quebec' │ 706 │ 5024737 │
620
- │ 1 │ 'hectares' │ 'Northwest Territories' │ 314 │ 4253907 │
621
- 2 │ 'hectares' │ 'Alberta' │ 1208 │ 3214444 │
622
- 3 │ 'hectares' │ 'British Columbia' │ 2496 │ 2856625 │
623
- 4 │ 'hectares' 'Saskatchewan' │ 560 │ 1801903 │
624
- 5 │ 'hectares' 'Ontario' │ 741 │ 441581 │
625
- 6 │ 'hectares' 'Yukon' │ 227 │ 395461 │
626
- 7 │ 'hectares' 'Manitoba' │ 301 │ 199200 │
627
- 8 │ 'hectares' 'Nova Scotia' │ 208 │ 25017 │
628
- 9 │ 'hectares' │ 'Newfoundland and Labrador' │ 85 │ 21833 │
629
- │ 10 │ 'hectares' │ 'Nunavut' │ 1 │ 2700 │
630
- 11 │ 'hectares' 'New Brunswick' │ 202 │ 854 │
631
- │ 12 │ 'hectares' │ null │ 124 │ 258 │
632
- └─────────┴────────────┴─────────────────────────────┴─────────┴───────────┘
633
- 13 rows in total (nbRowsToLog: 13)
634
-
635
- SimpleDB - Done in 184 ms / You saved 707 ms by using the cache
640
+ cache() for fires
641
+ Found in cache.
642
+ ttl of 1 min, 0 sec, 0 ms has not expired.
643
+ The creation date is May 28, 2026, at 4:37 p.m..
644
+ There are 54 sec, 941 ms left.
645
+ Data loaded in 21 ms.
646
+ Running computations previously took 312 ms.
647
+ You saved 291 ms.
648
+
649
+
650
+ cache() for provinces
651
+ Found in cache.
652
+ Data loaded in 0 ms.
653
+ Running computations previously took 247 ms.
654
+ You saved 247 ms.
655
+
656
+
657
+ cache() for firesInsideProvinces
658
+ Found in cache.
659
+ ttl of 1 min, 0 sec, 0 ms has not expired.
660
+ The creation date is May 28, 2026, at 4:37 p.m..
661
+ There are 54 sec, 972 ms left.
662
+ Data loaded in 0 ms.
663
+ Running computations previously took 50 ms.
664
+ You saved 50 ms.
665
+
666
+ [Note to readers: I have cut the table and chart.]
667
+
668
+ SimpleDB - Done in 27 ms / 588 ms saved by using the cache
636
669
  ```
637
670
 
638
671
  And if you run the script 60 seconds later, the fires and join/summary caches
639
672
  will have expired, but not the provinces one. Some of the code will have run,
640
- but not everything. The script still ran 1.5 times faster. This is quite handy
641
- in complex analysis with big datasets. The less you wait, the more fun you have!
673
+ but not everything. The script still ran roughly 1.5 times faster. This is quite
674
+ handy in complex analysis with big datasets. The less you wait, the more fun you
675
+ have!
642
676
 
643
677
  ```
644
- Found ./.sda-cache/fires.ff...8f.geojson in cache
645
- ttl of 60 sec has expired. The creation date is July 5, 2024, at 4:25 p.m.. It's is 4 min, 1 sec, 172 ms ago.
678
+ cache() for fires
679
+ Found in cache.
680
+ ttl of 1 min, 0 sec, 0 ms has expired.
681
+ The creation date is May 28, 2026, at 4:37 p.m..
682
+ It's is 1 min, 17 sec, 465 ms ago.
646
683
  Running and storing in cache.
647
- Duration: 424 ms. Wrote ./.sda-cache/fires.ff...8f.geojson.
684
+ Computations done in 340 ms.
685
+ Wrote in cache in 3 ms.
686
+
648
687
 
649
- Found ./.sda-cache/provinces.42...55.geojson in cache.
650
- Data loaded in 10 ms. Running the computations took 397 ms last time. You saved 387 ms.
688
+ cache() for provinces
689
+ Found in cache.
690
+ Data loaded in 1 ms.
691
+ Running computations previously took 247 ms.
692
+ You saved 246 ms.
651
693
 
652
- Fond ./.sda-cache/firesInsideProvinces.71...a8.parquet in cache
653
- ttl of 60 sec has expired. The creation date is July 5, 2024, at 4:25 p.m.. It's is 4 min, 1 sec, 239 ms ago.
694
+
695
+ cache() for firesInsideProvinces
696
+ Found in cache.
697
+ ttl of 1 min, 0 sec, 0 ms has expired.
698
+ The creation date is May 28, 2026, at 4:37 p.m..
699
+ It's is 1 min, 17 sec, 758 ms ago.
654
700
  Running and storing in cache.
655
- Duration: 42 ms. Wrote ./.sda-cache/firesInsideProvinces.71...a8.parquet.
656
-
657
- table firesInsideProvinces:
658
- ┌─────────┬────────────┬─────────────────────────────┬─────────┬───────────┐
659
- │ (index) │ value │ nameEnglish │ nbFires │ burntArea │
660
- ├─────────┼────────────┼─────────────────────────────┼─────────┼───────────┤
661
- │ 0 │ 'hectares' │ 'Quebec' │ 706 │ 5024737 │
662
- │ 1 │ 'hectares' │ 'Northwest Territories' │ 314 │ 4253907 │
663
- │ 2 │ 'hectares' │ 'Alberta' │ 1208 │ 3214444 │
664
- │ 3 │ 'hectares' │ 'British Columbia' │ 2496 │ 2856625 │
665
- │ 4 │ 'hectares' │ 'Saskatchewan' │ 560 │ 1801903 │
666
- │ 5 │ 'hectares' │ 'Ontario' │ 741 │ 441581 │
667
- │ 6 │ 'hectares' │ 'Yukon' │ 227 │ 395461 │
668
- │ 7 │ 'hectares' │ 'Manitoba' │ 301 │ 199200 │
669
- │ 8 │ 'hectares' │ 'Nova Scotia' │ 208 │ 25017 │
670
- │ 9 │ 'hectares' │ 'Newfoundland and Labrador' │ 85 │ 21833 │
671
- │ 10 │ 'hectares' │ 'Nunavut' │ 1 │ 2700 │
672
- │ 11 │ 'hectares' │ 'New Brunswick' │ 202 │ 854 │
673
- │ 12 │ 'hectares' │ null │ 124 │ 258 │
674
- └─────────┴────────────┴─────────────────────────────┴─────────┴───────────┘
675
- 13 rows in total (nbRowsToLog: 13)
676
-
677
- SimpleDB - Done in 594 ms / You saved 297 ms by using the cache
701
+ Computations done in 48 ms.
702
+ Wrote in cache in 1 ms.
703
+
704
+ [Note to readers: I have cut the table and chart.]
705
+
706
+ SimpleDB - Done in 399 ms / 246 ms saved by using the cache / 4 ms spent writing the cache
678
707
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nshiab/simple-data-analysis",
3
- "version": "5.20.0",
3
+ "version": "5.20.2",
4
4
  "description": "Easy-to-use and high-performance TypeScript library for data analysis. Works with tabular, geospatial and vector data.",
5
5
  "repository": {
6
6
  "type": "git",