Mercurial > gemma
comparison pkg/models/gauge.go @ 1637:dd31be75ce6d
Implemented gauge measurement import.
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 20 Dec 2018 12:06:37 +0100 |
parents | |
children | 334d13e63342 |
comparison
equal
deleted
inserted
replaced
1636:37ee25bc2bbe | 1637:dd31be75ce6d |
---|---|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 | |
2 // without warranty, see README.md and license for details. | |
3 // | |
4 // SPDX-License-Identifier: AGPL-3.0-or-later | |
5 // License-Filename: LICENSES/AGPL-3.0.txt | |
6 // | |
7 // Copyright (C) 2018 by via donau | |
8 // – Österreichische Wasserstraßen-Gesellschaft mbH | |
9 // Software engineering by Intevation GmbH | |
10 // | |
11 // Author(s): | |
12 // * Raimund Renkert <raimund.renkert@intevation.de> | |
13 | |
14 package models | |
15 | |
16 import ( | |
17 "fmt" | |
18 "strconv" | |
19 "time" | |
20 ) | |
21 | |
22 // GaugeMeasurementImport contains data used to define the endpoint | |
23 type GaugeMeasurementImport struct { | |
24 URL string `json:"url"` | |
25 Insecure bool `json:"insecure"` | |
26 } | |
27 | |
28 // GaugeMeasurement holds information about a gauge and the latest measurement | |
29 type GaugeMeasurement struct { | |
30 Gauge Isrs | |
31 LatestDateIssue time.Time | |
32 } | |
33 | |
34 // Isrs represents the gauge identification data structure | |
35 type Isrs struct { | |
36 CountryCode string | |
37 LoCode string | |
38 FairwaySection string | |
39 Orc string | |
40 Hectometre int | |
41 } | |
42 | |
43 // IsrsFromString converts string representation of isrs code to type Isrs | |
44 func IsrsFromString(isrsCode string) (*Isrs, error) { | |
45 if len(isrsCode) < 20 { | |
46 return nil, fmt.Errorf("to short") | |
47 } | |
48 hm, err := strconv.Atoi(isrsCode[15:20]) | |
49 if err != nil { | |
50 return nil, err | |
51 } | |
52 isrs := Isrs{ | |
53 CountryCode: isrsCode[0:2], | |
54 LoCode: isrsCode[2:5], | |
55 FairwaySection: isrsCode[5:10], | |
56 Orc: isrsCode[10:15], | |
57 Hectometre: hm, | |
58 } | |
59 return &isrs, nil | |
60 } | |
61 | |
62 // ToString creates a isrs code string from Isrs | |
63 func (isrs *Isrs) String() string { | |
64 return fmt.Sprintf("%s%s%s%s%05d", | |
65 isrs.CountryCode, | |
66 isrs.LoCode, | |
67 isrs.FairwaySection, | |
68 isrs.Orc, | |
69 isrs.Hectometre) | |
70 } |