This repository has been archived by the owner on Jun 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (75 loc) · 2.51 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"fmt"
"os"
"time"
"github.com/goark/cov19data/values"
"github.com/goark/errs"
"github.com/spiegel-im-spiegel/covid-2019-report/chart"
"github.com/spiegel-im-spiegel/covid-2019-report/imgutil"
)
const (
HistCasesFile = "./covid-2019-new-cases-histgram-in-japan.png"
HistDeathsFile = "./covid-2019-new-deaths-histgram-in-japan.png"
HistCasesFileShort = "./covid-2019-new-cases-histgram-in-japan-short.png"
HistDeathsFileShort = "./covid-2019-new-deaths-histgram-in-japan-short.png"
HistAllFile = "./covid-2019-histgram-in-japan.png"
HistAllFileShort = "./covid-2019-histgram-in-japan-short.png"
)
func makeGraph(from, to values.Date, histCasesFile, histDeathsFile string) error {
p := values.NewPeriod(from, to)
global, err := getGlobalHist(p)
if err != nil {
return errs.Wrap(err)
}
// tokyo, err := getTokyoHist(p)
// if err != nil {
// return errs.Wrap(err)
// }
histChart := chart.ImportHistgramData(global)
if len(histCasesFile) > 0 {
if err := chart.BarChartHistCases(histChart, histCasesFile); err != nil {
return errs.Wrap(err)
}
}
if len(histDeathsFile) > 0 {
if err := chart.BarChartHistDeaths(histChart, histDeathsFile); err != nil {
return errs.Wrap(err)
}
}
return nil
}
func main() {
lastDay := values.Today().AddDay(-8)
if err := makeGraph(values.NewDate(2020, time.Month(3), 11), lastDay, HistCasesFile, HistDeathsFile); err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err)
return
}
if err := imgutil.ConcatImageFiles(HistAllFile, HistCasesFile, HistDeathsFile); err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err)
return
}
// experimental
if err := makeGraph(lastDay.AddDay(-7*52), lastDay, HistCasesFileShort, HistDeathsFileShort); err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err)
return
}
if err := imgutil.ConcatImageFiles(HistAllFileShort, HistCasesFileShort, HistDeathsFileShort); err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err)
return
}
}
/* Copyright 2020-2022 Spiegel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/