Skip to content

Commit

Permalink
Added in price data, specific only to the commodities in the SWAP setup
Browse files Browse the repository at this point in the history
  • Loading branch information
qjhart committed Jun 2, 2015
1 parent 85706c1 commit 3e7a731
Show file tree
Hide file tree
Showing 3 changed files with 675 additions and 776 deletions.
63 changes: 61 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ PG.service:=farm-budgets-data

PG:=psql service=${PG.service} --variable=cwd=${path}

# This key is not included, you need to get one yourself, the
include usda.key

info:
@echo USDA KEY : ${usda.key}


nass-summary:=nass-summary-0.6-alpha

Expand All @@ -22,8 +28,9 @@ ${nass-summary}:${tgz}
nass-summary-tables: ${nass-summary}
${PG} --variable='nassdir=${nass-summary}' -f sql/nass-summary.sql

nass.csv:=$(patsubst %,nass/%.csv,county_adc land_rent commodity_harvest commodity_county_yield \
commodity_yield commodity_price commodity_list)
nass.csv:=$(patsubst %,nass/%.csv,county_adc land_rent \
commodity_harvest commodity_county_yield \
commodity_yield commodity_list)

.PHONY:nass.csv

Expand All @@ -36,6 +43,58 @@ ${nass.csv}:nass/%.csv:${nass-summary}
production.csv:=$(wildcard ucd/??-[A-Z]*.csv)
prices.csv:=$(wildcard ucd/??-prices.csv)

commodities:=HAY HAY+%26+HAYLAGE HAYLAGE GRASSES\
BARLEY BEANS CANOLA CORN LENTILS OATS POTATOES WHEAT SUGARBEETS

stats.harvest:=PRODUCTION AREA+HARVESTED WATER+APPLIED

states:=CA WA ID MT OR

usda.get=http://quickstats.nass.usda.gov/api/api_GET?key=${usda.key}&format=JSON&freq_desc=ANNUAL

empty:=
space:=${empty} ${empty}
comma:=,

usda.states:=$(subst ${space},&,$(patsubst %,state_alpha=%,${states}))
usda.com:=$(subst ${space},&,$(patsubst %,commodity_desc=%,${commodities}))
usda.stats.harvest:=$(subst ${space},&,$(patsubst %,statisitccat_desc=%,${stats.harvest}))

columns:=year commodity_desc statisticcat_desc county_code source_desc \
unit_desc prodn_practice_desc freq_desc asd_desc \
domain_desc util_practice_desc Value reference_period_desc \
class_desc asd_code agg_level_desc state_ansi domaincat_desc \
state_fips_code group_desc

jq.col:=$(subst ${space},${comma},$(patsubst %,.%,${columns}))

price.json:
curl "${usda.get}&${usda.states}&${usda.com}&statisticcat_desc=PRICE+RECEIVED&year__GE=2007" > $@

yield.json:
curl "${usda.get}&${usda.states}&${usda.com}&statisticcat_desc=YIELD&year__GE=2007" > $@

production.json:
curl "${usda.get}&${usda.states}&${usda.com}&statisticcat_desc=PRODUCTION&year__GE=2007" > $@ > $@

area.json:
curl "${usda.get}&state_alpha=CA&${usda.com}&statisticcat_desc=AREA+HARVESTED&year__GE=2007" > $@
curl "${usda.get}&state_alpha=ID&${usda.com}&statisticcat_desc=AREA+HARVESTED&year__GE=2007" >> $@
curl "${usda.get}&state_alpha=MT&${usda.com}&statisticcat_desc=AREA+HARVESTED&year__GE=2007" >> $@
curl "${usda.get}&state_alpha=OR&${usda.com}&statisticcat_desc=AREA+HARVESTED&year__GE=2007" >> $@
curl "${usda.get}&state_alpha=WA&${usda.com}&statisticcat_desc=AREA+HARVESTED&year__GE=2007" >> $@

nass/commodity_avg_price.csv nass/commodity_price.csv:nass/%.csv:
${PG} -c '\COPY (select * from farm_budget_data.$*) to $@ with csv header'

price.csv area.csv production.csv yield.csv:%.csv:%.json
jq --raw-output '.data | .[] | [${jq.col}] | @csv' < $< > $@

test:
for c in ${commodities}; do \
curl "${usda.get}&${usda.states}&commodity_desc=$$c&year__GE=2012" > $$c.json;\
done

