-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_dsd.py
187 lines (158 loc) · 5.8 KB
/
test_dsd.py
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
184
185
186
187
""" The test for the API """
import asyncio
import pprint
import logging
import time
import os
from datetime import datetime, timedelta
import pytz
from pyastroweatherio import (
AstroWeather,
AstroWeatherError,
)
_LOGGER = logging.getLogger(__name__)
pp = pprint.PrettyPrinter()
COLOR_BLACK = "1;30"
COLOR_RED = "1;31"
COLOR_GREEN = "1;32"
COLOR_BROWN = "1;33"
COLOR_BLUE = "1;34"
COLOR_PURPLE = "1;35"
COLOR_CYAN = "1;36"
# Backyard
latitude = float(os.environ["BACKYARD_LATITUDE"])
longitude = float(os.environ["BACKYARD_LONGITUDE"])
elevation = int(os.environ["BACKYARD_ELEVATION"])
timezone_info = os.environ["BACKYARD_TIMEZONE"]
# Peißenberg
# latitude=48.811
# longitude=11.017
# elevation=977
# timezone_info = "Europe/Berlin"
# Anchorage
# latitude=61.212
# longitude=-149.737
# elevation=115
# timezone_info = "America/Anchorage"
# Hacienda Los Andes
latitude=-30.29528
longitude=-70.71262
elevation=1000
timezone_info = "Chile/Continental"
# London
# latitude=51.5072
# longitude=0.1276
# elevation=11
# timezone_info = "Europe/London"
# Sydney
# latitude=-33.869
# longitude=151.198
# elevation=3
# timezone_info = "Australia/Sydney"
def esc(code):
return f"\033[{code}m"
def utc_to_local(utc_dt):
"""Localizes the datetime"""
local_tz = pytz.timezone(timezone_info)
local_dt = utc_dt.replace(tzinfo=pytz.utc).astimezone(local_tz)
return local_tz.normalize(local_dt)
def convert_to_hhmm(sec):
sec = sec % (24 * 3600)
hour = sec // 3600
sec %= 3600
min = sec // 60
sec %= 60
# return "%02d:%02d:%02d" % (hour, min, sec)
return "%02d:%02d" % (hour, min)
async def main() -> None:
"""Create the aiohttp session and run the example."""
logging.basicConfig(level=logging.DEBUG)
f = open("debug/test_dsd.csv", "w")
f.write(
"Datetime;Sun next Rising;Sun next Rising Astronomical;Sun next Setting;Sun next Setting Astronomical;Moon next Rising;Moon next Setting;Sun Altitude;Moon Altitude;DSD Moon rises;DSD Moon sets;DSD Moon always up;DSD Moon always down;NDA;DSD\n"
)
ds_string = "11/13/2023 00:00:00"
dt = datetime.strptime(ds_string, "%m/%d/%Y %H:%M:%S")
de_string = "11/15/2023 00:00:00"
de = datetime.strptime(de_string, "%m/%d/%Y %H:%M:%S")
start = time.time()
while dt < de:
astroweather = AstroWeather(
latitude=latitude,
longitude=longitude,
elevation=elevation,
timezone_info=timezone_info,
cloudcover_weight=3,
seeing_weight=2,
transparency_weight=1,
uptonight_path=".",
test_datetime=dt,
)
try:
data = await astroweather.get_location_data()
for row in data:
print(
f"{esc(COLOR_RED)}Date & Time: {esc(COLOR_GREEN)}{str(utc_to_local(dt))}{esc(COLOR_BLUE)}"
+ " - "
+ "SS "
+ str(datetime.strftime(utc_to_local(row.sun_next_setting), "%d.%m.%Y %H:%M:%S"))
+ "; "
+ "SR "
+ str(datetime.strftime(utc_to_local(row.sun_next_rising), "%d.%m.%Y %H:%M:%S"))
+ "; "
+ "SSA "
+ str(datetime.strftime(utc_to_local(row.sun_next_setting_astro), "%d.%m.%Y %H:%M:%S"))
+ "; "
+ "SRA "
+ str(datetime.strftime(utc_to_local(row.sun_next_rising_astro), "%d.%m.%Y %H:%M:%S"))
+ "; "
+ "MR "
+ str(datetime.strftime(utc_to_local(row.moon_next_rising), "%d.%m.%Y %H:%M:%S"))
+ "; "
+ "MS "
+ str(datetime.strftime(utc_to_local(row.moon_next_setting), "%d.%m.%Y %H:%M:%S"))
+ "; "
)
f.write(
str(datetime.strftime(utc_to_local(dt), "%d.%m.%Y %H:%M:%S"))
+ ";"
+ str(datetime.strftime(utc_to_local(row.sun_next_rising), "%d.%m.%Y %H:%M:%S"))
+ ";"
+ str(datetime.strftime(utc_to_local(row.sun_next_rising_astro), "%d.%m.%Y %H:%M:%S"))
+ ";"
+ str(datetime.strftime(utc_to_local(row.sun_next_setting), "%d.%m.%Y %H:%M:%S"))
+ ";"
+ str(datetime.strftime(utc_to_local(row.sun_next_setting_astro), "%d.%m.%Y %H:%M:%S"))
+ ";"
+ str(datetime.strftime(utc_to_local(row.moon_next_rising), "%d.%m.%Y %H:%M:%S"))
+ ";"
+ str(datetime.strftime(utc_to_local(row.moon_next_setting), "%d.%m.%Y %H:%M:%S"))
+ ";"
+ str(row.sun_altitude).replace(".", ",")
+ ";"
+ str(row.moon_altitude).replace(".", ",")
+ ";"
+ str(row.deep_sky_darkness_moon_rises)
+ ";"
+ str(row.deep_sky_darkness_moon_sets)
+ ";"
+ str(row.deep_sky_darkness_moon_always_up)
+ ";"
+ str(row.deep_sky_darkness_moon_always_down)
+ ";"
+ convert_to_hhmm(row.night_duration_astronomical)
+ ";"
+ convert_to_hhmm(row.deep_sky_darkness)
+ ";"
+ str(row.deepsky_forecast_today_plain)
+ ";"
+ str(row.deepsky_forecast_tomorrow_plain)
+ "\n"
)
except AstroWeatherError as err:
print(err)
dt = dt + timedelta(minutes=15)
f.close()
end = time.time()
print(f"Execution time: %s seconds", end - start)
asyncio.run(main())