Skip to content

Commit

Permalink
Fix No Feedback Defaults to 0 Score (Negative Feedback) in Snowflake (#…
Browse files Browse the repository at this point in the history
…304)

### Description
- Super simple code change
- Also changing snowflake db table schema (not code change not shown in
PR)
- Tested by creating new firestore collection indexes

closes #291
closes #296 (second issue is used to test, no code change related)
closes #275

---------

Co-authored-by: Wei Lee <weilee.rx@gmail.com>
  • Loading branch information
davidgxue and Lee-W authored Mar 1, 2024
1 parent 3836ee8 commit 4ba6d00
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions airflow/dags/metrcis/load_firestore_to_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ def load_request_data_from_firestore() -> list[tuple[str, int, bool, int]]:
.stream()
)

rows: list[tuple[str, int, bool, int]] = []
rows: list[tuple[str, int | None, bool, datetime]] = []
for doc in docs:
doc_dict = doc.to_dict()
uuid = doc_dict["uuid"]
score = doc_dict.get("score") or 0
score = doc_dict.get("score")
status = doc_dict.get("status") == "complete"
response_received_at = datetime.fromtimestamp(doc_dict.get("response_received_at"))
rows.append((uuid, score, status, response_received_at))
client = doc_dict.get("client")
rows.append((uuid, score, status, response_received_at, client))

return rows

Expand All @@ -77,9 +78,9 @@ def write_request_data_to_snowflake(rows: list[tuple[str, int, bool, int]]) -> N

insert_sql = f"""
INSERT INTO
{METRICS_SNOWFLAKE_DB_DATABASE}.{METRICS_SNOWFLAKE_DB_SCHEMA}.request(uuid, score, success, created_at)
{METRICS_SNOWFLAKE_DB_DATABASE}.{METRICS_SNOWFLAKE_DB_SCHEMA}.request(uuid, score, success, created_at, client)
VALUES
(?, ?, ?, ?)
(?, ?, ?, ?, ?)
"""
conn.cursor().executemany(insert_sql, rows)

Expand Down
4 changes: 2 additions & 2 deletions api/ask_astro/models/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class AskAstroRequest(BaseModel):
False,
description="Whether the request is an example",
)
client: str = Field(None, description="The client type used to send the request -- webapp/slack")
client: str | None = Field(None, description="The client type used to send the request -- webapp/slack")

def to_firestore(self) -> dict[str, Any]:
"""
Expand Down Expand Up @@ -107,7 +107,7 @@ def from_dict(cls, response_dict: dict[str, Any]) -> AskAstroRequest:
response_received_at=response_dict.get("response_received_at"),
is_processed=response_dict.get("is_processed", False),
is_example=response_dict.get("is_example", False),
client=response_dict["client"],
client=response_dict.get("client", None),
)


Expand Down

0 comments on commit 4ba6d00

Please sign in to comment.