Skip to content

Commit

Permalink
new layout
Browse files Browse the repository at this point in the history
  • Loading branch information
markyharris committed Mar 30, 2022
1 parent 7390ec0 commit 6e59b11
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 28 deletions.
2 changes: 1 addition & 1 deletion data.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kflg
6
-2
1800
0
139 changes: 139 additions & 0 deletions metar_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,3 +1650,142 @@ def center_text(text, font, x_pos, y_pos):
display.draw_red.text((x_pos, y_pos), cctype, fill=0, font=font24b)
x_pos, y_pos = center_text(ccheight, font24b, OUTER_CIRCLES[7][0], OUTER_CIRCLES[7][1]+10)
display.draw_red.text((x_pos, y_pos), ccheight, fill=0, font=font24b)


############
# layout8 #
############
# Worst Weather by airport
def layout8(display, metar, remarks, print_table, use_remarks):
fc_ap_dict = {}
vfr_dict,mvfr_dict,ifr_dict,lifr_dict = get_flightcat()

# Data layout for layout8.
# 0,0 in upper left hand corner. 800,480 in lower right corner
LINE0 = 15
LINE1 = 105
LINE2 = 195
LINE3 = 285
LINE4 = 375
LINE5 = 465

COL0 = 20
COL1 = 290
COL2 = 550
COL3 = 810

RADIUS = 10
MARGIN = 10
SPACING = (2*RADIUS)+MARGIN
ICON_OFFSET = COL1-COL0-60
NUM_AIRPORTS = 15

# Display box with airport and flight category. The box must be drawn first than the text
# To create rounded corner box provide the following variables in this order
# up_left_x, up_left_y, box_width, box_height, radius, box_color
def print_box(flight_cat, airport, pos1_x, pos1_y, pos2_x, pos2_y):
metar = Metar(airport)
# flightcategory, icon = flight_category(metar)
flightcategory = flight_cat
output = airport+":"+flightcategory+" "
w, h = display.draw_black.textsize(output, font=font36b)
w_name, h_name = display.draw_black.textsize(metar.data2["properties"]["name"][:26], font=font14b)
if flightcategory == "VFR":
icon = "sun"
display.round_line(pos1_x, pos1_y, pos2_x-pos1_x-SPACING, pos2_y-pos1_y-SPACING, RADIUS, "b", 0, 3)
display.draw_black.text(((pos2_x-pos1_x)/2-(w/2)+(pos1_x-COL0), (pos2_y-pos1_y)/2-(h/2)+(pos1_y-LINE0)-10), output, fill=0, font=font36b)
display.draw_icon(pos1_x+ICON_OFFSET, pos1_y, "b", 30, 30, icon)
display.draw_black.text(((pos2_x-pos1_x)/2-(w_name/2)+(pos1_x-COL0), pos1_y+40), metar.data2["properties"]["name"][:26], fill=0, font=font14b)
elif flightcategory == "MVFR":
icon = "25_clouds"
display.round_box(pos1_x, pos1_y, pos2_x-pos1_x-SPACING, pos2_y-pos1_y-SPACING, RADIUS, "b")
display.draw_black.text(((pos2_x-pos1_x)/2-(w/2)+(pos1_x-COL0), (pos2_y-pos1_y)/2-(h/2)+(pos1_y-LINE0)-10), output, fill=255, font=font36b)
display.draw_icon(pos1_x+ICON_OFFSET, pos1_y, "wb", 30, 30, icon)
display.draw_black.text(((pos2_x-pos1_x)/2-(w_name/2)+(pos1_x-COL0), pos1_y+40), metar.data2["properties"]["name"][:26], fill=255, font=font14b)
elif flightcategory == "IFR":
icon = "thunder"
display.round_line(pos1_x, pos1_y, pos2_x-pos1_x-SPACING, pos2_y-pos1_y-SPACING, RADIUS, "r")
display.draw_red.text(((pos2_x-pos1_x)/2-(w/2)+(pos1_x-COL0), (pos2_y-pos1_y)/2-(h/2)+(pos1_y-LINE0)-10), output, fill=0, font=font36b)
display.draw_icon(pos1_x+ICON_OFFSET, pos1_y, "r", 30, 30, icon)
display.draw_red.text(((pos2_x-pos1_x)/2-(w_name/2)+(pos1_x-COL0), pos1_y+40), metar.data2["properties"]["name"][:26], fill=0, font=font14b)
elif flightcategory == "LIFR":
icon = "mist"
display.round_box(pos1_x, pos1_y, pos2_x-pos1_x-SPACING, pos2_y-pos1_y-SPACING, RADIUS, "r")
display.draw_red.text(((pos2_x-pos1_x)/2-(w/2)+(pos1_x-COL0), (pos2_y-pos1_y)/2-(h/2)+(pos1_y-LINE0)-10), output, fill=255, font=font36b)
display.draw_icon(pos1_x+ICON_OFFSET, pos1_y, "wr", 30, 30, icon)
display.draw_red.text(((pos2_x-pos1_x)/2-(w_name/2)+(pos1_x-COL0), pos1_y+40), metar.data2["properties"]["name"][:26], fill=255, font=font14b)
else:
display.round_line(pos1_x, pos1_y, pos2_x-pos1_x-SPACING, pos2_y-pos1_y-SPACING, RADIUS, "b")
display.draw_red.text(((pos2_x-pos1_x)/2-(w/2)+(pos1_x-COL0), (pos2_y-pos1_y)/2-(h/2)+(pos1_y-LINE0)-10), output, fill=255, font=font36b)
display.draw_icon(pos1_x+ICON_OFFSET, pos1_y, "wr", 30, 30, icon)
display.draw_red.text(((pos2_x-pos1_x)/2-(w_name/2)+(pos1_x-COL0), pos1_y+40), metar.data2["properties"]["name"][:26], fill=255, font=font14b)

