Mercurial > gemma
comparison pkg/octree/classbreaks.go @ 4214:49564382ffff
Added a import queue job to recalculate the contour lines of the sounding results if the heights have changed.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 16 Aug 2019 13:15:34 +0200 |
parents | 37d5c4441c70 |
children | 7a9388943840 |
comparison
equal
deleted
inserted
replaced
4197:5d7ce7f926eb | 4214:49564382ffff |
---|---|
56 } | 56 } |
57 } | 57 } |
58 return heights | 58 return heights |
59 } | 59 } |
60 | 60 |
61 func LoadClassBreaks(ctx context.Context, tx *sql.Tx, key string) ([]float64, error) { | 61 func ParseClassBreaks(config string) ([]float64, error) { |
62 | 62 |
63 var config sql.NullString | 63 parts := strings.Split(config, ",") |
64 | |
65 err := tx.QueryRowContext(ctx, selectClassBreaksSQL, key).Scan(&config) | |
66 | |
67 switch { | |
68 case err == sql.ErrNoRows: | |
69 return nil, nil | |
70 case err != nil: | |
71 return nil, err | |
72 case !config.Valid: | |
73 return nil, errors.New("Invalid config string") | |
74 } | |
75 | |
76 parts := strings.Split(config.String, ",") | |
77 classes := make([]float64, 0, len(parts)) | 64 classes := make([]float64, 0, len(parts)) |
78 for _, part := range parts { | 65 for _, part := range parts { |
79 if idx := strings.IndexRune(part, ':'); idx >= 0 { | 66 if idx := strings.IndexRune(part, ':'); idx >= 0 { |
80 part = part[:idx] | 67 part = part[:idx] |
81 } | 68 } |
89 classes = append(classes, v) | 76 classes = append(classes, v) |
90 } | 77 } |
91 | 78 |
92 sort.Float64s(classes) | 79 sort.Float64s(classes) |
93 return classes, nil | 80 return classes, nil |
81 } | |
82 | |
83 func LoadClassBreaks(ctx context.Context, tx *sql.Tx, key string) ([]float64, error) { | |
84 | |
85 var config sql.NullString | |
86 | |
87 err := tx.QueryRowContext(ctx, selectClassBreaksSQL, key).Scan(&config) | |
88 | |
89 switch { | |
90 case err == sql.ErrNoRows: | |
91 return nil, nil | |
92 case err != nil: | |
93 return nil, err | |
94 case !config.Valid: | |
95 return nil, errors.New("Invalid config string") | |
96 } | |
97 | |
98 return ParseClassBreaks(config.String) | |
94 } | 99 } |
95 | 100 |
96 func ExtrapolateClassBreaks(cbs []float64, min, max float64) []float64 { | 101 func ExtrapolateClassBreaks(cbs []float64, min, max float64) []float64 { |
97 if min > max { | 102 if min > max { |
98 min, max = max, min | 103 min, max = max, min |