Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 3578cbf

Browse files
authored
Merge branch 'main' into computer-algebra
2 parents 7ca1dac + 612ab48 commit 3578cbf

21 files changed

+924
-609
lines changed

README.md

Lines changed: 256 additions & 248 deletions
Large diffs are not rendered by default.

projects/Calculator/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def average():
5757

5858
def factorial(num):
5959
"""
60-
Function to calculate the factorial of a number.
61-
60+
Function to calculate the factorial of a number.
61+
6262
Takes a number as an argument, calculates the factorial of the number,
6363
and returns the result.
6464
"""
@@ -71,7 +71,7 @@ def factorial(num):
7171
def complex_arithmetic():
7272
"""
7373
Function to execute complex arithmetic operations such as addition, subtraction, multiplication, and division.
74-
74+
7575
Asks the user to choose the operation and input the complex numbers as real and imaginary parts,
7676
performs the operation, and returns the result.
7777
"""
@@ -132,7 +132,7 @@ def complex_arithmetic():
132132
def binomial(num):
133133
"""
134134
Function to calculate the binomial coefficient.
135-
135+
136136
Takes two numbers as arguments, calculates the binomial coefficient using the formula n!/(k!(n-k)!),
137137
and returns the result.
138138
"""

projects/Calendar/displayCalendar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ def fetch_month():
4343
year_input = fetch_year()
4444
month_input = fetch_month()
4545

46-
display_cal(year_input, month_input)
46+
display_cal(year_input, month_input)

projects/Expense-Tracker/app.py

Lines changed: 128 additions & 101 deletions
Large diffs are not rendered by default.

projects/Expense-Tracker/expense_income_stats.py

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def get_stats(items) -> dict:
7979
dict: A dictionary containing general statistics for the list of items.
8080
"""
8181
if len(items) < 1:
82-
raise ValueError('The list of items must contain at least one item')
82+
raise ValueError("The list of items must contain at least one item")
8383

8484
return {
8585
"average": statistics.mean(items),
@@ -106,7 +106,9 @@ def get_stats_by_category(self) -> dict:
106106
category_names = self._items_db.get_category_names()
107107
out_dict = {}
108108
for category_name in category_names:
109-
items = [item for item in self._items_db.get_items_by_category(category_name)]
109+
items = [
110+
item for item in self._items_db.get_items_by_category(category_name)
111+
]
110112
out_dict[category_name] = self.get_stats_expense_and_income(items)
111113

112114
return out_dict
@@ -122,14 +124,21 @@ def get_stats_by_category_with_subcategories(self) -> dict:
122124
stats_dict = {}
123125
for category_name in category_names:
124126
# Case: With Category and Without Subcategory
125-
stats_dict[f'{category_name}-NoSubcategory'] = self.get_stats_expense_and_income(
126-
self._items_db.get_items_without_subcategory(category_name))
127+
stats_dict[f"{category_name}-NoSubcategory"] = (
128+
self.get_stats_expense_and_income(
129+
self._items_db.get_items_without_subcategory(category_name)
130+
)
131+
)
127132

128133
# Case: With Category and With Subcategory
129134
for subcategory in self._items_db.get_subcategory_names(category_name):
130-
stats_dict[f'{category_name}-{subcategory}'] = \
135+
stats_dict[f"{category_name}-{subcategory}"] = (
131136
self.get_stats_expense_and_income(
132-
self._items_db.get_items_by_category_and_subcategory(category_name, subcategory))
137+
self._items_db.get_items_by_category_and_subcategory(
138+
category_name, subcategory
139+
)
140+
)
141+
)
133142

134143
return stats_dict
135144

@@ -179,12 +188,12 @@ def to_dataframe(items) -> pd.DataFrame:
179188
rows = []
180189
for item in items:
181190
category = item.category
182-
row = {k: v for k, v in item.__dict__.items() if k != 'category'}
191+
row = {k: v for k, v in item.__dict__.items() if k != "category"}
183192

184193
if category is not None:
185-
row['category'] = category.name
194+
row["category"] = category.name
186195
if category.subcategory is not None:
187-
row['subcategory'] = category.subcategory
196+
row["subcategory"] = category.subcategory
188197

189198
rows.append(row)
190199

@@ -201,35 +210,37 @@ def generate_report(self):
201210
items = self.items_db.get_all_items()
202211
df = self.to_dataframe(items)
203212

204-
with pd.ExcelWriter(self.file_path, engine='xlsxwriter') as writer:
213+
with pd.ExcelWriter(self.file_path, engine="xlsxwriter") as writer:
205214
workbook = writer.book
206215

207216
# Raw Data Tab
208217
df.to_excel(
209218
writer,
210-
'Data', # worksheet name
211-
index=False # index does not contain relevant information
219+
"Data", # worksheet name
220+
index=False, # index does not contain relevant information
212221
)
213-
summary_sheet = writer.sheets['Data'] # Assigning a variable to the sheet allows formatting
222+
summary_sheet = writer.sheets[
223+
"Data"
224+
] # Assigning a variable to the sheet allows formatting
214225

215226
# Pivot Table Tab
216227
pivot_table = df.pivot_table(
217-
values='amount',
218-
index=['category', 'subcategory'],
228+
values="amount",
229+
index=["category", "subcategory"],
219230
aggfunc={
220-
'amount': ['mean', 'max', 'min'],
221-
}
231+
"amount": ["mean", "max", "min"],
232+
},
222233
)
223234

224235
# Flatten the hierarchical column index
225-
pivot_table.columns = [f'{agg}_amount' for agg in pivot_table.columns]
236+
pivot_table.columns = [f"{agg}_amount" for agg in pivot_table.columns]
226237

227238
pivot_table.to_excel(
228239
writer,
229-
'Summary By Category', # worksheet name
230-
index=True # index does not contain relevant information
240+
"Summary By Category", # worksheet name
241+
index=True, # index does not contain relevant information
231242
)
232-
summary_sheet = writer.sheets['Summary By Category']
243+
summary_sheet = writer.sheets["Summary By Category"]
233244

234245

235246
class PdfReport(Report):
@@ -247,11 +258,11 @@ def generate_report(self):
247258

248259
# Pivot Table Tab
249260
pivot_table = df.pivot_table(
250-
values='amount',
251-
index=['category', 'subcategory'],
261+
values="amount",
262+
index=["category", "subcategory"],
252263
aggfunc={
253-
'amount': ['mean', 'max', 'min'],
254-
}
264+
"amount": ["mean", "max", "min"],
265+
},
255266
)
256267
pivot_table = pivot_table.reset_index()
257268

@@ -267,13 +278,17 @@ def generate_report(self):
267278
table = Table(table_data)
268279

269280
# Style the table
270-
style = TableStyle([('BACKGROUND', (0, 0), (-1, 0), colors.gray),
271-
('TEXTCOLOR', (0, 0), (-1, 0), colors.whitesmoke),
272-
('ALIGN', (0, 0), (-1, -1), 'CENTER'),
273-
('FONTNAME', (0, 0), (-1, 0), 'Helvetica-Bold'),
274-
('BOTTOMPADDING', (0, 0), (-1, 0), 12),
275-
('BACKGROUND', (0, 1), (-1, -1), colors.beige),
276-
('GRID', (0, 0), (-1, -1), 1, colors.black)])
281+
style = TableStyle(
282+
[
283+
("BACKGROUND", (0, 0), (-1, 0), colors.gray),
284+
("TEXTCOLOR", (0, 0), (-1, 0), colors.whitesmoke),
285+
("ALIGN", (0, 0), (-1, -1), "CENTER"),
286+
("FONTNAME", (0, 0), (-1, 0), "Helvetica-Bold"),
287+
("BOTTOMPADDING", (0, 0), (-1, 0), 12),
288+
("BACKGROUND", (0, 1), (-1, -1), colors.beige),
289+
("GRID", (0, 0), (-1, -1), 1, colors.black),
290+
]
291+
)
277292

278293
table.setStyle(style)
279294

projects/Expense-Tracker/gui_widgets.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class ItemsTable(ttk.Treeview):
1414
"""
1515

