Spaces:
Runtime error
Runtime error
Download current_pricing.py from noor122/smartparking: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/spaces/noor122/smartparking/resolve/main/current_pricing.py
- Command line
-
hf download hf://spaces/noor122/smartparking/current_pricing.py
-
curl -L -o current_pricing.py https://huggingface.co/spaces/noor122/smartparking/resolve/main/current_pricing.py
1.79 kB
| from datetime import datetime, timedelta | |
| def calculate_live_parking(log_in_time, log_out_time, hourly_price): | |
| # ูู ู ููุด ููุช ุฏุฎูู | |
| if not log_in_time: | |
| return "0h 0m", float(hourly_price) | |
| # ูุดูู ุงูู Timezone ูู ู ูุฌูุฏ | |
| if log_in_time.tzinfo: | |
| log_in_time = log_in_time.replace(tzinfo=None) | |
| # ======================================================= | |
| # ๐ก ุงูุชุนุฏูู ุงูุณุญุฑู: ูู ูุนุฏ ูุงูู ููุง ูุซุจุช ุงูููุชุ | |
| # ======================================================= | |
| if log_out_time: | |
| # ูู ููู ููุช ุฎุฑูุฌ (ูุนูู ุงูุฎููุฉ ู ุด NULL)ุ ูุซุจุช ุงูุญุณุจุฉ ุนููู | |
| if log_out_time.tzinfo: | |
| log_out_time = log_out_time.replace(tzinfo=None) | |
| end_time = log_out_time | |
| else: | |
| # ูู ุงูุฎููุฉ ูุณู NULLุ ูุญุณุจ ุนูู ุชูููุช ุฏูููุชู (Live) | |
| end_time = datetime.utcnow() + timedelta(hours=3) | |
| # ======================================================= | |
| # ูุญุณุจ ุงููุฑู ุจูููู ุจุงูุฏูุงุฆู | |
| delta = end_time - log_in_time | |
| total_minutes = int(delta.total_seconds() // 60) | |
| if total_minutes <= 0: | |
| return "0h 0m", float(hourly_price) | |
| hours = total_minutes // 60 | |
| mins = total_minutes % 60 | |
| # ูุฌูุฒ ุงูููุช ูู Text | |
| time_str = f"{hours}h {mins}m" | |
| # ููุฌูู ุงูุญุณุงุจ: ูุณุฑ ุงูู 30 ุฏูููุฉ ุจุณุงุนุฉ | |
| billed_hours = hours | |
| if mins >= 30: | |
| billed_hours += 1 | |
| billed_hours = max(1, billed_hours) | |
| # ุญุณุงุจ ุงูุณุนุฑ ุงูููุงุฆู | |
| final_price = billed_hours * float(hourly_price) | |
| return time_str, final_price |