Skip to content

Commit

Permalink
added distance calculator which resolves [FEATURE REQUEST] Distance C…
Browse files Browse the repository at this point in the history
…alculator #5
  • Loading branch information
justinkumpe committed Oct 25, 2024
1 parent 14e52c8 commit e82beba
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 70 deletions.
112 changes: 56 additions & 56 deletions classes/CopperPair.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __tip(pair) -> str:
@property
def tip_color(self) -> str:
"""Tip Color"""
return self.__tip(self.pair)
return self.__tip(self.base_pair)

@staticmethod
def __tip_hex(tip: str) -> str:
Expand Down Expand Up @@ -71,7 +71,7 @@ def __ring(pair: int) -> str:
@property
def ring_color(self) -> str:
"""Ring Color"""
return self.__ring(self.pair)
return self.__ring(self.base_pair)

@staticmethod
def __ring_hex(tip: str) -> str:
Expand Down Expand Up @@ -99,55 +99,55 @@ def ring_hex(self) -> str:
def super_binder(self) -> int:
"""Super Binder Group"""
match self.pair:
case num if 1 <= num >= 625:
case num if 1 <= num <= 625:
return 1
case num if 626 <= num >= 1250:
case num if 626 <= num <= 1250:
return 2
case num if 1251 <= num >= 1875:
case num if 1251 <= num <= 1875:
return 3
case num if 1876 <= num >= 2500:
case num if 1876 <= num <= 2500:
return 4
case num if 2501 <= num >= 3125:
case num if 2501 <= num <= 3125:
return 5
case num if 3126 <= num >= 3750:
case num if 3126 <= num <= 3750:
return 6
case num if 3751 <= num >= 4375:
case num if 3751 <= num <= 4375:
return 7
case num if 4376 <= num >= 5000:
case num if 4376 <= num <= 5000:
return 8
case num if 5001 <= num >= 5625:
case num if 5001 <= num <= 5625:
return 9
case num if 5626 <= num >= 6250:
case num if 5626 <= num <= 6250:
return 10
case num if 6251 <= num >= 6875:
case num if 6251 <= num <= 6875:
return 11
case num if 6876 <= num >= 7500:
case num if 6876 <= num <= 7500:
return 12
case num if 7501 <= num >= 8125:
case num if 7501 <= num <= 8125:
return 13
case num if 8126 <= num >= 8750:
case num if 8126 <= num <= 8750:
return 14
case num if 8751 <= num >= 9375:
case num if 8751 <= num <= 9375:
return 15
case num if 9376 <= num >= 10000:
case num if 9376 <= num <= 10000:
return 16
case num if 10001 <= num >= 10625:
case num if 10001 <= num <= 10625:
return 17
case num if 10626 <= num >= 11250:
case num if 10626 <= num <= 11250:
return 18
case num if 112551 <= num >= 11875:
case num if 112551 <= num <= 11875:
return 19
case num if 11876 <= num >= 12500:
case num if 11876 <= num <= 12500:
return 20
case num if 12501 <= num >= 13125:
case num if 12501 <= num <= 13125:
return 21
case num if 13126 <= num >= 13750:
case num if 13126 <= num <= 13750:
return 22
case num if 13751 <= num >= 14375:
case num if 13751 <= num <= 14375:
return 23
case num if 14376 <= num >= 15000:
case num if 14376 <= num <= 15000:
return 24
case num if 15001 <= num >= 15625:
case num if 15001 <= num <= 15625:
return 25
case _:
return 0
Expand All @@ -156,55 +156,55 @@ def super_binder(self) -> int:
def binder(self) -> int:
"""Binder Number"""
match self.base_binder_pair:
case num if 1 <= num >= 25:
case num if 1 <= num <= 25:
return 1
case num if 26 <= num >= 50:
case num if 26 <= num <= 50:
return 2
case num if 51 <= num >= 75:
case num if 51 <= num <= 75:
return 3
case num if 76 <= num >= 100:
case num if 76 <= num <= 100:
return 4
case num if 101 <= num >= 125:
case num if 101 <= num <= 125:
return 5
case num if 126 <= num >= 150:
case num if 126 <= num <= 150:
return 6
case num if 151 <= num >= 175:
case num if 151 <= num <= 175:
return 7
case num if 176 <= num >= 200:
case num if 176 <= num <= 200:
return 8
case num if 201 <= num >= 225:
case num if 201 <= num <= 225:
return 9
case num if 226 <= num >= 250:
case num if 226 <= num <= 250:
return 10
case num if 251 <= num >= 275:
case num if 251 <= num <= 275:
return 11
case num if 276 <= num >= 300:
case num if 276 <= num <= 300:
return 12
case num if 301 <= num >= 325:
case num if 301 <= num <= 325:
return 13
case num if 326 <= num >= 350:
case num if 326 <= num <= 350:
return 14
case num if 351 <= num >= 375:
case num if 351 <= num <= 375:
return 15
case num if 376 <= num >= 400:
case num if 376 <= num <= 400:
return 16
case num if 401 <= num >= 425:
case num if 401 <= num <= 425:
return 17
case num if 426 <= num >= 450:
case num if 426 <= num <= 450:
return 18
case num if 451 <= num >= 475:
case num if 451 <= num <= 475:
return 19
case num if 476 <= num >= 500:
case num if 476 <= num <= 500:
return 20
case num if 501 <= num >= 525:
case num if 501 <= num <= 525:
return 21
case num if 526 <= num >= 550:
case num if 526 <= num <= 550:
return 22
case num if 551 <= num >= 575:
case num if 551 <= num <= 575:
return 23
case num if 576 <= num >= 600:
case num if 576 <= num <= 600:
return 24
case num if 601 <= num >= 625:
case num if 601 <= num <= 625:
return 25
case _:
return 0
Expand All @@ -224,19 +224,19 @@ def base_binder_pair(self) -> int:
@property
def binder_tip_color(self) -> str:
"""Binder Tip Color"""
return self.__tip_hex(self.__tip(self.binder))
return self.__tip(self.binder)

