You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cleaned up the functions, added back dependencias to DataFRames, JSONTables and CSV and now get_nass returns DF for JSON and CSV. Cleaned up and updated the README.md. Added compat bounds
Copy file name to clipboardExpand all lines: README.md
+27-40Lines changed: 27 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,6 @@
8
8
```@julia
9
9
add USDAQuickStats
10
10
```
11
-
12
11
## Index
13
12
14
13
The package contains following functions:
@@ -19,22 +18,22 @@ The package contains following functions:
19
18
-`get_nass`
20
19
21
20
## Tutorial and Workflow
22
-
### Set up an Envionment Variable for the NASS API key
21
+
### Set up an Environment Variable for the NASS API key
23
22
24
-
To start using the API, you first need to get a **personal API key**.
23
+
To start using the API, the user first needs to get a **personal API key**.
25
24
26
-
You can request a NASS API key at [https://quickstats.nass.usda.gov/api](https://quickstats.nass.usda.gov/api).
25
+
The user can request a NASS API key at [https://quickstats.nass.usda.gov/api](https://quickstats.nass.usda.gov/api).
27
26
28
-
Once you receive your key, you can either set it up as an environment variable called USDA_QUICK_SURVEY_KEY" or set it up during a new julia session with
27
+
The API keycan be saved as an environment variable called "USDA_QUICK_SURVEY_KEY" or used during each new Julia session by setting it up using:
29
28
30
29
```@julia
31
30
using USDAQuickStats
32
31
set_api_key("YOUR_KEY"::String)
33
32
```
34
33
35
-
where you manually replace `YOUR_KEY` with your private API key.
34
+
replacing `"YOUR_KEY"` with the private API key as a string.
36
35
37
-
If you are constantly using the database, you might want to make your key into a permanent variable in your environment.
36
+
Saving the key into a permanent variable in your environment is dependent on the operating system.
38
37
39
38
### Query the database
40
39
@@ -46,45 +45,23 @@ The API for the Quick Stats database provides three main functions:
46
45
47
46
**get_nass**
48
47
48
+
`get_nass(args...; format="json")
49
+
`
49
50
The main function is `get_nass`, which queries the main USDA Quick Stats database.
50
51
51
-
The description of the different fields for the database is available [here].(https://quickstats.nass.usda.gov/api)
52
+
`args...` is a list of the different headers from the database that can be queried. Each argument is a string with the name of the header and the value from that header in uppercase, e.g. `"header=VALUE`. The description of the different headers (also called columns) for the database is available [here].(https://quickstats.nass.usda.gov/api)
52
53
53
-
In this example I queried the survey data for oranges in California (CA) for the year 2019. I'm interested in the variables "ACRES BEARING" and "PRICE RECEIVED".
54
+
The `format` keyword can be added to the query after a semicolon `;` and defines the format of the response. It is set to `JSON` as a default, other formats provided by the database are `CSV` and `XML`.
The function returns a DataFrame with the requested query for the `JSON` and `CSV` formats, no DataFrame has been implemented for the `XML` format yet, PR's welcome.
59
57
60
-
```@julia
61
-
JSON3.Object{Array{UInt8,1},Array{UInt64,1}} with 1 entry:
62
-
:data => JSON3.Object[{…
63
-
```
64
-
65
-
The function produces a JSON object by default which can be saved and parsed in different ways.
58
+
In the following example, the survey data for oranges in California (CA) for the year 2019 was queried for information about the headers "ACRES BEARING" and "PRICE RECEIVED".
66
59
67
-
The `format` keyword can be added to the query after a semicolon `;` to request other formats outputs, CSV and XML are also available.
60
+
Notice that header values that have spaces in them need to be passed with the symbol `%20` replacing the space. In general, no spaces are allowed in the query.
`get_param_values` is a helper query that allow user to check the values of a parameter in the query. This is useful when constructing different query strings.
82
+
`get_param_values(arg)` is a helper query that allow user to check the values of a field `arg` from the database. This is useful when constructing different query strings, as it allows the user to determine which values are available on each field.
106
83
107
84
```@julia
108
-
get_param_values("sector_desc")
85
+
db_values = get_param_values("sector_desc")
109
86
```
110
87
111
88
output
@@ -115,12 +92,20 @@ JSON3.Object{Array{UInt8,1},Array{UInt64,1}} with 1 entry:
If the user need to access the values, they are available as an array `db_values[:sector_desc]`.
96
+
118
97
**get_counts**
119
98
120
-
`get_counts` is a helper query that allows user to check the number of records a query will produce before performing the query. This is important because the USDA Quick Stats API has a limit of 50,000 records per query. Any query requesting a number of records larger than this limit will fail.
99
+
`get_counts(args...)` is a helper query that allows user to check the number of records a query using the fields in `args...` will produce before performing the query. This is important because the USDA Quick Stats API has a limit of 50,000 records per query. Any query requesting a number of records larger than this limit will fail.
100
+
101
+
As in `get_nass`, `args...` is a list of the different headers from the database that can be queried. Each argument is a string with the name of the header and the value from that header in uppercase, e.g. `"header=VALUE`. The description of the different headers (also called columns) for the database is available [here].(https://quickstats.nass.usda.gov/api)
102
+
103
+
In the following example, the number of records for survey data for oranges in California (CA) for the year 2019 with information about the headers "ACRES BEARING" and "PRICE RECEIVED" was queried.
104
+
105
+
Notice that header values that have spaces in them need to be passed with the symbol `%20` replacing the space. In general, no spaces are allowed in the query.
0 commit comments