Add example projects
This commit is contained in:
47
examples/complex_project/processor.py
Normal file
47
examples/complex_project/processor.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
"""
|
||||||
|
Data processing module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import Dict, Any, List
|
||||||
|
from .config import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class DataProcessor:
|
||||||
|
"""Processes data according to configuration."""
|
||||||
|
|
||||||
|
def __init__(self, config: AppConfig):
|
||||||
|
self.config = config
|
||||||
|
self.cache: Dict[str, Any] = {}
|
||||||
|
|
||||||
|
def process_data(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
|
"""Process input data."""
|
||||||
|
cache_key = str(data)
|
||||||
|
|
||||||
|
if cache_key in self.cache:
|
||||||
|
return self.cache[cache_key]
|
||||||
|
|
||||||
|
result = self._transform(data)
|
||||||
|
self.cache[cache_key] = result
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def _transform(self, data: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
|
"""Transform data."""
|
||||||
|
return {
|
||||||
|
"processed": True,
|
||||||
|
"data": data,
|
||||||
|
"timestamp": self._get_timestamp()
|
||||||
|
}
|
||||||
|
|
||||||
|
def _get_timestamp(self) -> str:
|
||||||
|
"""Get current timestamp."""
|
||||||
|
import datetime
|
||||||
|
return datetime.datetime.now().isoformat()
|
||||||
|
|
||||||
|
def batch_process(self, items: List[Dict]) -> List[Dict]:
|
||||||
|
"""Process multiple items."""
|
||||||
|
return [self.process_data(item) for item in items]
|
||||||
|
|
||||||
|
def clear_cache(self) -> None:
|
||||||
|
"""Clear the cache."""
|
||||||
|
self.cache.clear()
|
||||||
Reference in New Issue
Block a user