-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnowcast.go
55 lines (49 loc) · 1.22 KB
/
nowcast.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import "fmt"
type PositionConfig struct {
X int
Y int
CursorHeight int
MapID int
Trim TrimConfig
}
type TrimConfig struct {
Trim bool
X int
Y int
Width int
Height int
}
type NowcastComposer struct {
Pos PositionConfig
Images NowcastImages
Annotated NowcastImages
Rain RainInfo
}
func NewComposer(pos PositionConfig) (NowcastComposer, error) {
var composer NowcastComposer
images, err := DownloadableImage(pos.MapID)
if err != nil {
return composer, fmt.Errorf("downloadable image : %w", err)
}
err = images.Fetch()
if err != nil {
return composer, fmt.Errorf("fetch : %w", err)
}
rain, err := images.SeekRainInfo(pos)
if err != nil {
return composer, fmt.Errorf("seek rain info : %w", err)
}
charts, err := GenerateCharts(rain, pos.Trim.GetWidth())
if err != nil {
return composer, fmt.Errorf("generate charts : %w", err)
}
annotated, err := images.Annotate(pos, charts)
if err != nil {
return composer, fmt.Errorf("annotate : %w", err)
}
return NowcastComposer{Pos: pos, Images: images, Annotated: annotated, Rain: rain}, nil
}
func (c *NowcastComposer) Rainy(threshold int) bool {
return c.Rain.RainTotal() >= threshold
}