-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
100 lines (76 loc) · 3.47 KB
/
utils.py
File metadata and controls
100 lines (76 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import pandas as pd
import os
# --- 1. SYNONYMS DATABASE ---
def get_synonyms():
return {
# Engine / Check Engine
"engine": "check_engine", "engin": "check_engine", "enjin": "check_engine",
"motor": "check_engine", "check": "check_engine",
# Oil
"oil": "oil_pressure", "oyl": "oil_pressure", "oill": "oil_pressure",
# Battery
"battery": "battery", "batry": "battery", "batery": "battery", "batary": "battery",
# Brakes
"brake": "brake", "brak": "brake", "break": "brake", "brek": "brake",
# ABS
"abs": "abs", "antilock": "abs", "anti-lock": "abs",
# Airbag
"airbag": "airbag", "air bag": "airbag", "srs": "airbag",
# Fuel
"fuel": "low_fuel", "gas": "low_fuel", "petrol": "low_fuel", "diesel": "low_fuel", "empty": "low_fuel",
# Tires
"tire": "tire_pressure", "tyre": "tire_pressure", "flat": "tire_pressure", "pressure": "tire_pressure",
# Temperature / Coolant
"heat": "coolant_temp", "overheat": "coolant_temp", "hot": "coolant_temp",
"temp": "coolant_temp", "temperature": "coolant_temp", "coolant": "coolant_temp",
# Seatbelt
"seatbelt": "seat_belt", "belt": "seat_belt", "bukle": "seat_belt",
# Door
"door": "door_open", "open": "door_open", "close": "door_open",
# Lights
"beam": "high_beam", "high": "high_beam", "brights": "high_beam",
"fog": "fog_light", "mist": "fog_light",
# Fluids
"washer": "washer_fluid", "water": "washer_fluid", "wipe": "washer_fluid", "fluid": "washer_fluid",
# Controls
"cruise": "cruise_control", "cruse": "cruise_control",
"traction": "traction_control", "trac": "traction_control", "slip": "traction_control",
"steering": "power_steering", "steer": "power_steering", "wheel": "power_steering",
# DPF / Exhaust
"dpf": "dpf", "diesel filter": "dpf", "particulate": "dpf", "soot": "dpf", "exhaust filter": "dpf",
}
# --- 2. TEXT PARSER ---
def parse_text_common(user_text, synonyms):
user_text = user_text.lower()
found_labels = set()
for word, label in synonyms.items():
if word in user_text:
found_labels.add(label)
return list(found_labels)
# --- 3. COST ESTIMATOR (UPDATED FOR SRI LANKA & LABOR) ---
class CostEstimator:
def __init__(self, csv_file='costs.csv'):
self.csv_file = csv_file
self.df = None
self.load_data()
def load_data(self):
if os.path.exists(self.csv_file):
self.df = pd.read_csv(self.csv_file)
else:
print(f"⚠️ Warning: {self.csv_file} not found.")
def get_estimate(self, label):
if self.df is None or self.df.empty:
return None
# Filter for the specific label
data = self.df[self.df['label'] == label]
if data.empty:
return None
row = data.iloc[0]
# Calculate average cost
avg_cost = (row['low_cost'] + row['high_cost']) / 2
return {
"part": row['part_name'],
"average": f"Rs.{int(avg_cost):,}", # Added comma for thousands separator (e.g. Rs.45,000)
"range": f"Rs.{int(row['low_cost']):,} - Rs.{int(row['high_cost']):,}",
"labor": row['labor_hours'] # <--- NEW: Reads labor hours from CSV
}