Skip to content

Commit

Permalink
feat: add script to process csvs from yijing app
Browse files Browse the repository at this point in the history
  • Loading branch information
montchr committed Oct 13, 2024
1 parent 8e8e093 commit 3fb97ac
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions home/profiles/development/data-wrangling.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# as CSV, TSV, and tabular JSON"
# <https://github.com/johnkerl/miller>
pkgs.miller

# TODO: not yet: <https://github.com/NixOS/nixpkgs/pull/296424>
# pkgs.qsv # "CSVs sliced, diced & analyzed" (maintained fork of xsv)
pkgs.tidy-viewer # `tv` => Pretty-print CSV files
Expand Down
1 change: 1 addition & 0 deletions packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
tinty = callPackage ./tinty/package.nix { };
tomlfmt = callPackage ./tomlfmt/package.nix { };
wp-to-psr-4 = callPackage ./wp-to-psr-4/package.nix { };
yijing-q-merge-csv = callPackage ./yijing-q-merge-csv/package.nix { };

# TODO: not ready
# wp-cli = callPackage ./wp-cli/package.nix { };
Expand Down
25 changes: 25 additions & 0 deletions packages/yijing-q-merge-csv/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ miller, writeShellApplication }:
let
initialOrder = "datetime,method,setting,query,hex_primary,hex_relating,unknown_1,date,unknown_2,unknown_3,seq_primary,seq_relating,uuid";
newOrder = "datetime,relevance,query,setting,hex_primary,seq_primary,hex_relating,seq_relating";
in
writeShellApplication {
name = "yijing-q-merge-csv";
runtimeInputs = [ miller ];
text = ''
DIR=''${1:-$HOME/Documents/data/yijing/app}
mlr --csv \
--ifs ';' \
--lazy-quotes \
--implicit-csv-header \
label ${initialOrder} \
then cat \
then sort -f datetime \
then uniq -a -c \
then rename count,relevance \
then reorder -f ${newOrder} \
$DIR/_raw/YiJing-Q-* \
> $DIR/yijing-q.merged.csv
'';
}

0 comments on commit 3fb97ac

Please sign in to comment.