# build dictionary
if len(lifr_dict) > 0:
for key, value in lifr_dict.items():
fc_ap_dict[key] = value

if len(ifr_dict) > 0:
for key, value in ifr_dict.items():
fc_ap_dict[key] = value

if len(mvfr_dict) > 0:
for key, value in mvfr_dict.items():
fc_ap_dict[key] = value

if len(fc_ap_dict) < NUM_AIRPORTS:
for key, value in vfr_dict.items():
fc_ap_dict[key] = value
if len(fc_ap_dict) >= NUM_AIRPORTS:
break

fc_ap_dict = dict(list(fc_ap_dict.items())[:NUM_AIRPORTS]) # Trim dict

# print(len(fc_ap_dict)) # debug
# print(fc_ap_dict) # debug
keys_ap = list(fc_ap_dict.keys())
values_ap = list(fc_ap_dict.values())

# Column 1
airport, flight_cat = keys_ap[0], values_ap[0]
print_box(flight_cat, airport, COL0, LINE0, COL1, LINE1)
airport, flight_cat = keys_ap[1], values_ap[1]
print_box(flight_cat, airport, COL0, LINE1, COL1, LINE2)
airport, flight_cat = keys_ap[2], values_ap[2]
print_box(flight_cat, airport, COL0, LINE2, COL1, LINE3)
airport, flight_cat = keys_ap[3], values_ap[3]
print_box(flight_cat, airport, COL0, LINE3, COL1, LINE4)
airport, flight_cat = keys_ap[4], values_ap[4]
print_box(flight_cat, airport, COL0, LINE4, COL1, LINE5)

# Column 2
airport, flight_cat = keys_ap[5], values_ap[5]
print_box(flight_cat, airport, COL1, LINE0, COL2, LINE1)
airport, flight_cat = keys_ap[6], values_ap[6]
print_box(flight_cat, airport, COL1, LINE1, COL2, LINE2)
airport, flight_cat = keys_ap[7], values_ap[7]
print_box(flight_cat, airport, COL1, LINE2, COL2, LINE3)
airport, flight_cat = keys_ap[8], values_ap[8]
print_box(flight_cat, airport, COL1, LINE3, COL2, LINE4)
airport, flight_cat = keys_ap[9], values_ap[9]
print_box(flight_cat, airport, COL1, LINE4, COL2, LINE5)

