Mercurial > gemma
comparison pkg/imports/sr.go @ 1498:5df748916fcf
Finished API docs for sounding result imports.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 04 Dec 2018 19:25:35 +0100 |
parents | 3bf1f0de0763 |
children | 048d1891e004 |
comparison
equal
deleted
inserted
replaced
1497:b41ad15cc55f | 1498:5df748916fcf |
---|---|
38 "gemma.intevation.de/gemma/pkg/common" | 38 "gemma.intevation.de/gemma/pkg/common" |
39 "gemma.intevation.de/gemma/pkg/models" | 39 "gemma.intevation.de/gemma/pkg/models" |
40 "gemma.intevation.de/gemma/pkg/octree" | 40 "gemma.intevation.de/gemma/pkg/octree" |
41 ) | 41 ) |
42 | 42 |
43 // SoundingResult is a Job to import sounding reults | |
44 // from a ZIP file into the database. | |
43 type SoundingResult struct { | 45 type SoundingResult struct { |
46 // Dir is the folder in the file system where the | |
47 // 'sr.zip' is expect to be. | |
44 Dir string `json:"dir"` | 48 Dir string `json:"dir"` |
45 | 49 |
46 // Override data | 50 // Override data |
47 Date *models.SoundingResultDate `json:"date,omitempty"` | 51 // Date if given overrides the date value from the meta.json. |
48 Bottleneck *string `json:"bottleneck,omitempty"` | 52 Date *models.SoundingResultDate `json:"date,omitempty"` |
49 EPSG *uint `json:"epsg,omitempty"` | 53 // Date if given overrides the name of the bottleneck from the meta.json. |
50 DepthReference *string `json:"depth-reference,omitempty"` | 54 Bottleneck *string `json:"bottleneck,omitempty"` |
55 // EPSG if given overrides the EPSG code from the meta.json. | |
56 // Defaults to WGS84. | |
57 EPSG *uint `json:"epsg,omitempty"` | |
58 // DepthReference if given overides the DepthReference value | |
59 // from the meta.json. | |
60 DepthReference *string `json:"depth-reference,omitempty"` | |
51 } | 61 } |
52 | 62 |
53 const ( | 63 const ( |
54 contourStepWidth = 0.1 | 64 contourStepWidth = 0.1 |
55 contourTolerance = 0.1 | 65 contourTolerance = 0.1 |
56 ) | 66 ) |
57 | 67 |
68 // SRJobKind is the unique name of a SoundingResult import job. | |
58 const SRJobKind JobKind = "sr" | 69 const SRJobKind JobKind = "sr" |
59 | 70 |
60 type srJobCreator struct{} | 71 type srJobCreator struct{} |
61 | 72 |
62 func init() { | 73 func init() { |
153 FROM waterway.sounding_results sr | 164 FROM waterway.sounding_results sr |
154 WHERE id = $1 | 165 WHERE id = $1 |
155 ` | 166 ` |
156 ) | 167 ) |
157 | 168 |
169 // FromString revives a SoundingResult import from a string. | |
158 func (sr *SoundingResult) FromString(data string) error { | 170 func (sr *SoundingResult) FromString(data string) error { |
159 return json.NewDecoder(strings.NewReader(data)).Decode(sr) | 171 return json.NewDecoder(strings.NewReader(data)).Decode(sr) |
160 } | 172 } |
161 | 173 |
174 // ToString serializes a SoundingResult import into a string to | |
175 // be revived by FromString. | |
162 func (sr *SoundingResult) ToString() (string, error) { | 176 func (sr *SoundingResult) ToString() (string, error) { |
163 var b strings.Builder | 177 var b strings.Builder |
164 if err := json.NewEncoder(&b).Encode(sr); err != nil { | 178 if err := json.NewEncoder(&b).Encode(sr); err != nil { |
165 return "", err | 179 return "", err |
166 } | 180 } |
167 return b.String(), nil | 181 return b.String(), nil |
168 } | 182 } |
169 | 183 |
184 // Do executes the actual sounding result import. | |
170 func (sr *SoundingResult) Do( | 185 func (sr *SoundingResult) Do( |
171 ctx context.Context, | 186 ctx context.Context, |
172 importID int64, | 187 importID int64, |
173 conn *sql.Conn, | 188 conn *sql.Conn, |
174 feedback Feedback, | 189 feedback Feedback, |
311 Lon: lon, | 326 Lon: lon, |
312 } | 327 } |
313 return &summary, err | 328 return &summary, err |
314 } | 329 } |
315 | 330 |
331 // CleanUp removes the folder containing the ZIP file with the | |
332 // the sounding result import. | |
316 func (sr *SoundingResult) CleanUp() error { | 333 func (sr *SoundingResult) CleanUp() error { |
317 return os.RemoveAll(sr.Dir) | 334 return os.RemoveAll(sr.Dir) |
318 } | 335 } |
319 | 336 |
320 func (sr *SoundingResult) completeOverride() bool { | 337 func (sr *SoundingResult) completeOverride() bool { |