EV 충전 플랫폼 초기 백업
This commit is contained in:
51
app/services/billing.py
Normal file
51
app/services/billing.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""전력량 기반 요금 정산 서비스
|
||||
|
||||
OCPP MeterValues의 Energy.Active.Import.Register (Wh 단위)를
|
||||
세션 시작/종료 시점에 기록하여 실제 충전량 기반 요금 계산.
|
||||
"""
|
||||
|
||||
from app.config import get_settings
|
||||
|
||||
settings = get_settings()
|
||||
|
||||
|
||||
def calculate_bill(start_wh: int, end_wh: int) -> dict:
|
||||
"""충전 요금 계산
|
||||
|
||||
Args:
|
||||
start_wh: 충전 시작 시 meter 값 (Wh)
|
||||
end_wh: 충전 종료 시 meter 값 (Wh)
|
||||
|
||||
Returns:
|
||||
dict: 정산 내역
|
||||
"""
|
||||
charged_wh = max(0, end_wh - start_wh)
|
||||
charged_kwh = charged_wh / 1000
|
||||
|
||||
electricity_cost = round(charged_kwh * settings.ELECTRICITY_RATE)
|
||||
service_fee = round(charged_kwh * settings.SERVICE_MARGIN)
|
||||
total_bill = round(charged_kwh * settings.total_rate)
|
||||
|
||||
# CPO 방식(350원/kWh) 대비 절감액
|
||||
cpo_rate = 350
|
||||
saved_vs_cpo = round(charged_kwh * (cpo_rate - settings.total_rate))
|
||||
|
||||
return {
|
||||
"charged_wh": charged_wh,
|
||||
"charged_kwh": round(charged_kwh, 3),
|
||||
"electricity_cost": electricity_cost,
|
||||
"service_fee": service_fee,
|
||||
"total_bill": total_bill,
|
||||
"saved_vs_cpo": saved_vs_cpo,
|
||||
}
|
||||
|
||||
|
||||
def estimate_charge_cost(kwh: float) -> dict:
|
||||
"""예상 충전 요금 계산 (QR 결제 화면용)"""
|
||||
return {
|
||||
"estimated_kwh": kwh,
|
||||
"rate_per_kwh": settings.total_rate,
|
||||
"estimated_cost": round(kwh * settings.total_rate),
|
||||
"cpo_comparison": round(kwh * 350),
|
||||
"savings": round(kwh * (350 - settings.total_rate)),
|
||||
}
|
||||
Reference in New Issue
Block a user