# Column 3
airport, flight_cat = keys_ap[10], values_ap[10]
print_box(flight_cat, airport, COL2, LINE0, COL3, LINE1)
airport, flight_cat = keys_ap[11], values_ap[11]
print_box(flight_cat, airport, COL2, LINE1, COL3, LINE2)
airport, flight_cat = keys_ap[12], values_ap[12]
print_box(flight_cat, airport, COL2, LINE2, COL3, LINE3)
airport, flight_cat = keys_ap[13], values_ap[13]
print_box(flight_cat, airport, COL2, LINE3, COL3, LINE4)
airport, flight_cat = keys_ap[14], values_ap[14]
print_box(flight_cat, airport, COL2, LINE4, COL3, LINE5)

now = datetime.now()
next_update = now + timedelta(0,int(interval)) # days, seconds
next_update_text = "Next Update at "+next_update.strftime("%I:%M %p, %m/%d/%Y")
w_upd, h_upd = display.draw_black.textsize(next_update_text, font=font20b)
display.draw_black.text((400-(w_upd/2), 460), next_update_text, fill=0, font=font20b)


8 changes: 4 additions & 4 deletions metar_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
from waveshare_epd import epd7in5b_V2

# Layouts - add new layouts to this list as necessary
layout_list = [layout0,layout1,layout2,layout3,layout4,layout5,layout6,layout7] # ,layout6 Add layout routine names here
layout_list = [layout0,layout1,layout2,layout3,layout4,layout5,layout6,layout7,layout8] # ,layout6 Add layout routine names here

# Check for cmdline args and use passed variables instead of the defaults above
if len(sys.argv) > 1:
Expand Down Expand Up @@ -116,9 +116,9 @@ def main():
epd = epd7in5b_V2.EPD() # Instantiate instance for display.

while True:
try:
# try:
# error = 1/0 #debug # forces error to test the try-except statements
# if True: # used instead of the try-except statements for debug purposes.
if True: # used instead of the try-except statements for debug purposes.
current_time = time.strftime("%m/%d/%Y %H:%M", time.localtime())

metar = Metar(airport)
Expand Down Expand Up @@ -147,7 +147,7 @@ def main():
epd.init()
epd.sleep()

except Exception as e:
# except Exception as e:
time.sleep(2)
print("Error Occurred in Main While Loop")
exception_type, exception_object, exception_traceback = sys.exc_info()
Expand Down
64 changes: 64 additions & 0 deletions metar_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,75 @@

# Imports
from metar_remarks import *
import urllib.request, urllib.error, urllib.parse
import xml.etree.ElementTree as ET

# Misc Variables
decode = [] # used to decode the raw metar
print_table = [] # Store decoded remark definitions to display
remarks = "" # Build remarks string to display

# Class Bravo airports used to find bad weather to display on Multiple Airports Layout5
class_b = ["KPHX", "KLAX", "KNKX", "KSAN", "KSFO", "KDEN", "KMCO", "KMIA", "KTPA", "KATL", \
"PHNL", "KORD", "KCVG", "KMSY", "KADW", "KBWI", "KBOS", "KDTW", "KMSP", "KMCI", \
"KSTL", "KLAS", "KLSV", "KEWR", "KJFK", "KLGA", "KCLT", "KCLE", "KPHL", "KPIT", \
"KMEM", "KDAL", "KDFW", "KHOU", "KIAH", "KSLC", "KDCA", "KIAD", "KSEA"]

