Mercurial > gemma
annotate pkg/common/time.go @ 3260:909a19e97db9
client: import stretches: changed icon for selecting distance mark to crosshairs
author | Markus Kottlaender <markus@intevation.de> |
---|---|
date | Tue, 14 May 2019 19:52:26 +0200 |
parents | 8c4c1b3fd856 |
children | c86a8e70b40f |
rev | line source |
---|---|
2150
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
2929
e5f5afa45451
Change basic in/out datetime format to RFC3339
Bernhard Reiter <bernhard@intevation.de>
parents:
2150
diff
changeset
|
7 // Copyright (C) 2018, 2019 by via donau |
2150
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
2929
e5f5afa45451
Change basic in/out datetime format to RFC3339
Bernhard Reiter <bernhard@intevation.de>
parents:
2150
diff
changeset
|
13 // * Bernhard E. Reiter <bernhard.reiter@intevation.de> |
2150
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 package common |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
3027
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
17 import ( |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
18 "math" |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
19 "time" |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
20 ) |
2929
e5f5afa45451
Change basic in/out datetime format to RFC3339
Bernhard Reiter <bernhard@intevation.de>
parents:
2150
diff
changeset
|
21 |
2150
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 const ( |
2929
e5f5afa45451
Change basic in/out datetime format to RFC3339
Bernhard Reiter <bernhard@intevation.de>
parents:
2150
diff
changeset
|
23 // time.RFC3339 equals "simplified ISO format as defined by ECMA-262" |
e5f5afa45451
Change basic in/out datetime format to RFC3339
Bernhard Reiter <bernhard@intevation.de>
parents:
2150
diff
changeset
|
24 // https://tc39.github.io/ecma262/#sec-date-time-string-format |
e5f5afa45451
Change basic in/out datetime format to RFC3339
Bernhard Reiter <bernhard@intevation.de>
parents:
2150
diff
changeset
|
25 // and "SHOULD be used in new protocols on the Internet." (RFC section 5.6) |
e5f5afa45451
Change basic in/out datetime format to RFC3339
Bernhard Reiter <bernhard@intevation.de>
parents:
2150
diff
changeset
|
26 TimeFormat = time.RFC3339 |
2150
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 DateFormat = "2006-01-02" |
2c67c51d57ad
Print templates: Implemented GET of all templates.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 ) |
3027
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
29 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
30 type ValueRangeKind int |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
31 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
32 const ( |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
33 ValueBelow ValueRangeKind = -1 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
34 ValueInside ValueRangeKind = 0 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
35 ValueAbove ValueRangeKind = +1 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
36 ) |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
37 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
38 func InterpolateValueByTime(t1 time.Time, m1 float64, t2 time.Time, m2 float64) func(time.Time) (float64, ValueRangeKind) { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
39 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
40 // f(t1) = m1 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
41 // f(t2) = m2 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
42 // m1 = t1*a + b <=> b = m1 - t1*a |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
43 // m2 = t2*a + b |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
44 // m1 - m2 = a*(t1 - t2) |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
45 // a = (m1 - m2)/(t1 - t2) for t1 != t2 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
46 |
3095
8c4c1b3fd856
Compare time.Time's with Equal.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3027
diff
changeset
|
47 if t1.Equal(t2) { |
3027
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
48 return func(t time.Time) (float64, ValueRangeKind) { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
49 switch { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
50 case t.Before(t1): |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
51 return 0, ValueBelow |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
52 case t.After(t1): |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
53 return 0, ValueAbove |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
54 default: |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
55 return m1 + (m2-m1)/2, ValueInside |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
56 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
57 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
58 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
59 var min, max time.Time |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
60 if t1.Before(t2) { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
61 min, max = t1, t2 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
62 } else { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
63 min, max = t2, t1 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
64 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
65 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
66 a := (m1 - m2) / t1.Sub(t2).Seconds() |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
67 b := m1 - a*float64(t1.Unix()) |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
68 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
69 return func(t time.Time) (float64, ValueRangeKind) { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
70 switch { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
71 case t.Before(min): |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
72 return 0, ValueBelow |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
73 case t.After(max): |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
74 return 0, ValueAbove |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
75 default: |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
76 return a*float64(t.Unix()) + b, ValueInside |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
77 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
78 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
79 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
80 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
81 func InterpolateTimeByValue(t1 time.Time, m1 float64, t2 time.Time, m2 float64) func(float64) (time.Time, ValueRangeKind) { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
82 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
83 // f(m1) = t1 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
84 // f(m2) = t2 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
85 // t1 = m1*a + b <=> b = t1 - m1*a |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
86 // t2 = m2*a + b |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
87 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
88 // t1 - t2 = a*(m1 - m2) |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
89 // a = (t1-t2)/(m1 - m2) for m1 != m2 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
90 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
91 if m1 == m2 { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
92 return func(m float64) (time.Time, ValueRangeKind) { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
93 switch { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
94 case m < m1: |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
95 return time.Time{}, ValueBelow |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
96 case m > m1: |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
97 return time.Time{}, ValueAbove |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
98 default: |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
99 return t1.Add(t2.Sub(t1) / 2), ValueInside |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
100 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
101 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
102 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
103 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
104 min, max := math.Min(m1, m2), math.Max(m1, m2) |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
105 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
106 a := t1.Sub(t2).Seconds() / (m1 - m2) |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
107 b := float64(t1.Unix()) - m1*a |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
108 |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
109 return func(m float64) (time.Time, ValueRangeKind) { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
110 switch { |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
111 case m < min: |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
112 return time.Time{}, ValueBelow |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
113 case m > max: |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
114 return time.Time{}, ValueAbove |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
115 default: |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
116 return time.Unix(int64(math.Ceil(m*a+b)), 0), ValueInside |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
117 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
118 } |
84e6577a474b
Fairway availability: More robust time and value interpolations including corner cases. Still TODO: Distribute to classes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2929
diff
changeset
|
119 } |