Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kma 163213435 write import fuel function #1793

Merged
merged 50 commits into from Mar 5, 2019
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a648bc5
Add pseudocode for function to save fuel price data
kimallen Feb 6, 2019
0d4fc4b
Add function to calculate baseline rate; add testing file; fill out s…
kimallen Feb 7, 2019
6bbb49e
Write function to fetch twelve months of fuel prices from db
kimallen Feb 7, 2019
aa1dbcb
Add test for fetch of last 12 months of fuel data
kimallen Feb 8, 2019
b31c73f
Debug off-by-1 error in test
kimallen Feb 8, 2019
788438b
Move files to service directory; fill out local functions; refactor test
kimallen Feb 9, 2019
b9f1e6a
Flush out fields and values to save in DB; add functionality to retur…
kimallen Feb 11, 2019
05737b0
Add a CLI command that calls the fuel price function
kimallen Feb 12, 2019
0e5e518
Adjust datestring format and loop to get correct months from db; add …
kimallen Feb 12, 2019
966b03b
Add more error handling; adjust structs to be able to access fuel dat…
kimallen Feb 13, 2019
b396c69
Add error handling; uncomment and adjust code to get earliest week of…
kimallen Feb 13, 2019
e9925b8
Add components for adding EIA_KEY as an envt variable
kimallen Feb 13, 2019
e5c69b0
Move files from service directory to services directory (and remove s…
kimallen Feb 14, 2019
756d981
Add (failing) test for AddFuelDieselPricesCall
kimallen Feb 14, 2019
89edd43
Change names to align with our service object conventions; fix format…
kimallen Feb 16, 2019
f558c26
Rename files again to match struct rather than method
kimallen Feb 18, 2019
c425bfa
Replace references to time.Now() with clock; Make fetch of last few m…
kimallen Feb 20, 2019
9acf402
Account for error returned as successful json response; add error han…
kimallen Feb 21, 2019
9045142
Fix key name in flag; add to config definitions
kimallen Feb 21, 2019
82ee2eb
Fix query using date_part; adjust years for currentDate and shipmentD…
kimallen Feb 21, 2019
75502cc
Pull out actual fetch into its own function
kimallen Feb 21, 2019
5834f55
Add fetch funciton as part of struct and start mock function for test…
kimallen Feb 22, 2019
10c7c2d
Set up api key and eia url as environment variablesto; fix 1 off bug …
kimallen Feb 23, 2019
4f6de55
Use function to hide url and key; use raw url for container configs
kimallen Feb 25, 2019
a678e4a
Parse and add query to url
kimallen Feb 25, 2019
394bdb2
Make log more explicit
kimallen Feb 26, 2019
f234c41
Add function to find the first Monday, or next non-holiday after the …
kimallen Feb 27, 2019
31f2b03
Outline tests to write in test file
kimallen Feb 27, 2019
2327ff8
Fill in test cases and test case data; remove commented code
kimallen Feb 28, 2019
16dcc73
Fix data structure in mocked responses; move tests to where db is in …
kimallen Feb 28, 2019
963afa9
Push changes on Gopkg from new pkg
kimallen Feb 28, 2019
dfa4e03
Add test for BaselineRate value saved to db
kimallen Feb 28, 2019
3e4d8f7
Fix type of expected values and change to use actual values from onli…
kimallen Feb 28, 2019
e385f5d
Make baselineRate 0 if the fuel price is less than or equal to the ba…
kimallen Feb 28, 2019
f767abc
Fix indenting and be more specific in error message
kimallen Mar 1, 2019
6c46709
Fix verrs error conditional; refactor getFirstMondayOrHolidayAfter; r…
kimallen Mar 1, 2019
1cc84ff
Add missing server test; adjust awkward error message
kimallen Mar 1, 2019
6804ae0
Make clocks UTC; rewrite query style for BETWEEN
kimallen Mar 1, 2019
5a07dbe
Merge branch 'master' into kma-163213435-write-import-fuel-function
kimallen Mar 2, 2019
5c3142a
Account for Monday holiday; refactor conditionals
kimallen Mar 2, 2019
afb3626
Change type of OtherData to accomodate unknown data; add test for non…
kimallen Mar 3, 2019
50c3013
Fix path to cmd file
kimallen Mar 4, 2019
45d9f36
Add omitempty to fields that could not exist in data structure
kimallen Mar 4, 2019
ac45160
Use more specific format types in string interpolation; remove TODO c…
kimallen Mar 4, 2019
770ca2d
Replace default logger with custom logger
kimallen Mar 4, 2019
99e035e
Refactor pubDateString conversion; fix zap.logger type conflict
kimallen Mar 4, 2019
1cdf848
Move tests into subtests; add comments to explain formula used to get…
kimallen Mar 5, 2019
7babf17
Add comment for intInSlice function
kimallen Mar 5, 2019
b2a1b9b
Handle as error if type assertions fail by using 'ok' syntax
kimallen Mar 5, 2019
ab10e52
Merge branch 'master' into kma-163213435-write-import-fuel-function
kimallen Mar 5, 2019
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+22 −5
Diff settings

Always

Just for now

Handle as error if type assertions fail by using 'ok' syntax

  • Loading branch information...
kimallen committed Mar 5, 2019
commit b2a1b9b99dc6b7c4eb45b0200b025055ecc5c77b
@@ -196,7 +196,11 @@ func (u DieselFuelPriceStorer) getMissingRecordsPrices(missingMonths []int) (fue
// handle all possible responses
if len(result.OtherData) != 0 {
if result.OtherData["error"] == 1 {
return nil, errors.New(result.OtherData["error"].(string))
errMsg, ok := result.OtherData["error"].(string)
if !ok {
return nil, errors.New("data returned from api as error failed string type assertion")
}
return nil, errors.New(errMsg)
}
return nil, errors.New("Unexpected response from GET request to eia.gov's open data")
} else if len(result.SeriesData) == 0 {
@@ -206,15 +210,22 @@ func (u DieselFuelPriceStorer) getMissingRecordsPrices(missingMonths []int) (fue

// select the fuel data for the first week of data available for the month
dateString := ""
var ok bool
var price float64
if len(monthFuelData) >= 1 {
weekIndex := 0
var min int

// find earliest date(String) in the month
for i, weekData := range monthFuelData {
dateString = weekData[0].(string)
price = weekData[1].(float64)
dateString, ok = weekData[0].(string)
if !ok {
return nil, errors.New("data returned from api as pub_date failed string type assertion")
}
price, ok = weekData[1].(float64)
if !ok {
return nil, errors.New("data returned as fuel price failed float64 type assertion")
}
pubDateAsInt, err := strconv.Atoi(dateString)
if err != nil {
return nil, errors.Wrap(err, "pubDate conversion from string to int")
@@ -224,8 +235,14 @@ func (u DieselFuelPriceStorer) getMissingRecordsPrices(missingMonths []int) (fue
weekIndex = i
}
}
dateString = monthFuelData[weekIndex][0].(string)
price = monthFuelData[weekIndex][1].(float64)
dateString, ok = monthFuelData[weekIndex][0].(string)
if !ok {
return nil, errors.New("data returned from api as pub_date failed string type assertion")
}
price, ok = monthFuelData[weekIndex][1].(float64)
if !ok {
return nil, errors.New("data returned as fuel price failed float64 type assertion")
}
} else if len(monthFuelData) == 0 {
// Throw error if data should be available but is not
if month == int(currentDate.Month()) {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.