OBP60v/pages/tide.py

78 lines
2.1 KiB
Python

"""
Tide Vorausschau
"""
import cairo
from .page import Page
class Tide(Page):
def __init__(self, pageno, cfg, appdata, boatdata):
super().__init__(pageno, cfg, appdata, boatdata)
self.station = "f3c6ee73-5561-4068-96ec-364016e7d9ef" # Schulau
def draw(self, ctx):
# Title
ctx.select_font_face("Ubuntu", cairo.FontSlant.NORMAL, cairo.FontWeight.BOLD)
ctx.set_font_size(24)
ctx.move_to(8, 40)
ctx.show_text("Tide prediction")
ctx.set_font_size(16)
ctx.set_line_width(2)
ctx.move_to(220, 40)
ctx.show_text("Schulau, Elbe")
x0 = 40 # links unten
y0 = 250
x1 = 380 # rechts oben
y1 = 60
# X-Achse
ctx.move_to(x0 + 0.5, y0 + 0.5)
ctx.line_to(x0 + 0.5, y1 + 0.5)
# self.draw_text_center(ctx, x0 - 20, y0 + (y1 -y0) / 2, "Höhe, cm", rotate=True)
self.draw_text_center(ctx, 60, 150, "Höhe, cm", rotate=True)
#self.draw_text_center(ctx, 100, 100, "Höhe, cm", rotate=False)
#ctx.move_to(90, 90) # Rotationsursprung
#ctx.line_to(110, 110)
#ctx.move_to(90, 110)
#ctx.line_to(110, 90)
#ctx.stroke()
# Y-Achse
ctx.move_to(x0 + 0.5, y0 + 0.5)
ctx.line_to(x1 + 0.5, y0 + 0.5)
self.draw_text_center(ctx, x0 + (x1 - x0) / 2, y0 + 12, "Zeit, h")
ctx.stroke()
ymin, ymax = self.app.web.get_tide_minmax()
rawdata = self.app.web.get_tide()
ctx.move_to(x0 - 32, y0 + 8)
ctx.show_text(str(ymin))
ctx.move_to(x0 - 32, y1 + 8)
ctx.show_text(str(ymax))
ctx.move_to(x0 + 16, y0 + 16)
ctx.show_text(f"n = {len(rawdata)}")
dx = (x1 - x0) / len(rawdata)
x = x0
while rawdata[0][0] is None:
x += dx
del rawdata[0]
y = (rawdata[0][0] - ymin) / (ymax - ymin) * (y0 - y1)
ctx.move_to(x, y0 - (rawdata[0][0] - ymin))
del rawdata[0]
x += dx
for val in rawdata:
y = (val[0] - ymin) / (ymax - ymin) * (y0 - y1)
ctx.line_to(x, y0 - y)
x += dx