@property
def binder_ring_color(self) -> str:
"""Binder Ring Color"""
return self.__ring_hex(self.__tip(self.binder))
return self.__ring(self.binder)

@property
def super_binder_tip_color(self) -> str:
"""Super Binder Tip Color"""
return self.__tip_hex(self.__tip(self.super_binder))
return self.__tip(self.super_binder)

@property
def super_binder_ring_color(self) -> str:
"""Super Binder Ring Color"""
return self.__ring_hex(self.__ring(self.super_binder))
return self.__ring(self.super_binder)
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def view(data: fs.Datasy):
text="Static IP Instructions", on_click=data.go("/uv/statics")
),
ft.PopupMenuItem(
text="Copper Pair to Color", on_click=data.go("/copper/pair_to_color")
text="Copper Pair Calculator", on_click=data.go("/copper/pair_to_color")
),
ft.PopupMenuItem(
text="Distance Calculator", on_click=data.go("/distance_calc")
),
]
),
Expand Down
18 changes: 9 additions & 9 deletions views/copper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ def copper_color_code_page(data: fs.Datasy):
horizontal_alignment="center",
appbar=view.appbar,
bgcolor=AppColors.BG,
scroll=ft.ScrollMode.ALWAYS
scroll=ft.ScrollMode.ALWAYS,
)


@copper.page("/pair_to_color/{pair}", title="Copper Color To Pair")
@copper.page("/pair_to_color", title="Copper Color To Pair")
def copper_pair_to_color_page(data: fs.Datasy, pair=""):
"""Copper Pair to Color Page"""

def changed_pair():
"""Changed Pair"""
data.page.go(f"/copper/pair_to_color/{pair_field.value}")

view = data.view
title = ft.Text(
value="Copper Pair Calculator",
Expand All @@ -55,21 +58,19 @@ def changed_pair():
border_color=ft.colors.WHITE,
width=100,
value=pair,
on_change=lambda e: changed_pair()
on_change=lambda e: changed_pair(),
)
if pair == "":
pair_info = ft.Text(
(
""
),
text_align=ft.alignment.center,
color=ft.colors.WHITE,
(""),
text_align=ft.alignment.center,
color=ft.colors.WHITE,
)
else:
pair_data = CopperPair(int(pair))
pair_info = ft.Text(
(
f"Pair: {pair} ({pair_data.tip_color}/{pair_data.ring_color})\n"
f"Pair: {pair_data.base_pair} ({pair_data.tip_color}/{pair_data.ring_color})\n"
f"Binder: {pair_data.binder} ({pair_data.binder_tip_color}/{pair_data.binder_ring_color})\n"
f"Super Binder: {pair_data.super_binder} ({pair_data.super_binder_tip_color}/{pair_data.super_binder_ring_color})\n"
),
Expand Down Expand Up @@ -102,4 +103,3 @@ def changed_pair():
appbar=view.appbar,
bgcolor=AppColors.BG,
)

80 changes: 80 additions & 0 deletions views/distance_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""UVT Home"""

import flet as ft # type: ignore
import flet_easy as fs # type: ignore
from assets.app_colors import AppColors

copper = fs.AddPagesy()


@copper.page("/distance_calc", title="Distance Calculator")
def distance_calc_page(data: fs.Datasy):
"""Distance Calculator Page"""

view = data.view
title = ft.Text(
value="Distance Calculator",
text_align=ft.alignment.center,
color=ft.colors.WHITE,
)
text = ft.Text("")
conversion_units = ft.Dropdown(
options=[
ft.dropdown.Option("Miles to Feet", alignment=ft.alignment.center),
ft.dropdown.Option("Feet to Miles", alignment=ft.alignment.center),
],
value="Miles to Feet",
alignment=ft.alignment.center,
color=ft.colors.WHITE,
width=100,
on_change=lambda e: changed_value(),
)

def changed_value():
"""Changed Value"""
units = float(pair_field.value)
if conversion_units.value == "Miles to Feet":
new_units = units * 5280
text.value = f"{units} miles = {new_units} feet"
else:
new_units = units / 5280
text.value = f"{units} feet = {new_units} miles"
data.page.update()

pair_field = ft.TextField(
text_align=ft.TextAlign.CENTER,
keyboard_type=ft.KeyboardType.NUMBER,
autofocus=True,
helper_text="Pair Number",
color=ft.colors.WHITE,
border_color=ft.colors.WHITE,
width=100,
on_change=lambda e: changed_value(),
)

container = ft.Container(
bgcolor=AppColors.BG,
# border_radius=35,
# width=400,
# height=850,
content=ft.Stack(
controls=[
ft.Column(
controls=[
pair_field,
conversion_units,
]
)
]
),
# padding=50,
alignment=ft.alignment.top_center,
)

return ft.View(
controls=[title, container, text],
vertical_alignment="center",
horizontal_alignment="center",
appbar=view.appbar,
bgcolor=AppColors.BG,
)
Loading

0 comments on commit e82beba

Please sign in to comment.