def test_get_dusks_and_dawns_mount_ellsworth_summer(self):
     now = datetime.fromisoformat('2021-07-10T12:00:00+02:00')
     result = celestial.get_dusks_and_dawns(self.MOUNT_ELLSWORTH_LOCATION,
                                            now)
     self.assertEqual(result["twilights"], [4, 3, 4])
Esempio n. 2
0
def get_celestial_panel(position: Position, fonts: Fonts,
                        config: SectionProxy) -> Image.Image:
    logger = logging.getLogger(__name__)
    logger.info('Generating celestial panel')
    x_size = 400
    y_size = 600
    image = Image.new('L', (x_size, y_size), 0xff)
    draw = ImageDraw.Draw(image)

    utils.draw_title(draw, fonts['font_sm'], 'SKY')

    # Icons
    now = datetime.datetime.now().astimezone()
    dusks_and_dawns = get_dusks_and_dawns(position, now)

    tick_height = 50
    y_base = 80 + (9 - len(dusks_and_dawns["twilights"])) * tick_height // 2
    x_base = 150
    tick_width = 20
    tick_gap = 20
    arrow_gap = 5
    arrow_width = 25

    y_position = y_base
    for shade in dusks_and_dawns["twilights"]:
        color = get_shade_color(shade)
        draw.rectangle(
            ((x_base + tick_gap, y_position),
             (x_base + tick_gap + tick_width, y_position + tick_height)),
            color)
        y_position += tick_height

    y_position = y_base
    for new_threshold in dusks_and_dawns["times"]:
        (hours, minutes) = parse_sunrise_sunset_hour_minute(new_threshold)
        draw.text((x_base - 60, y_position + tick_height),
                  ":",
                  font=fonts['font_xs'],
                  fill=0,
                  anchor='mm')
        draw.text((x_base - 53, y_position + tick_height),
                  minutes,
                  font=fonts['font_xs'],
                  fill=0,
                  anchor='lm')
        draw.text((x_base - 67, y_position + tick_height),
                  hours,
                  font=fonts['font_xs'],
                  fill=0,
                  anchor='rm')
        draw.rectangle(((x_base + 10, y_position + tick_height - 1),
                        (x_base + 20, y_position + tick_height + 1)), "#000")
        y_position += tick_height

    arrow_offset = y_base + dusks_and_dawns[
        "now_index"] * tick_height + tick_height // 2
    draw.polygon([(x_base + tick_gap + tick_width + arrow_gap + arrow_width,
                   -10 + arrow_offset),
                  (x_base + tick_gap + tick_width + arrow_gap, arrow_offset),
                  (x_base + tick_gap + tick_width + arrow_gap + arrow_width,
                   10 + arrow_offset)], "#000")

    (moon_phase, percent) = get_moon_phase()
    moon_font_chr = get_moon_phase_chr(moon_phase)
    font_moon = fonts['font_misc_md']
    draw.text((3 * x_size // 4, 90),
              moon_font_chr,
              font=font_moon,
              fill=0,
              anchor="ma")
    ascent, descent = font_moon.getmetrics()
    utils.draw_quantity(draw, (3 * x_size // 4, 90 + ascent + descent + 70),
                        str(round(percent)), '%', fonts)

    # Borders
    if (config.getboolean('DRAW_PANEL_BORDERS')):
        draw.polygon([(0, 0), (x_size - 1, 0), (x_size - 1, y_size - 1),
                      (0, y_size - 1), (0, 0)])

    return image
 def test_get_dusks_and_dawns_quaanaak_spring(self):
     now = datetime.fromisoformat('2021-03-06T12:00:00+02:00')
     result = celestial.get_dusks_and_dawns(self.QUAANAAK_LOCATION, now)
     self.assertEqual(result["twilights"], [4, 3, 2, 1, 0, 1, 2, 3])
 def test_get_dusks_and_dawns_quaanaak_summer(self):
     now = datetime.fromisoformat('2021-06-01T12:00:00+02:00')
     result = celestial.get_dusks_and_dawns(self.MCMURDO_LOCATION, now)
     self.assertEqual(result["twilights"], [4, 3, 2, 3, 4])
 def test_get_dusks_and_dawns_ivalo_spring(self):
     now = datetime.fromisoformat('2021-04-01T12:00:00+02:00')
     result = celestial.get_dusks_and_dawns(self.IVALO_LOCATION, now)
     self.assertEqual(result["twilights"], [3, 2, 1, 0, 1, 2, 3])
 def test_get_dusks_and_dawns_ivalo_summer(self):
     now = datetime.fromisoformat('2021-06-01T12:00:00+02:00')
     result = celestial.get_dusks_and_dawns(self.IVALO_LOCATION, now)
     self.assertEqual(result["twilights"], [0])
     self.assertEqual(result["now_index"], 0)
 def test_get_dusks_and_dawns_ivalo_winter(self):
     now = datetime.fromisoformat('2021-12-04T12:00:00+02:00')
     result = celestial.get_dusks_and_dawns(self.IVALO_LOCATION, now)
     self.assertEqual(result["twilights"], [4, 3, 2, 1, 2, 3, 4])
 def test_get_dusks_and_dawns_helsinki(self):
     now = datetime.fromisoformat('2021-08-21T12:00:00+02:00')
     result = celestial.get_dusks_and_dawns(self.HELSINKI_LOCATION, now)
     self.assertEqual(result["twilights"], [3, 2, 1, 0, 1, 2, 3, 4])
 def test_get_dusks_and_dawns_helsinki_winter_nautical_dusk(self):
     now = datetime.fromisoformat('2021-12-21T16:30:00+02:00')
     result = celestial.get_dusks_and_dawns(self.HELSINKI_LOCATION, now)
     self.assertEqual(result["twilights"], [4, 3, 2, 1, 0, 1, 2, 3, 4])
     self.assertEqual(result["now_index"], 6)