@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.
- package/README.md +130 -101
- 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, "
|
|
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("
|
|
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 = "
|
|
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 = "
|
|
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://
|
|
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
|
|
471
|
-
automatically added to your `.gitignore` and you can use
|
|
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
|
|
532
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
│
|
|
580
|
-
│
|
|
581
|
-
|
|
582
|
-
│
|
|
583
|
-
│
|
|
584
|
-
│
|
|
585
|
-
│
|
|
586
|
-
│
|
|
587
|
-
│
|
|
588
|
-
│
|
|
589
|
-
│
|
|
590
|
-
│
|
|
591
|
-
│
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
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/number │ DOUBLE/number │
|
|
587
|
+
├────────────────┼───────────────────────────┼────────────────┼───────────────┤
|
|
588
|
+
│ hectares │ Quebec │ 706 │ 5024737 │
|
|
589
|
+
│ hectares │ Northwest Territories │ 314 │ 4253907 │
|
|
590
|
+
│ hectares │ Alberta │ 1208 │ 3214444 │
|
|
591
|
+
│ hectares │ British Columbia │ 2496 │ 2856625 │
|
|
592
|
+
│ hectares │ Saskatchewan │ 560 │ 1801903 │
|
|
593
|
+
│ hectares │ Ontario │ 741 │ 441581 │
|
|
594
|
+
│ hectares │ Yukon │ 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
|
|
637
|
+
Thanks to caching, the script ran 25 times faster!
|
|
602
638
|
|
|
603
639
|
```
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
Data loaded in
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
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
|
|
641
|
-
in complex analysis with big datasets. The less you wait, the more fun you
|
|
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
|
-
|
|
645
|
-
|
|
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
|
-
|
|
684
|
+
Computations done in 340 ms.
|
|
685
|
+
Wrote in cache in 3 ms.
|
|
686
|
+
|
|
648
687
|
|
|
649
|
-
|
|
650
|
-
|
|
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
|
-
|
|
653
|
-
|
|
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
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
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