Skip to content

Commit

Permalink
كتابة بعض التعليقات على النماذج واضافة مكتبة لإدارة الاعدادات
Browse files Browse the repository at this point in the history
  • Loading branch information
vzool committed Oct 7, 2024
1 parent c459ad5 commit 373b742
Show file tree
Hide file tree
Showing 7 changed files with 578 additions and 3 deletions.
527 changes: 527 additions & 0 deletions .idea/dbnavigator.xml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ init:
clean:
rm -rf *.csv
rm -rf *.camel
rm -rf *.sqlite
rm -rf *.json
rm -rf *.txt
rm -rf zakat_test_db
rm -rf zakat/*.csv
rm -rf zakat/*.camel
rm -rf zakat/*.json
rm -rf zakat/zakat_test_db
rm -rf tests/*.csv
rm -rf tests/*.camel
rm -rf tests/*.sqlite
rm -rf tests/*.json
rm -rf tests/zakat_test_db
rm -rf snapshots

.PHONY: dev-build
Expand All @@ -32,6 +37,7 @@ deps:
python3 -m pip install --upgrade twine
python3 -m pip install --upgrade pyyaml
python3 -m pip install --upgrade camelx
python3 -m pip install --upgrade vzool-config
python3 -m pip install --upgrade pytest==8.2.2
python3 -m pip install --upgrade pytest-runner==6.0.1
python3 -m pip install --upgrade twine
Expand Down
Binary file added config.db
Binary file not shown.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ classifiers = [
]
dependencies=[
'camelx',
'vzool-config',
]

[project.urls]
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
),
requires=[
'camelx',
'vzool-config',
],
)
1 change: 1 addition & 0 deletions tests/test_zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def test_zakat_tracker():
DictModel(db_path="./zakat_test_db/zakat.camel", history_mode=True),
# SQLiteModel(db_path="./zakat_test_db/zakat.sqlite", history_mode=True),
]:
assert model.test(debug=True)
ledger = ZakatTracker(model=model)
start = Helper.time()
assert ledger.test(debug=True)
Expand Down
45 changes: 42 additions & 3 deletions zakat/zakat_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
from datetime import timedelta
from abc import ABC, abstractmethod
import sqlite3
from vzool_config import ConfigManager


class WeekDay(Enum):
Expand Down Expand Up @@ -967,6 +968,19 @@ def clean_history(self, lock: int | None = None) -> int:
int: The number of locks cleaned up.
"""

@staticmethod
@abstractmethod
def test(debug: bool = False) -> bool:
"""
Performs a test operation for the model if required.
Parameters:
debug (bool, optional): If True, enables debug mode. Defaults to False.
Returns:
bool: The result of the test operation.
"""


class Helper:
@staticmethod
Expand Down Expand Up @@ -1362,6 +1376,13 @@ def day_to_time(day: int, month: int = 6, year: int = 2024) -> int: # افتر


class DictModel(Model):
"""
A dictionary-based model.
This class provides a convenient way to represent data as a dictionary.
It may offer additional features like validation, serialization, or deserialization.
"""

def __init__(self, db_path: str = "./zakat_db/zakat.camel", history_mode: bool = True):
"""
Initialize DictModel with database path and history mode.
Expand Down Expand Up @@ -2441,6 +2462,10 @@ def import_csv_cache_path(self):
_, filename = os.path.split(path + f'.import_csv.{ext}')
return self.base_path(filename)

@staticmethod
def test(debug: bool = False) -> bool:
return True


class SQLiteDatabase:
def __init__(self, db_file):
Expand Down Expand Up @@ -2502,13 +2527,21 @@ def close(self):


class SQLiteModel(Model):
"""
A model that maps to a SQLite database tables.
This class provides a convenient way to interact with SQLite data, encapsulating database operations.
It may offer features like automatic mapping to database columns, validation, and query building.
"""

def __init__(self, db_path: str = "./zakat_db/zakat.sqlite", history_mode: bool = True):
self._db = None
self._base_path = None
self._vault_path = None
self._history_mode = None
self.path(db_path)
self.create_db()
self.config = ConfigManager(self.path())
self.history(history_mode)

def create_db(self):
Expand Down Expand Up @@ -2725,10 +2758,10 @@ def log_size(self, account: int) -> int:
pass

def nolock(self) -> bool:
pass
return self.config.get(key='nolock', default=True)

def lock(self) -> int:
pass
return self.config.get(key='lock')

def free(self, lock: int, auto_save: bool = True) -> bool:
pass
Expand Down Expand Up @@ -2800,6 +2833,11 @@ def snapshots(self, hide_missing: bool = True, verified_hash_only: bool = False)
def clean_history(self, lock: int | None = None) -> int:
pass

@staticmethod
def test(debug: bool = False) -> bool:
ConfigManager.test(debug=debug)
return True


class ZakatTracker:
"""
Expand Down Expand Up @@ -4216,8 +4254,9 @@ def test(debug: bool = False):
durations = {}
for model in [
DictModel(db_path="./zakat_test_db/zakat.camel", history_mode=True),
#SQLiteModel(db_path="./zakat_test_db/zakat.sqlite", history_mode=True),
SQLiteModel(db_path="./zakat_test_db/zakat.sqlite", history_mode=True),
]:
assert model.test(debug=debug)
ledger = ZakatTracker(model=model)
start = Helper.time()
assert ledger.test(debug=debug)
Expand Down

0 comments on commit 373b742

Please sign in to comment.