hopegeb commited on
Commit
5d0af5f
·
verified ·
1 Parent(s): 3eba2fe

Update app.py

Browse files

digit to letter amharic and tigrigna library

Files changed (1) hide show
  1. app.py +136 -162
app.py CHANGED
@@ -1,162 +1,136 @@
1
- import faicons as fa
2
- import plotly.express as px
3
-
4
- # Load data and compute static values
5
- from shared import app_dir, tips
6
- from shinywidgets import render_plotly
7
-
8
- from shiny import reactive, render
9
- from shiny.express import input, ui
10
-
11
- bill_rng = (min(tips.total_bill), max(tips.total_bill))
12
-
13
- # Add page title and sidebar
14
- ui.page_opts(title="Restaurant tipping", fillable=True)
15
-
16
- with ui.sidebar(open="desktop"):
17
- ui.input_slider(
18
- "total_bill",
19
- "Bill amount",
20
- min=bill_rng[0],
21
- max=bill_rng[1],
22
- value=bill_rng,
23
- pre="$",
24
- )
25
- ui.input_checkbox_group(
26
- "time",
27
- "Food service",
28
- ["Lunch", "Dinner"],
29
- selected=["Lunch", "Dinner"],
30
- inline=True,
31
- )
32
- ui.input_action_button("reset", "Reset filter")
33
-
34
- # Add main content
35
- ICONS = {
36
- "user": fa.icon_svg("user", "regular"),
37
- "wallet": fa.icon_svg("wallet"),
38
- "currency-dollar": fa.icon_svg("dollar-sign"),
39
- "ellipsis": fa.icon_svg("ellipsis"),
40
- }
41
-
42
- with ui.layout_columns(fill=False):
43
- with ui.value_box(showcase=ICONS["user"]):
44
- "Total tippers"
45
-
46
- @render.express
47
- def total_tippers():
48
- tips_data().shape[0]
49
-
50
- with ui.value_box(showcase=ICONS["wallet"]):
51
- "Average tip"
52
-
53
- @render.express
54
- def average_tip():
55
- d = tips_data()
56
- if d.shape[0] > 0:
57
- perc = d.tip / d.total_bill
58
- f"{perc.mean():.1%}"
59
-
60
- with ui.value_box(showcase=ICONS["currency-dollar"]):
61
- "Average bill"
62
-
63
- @render.express
64
- def average_bill():
65
- d = tips_data()
66
- if d.shape[0] > 0:
67
- bill = d.total_bill.mean()
68
- f"${bill:.2f}"
69
-
70
-
71
- with ui.layout_columns(col_widths=[6, 6, 12]):
72
- with ui.card(full_screen=True):
73
- ui.card_header("Tips data")
74
-
75
- @render.data_frame
76
- def table():
77
- return render.DataGrid(tips_data())
78
-
79
- with ui.card(full_screen=True):
80
- with ui.card_header(class_="d-flex justify-content-between align-items-center"):
81
- "Total bill vs tip"
82
- with ui.popover(title="Add a color variable", placement="top"):
83
- ICONS["ellipsis"]
84
- ui.input_radio_buttons(
85
- "scatter_color",
86
- None,
87
- ["none", "sex", "smoker", "day", "time"],
88
- inline=True,
89
- )
90
-
91
- @render_plotly
92
- def scatterplot():
93
- color = input.scatter_color()
94
- return px.scatter(
95
- tips_data(),
96
- x="total_bill",
97
- y="tip",
98
- color=None if color == "none" else color,
99
- trendline="lowess",
100
- )
101
-
102
- with ui.card(full_screen=True):
103
- with ui.card_header(class_="d-flex justify-content-between align-items-center"):
104
- "Tip percentages"
105
- with ui.popover(title="Add a color variable"):
106
- ICONS["ellipsis"]
107
- ui.input_radio_buttons(
108
- "tip_perc_y",
109
- "Split by:",
110
- ["sex", "smoker", "day", "time"],
111
- selected="day",
112
- inline=True,
113
- )
114
-
115
- @render_plotly
116
- def tip_perc():
117
- from ridgeplot import ridgeplot
118
-
119
- dat = tips_data()
120
- dat["percent"] = dat.tip / dat.total_bill
121
- yvar = input.tip_perc_y()
122
- uvals = dat[yvar].unique()
123
-
124
- samples = [[dat.percent[dat[yvar] == val]] for val in uvals]
125
-
126
- plt = ridgeplot(
127
- samples=samples,
128
- labels=uvals,
129
- bandwidth=0.01,
130
- colorscale="viridis",
131
- colormode="row-index",
132
- )
133
-
134
- plt.update_layout(
135
- legend=dict(
136
- orientation="h", yanchor="bottom", y=1.02, xanchor="center", x=0.5
137
- )
138
- )
139
-
140
- return plt
141
-
142
-
143
- ui.include_css(app_dir / "styles.css")
144
-
145
- # --------------------------------------------------------
146
- # Reactive calculations and effects
147
- # --------------------------------------------------------
148
-
149
-
150
- @reactive.calc
151
- def tips_data():
152
- bill = input.total_bill()
153
- idx1 = tips.total_bill.between(bill[0], bill[1])
154
- idx2 = tips.time.isin(input.time())
155
- return tips[idx1 & idx2]
156
-
157
-
158
- @reactive.effect
159
- @reactive.event(input.reset)
160
- def _():
161
- ui.update_slider("total_bill", value=bill_rng)
162
- ui.update_checkbox_group("time", selected=["Lunch", "Dinner"])
 