import:
${PG} -c 'create schema farm_budget_data' || true
${PG} -f 'sql/production.sql';
Expand Down
73 changes: 73 additions & 0 deletions nass/commodity_avg_price.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
location,commodity,price,unit
06,BARLEY,5.09,$ / BU
06,"BEANS, DRY EDIBLE",54.86,$ / CWT
06,HAY,179.50,$ / TON
06,"HAY, ALFALFA",189.00,$ / TON
06,"HAY, (EXCL ALFALFA)",148.13,$ / TON
06,OATS,3.57,$ / BU
06,POTATOES,13.44,$ / CWT
06,"POTATOES, FALL",8.53,$ / CWT
06,"POTATOES, SPRING",14.69,$ / CWT
06,"POTATOES, SUMMER",13.47,$ / CWT
06,"POTATOES, WINTER",18.87,$ / CWT
06,SUGARBEETS,56.71,$ / TON
06,WHEAT,6.70,$ / BU
06,"WHEAT, SPRING, DURUM",6.29,$ / BU
06,"WHEAT, WINTER",5.77,$ / BU
16,BARLEY,5.33,$ / BU
16,"BEANS, DRY EDIBLE",32.61,$ / CWT
16,CANOLA,19.42,$ / CWT
16,HAY,171.63,$ / TON
16,"HAY, ALFALFA",174.38,$ / TON
16,"HAY, (EXCL ALFALFA)",136.50,$ / TON
16,LENTILS,28.84,$ / CWT
16,OATS,2.80,$ / BU
16,POTATOES,7.20,$ / CWT
16,"POTATOES, FALL",7.20,$ / CWT
16,SUGARBEETS,48.40,$ / TON
16,WHEAT,6.46,$ / BU
16,"WHEAT, SPRING, DURUM",7.55,$ / BU
16,"WHEAT, SPRING, (EXCL DURUM)",6.77,$ / BU
16,"WHEAT, WINTER",6.29,$ / BU
30,BARLEY,5.28,$ / BU
30,"BEANS, DRY EDIBLE",30.56,$ / CWT
30,CANOLA,19.18,$ / CWT
30,HAY,109.38,$ / TON
30,"HAY, ALFALFA",110.50,$ / TON
30,"HAY, (EXCL ALFALFA)",103.38,$ / TON
30,LENTILS,23.78,$ / CWT
30,OATS,3.00,$ / BU
30,POTATOES,11.71,$ / CWT
30,"POTATOES, FALL",11.71,$ / CWT
30,SUGARBEETS,54.63,$ / TON
30,WHEAT,6.79,$ / BU
30,"WHEAT, SPRING, DURUM",8.11,$ / BU
30,"WHEAT, SPRING, (EXCL DURUM)",7.12,$ / BU
30,"WHEAT, WINTER",6.39,$ / BU
41,BARLEY,4.21,$ / BU
41,"BEANS, DRY EDIBLE",35.84,$ / CWT
41,CANOLA,20.47,$ / CWT
41,HAY,189.38,$ / TON
41,"HAY, ALFALFA",190.00,$ / TON
41,"HAY, (EXCL ALFALFA)",186.38,$ / TON
41,OATS,3.40,$ / BU
41,POTATOES,8.11,$ / CWT
41,"POTATOES, FALL",8.11,$ / CWT
41,SUGARBEETS,48.40,$ / TON
41,WHEAT,6.83,$ / BU
41,"WHEAT, SPRING, (EXCL DURUM)",7.40,$ / BU
41,"WHEAT, WINTER",6.72,$ / BU
53,BARLEY,4.11,$ / BU
53,"BEANS, DRY EDIBLE",34.61,$ / CWT
53,CANOLA,22.15,$ / CWT
53,HAY,190.25,$ / TON
53,"HAY, ALFALFA",186.25,$ / TON
53,"HAY, (EXCL ALFALFA)",202.13,$ / TON
53,LENTILS,29.55,$ / CWT
53,OATS,2.98,$ / BU
53,POTATOES,7.45,$ / CWT
53,"POTATOES, FALL",7.45,$ / CWT
53,SUGARBEETS,39.45,$ / TON
53,WHEAT,6.67,$ / BU
53,"WHEAT, SPRING, (EXCL DURUM)",7.39,$ / BU
53,"WHEAT, WINTER",6.49,$ / BU
Loading

0 comments on commit 3e7a731

Please sign in to comment.