Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 83 additions & 7 deletions uc-0a/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,97 @@ def classify_complaint(row: dict) -> dict:
"""
Classify a single complaint row.
Returns: dict with keys: complaint_id, category, priority, reason, flag

TODO: Build this using your AI tool guided by your agents.md and skills.md.
Your RICE enforcement rules must be reflected in this function's behaviour.
"""
raise NotImplementedError("Build this using your AI tool + RICE prompt")
complaint_id = row.get('complaint_id', row.get('id', 'unknown'))
desc_raw = row.get('description', '')

# Error handling for nulls/empty
if not desc_raw or str(desc_raw).strip() == '':
return {
"complaint_id": complaint_id,
"category": "Other",
"priority": "Normal",
"reason": "Description is missing or empty.",
"flag": "NEEDS_REVIEW"
}

desc = str(desc_raw).lower()

# 1. Category Classification & Reasons
category = "Other"
flag = ""
reason = ""

if "pothole" in desc:
category = "Pothole"
reason = "Description contains 'pothole'."
elif "flood" in desc or "water" in desc:
category = "Flooding"
reason = "Description contains 'flood' or 'water'."
else:
# Refusal condition
category = "Other"
flag = "NEEDS_REVIEW"
reason = "Category cannot be determined from description alone."

# 2. Priority Rules
urgent_keywords = ["injury", "child", "school"]
found_urgent = [kw for kw in urgent_keywords if kw in desc]

if found_urgent:
priority = "Urgent"
reason += f" Flagged as Urgent due to: {', '.join(found_urgent)}."
else:
priority = "Normal"

return {
"complaint_id": complaint_id,
"category": category,
"priority": priority,
"reason": reason.strip(),
"flag": flag
}


def batch_classify(input_path: str, output_path: str):
"""
Read input CSV, classify each row, write results CSV.

TODO: Build this using your AI tool.
Must: flag nulls, not crash on bad rows, produce output even if some rows fail.
"""
raise NotImplementedError("Build this using your AI tool + RICE prompt")
results = []

try:
with open(input_path, mode='r', encoding='utf-8') as infile:
reader = csv.DictReader(infile)
for row_idx, row in enumerate(reader):
try:
result = classify_complaint(row)
results.append(result)
except Exception as e:
# Catch-all to prevent crash on bad rows
results.append({
"complaint_id": row.get('complaint_id', f"row_{row_idx}"),
"category": "Error",
"priority": "Unknown",
"reason": f"Processing error: {str(e)}",
"flag": "NEEDS_REVIEW"
})
except Exception as e:
print(f"Error reading input file {input_path}: {e}")
return

if not results:
print("No results generated.")
return

try:
fieldnames = ["complaint_id", "category", "priority", "reason", "flag"]
with open(output_path, mode='w', encoding='utf-8', newline='') as outfile:
writer = csv.DictWriter(outfile, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(results)
except Exception as e:
print(f"Error writing to output file {output_path}: {e}")


if __name__ == "__main__":
Expand Down
16 changes: 16 additions & 0 deletions uc-0a/results_ahmedabad.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,category,priority,reason,flag
AM-202401,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202402,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202405,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202406,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202407,Other,Urgent,Category cannot be determined from description alone. Flagged as Urgent due to: child.,NEEDS_REVIEW
AM-202410,Pothole,Normal,Description contains 'pothole'.,
AM-202414,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202417,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202421,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202424,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202429,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202431,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202435,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202444,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
AM-202445,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
16 changes: 16 additions & 0 deletions uc-0a/results_hyderabad.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,category,priority,reason,flag
GH-202401,Flooding,Normal,Description contains 'flood' or 'water'.,
GH-202402,Flooding,Normal,Description contains 'flood' or 'water'.,
GH-202406,Flooding,Normal,Description contains 'flood' or 'water'.,
GH-202407,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
GH-202410,Pothole,Normal,Description contains 'pothole'.,
GH-202411,Pothole,Normal,Description contains 'pothole'.,
GH-202412,Pothole,Urgent,Description contains 'pothole'. Flagged as Urgent due to: school.,
GH-202417,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
GH-202420,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
GH-202422,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
GH-202424,Flooding,Normal,Description contains 'flood' or 'water'.,
GH-202428,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
GH-202432,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
GH-202448,Flooding,Normal,Description contains 'flood' or 'water'.,
GH-202438,Flooding,Normal,Description contains 'flood' or 'water'.,
16 changes: 16 additions & 0 deletions uc-0a/results_kolkata.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,category,priority,reason,flag
KM-202401,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
KM-202402,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
KM-202405,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
KM-202409,Pothole,Normal,Description contains 'pothole'.,
KM-202410,Pothole,Normal,Description contains 'pothole'.,
KM-202411,Pothole,Normal,Description contains 'pothole'.,
KM-202415,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
KM-202418,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
KM-202421,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
KM-202422,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
KM-202426,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
KM-202430,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
KM-202434,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
KM-202436,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
KM-202438,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
16 changes: 16 additions & 0 deletions uc-0a/results_pune.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
complaint_id,category,priority,reason,flag
PM-202401,Pothole,Normal,Description contains 'pothole'.,
PM-202402,Pothole,Urgent,"Description contains 'pothole'. Flagged as Urgent due to: child, school.",
PM-202406,Flooding,Normal,Description contains 'flood' or 'water'.,
PM-202408,Flooding,Normal,Description contains 'flood' or 'water'.,
PM-202410,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
PM-202411,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
PM-202413,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
PM-202418,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
PM-202419,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
PM-202420,Other,Urgent,Category cannot be determined from description alone. Flagged as Urgent due to: injury.,NEEDS_REVIEW
PM-202427,Flooding,Normal,Description contains 'flood' or 'water'.,
PM-202428,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
PM-202430,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
PM-202433,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
PM-202446,Other,Normal,Category cannot be determined from description alone.,NEEDS_REVIEW
Loading