-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
57 lines (47 loc) · 2.78 KB
/
Makefile
File metadata and controls
57 lines (47 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! /usr/bin/make -f
# Until we get our own bower setup, we continue to get other projects by hand.
# We can leave these in the original folder however.
path:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
PG.service:=farm-budgets-data
PG:=psql service=${PG.service} --variable=cwd=${path}
#include nass.mk
files.csv:=$(shell find . -name files.csv)
auto.csv:=$(shell find . -name units.csv -o -name materials.csv -o -name material_requirements.csv -o -name prices.csv)
production.csv:=$(wildcard ucd/??-[A-Z]*.csv)
yields.csv:=$(wildcard ucd/??-yields.csv)
INFO::
@echo files.csv:=${files.csv}
@echo auto.csv:=${auto.csv}
echo ${production.csv}
echo ${prices.csv}
import:
${PG} -f 'sql/farm-budgets-data.sql';
poplar-example.json:
${PG} -At --pset=footer -c 'select budget from "farm-budgets-data".budget_as_json' |\
jq 'del(.[][][] | select(. == null)) | del(.[][][]|select(. == "")) | del(.[][][][][] | select(. == null)) | del(.[][][][][][][] | select(. ==null))' 2>/dev/null > $@
foo:
# for c in ${production.csv}; do\
# ${PG} -c "\COPY farm_budget_data.production (material,location,phase,operation,commodity,unit,amount) from $$c with csv header";\
# f=`basename $$c .csv | sed -e 's/^...//'`;\
# ${PG} -c "update farm_budget_data.production set commodity=upper(trim( both from replace('$$f','_',' '))), filename='$$c' where commodity is null";\
# ${PG} -c "update farm_budget_data.production set filename='$$c' where filename is null";\
# done;
# for p in ${prices.csv}; do\
# ${PG} -c "\COPY farm_budget_data.price (material,location,year,price,unit) from $$p with csv header";\
# ${PG} -c "update farm_budget_data.price set filename='$$p' where filename is null";\
# done;
# for p in ${yields.csv}; do\
# ${PG} -c "\COPY farm_budget_data.yield (commodity,location,unit,value) from $$p with csv header";\
# ${PG} -c "update farm_budget_data.yield set filename='$$p' where filename is null";\
# done;
export:
${PG} -f 'sql/export.sql';
for f in `${PG} --pset=footer -A -t -c "select distinct filename from farm_budget_data.production"`; do\
${PG} -c "\COPY (select distinct material,location,phase,operation,commodity,unit,amount from farm_budget_data.production where filename='$$f' order by phase,material,operation,commodity) to $$f with csv header";\
done;
for f in `${PG} --pset=footer -A -t -c "select distinct filename from farm_budget_data.price"`; do\
${PG} -c "\COPY (select material,location,year,price,unit from farm_budget_data.price where filename='$$f' order by material,unit) to $$f with csv header";\
done;
for f in `${PG} --pset=footer -A -t -c "select distinct filename from farm_budget_data.yield"`; do\
${PG} -c "\COPY (select commodity,location,unit,value from farm_budget_data.yield where filename='$$f' order by location,commodity,unit) to $$f with csv header";\
done;