1
+ def amharic_number_reader(number):
2
+ nums = []
3
+ val = list(number) # Convert the number string to a list of digits
4
+ readNums1 = ["አንድ", "ሁለት", "ሶስት", "አራት", "አምስት", "ስድስት", "ሰባት", "ስምንት", "ዘጠኝ", "ዜሮ"]
5
+ readNums2 = ["አስራ", "ሃያ", "ሰላሳ", "አርባ", "ሃምሳ", "ስልሳ", "ሰባ", "ሰማንያ", "ዘጠና"]
6
+ readNums3 = ["", "መቶ", "ሺ", "አስር ሺ", "መቶ ሺ", "ሚልዮን", "አስር ሚልዮን", "ቢልዮን", "አስር ቢልዮን", "ትሪልዮን"]
7
+
8
+ group_count = len(val)
9
+
10
+ for i, digit in enumerate(val):
11
+ digit = int(digit)
12
+ position = group_count - i - 1 # Position from the right
13
+
14
+ if position == 12: # Trillions
15
+ if digit != 0:
16
+ nums.append(readNums1[digit - 1])
17
+ nums.append(readNums3[9]) # 'ትሪልዮን'
18
+ elif position == 11: # Hundreds of trillions
19
+ if digit != 0:
20
+ nums.append(readNums1[digit - 1])
21
+ nums.append(readNums3[1]) # 'መቶ'
22
+ elif position == 10: # Tens of trillions
23
+ if digit != 0:
24
+ nums.append(readNums2[digit - 1])
25
+ elif position == 9: # Billions
26
+ if digit != 0:
27
+ nums.append(readNums1[digit - 1])
28
+ nums.append(readNums3[7]) # 'ቢልዮን'
29
+ elif position == 8: # Hundreds of billions
30
+ if digit != 0:
31
+ nums.append(readNums1[digit - 1])
32
+ nums.append(readNums3[1]) # 'መቶ'
33
+ elif position == 7: # Tens of billions
34
+ if digit != 0:
35
+ nums.append(readNums2[digit - 1])
36
+ elif position == 6: # Millions
37
+ if digit != 0:
38
+ nums.append(readNums1[digit - 1])
39
+ nums.append(readNums3[5]) # 'ሚልዮን'
40
+ elif position == 5: # Hundreds of thousands
41
+ if digit != 0:
42
+ nums.append(readNums1[digit - 1])
43
+ nums.append(readNums3[1]) # 'መቶ'
44
+ elif position == 4: # Tens of thousands
45
+ if digit != 0:
46
+ nums.append(readNums2[digit - 1])
47
+ elif position == 3: # Thousands
48
+ if digit != 0:
49
+ nums.append(readNums1[digit - 1])
50
+ nums.append(readNums3[2]) # 'ሺ'
51
+ elif position == 2: # Hundreds
52
+ if digit != 0:
53
+ nums.append(readNums1[digit - 1])
54
+ nums.append(readNums3[1]) # 'መቶ'
55
+ elif position == 1: # Tens
56
+ if digit != 0:
57
+ nums.append(readNums2[digit - 1])
58
+ elif position == 0: # Ones
59
+ if digit != 0:
60
+ nums.append(readNums1[digit - 1])
61
+
62
+ return " ".join(nums) # Return as a sentence
63
+ def tigrigna_number_reader(number):
64
+ nums = []
65
+ val = list(number) # Convert the number string to a list of digits
66
+ readNums1 = ["ሓደ", "ክልተ", "ሰለስተ", "ኣርባዕተ", "ሓሙሽተ", "ሽዱሽተ", "ሸዋዓተ", "ሸሞንተ", "ትሽዓተ", "ባዶ"]
67
+ readNums2 = ["ዓሰርተ", "ዕስራ", "ሰላሳ", "ዓርባዓ", "ሓምሳ", "ስልሳ", "ሰብዓ", "ሰማንያ", "ቴስዓ"]
68
+ readNums3 = ["", "ምእቲ", "ሽሕ", "ዓስርተ ሽሕ", "መቶ ሺሕ", "ሚልዮን", "ዓስርተ ሚልዮን", "ቢልዮን", "ዓስርተ ቢልዮን", "ትሪልዮን"]
69
+
70
+ group_count = len(val)
71
+
72
+ for i, digit in enumerate(val):
73
+ digit = int(digit)
74
+ position = group_count - i - 1 # Position from the right
75
+
76
+ if position == 12: # Trillions
77
+ if digit != 0:
78
+ nums.append(readNums1[digit - 1])
79
+ nums.append(readNums3[9]) # 'ትሪልዮን'
80
+ elif position == 11: # Hundreds of trillions
81
+ if digit != 0:
82
+ nums.append(readNums1[digit - 1])
83
+ nums.append(readNums3[1]) # 'መቶ'
84
+ elif position == 10: # Tens of trillions
85
+ if digit != 0:
86
+ nums.append(readNums2[digit - 1])
87
+ elif position == 9: # Billions
88
+ if digit != 0:
89
+ nums.append(readNums1[digit - 1])
90
+ nums.append(readNums3[7]) # 'ቢልዮን'
91
+ elif position == 8: # Hundreds of billions
92
+ if digit != 0:
93
+ nums.append(readNums1[digit - 1])
94
+ nums.append(readNums3[1]) # 'መቶ'
95
+ elif position == 7: # Tens of billions
96
+ if digit != 0:
97
+ nums.append(readNums2[digit - 1])
98
+ elif position == 6: # Millions
99
+ if digit != 0:
100
+ nums.append(readNums1[digit - 1])
101
+ nums.append(readNums3[5]) # 'ሚልዮን'
102
+ elif position == 5: # Hundreds of thousands
103
+ if digit != 0:
104
+ nums.append(readNums1[digit - 1])
105
+ nums.append(readNums3[1]) # 'መቶ'
106
+ elif position == 4: # Tens of thousands
107
+ if digit != 0:
108
+ nums.append(readNums2[digit - 1])
109
+ elif position == 3: # Thousands
110
+ if digit != 0:
111
+ nums.append(readNums1[digit - 1])
112
+ nums.append(readNums3[2]) # 'ሺ'
113
+ elif position == 2: # Hundreds
114
+ if digit != 0:
115
+ nums.append(readNums1[digit - 1])
116
+ nums.append(readNums3[1]) # 'መቶ'
117
+ elif position == 1: # Tens
118
+ if digit != 0:
119
+ nums.append(readNums2[digit - 1])
120
+ elif position == 0: # Ones
121
+ if digit != 0:
122
+ nums.append(readNums1[digit - 1])
123
+
124
+ return " ".join(nums) # Return as a sentence
125
+
126
+
127
+ # Example Outputs
128
+ print(tigrigna_number_reader("1221"))
129
+ #ሓደ ሽሕን ክልተ ምእቲን ዕስራን ሓደን
130
+
131
+
132
+ print(tigrigna_number_reader("221222345681"))
133
+ #ክልተ ምእቲ ዕስራ ሓደ ቢልዮንን ክልተ ምእቲ ዕስራ ክልተ ሚልዮንን ሰለስተ ምእቲ ዓርባዓ ሓሙሽተ ሽሕን ሽዱሽተ ምእቲን ሰማንያን ሓደን
134
+
135
+ print(tigrigna_number_reader("8221222345681"))
136
+ #ሸሞንተ ትሪልዮን ክልተ ምእቲ ዕስራ ሓደ ቢልዮን ክልተ ምእቲ ዕስራ ክልተ ሚልዮን ሰለስተ ምእቲ ዓርባዓ ሓሙሽተ ሽሕ ሽዱሽተ ምእቲ ሰማንያ ሓደ