Spaces:
Sleeping
Sleeping
Toan2004-ai commited on
Commit ·
d77520c
1
Parent(s): 603498a
add readme config
Browse files
engine.py
CHANGED
|
@@ -165,41 +165,47 @@ def final_process_eme_technical_guided(input_text):
|
|
| 165 |
final_discounts.append(fallback_disc)
|
| 166 |
|
| 167 |
# INCENTIVES
|
| 168 |
-
|
| 169 |
-
if not isinstance(
|
| 170 |
-
|
| 171 |
|
| 172 |
final_incentives = []
|
| 173 |
|
| 174 |
-
# 1. Xử lý
|
| 175 |
-
for item in
|
|
|
|
| 176 |
desc = item.get("description") or item.get("displayName", "")
|
| 177 |
-
amount = extract_amount_from_text(desc)
|
| 178 |
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
"incentive_type": "WELCOME_CREDIT" if "Once Off" in desc else "OTHER",
|
| 181 |
"raw_category": item.get("category", "OTHER"),
|
| 182 |
"display_name": desc,
|
| 183 |
"amount_aud": amount,
|
| 184 |
"value_display": f"${amount}" if amount else None,
|
| 185 |
"is_recurring": False if "Once Off" in desc else True,
|
| 186 |
-
"
|
| 187 |
"customer_scope": ["RESIDENTIAL"],
|
| 188 |
-
"limit_per_account": "1"
|
|
|
|
| 189 |
})
|
| 190 |
-
final_incentives.append(inc)
|
| 191 |
|
| 192 |
-
# 2. Xử lý Solar FIT
|
| 193 |
-
if
|
| 194 |
for s_fit in electricity_contract["solarFeedInTariff"]:
|
| 195 |
rates = s_fit.get("singleTariff", {}).get("rates", [])
|
| 196 |
unit_price = float(rates[0].get("unitPrice", 0.005)) if rates else 0.005
|
| 197 |
|
| 198 |
-
|
| 199 |
"incentive_type": "SOLAR_REBATE",
|
| 200 |
"raw_category": "retailer_solar_fiT",
|
| 201 |
"display_name": s_fit.get("displayName") or "Current FIT policy",
|
| 202 |
-
"amount_aud": unit_price,
|
|
|
|
| 203 |
"value_display": f"${unit_price}/kWh",
|
| 204 |
"is_recurring": True,
|
| 205 |
"customer_scope": ["RESIDENTIAL"],
|
|
@@ -207,12 +213,11 @@ def final_process_eme_technical_guided(input_text):
|
|
| 207 |
"timing_months": 1,
|
| 208 |
"limit_per_account": "1"
|
| 209 |
})
|
| 210 |
-
final_incentives.append(fit_inc)
|
| 211 |
|
| 212 |
parsed_json["eligibility"] = model_eligibility
|
| 213 |
parsed_json["fees"] = final_fees
|
| 214 |
parsed_json["discounts"] = final_discounts
|
| 215 |
-
parsed_json["incentives"] =
|
| 216 |
|
| 217 |
try:
|
| 218 |
return EnergyTargetSchema(**parsed_json)
|
|
|
|
| 165 |
final_discounts.append(fallback_disc)
|
| 166 |
|
| 167 |
# INCENTIVES
|
| 168 |
+
model_incentives = parsed_json.get("incentives", [])
|
| 169 |
+
if not isinstance(model_incentives, list):
|
| 170 |
+
model_incentives = [model_incentives] if isinstance(model_incentives, dict) else []
|
| 171 |
|
| 172 |
final_incentives = []
|
| 173 |
|
| 174 |
+
# 1. Xử lý Incentive từ JSON đầu vào (Welcome Credit, v.v.)
|
| 175 |
+
for item in model_incentives:
|
| 176 |
+
if not isinstance(item, dict): continue
|
| 177 |
desc = item.get("description") or item.get("displayName", "")
|
|
|
|
| 178 |
|
| 179 |
+
# Trích xuất số tiền ($125) từ chuỗi mô tả
|
| 180 |
+
amount_match = re.search(r'\$(\d+(?:\.\d+)?)', desc)
|
| 181 |
+
amount = float(amount_match.group(1)) if amount_match else None
|
| 182 |
+
|
| 183 |
+
# Mapping trực tiếp vào cấu trúc 21 trường
|
| 184 |
+
final_incentives.append({
|
| 185 |
"incentive_type": "WELCOME_CREDIT" if "Once Off" in desc else "OTHER",
|
| 186 |
"raw_category": item.get("category", "OTHER"),
|
| 187 |
"display_name": desc,
|
| 188 |
"amount_aud": amount,
|
| 189 |
"value_display": f"${amount}" if amount else None,
|
| 190 |
"is_recurring": False if "Once Off" in desc else True,
|
| 191 |
+
"tax_inclusive": True,
|
| 192 |
"customer_scope": ["RESIDENTIAL"],
|
| 193 |
+
"limit_per_account": "1",
|
| 194 |
+
"trigger": "FIRST_BILL" if "Once Off" in desc else None
|
| 195 |
})
|
|
|
|
| 196 |
|
| 197 |
+
# 2. Xử lý Solar FIT (Fallback từ electricity_contract)
|
| 198 |
+
if "solarFeedInTariff" in electricity_contract:
|
| 199 |
for s_fit in electricity_contract["solarFeedInTariff"]:
|
| 200 |
rates = s_fit.get("singleTariff", {}).get("rates", [])
|
| 201 |
unit_price = float(rates[0].get("unitPrice", 0.005)) if rates else 0.005
|
| 202 |
|
| 203 |
+
final_incentives.append({
|
| 204 |
"incentive_type": "SOLAR_REBATE",
|
| 205 |
"raw_category": "retailer_solar_fiT",
|
| 206 |
"display_name": s_fit.get("displayName") or "Current FIT policy",
|
| 207 |
+
"amount_aud": unit_price,
|
| 208 |
+
"tax_inclusive": True,
|
| 209 |
"value_display": f"${unit_price}/kWh",
|
| 210 |
"is_recurring": True,
|
| 211 |
"customer_scope": ["RESIDENTIAL"],
|
|
|
|
| 213 |
"timing_months": 1,
|
| 214 |
"limit_per_account": "1"
|
| 215 |
})
|
|
|
|
| 216 |
|
| 217 |
parsed_json["eligibility"] = model_eligibility
|
| 218 |
parsed_json["fees"] = final_fees
|
| 219 |
parsed_json["discounts"] = final_discounts
|
| 220 |
+
parsed_json["incentives"] = final_incentives
|
| 221 |
|
| 222 |
try:
|
| 223 |
return EnergyTargetSchema(**parsed_json)
|