comparison pkg/imports/agm.go @ 4177:8b75ac5e243e

Made 'staticcheck' happy with pgxutils package.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 05 Aug 2019 17:16:46 +0200
parents 5a650cde0574
children 51e90370eced
comparison
equal deleted inserted replaced
4176:c9315a6eb2c2 4177:8b75ac5e243e
218 218
219 for j := range headerFields { 219 for j := range headerFields {
220 if headerFields[j].name == h { 220 if headerFields[j].name == h {
221 if *headerFields[j].idx != -1 { 221 if *headerFields[j].idx != -1 {
222 return fmt.Errorf( 222 return fmt.Errorf(
223 "There is more than one column namend '%s'", h) 223 "there is more than one column namend '%s'", h)
224 } 224 }
225 *headerFields[j].idx = i 225 *headerFields[j].idx = i
226 continue nextHeader 226 continue nextHeader
227 } 227 }
228 } 228 }
233 if headerFields[i].name != "unit" && *headerFields[i].idx == -1 { 233 if headerFields[i].name != "unit" && *headerFields[i].idx == -1 {
234 missing = append(missing, headerFields[i].name) 234 missing = append(missing, headerFields[i].name)
235 } 235 }
236 } 236 }
237 if len(missing) > 0 { 237 if len(missing) > 0 {
238 return fmt.Errorf("Missing columns: %s", strings.Join(missing, ", ")) 238 return fmt.Errorf("missing columns: %s", strings.Join(missing, ", "))
239 } 239 }
240 240
241 return nil 241 return nil
242 } 242 }
243 243
334 } 334 }
335 335
336 gids := row[fkGaugeIDIdx] 336 gids := row[fkGaugeIDIdx]
337 gid, err := models.IsrsFromString(gids) 337 gid, err := models.IsrsFromString(gids)
338 if err != nil { 338 if err != nil {
339 return nil, fmt.Errorf("Invalid ISRS code line %d: %v", line, err) 339 return nil, fmt.Errorf("invalid ISRS code line %d: %v", line, err)
340 } 340 }
341 341
342 if exists, found := checkedGauges[*gid]; found { 342 if exists, found := checkedGauges[*gid]; found {
343 if !exists { 343 if !exists {
344 // Just ignore the line since we have already warned 344 // Just ignore the line since we have already warned
364 } 364 }
365 } 365 }
366 366
367 md, err := guessDate(row[measureDateIdx]) 367 md, err := guessDate(row[measureDateIdx])
368 if err != nil { 368 if err != nil {
369 return nil, fmt.Errorf("Invalid 'measure_date' line %d: %v", line, err) 369 return nil, fmt.Errorf("invalid 'measure_date' line %d: %v", line, err)
370 } 370 }
371 if v := mdMinMax[*gid]; v != nil { 371 if v := mdMinMax[*gid]; v != nil {
372 if md.Before(v[0]) { 372 if md.Before(v[0]) {
373 v[0] = md 373 v[0] = md
374 } 374 }
385 newDateIssue := time.Now() 385 newDateIssue := time.Now()
386 newReferenceCode := "ZPG" 386 newReferenceCode := "ZPG"
387 387
388 value, err := strconv.ParseFloat(row[valueIdx], 32) 388 value, err := strconv.ParseFloat(row[valueIdx], 32)
389 if err != nil { 389 if err != nil {
390 return nil, fmt.Errorf("Invalid 'value' line %d: %v", line, err) 390 return nil, fmt.Errorf("invalid 'value' line %d: %v", line, err)
391 } 391 }
392 newValue := value 392 newValue := value
393 393
394 newDateInfo := newDateIssue 394 newDateInfo := newDateIssue
395 395
515 if len(entries) == 0 && removed == 0 { 515 if len(entries) == 0 && removed == 0 {
516 return nil, UnchangedError("No changes from AGM import") 516 return nil, UnchangedError("No changes from AGM import")
517 } 517 }
518 518
519 if err = tx.Commit(); err != nil { 519 if err = tx.Commit(); err != nil {
520 return nil, fmt.Errorf("Commit failed: %v", err) 520 return nil, fmt.Errorf("commit failed: %v", err)
521 } 521 }
522 522
523 // Sort here to mix the deletes right beside the matching inserts/updates. 523 // Sort here to mix the deletes right beside the matching inserts/updates.
524 // This also makes the output deterministic. 524 // This also makes the output deterministic.
525 sort.Slice(entries, func(i, j int) bool { 525 sort.Slice(entries, func(i, j int) bool {