-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0674309
commit 2b14410
Showing
6 changed files
with
222 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Ellipsoid Volume | ||
from typing import List | ||
|
||
def prostate_vol(x: List[float]): | ||
"""Calculate prostate volume (ml) and diagnosis""" | ||
v = ellipsoid_list(x) | ||
if v < 25: | ||
dx = "Normal" | ||
elif v == 25: | ||
dx = "Normal or Prominent" | ||
elif v < 40: | ||
dx = "Prominent" | ||
elif v == 40: | ||
dx = "Prominent or Enlarged" | ||
else: | ||
dx = "Enlarged" | ||
|
||
return f"Prostate vol: {round(v, 2)} ml ({dx})" | ||
|
||
|
||
|
||
def ellipsoid(d1, d2, d3): | ||
"""Calculate ellipsoid volume from 3 perpendicular **diameters**""" | ||
import math | ||
volume = (4/3) * math.pi * d1/2 * d2/2 * d3/2 | ||
return volume | ||
|
||
def ellipsoid_list(x: List[float]): | ||
"""Calculate ellipsoid volume from 3 perpendicular **diameters** (List input)""" | ||
try: | ||
return ellipsoid(*x) | ||
except TypeError: | ||
raise TypeError(f"{x} must be a list of three floats") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .designct_app import AppDesignCT | ||
from .mean_app import AppMean | ||
from .spine_ht_loss_app import AppSpineHtLoss | ||
from .spine_ht_loss_app import AppSpineHtLoss | ||
from .vol_app import AppVol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class Manual: | ||
mean_app = f"""Use spaces or comma to separate numbers (e.g. 1.1 1.2)""" | ||
spine_ht_loss_app = f"""Input height in centimeter and use two values to calculate mean, separated by spaces or comma (e.g. 10 12)""" | ||
spine_ht_loss_app = f"""Input height in centimeter and use two values to calculate mean, separated by spaces or comma (e.g. 10 12)""" | ||
vol_app = f"""Input perpendicular diameters (cm) in 3 planes, separated by spaces or comma (e.g. 4.4 4.5 4.6)""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import flet as ft | ||
from flet import Container, Column, Row, ResponsiveRow | ||
import pyperclip | ||
|
||
from calc.vol import prostate_vol | ||
from calc._utils import parse_str_to_num_or_list, read_markdown_file | ||
from module.man import Manual | ||
|
||
class AppVol(ft.UserControl): | ||
def __init__(self): | ||
super().__init__() | ||
|
||
## Input Diameters | ||
self.input_numbers_text = ft.TextField( | ||
label="Diameters in 3 planes (cm)", hint_text="e.g. 4.4 4.5 4.6" | ||
) | ||
|
||
# Button | ||
self.btn = ft.ElevatedButton(text="Generate", on_click=self.button_gen_clicked) | ||
self.btn_copy = ft.IconButton(icon=ft.icons.CONTENT_COPY, icon_size=20, tooltip="Copy output", on_click=self.button_cp_clicked) | ||
|
||
# Output text | ||
txt_size = 14 # 14 | ||
self.output_text_field = ft.TextField(label="Prostate Volume", value="", multiline=True, read_only=False, text_size=txt_size) | ||
|
||
def build(self): | ||
rr = ResponsiveRow( | ||
controls=[ | ||
ft.Text("Prostate Volume", theme_style=ft.TextThemeStyle.TITLE_LARGE), | ||
Column(col={"sm": 6}, | ||
controls = [ | ||
self.input_numbers_text, | ||
# Manual | ||
ft.Text(Manual.vol_app, theme_style = ft.TextThemeStyle.BODY_SMALL, color=ft.colors.GREY), | ||
# ft.Markdown(Manual.mean_app, selectable=True) | ||
], alignment=ft.MainAxisAlignment.START), | ||
Column(col={"sm": 6}, | ||
controls = [ | ||
self.output_text_field, | ||
Row([self.btn, self.btn_copy], alignment=ft.MainAxisAlignment.START), | ||
], alignment=ft.MainAxisAlignment.START) | ||
] | ||
) | ||
lv = ft.ListView(controls=[rr], expand=1, spacing=5, padding=10, auto_scroll=False) | ||
return lv | ||
|
||
def button_cp_clicked(self, e): | ||
pyperclip.copy(self.output_text_field.value) | ||
|
||
def button_gen_clicked(self, e): | ||
self._log() | ||
self.output_text_field.value = self.calc() | ||
self.output_text_field.focus() | ||
self.output_text_field.update() | ||
|
||
def _log(self): | ||
print("Btn clicked") | ||
print(f"Input: {self.input_numbers_text.value}") | ||
print(self.calc()) | ||
|
||
def calc(self): | ||
numbers = parse_str_to_num_or_list(self.input_numbers_text.value) | ||
mean = prostate_vol(numbers) | ||
return mean |