-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.go
183 lines (165 loc) · 5.01 KB
/
utils.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package main
import (
"math"
"time"
"github.com/go-echarts/go-echarts/v2/charts"
"github.com/go-echarts/go-echarts/v2/opts"
"github.com/mshafiee/swephgo"
)
/* charts */
func innerPositionChart(startTime time.Time, years int, months int) *charts.Line {
lineChart := charts.NewLine()
var x []string
var z, m, v, u []opts.LineData
start := nod(startTime)
end := start.AddDate(years, months, 0)
ipl := swephgo.SeMoon
for d := start; d.After(end) == false; d = d.AddDate(0, 0, 1) {
x = append(x, d.In(location).Format("Jan _2, 06"))
waldo, _ := Waldo(d, ipl, swephgo.SeflgSwieph+swephgo.SeflgRadians)
z = append(z, opts.LineData{Value: math.Cos(waldo[0])})
waldo, _ = Waldo(d, ipl+1, swephgo.SeflgSwieph+swephgo.SeflgRadians)
m = append(m, opts.LineData{Value: math.Cos(waldo[0])})
waldo, _ = Waldo(d, ipl+2, swephgo.SeflgSwieph+swephgo.SeflgRadians)
v = append(v, opts.LineData{Value: math.Cos(waldo[0])})
waldo, _ = Waldo(d, ipl+3, swephgo.SeflgSwieph+swephgo.SeflgRadians)
u = append(u, opts.LineData{Value: math.Cos(waldo[0])})
}
lineChart.SetGlobalOptions(
charts.WithTitleOpts(opts.Title{
Title: "Moon - Mercury - Venus - Mars Position",
}),
charts.WithYAxisOpts(opts.YAxis{
Scale: true,
Min: -1.0,
Max: 1.0,
}),
charts.WithDataZoomOpts(opts.DataZoom{
Type: "slider",
XAxisIndex: []int{0},
}),
charts.WithTooltipOpts(opts.Tooltip{
Show: true,
}),
charts.WithToolboxOpts(opts.Toolbox{
Show: true,
Right: "20%",
Feature: &opts.ToolBoxFeature{
SaveAsImage: &opts.ToolBoxFeatureSaveAsImage{
Show: true,
Type: "png",
Title: "save as image",
},
}},
),
)
lineChart.SetXAxis(x).AddSeries("Moon", z)
lineChart.SetXAxis(x).AddSeries("Mercury", m)
lineChart.SetXAxis(x).AddSeries("Venus", v)
lineChart.SetXAxis(x).AddSeries("Mars", u)
return lineChart
}
func outerPositionChart(startTime time.Time, years int, months int) *charts.Line {
lineChart := charts.NewLine()
var x []string
var j, s, u, n, p []opts.LineData
start := nod(startTime)
end := start.AddDate(years, months, 0)
ipl := swephgo.SeJupiter
for d := start; d.After(end) == false; d = d.AddDate(0, 0, 1) {
x = append(x, d.In(location).Format("Jan _2, 06"))
waldo, _ := Waldo(d, ipl, swephgo.SeflgSwieph+swephgo.SeflgRadians)
j = append(j, opts.LineData{Value: math.Cos(waldo[0])})
waldo, _ = Waldo(d, ipl+1, swephgo.SeflgSwieph+swephgo.SeflgRadians)
s = append(s, opts.LineData{Value: math.Cos(waldo[0])})
waldo, _ = Waldo(d, ipl+2, swephgo.SeflgSwieph+swephgo.SeflgRadians)
u = append(u, opts.LineData{Value: math.Cos(waldo[0])})
waldo, _ = Waldo(d, ipl+3, swephgo.SeflgSwieph+swephgo.SeflgRadians)
n = append(n, opts.LineData{Value: math.Cos(waldo[0])})
waldo, _ = Waldo(d, ipl+4, swephgo.SeflgSwieph+swephgo.SeflgRadians)
p = append(p, opts.LineData{Value: math.Cos(waldo[0])})
}
lineChart.SetGlobalOptions(
charts.WithTitleOpts(opts.Title{
Title: "Jupiter - Saturn - Uranus - Neptune - Pluto",
}),
charts.WithYAxisOpts(opts.YAxis{
Scale: true,
Min: -1.0,
Max: 1.0,
}),
charts.WithDataZoomOpts(opts.DataZoom{
Type: "slider",
XAxisIndex: []int{0},
}),
charts.WithTooltipOpts(opts.Tooltip{
Show: true,
}),
charts.WithToolboxOpts(opts.Toolbox{
Show: true,
Right: "20%",
Feature: &opts.ToolBoxFeature{
SaveAsImage: &opts.ToolBoxFeatureSaveAsImage{
Show: true,
Type: "png",
Title: "save as image",
},
}},
),
)
lineChart.SetXAxis(x).AddSeries("Jupiter", j)
lineChart.SetXAxis(x).AddSeries("Saturn", s)
lineChart.SetXAxis(x).AddSeries("Uranus", u)
lineChart.SetXAxis(x).AddSeries("Neptune", n)
lineChart.SetXAxis(x).AddSeries("Pluto", p)
return lineChart
}
/* general helpers */
func jdToUTC(jd *float64) time.Time {
year := make([]int, 1)
month := make([]int, 1)
day := make([]int, 1)
hour := make([]float64, 1)
swephgo.Revjul(*jd, swephgo.SeGregCal, year, month, day, hour)
h := int(hour[0])
m := int(60 * (hour[0] - float64(h)))
utc := time.Date(year[0], time.Month(month[0]), day[0], h, m, 0, 0, time.UTC)
return utc
}
func jdToLocal(jd *float64) time.Time {
utc := jdToUTC(jd)
return utc.In(location)
}
func julian(d time.Time) *float64 {
h := float64(d.Hour()) + float64(d.Minute())/60 + float64(d.Second())/3600
jd := swephgo.Julday(d.Year(), int(d.Month()), d.Day(), h, swephgo.SeGregCal)
return &jd
}
/* Begining of the Day */
func bod(t time.Time) time.Time {
year, month, day := t.Date()
return time.Date(year, month, day, 0, 0, 0, 0, time.Local)
}
/* Noon of the Day */
func nod(t time.Time) time.Time {
year, month, day := t.Date()
return time.Date(year, month, day, 12, 0, 0, 0, time.Local)
}
func smallestSignedAngleBetween(x float64, y float64) float64 {
return math.Min(2.0*math.Pi-math.Abs(x-y), math.Abs(x-y))
}
func fixangle(a float64) float64 {
return (a - 360*math.Floor(a/360))
}
func rad2deg(r float64) float64 {
return (r * 180) / math.Pi
}
func deg2rad(d float64) float64 {
return (d * math.Pi) / 180
}
func bool2int(b bool) int {
if b {
return 1
}
return 0
}