From aaaffd342d064c0d8dc4daa2c555522281d140c6 Mon Sep 17 00:00:00 2001 From: dfusion-dev Date: Sat, 14 Dec 2024 11:52:20 -0700 Subject: [PATCH 1/4] clean score logic --- psl_proof/proof.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/psl_proof/proof.py b/psl_proof/proof.py index ed68b9d..4cec568 100644 --- a/psl_proof/proof.py +++ b/psl_proof/proof.py @@ -97,15 +97,12 @@ def generate(self) -> ProofResponse: and self.proof_response.quality >= score_threshold and self.proof_response.uniqueness >= score_threshold ) - total_score = ( - self.proof_response.authenticity * 0.25 - + self.proof_response.ownership * 0.25 - + self.proof_response.quality * 0.25 - + self.proof_response.uniqueness * 0.25 + total_score = 0.0 if not self.proof_response.valid else ( + self.proof_response.quality * 0.5 + + self.proof_response.uniqueness * 0.5 ) self.proof_response.score = round(total_score, 2) self.proof_response.attributes = { - 'proof_valid': is_data_authentic, 'did_score_content': True, 'source': source_data.source.name, 'revision': data_revision, @@ -188,7 +185,6 @@ def get_source_data(input_data: Dict[str, Any]) -> SourceData: ) input_chats = input_data.get('chats', []) - #print(f"input_chats: {input_chats}") source_chats = source_data.source_chats for input_chat in input_chats: From 390fce36bdc8c3b175795625ef59c48098fbfa0d Mon Sep 17 00:00:00 2001 From: dfusion-dev Date: Sat, 14 Dec 2024 20:04:38 -0700 Subject: [PATCH 2/4] use logging if these fail --- psl_proof/utils/verification.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/psl_proof/utils/verification.py b/psl_proof/utils/verification.py index a875d6b..672d249 100644 --- a/psl_proof/utils/verification.py +++ b/psl_proof/utils/verification.py @@ -1,5 +1,6 @@ from typing import Optional, Dict, Any import requests +import logging from dataclasses import dataclass from psl_proof.models.cargo_data import SourceData from psl_proof.utils.validation_api import get_validation_api_url @@ -29,12 +30,15 @@ def verify_token(config: Dict[str, Any], source_data: SourceData) -> Optional[Ve ) return result except ValueError as e: - print("Error parsing JSON response:", e) - RuntimeError("Error parsing JSON response:", e) # Replace with logging in production + logging.error(f"Error during parsing verification status: {e}") + traceback.print_exc() + sys.exit(1) else: - print(f"verify_token failed. Status code: {response.status_code}, Response: {response.text}") # Replace with logging - RuntimeError(f"verify_token failed. Status code: {response.status_code}, Response: {response.text}") # Replace with logging + logging.error(f"Error, unexpected verification response: {e}") + traceback.print_exc() + sys.exit(1) except requests.exceptions.RequestException as e: - print("verify_token:", e) # Replace with logging - RuntimeError("verify_token:", e) # Replace with logging + logging.error(f"Error during verification: {e}") + traceback.print_exc() + sys.exit(1) From 65bb9701cf8acdd5317a1937e5fc032e5ec04f59 Mon Sep 17 00:00:00 2001 From: dfusion-dev Date: Sat, 14 Dec 2024 20:42:13 -0700 Subject: [PATCH 3/4] only run on main for now --- .github/workflows/build-and-release.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 8912ef4..d9b1fb4 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -3,8 +3,6 @@ name: Build and Release on: push: branches: [main] - pull_request: - branches: [main] permissions: contents: write From 3f9a94cc780a8af97e50547849f30099ab84f485 Mon Sep 17 00:00:00 2001 From: dfusion-dev Date: Mon, 16 Dec 2024 00:48:55 -0700 Subject: [PATCH 4/4] added logging score --- psl_proof/proof.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/psl_proof/proof.py b/psl_proof/proof.py index 4cec568..20a7f97 100644 --- a/psl_proof/proof.py +++ b/psl_proof/proof.py @@ -50,7 +50,7 @@ def generate(self) -> ProofResponse: print(f"verify_result: {verify_result}") is_data_authentic = verify_result.is_valid proof_failed_reason = verify_result.error_text - + cargo_data = CargoData( source_data = source_data, source_id = source_user_hash_64 @@ -82,6 +82,7 @@ def generate(self) -> ProofResponse: 'chat_data': None } self.proof_response.metadata = metadata + logging.info(f"ProofResponseAttributes: {json.dumps(self.proof_response.attributes, indent=2)}") return self.proof_response #validate/proof data ... @@ -103,11 +104,12 @@ def generate(self) -> ProofResponse: ) self.proof_response.score = round(total_score, 2) self.proof_response.attributes = { + 'score': self.proof_response.score, 'did_score_content': True, 'source': source_data.source.name, 'revision': data_revision, 'submitted_on': current_datetime, - 'chat_data': cargo_data.get_chat_list_data() + 'chat_data': None } self.proof_response.metadata = metadata @@ -116,7 +118,7 @@ def generate(self) -> ProofResponse: self.config, source_data ) - print(f"proof data: {self.proof_response}") + logging.info(f"ProofResponseAttributes: {json.dumps(self.proof_response.attributes, indent=2)}") return self.proof_response def get_telegram_data(