# Class Charlie airports used to find bad weather to display on Multiple Airports Layout5
class_c = ['KBHM', 'KHSV', 'KMOB', 'PANC', 'KDMA', 'KTUS', 'KLIT', 'KXNA', 'KBAB', 'KBUR', \
'KFAT', 'KMRY', 'KOAK', 'KONT', 'KRIV', 'KSBA', 'KSJC', 'KSMF', 'KSNA', 'KCOS', \
'KBDL', 'KDAB', 'KFLL', 'KJAX', 'KNDZ', 'KNPA', 'KNSE', 'KPBI', 'KPNS', 'KRSW', \
'KSFB', 'KSRQ', 'KTLH', 'KSAV', 'PHOG', 'KBOI', 'KCMI', 'KMDW', 'KMLI', 'KPIA', \
'KSPI', 'KEVV', 'KFWA', 'KIND', 'KSBN', 'KCID', 'KDSM', 'KICT', 'KLEX', 'KSDF', \
'KBAD', 'KBTR', 'KLFT', 'KSHV', 'KBGR', 'KPWM', 'KFNT', 'KGRR', 'KLAN', 'KCBM', \
'KJAN', 'KSGF', 'KBIL', 'KLNK', 'KOFF', 'KOMA', 'KRNO', 'KMHT', 'KACY', 'KABQ', \
'KALB', 'KBUF', 'KISP', 'KROC', 'KSYR', 'KAVL', 'KFAY', 'KGSO', 'KPOB', 'KRDU', \
'KCAK', 'KCMH', 'KDAY', 'KTOL', 'KOKC', 'KTIK', 'KTUL', 'KPDX', 'KABE', 'KPVD', \
'KCAE', 'KCHS', 'KGSP', 'KMYR', 'KSSC', 'KBNA', 'KCHA', 'KTYS', 'KABI', 'KAMA', \
'KAUS', 'KCRP', 'KDLF', 'KDYS', 'KELP', 'KHRL', 'KLBB', 'KMAF', 'KSAT', 'KBTV', \
'KORF', 'KRIC', 'KROA', 'KGEG', 'KNUW', 'KSKA', 'KCRW', 'KGRB', 'KMKE', 'KMSN', \
'TJSJ', 'TIST']

# Get Flight Categories for Class B and Class C airports
def get_flightcat():
# api url
url = "https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&mostRecentForEachStation=constraint&hoursBeforeNow=2.5&stationString="

fc_dict = {}
vfr_dict = {}
mvfr_dict = {}
ifr_dict = {}
lifr_dict = {}

# Build URL with class b and class c airports
for ap in class_b:
url = url+ap+","
for ap in class_c:
url = url+ap+","

content = urllib.request.urlopen(url).read()
root = ET.fromstring(content) #Process XML data returned from FAA
for data in root.iter('data'):
num_results = data.attrib['num_results']
print(num_results)

for metar in root.iter('METAR'):
stationId = metar.find('station_id').text
flightcategory = metar.find('flight_category').text
fc_dict[stationId] = flightcategory

for key in fc_dict:
if "MVFR" in fc_dict[key]:
mvfr_dict[key] = "MVFR"
elif "IFR" in fc_dict[key]:
ifr_dict[key] = "IFR"
elif "LIFR" in fc_dict[key]:
lifr_dict[key] = "LIFR"
else:
vfr_dict[key] = "VFR"

return(vfr_dict,mvfr_dict,ifr_dict,lifr_dict)


# Decodes the flight category from the raw metar string
def flight_category(metar):
Expand Down
24 changes: 1 addition & 23 deletions metar_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Default User Settings
airport = "KFLG" # enter default airport identifier to display
interval = 1800 # enter default time in seconds between METAR updates - 3600 = 1 hour
use_disp_format = 7 # Choose which display layout to use. -1 = Random layout, -2 = Cycle layouts
use_disp_format = 8 # Choose which display layout to use. -1 = Random layout, -2 = Cycle layouts
use_remarks = 1 # 0 = display airport information, 1 = display metar remarks info

