jinruiyang commited on
Commit ·
f3e982e
1
Parent(s): 3f57f8c
Add query_id to Google Sheets and auto-insert headers if missing
Browse files- backend/api.py +2 -1
- ir/sheets_storage.py +10 -2
backend/api.py
CHANGED
|
@@ -384,7 +384,8 @@ async def api_entity_feedback(request: EntityFeedbackRequest, req: Request):
|
|
| 384 |
rating=ratings_str,
|
| 385 |
page=1,
|
| 386 |
client_ip=client_ip,
|
| 387 |
-
comment=request.comment or ""
|
|
|
|
| 388 |
)
|
| 389 |
sheets_saved = success
|
| 390 |
except Exception as e:
|
|
|
|
| 384 |
rating=ratings_str,
|
| 385 |
page=1,
|
| 386 |
client_ip=client_ip,
|
| 387 |
+
comment=request.comment or "",
|
| 388 |
+
query_id=request.query_id
|
| 389 |
)
|
| 390 |
sheets_saved = success
|
| 391 |
except Exception as e:
|
ir/sheets_storage.py
CHANGED
|
@@ -90,6 +90,12 @@ def _get_or_create_worksheet(name: str, headers: List[str]):
|
|
| 90 |
# Try to get existing worksheet
|
| 91 |
try:
|
| 92 |
worksheet = spreadsheet.worksheet(name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
except gspread.WorksheetNotFound:
|
| 94 |
# Create new worksheet
|
| 95 |
worksheet = spreadsheet.add_worksheet(title=name, rows=1000, cols=len(headers))
|
|
@@ -112,7 +118,8 @@ def save_rating_to_sheets(
|
|
| 112 |
rating: str,
|
| 113 |
page: int,
|
| 114 |
client_ip: str = "unknown",
|
| 115 |
-
comment: str = ""
|
|
|
|
| 116 |
) -> bool:
|
| 117 |
"""
|
| 118 |
Save an entity rating to Google Sheets.
|
|
@@ -120,7 +127,7 @@ def save_rating_to_sheets(
|
|
| 120 |
Returns True if successful, False otherwise.
|
| 121 |
"""
|
| 122 |
headers = [
|
| 123 |
-
"timestamp", "client_ip", "query", "category",
|
| 124 |
"entity_id", "entity_name", "rank", "score", "rating", "page", "comment"
|
| 125 |
]
|
| 126 |
|
|
@@ -131,6 +138,7 @@ def save_rating_to_sheets(
|
|
| 131 |
try:
|
| 132 |
row = [
|
| 133 |
datetime.now().isoformat(),
|
|
|
|
| 134 |
client_ip,
|
| 135 |
query,
|
| 136 |
category,
|
|
|
|
| 90 |
# Try to get existing worksheet
|
| 91 |
try:
|
| 92 |
worksheet = spreadsheet.worksheet(name)
|
| 93 |
+
# Check if headers exist (first row)
|
| 94 |
+
first_row = worksheet.row_values(1)
|
| 95 |
+
if not first_row or first_row[0] != headers[0]:
|
| 96 |
+
# Insert headers at row 1
|
| 97 |
+
worksheet.insert_row(headers, 1)
|
| 98 |
+
logger.info(f"Added headers to worksheet: {name}")
|
| 99 |
except gspread.WorksheetNotFound:
|
| 100 |
# Create new worksheet
|
| 101 |
worksheet = spreadsheet.add_worksheet(title=name, rows=1000, cols=len(headers))
|
|
|
|
| 118 |
rating: str,
|
| 119 |
page: int,
|
| 120 |
client_ip: str = "unknown",
|
| 121 |
+
comment: str = "",
|
| 122 |
+
query_id: str = ""
|
| 123 |
) -> bool:
|
| 124 |
"""
|
| 125 |
Save an entity rating to Google Sheets.
|
|
|
|
| 127 |
Returns True if successful, False otherwise.
|
| 128 |
"""
|
| 129 |
headers = [
|
| 130 |
+
"timestamp", "query_id", "client_ip", "query", "category",
|
| 131 |
"entity_id", "entity_name", "rank", "score", "rating", "page", "comment"
|
| 132 |
]
|
| 133 |
|
|
|
|
| 138 |
try:
|
| 139 |
row = [
|
| 140 |
datetime.now().isoformat(),
|
| 141 |
+
query_id,
|
| 142 |
client_ip,
|
| 143 |
query,
|
| 144 |
category,
|