# HG changeset patch # User Sascha L. Teichmann # Date 1570203471 -7200 # Node ID 7465b6244d5eb11670da38b511c0822d332f5b75 # Parent 9f2d690b7076d5ab3d7f7a5bbffcac52a82568fc FA import: Code clean-up for handling default LOS. diff -r 9f2d690b7076 -r 7465b6244d5e pkg/imports/fa.go --- a/pkg/imports/fa.go Fri Oct 04 17:12:26 2019 +0200 +++ b/pkg/imports/fa.go Fri Oct 04 17:37:51 2019 +0200 @@ -292,6 +292,14 @@ return &summary, nil } +// defaultLOS defaults to LOS3 when no expicit LOS is given. +func defaultLOS(los *ifaf.LosEnum) ifaf.LosEnum { + if los == nil { + return ifaf.LosEnumLOS3 + } + return *los +} + func doForFAs( ctx context.Context, bnIds bottlenecks, @@ -300,8 +308,6 @@ feedback Feedback, ) ([]string, error) { - default_los := ifaf.LosEnumLOS3 - insertFAStmt, err := tx.PrepareContext(ctx, insertFASQL) if err != nil { return nil, err @@ -373,10 +379,6 @@ if faRes.Effective_fairway_availability != nil { efaCount := 0 for _, efa := range faRes.Effective_fairway_availability.EffectiveFairwayAvailability { - los := &default_los - if efa.Level_of_Service != nil { - los = efa.Level_of_Service - } fgt := efa.Forecast_generation_time if efa.Forecast_generation_time.Status == pgtype.Undefined { fgt = pgtype.Timestamp{ @@ -387,7 +389,7 @@ ctx, faID, efa.Measure_date, - string(*los), + string(defaultLOS(efa.Level_of_Service)), efa.Available_depth_value, efa.Available_width_value, efa.Water_level_value, @@ -412,14 +414,10 @@ if faRes.Reference_values != nil { rvCount := 0 for _, fav := range faRes.Reference_values.ReferenceValue { - los := &default_los - if fav.Level_of_Service != nil { - los = fav.Level_of_Service - } res, err := insertFAVStmt.ExecContext( ctx, faID, - los, + string(defaultLOS(fav.Level_of_Service)), fav.Fairway_depth, fav.Fairway_width, fav.Fairway_radius,