# Random Airports Choices (Layout5):
Expand All @@ -17,25 +17,3 @@
random_airports = ["KEYW","KFVE","KSEA","KCVG", "KLAS","KCMR","KGRR","KMSN", \
"KLAX","KNBC","KFVE","KBUF"] #, "KTPA", "KLAS","KGEU","KOLS", \
# "KSAN", "KPDX", "KBOI", "KMSP", "KSTL", "KBNA", "KTYS"]

# Class Bravo airports used to find bad weather to display on Multiple Airports Layout5
class_b = ["KPHX", "KLAX", "KNKX", "KSAN", "KSFO", "KDEN", "KMCO", "KMIA", "KTPA", "KATL", \
"PHNL", "KORD", "KCVG", "KMSY", "KADW", "KBWI", "KBOS", "KDTW", "KMSP", "KMCI", \
"KSTL", "KLAS", "KLSV", "KEWR", "KJFK", "KLGA", "KCLT", "KCLE", "KPHL", "KPIT", \
"KMEM", "KDAL", "KDFW", "KHOU", "KIAH", "KSLC", "KDCA", "KIAD", "KSEA"]

# Class Charlie airports used to find bad weather to display on Multiple Airports Layout5
class_c = ['KBHM', 'KHSV', 'KMOB', 'PANC', 'KDMA', 'KTUS', 'KLIT', 'KXNA', 'KBAB', 'KBUR', \
'KFAT', 'KMRY', 'KOAK', 'KONT', 'KRIV', 'KSBA', 'KSJC', 'KSMF', 'KSNA', 'KCOS', \
'KBDL', 'KDAB', 'KFLL', 'KJAX', 'KNDZ', 'KNPA', 'KNSE', 'KPBI', 'KPNS', 'KRSW', \
'KSFB', 'KSRQ', 'KTLH', 'KSAV', 'PHOG', 'KBOI', 'KCMI', 'KMDW', 'KMLI', 'KPIA', \
'KSPI', 'KEVV', 'KFWA', 'KIND', 'KSBN', 'KCID', 'KDSM', 'KICT', 'KLEX', 'KSDF', \
'KBAD', 'KBTR', 'KLFT', 'KSHV', 'KBGR', 'KPWM', 'KFNT', 'KGRR', 'KLAN', 'KCBM', \
'KJAN', 'KSGF', 'KBIL', 'KLNK', 'KOFF', 'KOMA', 'KRNO', 'KMHT', 'KACY', 'KABQ', \
'KALB', 'KBUF', 'KISP', 'KROC', 'KSYR', 'KAVL', 'KFAY', 'KGSO', 'KPOB', 'KRDU', \
'KCAK', 'KCMH', 'KDAY', 'KTOL', 'KOKC', 'KTIK', 'KTUL', 'KPDX', 'KABE', 'KPVD', \
'KCAE', 'KCHS', 'KGSP', 'KMYR', 'KSSC', 'KBNA', 'KCHA', 'KTYS', 'KABI', 'KAMA', \
'KAUS', 'KCRP', 'KDLF', 'KDYS', 'KELP', 'KHRL', 'KLBB', 'KMAF', 'KSAT', 'KBTV', \
'KORF', 'KRIC', 'KROA', 'KGEG', 'KNUW', 'KSKA', 'KCRW', 'KGRB', 'KMKE', 'KMSN', \
'TJSJ', 'TIST']

1 change: 1 addition & 0 deletions templates/metar.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ <h2>METAR E-Paper Display Selector</h2>
<option value="5" {% if data_field2=="5" %} selected="selected" {% endif %}>Multiple Airport Flight Categories</option>
<option value="6" {% if data_field2=="6" %} selected="selected" {% endif %}>Airport Map and Flight Category</option>
<option value="7" {% if data_field2=="7" %} selected="selected" {% endif %}>Flight Category In Circles</option>
<option value="8" {% if data_field2=="8" %} selected="selected" {% endif %}>Worst Class B & C Airport Weather</option>

</select>
<br><p>
Expand Down

0 comments on commit 6e59b11

Please sign in to comment.