relpipe-data/examples/guile-file-count-size-sum.sh
author František Kučera <franta-hg@frantovo.cz>
Fri, 25 Sep 2020 14:38:24 +0200
branchv_0
changeset 316 d7ae02390fac
parent 248 e76ca9f7d6cb
permissions -rwxr-xr-x
relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
248
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
#!/bin/bash
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
# argument: directory path
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
# prints file count and sum of file sizes
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
find "$1" -type f -print0 \
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
	| relpipe-in-filesystem \
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
		--file path \
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
		--file size \
316
d7ae02390fac relpipe-tr-guile.cpp → relpipe-tr-scheme.cpp
František Kučera <franta-hg@frantovo.cz>
parents: 248
diff changeset
    10
	| relpipe-tr-scheme \
248
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
		--relation 'f.*' \
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
		--output-attribute 'count' integer \
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
		--output-attribute 'sum'   integer \
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
		--before-records '
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
			(define $sum   0)
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
			(define $count 0)
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
			(define return-sum #f)' \
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
		--for-each '
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
			(set! $sum   (+ $sum   $size) )
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
			(set! $count (+ $count 1    ) )' \
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
		--where '#f' \
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
		--after-records '(set! return-sum #t)' \
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
		--has-more-records '
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
			(if return-sum
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
				(begin (set! return-sum #f) #t)
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
				#f
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
			)' \
e76ca9f7d6cb examples: Aggregating data with Guile
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
	| relpipe-out-tabular