1616
_COLUMN_PAIRS = [
17-
('#0', 'ID'),
18-
('name', 'Name'),
19-
('amount', 'Amount'),
20-
('description', 'Description'),
21-
('date', 'Date'),
22-
('category', 'Category'),
23-
('subcategory', 'Subcategory'),
17+
("#0", "ID"),
18+
("name", "Name"),
19+
("amount", "Amount"),
20+
("description", "Description"),
21+
("date", "Date"),
22+
("category", "Category"),
23+
("subcategory", "Subcategory"),
2424
]
2525

2626
def __init__(self, parent, items_db: ItemsDB, *args, **kwargs):
@@ -34,7 +34,12 @@ def __init__(self, parent, items_db: ItemsDB, *args, **kwargs):
3434
**kwargs: Additional keyword arguments for `ttk.Treeview`.
3535
"""
3636

37-
super().__init__(parent, *args, columns=tuple(col for col, _ in self._COLUMN_PAIRS if '#' not in col), **kwargs)
37+
super().__init__(
38+
parent,
39+
*args,
40+
columns=tuple(col for col, _ in self._COLUMN_PAIRS if "#" not in col),
41+
**kwargs,
42+
)
3843

3944
for i, j in self._COLUMN_PAIRS:
4045
self.heading(i, text=j)
@@ -124,11 +129,7 @@ def load_items(self):
124129
else:
125130
values += (None, None)
126131

127-
self.insert('',
128-
idx,
129-
text=f'{item.item_id}',
130-
values=values
131-
)
132+
self.insert("", idx, text=f"{item.item_id}", values=values)
132133

133134

134135
class SummaryByCategoryPivotTable:
@@ -145,7 +146,7 @@ def __init__(self, parent):
145146
self.parent = parent
146147

147148
db_path = Path(__file__).resolve().parent
148-
self.stats = ExpenseIncomeStats(str(db_path / 'items.json'))
149+
self.stats = ExpenseIncomeStats(str(db_path / "items.json"))
149150
self.tree = None
150151

151152
def update_pivot_table(self):
@@ -176,7 +177,7 @@ def update_pivot_table(self):
176177
for category in data.keys():
177178
self.tree.heading(category, text=category)
178179

179-
self.tree['show'] = 'headings'
180+
self.tree["show"] = "headings"
180181

181182
def clean_string(input_string):
182183
cleaned_string = input_string.replace("_", " ").title()

0 commit comments

Comments
 (0)