Skip to content

Commit

Permalink
توسيع دالة عرض القيود اليومية بحيث تحتوي احصائيات على مستوى الأسبوع و…
Browse files Browse the repository at this point in the history
…الشهر والسنة
  • Loading branch information
vzool committed Aug 5, 2024
1 parent 8882567 commit 8f66491
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .idea/zakat.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = 'zakat'
version = '0.2.91'
version = '0.2.92'
authors = [
{ name='Abdelaziz Elrashed Elshaikh Mohamed', email='[email protected]' },
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='zakat',
version='0.2.91',
version='0.2.92',
description='A Python Library for Islamic Financial Management.',
author='Abdelaziz Elrashed Elshaikh Mohamed',
author_email='[email protected]',
Expand Down
2 changes: 2 additions & 0 deletions zakat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Action,
JSONEncoder,
MathOperation,
WeekDay,
)

from zakat.file_server import (
Expand All @@ -34,6 +35,7 @@
"Action",
"JSONEncoder",
"MathOperation",
"WeekDay",
"start_file_server",
"find_available_port",
"FileType",
Expand Down
141 changes: 123 additions & 18 deletions zakat/zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@
from time import time_ns
from camelx import Camel, CamelRegistry
import shutil
from datetime import timedelta


class WeekDay(Enum):
Monday = 0
Tuesday = 1
Wednesday = 2
Thursday = 3
Friday = 4
Saturday = 5
Sunday = 6


class Action(Enum):
Expand Down Expand Up @@ -201,7 +212,7 @@ def Version() -> str:
Returns:
str: The current version of the software.
"""
return '0.2.91'
return '0.2.92'

@staticmethod
def ZakatCut(x: float) -> float:
Expand Down Expand Up @@ -1218,7 +1229,7 @@ def logs(self, account) -> dict:
return self._vault['account'][account]['log']
return {}

def daily_logs(self, debug: bool = False):
def daily_logs(self, weekday: WeekDay = WeekDay.Friday, debug: bool = False):
"""
Retrieve the daily logs (transactions) from all accounts.
Expand All @@ -1227,25 +1238,66 @@ def daily_logs(self, debug: bool = False):
and the values are dictionaries containing the total value and the logs for that group.
Parameters:
weekday (WeekDay): Select the weekday is collected for the week data. Default is WeekDay.Friday.
debug (bool): Whether to print debug information. Default is False.
Returns:
dict: A dictionary containing the daily logs.
Example:
>>> tracker = ZakatTracker()
>>> tracker.track(51, 'desc', 'account1')
>>> tracker.sub(51, 'desc', 'account1')
>>> tracker.track(100, 'desc', 'account2')
>>> tracker.daily_logs()
{
1632057600: {
'total': 151,
'transfer': False,
'rows': [
{'value': 51, 'account': 'account1', 'file': {}, 'ref': 1690977015000000000, 'desc': 'desc'},
{'value': 100, 'account': 'account2', 'file': {}, 'ref': 1690977015000000000, 'desc': 'desc'}
]
}
'daily': {
'2024-06-30': {
'positive': 100,
'negative': 51,
'total': 99,
'rows': [
{
'account': 'account1',
'desc': 'desc',
'file': {},
'ref': None,
'value': -51,
'time': 1690977015000000000,
'transfer': False,
},
{
'account': 'account2',
'desc': 'desc',
'file': {},
'ref': None,
'value': 100,
'time': 1690977015000000000,
'transfer': False,
},
],
},
},
'weekly': {
datetime: {
'positive': 100,
'negative': 51,
'total': 99,
},
},
'monthly': {
'2024-06': {
'positive': 100,
'negative': 51,
'total': 99,
},
},
'yearly': {
2024: {
'positive': 100,
'negative': 51,
'total': 99,
},
},
}
"""
logs = {}
Expand All @@ -1258,12 +1310,23 @@ def daily_logs(self, debug: bool = False):
logs[k].append(v)
if debug:
print('logs', logs)
y = {}
y = {
'daily': {},
'weekly': {},
'monthly': {},
'yearly': {},
}
for i in sorted(logs, reverse=True):
dt = self.time_to_datetime(i)
group = self.day_to_time(dt.day, dt.month, dt.year)
if group not in y:
y[group] = {
daily = f'{dt.year}-{dt.month:02d}-{dt.day:02d}'
weekly = dt - timedelta(days=weekday.value)
monthly = f'{dt.year}-{dt.month:02d}'
yearly = dt.year
# daily
if daily not in y['daily']:
y['daily'][daily] = {
'positive': 0,
'negative': 0,
'total': 0,
'rows': [],
}
Expand All @@ -1273,9 +1336,51 @@ def daily_logs(self, debug: bool = False):
for z in logs[i]:
if debug:
print('z', z)
y[group]['total'] += z['value']
# daily
value = z['value']
if value > 0:
y['daily'][daily]['positive'] += value
else:
y['daily'][daily]['negative'] += -value
y['daily'][daily]['total'] += value
z['transfer'] = transfer
y[group]['rows'].append(z)
y['daily'][daily]['rows'].append(z)
# weekly
if weekly not in y['weekly']:
y['weekly'][weekly] = {
'positive': 0,
'negative': 0,
'total': 0,
}
if value > 0:
y['weekly'][weekly]['positive'] += value
else:
y['weekly'][weekly]['negative'] += -value
y['weekly'][weekly]['total'] += value
# monthly
if monthly not in y['monthly']:
y['monthly'][monthly] = {
'positive': 0,
'negative': 0,
'total': 0,
}
if value > 0:
y['monthly'][monthly]['positive'] += value
else:
y['monthly'][monthly]['negative'] += -value
y['monthly'][monthly]['total'] += value
# yearly
if yearly not in y['yearly']:
y['yearly'][yearly] = {
'positive': 0,
'negative': 0,
'total': 0,
}
if value > 0:
y['yearly'][yearly]['positive'] += value
else:
y['yearly'][yearly]['negative'] += -value
y['yearly'][yearly]['total'] += value
if debug:
print('y', y)
return y
Expand Down Expand Up @@ -1840,7 +1945,7 @@ def zakat(self, report: tuple, parts: Dict[str, Dict | bool | Any] = None, debug
target_exchange = self.exchange(account)
amount = ZakatTracker.exchange_calc(part['part'], part['rate'], target_exchange['rate'])
self.sub(
unscaled_value=self.unscale(amount),
unscaled_value=self.unscale(int(amount)),
desc='zakat-part-دفعة-زكاة',
account=account,
debug=debug,
Expand Down

0 comments on commit 8f66491

Please sign in to comment.