focusing on elevation first
This commit is contained in:
@@ -57,8 +57,8 @@ def parse_periods(observer: Observer, periods: Dict):
|
|||||||
datetime.strptime(period['time'], '%I:%M:%S%p').time()
|
datetime.strptime(period['time'], '%I:%M:%S%p').time()
|
||||||
).astimezone()
|
).astimezone()
|
||||||
|
|
||||||
# res = {'time': time.replace(tzinfo=None)}
|
res = {'time': time.replace(tzinfo=None)}
|
||||||
res = {'time': time.replace(tzinfo=HOME_TZ)}
|
# res = {'time': time.replace(tzinfo=HOME_TZ)}
|
||||||
# res = {'time': time}
|
# res = {'time': time}
|
||||||
res.update({k: period[k] for k in ['brightness', 'color_temp'] if k in period})
|
res.update({k: period[k] for k in ['brightness', 'color_temp'] if k in period})
|
||||||
yield res
|
yield res
|
||||||
@@ -76,30 +76,28 @@ class DaylightAdjuster:
|
|||||||
def __post_init__(self, periods: Dict, resolution: int):
|
def __post_init__(self, periods: Dict, resolution: int):
|
||||||
self.logger: logging.Logger = logging.getLogger(type(self).__name__)
|
self.logger: logging.Logger = logging.getLogger(type(self).__name__)
|
||||||
today = self.datetime.date()
|
today = self.datetime.date()
|
||||||
self.times = pd.date_range(
|
times = pd.date_range(
|
||||||
today, today + timedelta(days=1),
|
today, today + timedelta(days=1),
|
||||||
periods=resolution,
|
periods=resolution,
|
||||||
tz=HOME_TZ
|
tz=HOME_TZ
|
||||||
)
|
)
|
||||||
# self.logger.info(
|
|
||||||
# f'{type(self.times).__name__}:\n' +
|
|
||||||
# '\n'.join(f' {dt}' for dt in self.times[:5]) +
|
|
||||||
# '\n ...\n' +
|
|
||||||
# '\n'.join(f' {dt}' for dt in self.times[-5:])
|
|
||||||
# )
|
|
||||||
|
|
||||||
with suppress(UserWarning):
|
pytimes = [dt.to_pydatetime() for dt in times]
|
||||||
self.elevation = pd.Series(
|
|
||||||
(elevation(self.observer, dt.to_pydatetime()) for dt in self.times),
|
|
||||||
self.times,
|
|
||||||
name='elevation'
|
|
||||||
)
|
|
||||||
self.elevation.index = self.elevation.index.tz_convert(HOME_TZ)
|
|
||||||
|
|
||||||
self.df = pd.concat([
|
el = pd.Series(
|
||||||
pd.DataFrame(parse_periods(self.observer, periods)).set_index('time'),
|
(elevation(self.observer, dt) for dt in pytimes),
|
||||||
self.elevation
|
times, name='elevation'
|
||||||
], axis=1).sort_index().interpolate().bfill().ffill()
|
)
|
||||||
|
|
||||||
|
# el.index = el.index.tz_convert(HOME_TZ)
|
||||||
|
# el.index = el.index.tz_convert(None)
|
||||||
|
|
||||||
|
self.df = pd.DataFrame(el)
|
||||||
|
|
||||||
|
# self.df = pd.concat([
|
||||||
|
# pd.DataFrame(parse_periods(self.observer, periods)).set_index('time'),
|
||||||
|
# el
|
||||||
|
# ], axis=1).sort_index().interpolate().bfill().ffill()
|
||||||
|
|
||||||
# self.df.index = self.df.index.to_series().dt.tz_localize(None)
|
# self.df.index = self.df.index.to_series().dt.tz_localize(None)
|
||||||
|
|
||||||
@@ -115,12 +113,12 @@ class DaylightAdjuster:
|
|||||||
|
|
||||||
def elevation_fig(self):
|
def elevation_fig(self):
|
||||||
fig, ax = plt.subplots(figsize=(10, 7))
|
fig, ax = plt.subplots(figsize=(10, 7))
|
||||||
handles = ax.plot(self.elevation)
|
handles = ax.plot(self.df['elevation'])
|
||||||
|
|
||||||
ax.set_ylabel('Elevation')
|
ax.set_ylabel('Elevation')
|
||||||
ax.set_ylim(-100, 100)
|
ax.set_ylim(-100, 100)
|
||||||
format_x_axis(fig)
|
format_x_axis(fig)
|
||||||
ax.set_xlim(self.elevation.index[0], self.elevation.index[-1])
|
ax.set_xlim(self.df.index[0], self.df.index[-1])
|
||||||
|
|
||||||
ax2 = ax.twinx()
|
ax2 = ax.twinx()
|
||||||
# handles.extend(ax2.plot(normalize(self.df['brightness'], 1, 255), 'tab:orange'))
|
# handles.extend(ax2.plot(normalize(self.df['brightness'], 1, 255), 'tab:orange'))
|
||||||
|
|||||||
Reference in New Issue
Block a user