From 3768cfef6ce6bf2c11c31cc36c5df736faaf02ed Mon Sep 17 00:00:00 2001 From: RicLaiZA <62895964+RicLaiZA@users.noreply.github.com> Date: Mon, 16 Dec 2024 22:08:15 +0200 Subject: [PATCH] remove unwanted code (#5) Co-authored-by: Ubuntu --- psl_proof/__main__.py | 1 + psl_proof/models/cargo_data.py | 13 +++++++------ psl_proof/proof.py | 9 ++++----- psl_proof/utils/submission.py | 25 ++++++++++++++++--------- psl_proof/utils/validate_data.py | 26 +++++++++++--------------- psl_proof/utils/verification.py | 2 +- 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/psl_proof/__main__.py b/psl_proof/__main__.py index 73f6ab0..8ec9575 100644 --- a/psl_proof/__main__.py +++ b/psl_proof/__main__.py @@ -20,6 +20,7 @@ def load_config() -> Dict[str, Any]: 'input_dir': INPUT_DIR, 'salt': '5EkntCWI', 'validator_base_api_url': 'https://api.vana.genesis.dfusion.ai' + #'validator_base_api_url': 'https://07c8-169-0-170-105.ngrok-free.app' } logging.info(f"Using config: {json.dumps(config, indent=2)}") return config diff --git a/psl_proof/models/cargo_data.py b/psl_proof/models/cargo_data.py index 0068be5..e778fda 100644 --- a/psl_proof/models/cargo_data.py +++ b/psl_proof/models/cargo_data.py @@ -183,16 +183,17 @@ def to_verification_json(self) -> dict: # ChatData for Source (final destination data structure) @dataclass class ChatData: - chat_id: int chat_length: int - + chat_start_on: datetime = None + chat_ended_on: datetime = None sentiment: Dict[str, Any] = field(default_factory=dict) keywords: Dict[str, Any] = field(default_factory=dict) def to_dict(self): return { - "chat_id": self.chat_id, "chat_length": self.chat_length, + "chat_start_on": self.chat_start_on.isoformat(), + "chat_ended_on": self.chat_ended_on.isoformat(), "sentiment": self.sentiment, # No need to call .to_dict() for dicts "keywords": self.keywords, # Same for other dict fields } @@ -202,14 +203,14 @@ def to_dict(self): class CargoData: source_data: SourceData source_id: str - chat_list: List[ChatData] = field(default_factory=list) + # chat_list: List[ChatData] = field(default_factory=list) def to_dict(self): # Return a dictionary representation of the CargoData object return { "source_data": self.source_data, # Assuming source_data can be serialized directly - "source_id": self.source_id, - "chat_list": [chat.to_dict() for chat in self.chat_list] # Convert each ChatData in the list to a dict + "source_id": self.source_id #, + #"chat_list": [chat.to_dict() for chat in self.chat_list] # Convert each ChatData in the list to a dict } @staticmethod diff --git a/psl_proof/proof.py b/psl_proof/proof.py index 20a7f97..a2ed132 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 @@ -78,8 +78,7 @@ def generate(self) -> ProofResponse: 'did_score_content': False, 'source': source_data.source.name, 'revision': data_revision, - 'submitted_on': current_datetime, - 'chat_data': None + 'submitted_on': current_datetime } self.proof_response.metadata = metadata logging.info(f"ProofResponseAttributes: {json.dumps(self.proof_response.attributes, indent=2)}") @@ -108,8 +107,8 @@ def generate(self) -> ProofResponse: 'did_score_content': True, 'source': source_data.source.name, 'revision': data_revision, - 'submitted_on': current_datetime, - 'chat_data': None + 'submitted_on': current_datetime + #'chat_data': None #RL: No longer generate usesful data... } self.proof_response.metadata = metadata diff --git a/psl_proof/utils/submission.py b/psl_proof/utils/submission.py index da6fbfe..92ca95a 100644 --- a/psl_proof/utils/submission.py +++ b/psl_proof/utils/submission.py @@ -63,15 +63,18 @@ def get_historical_chats( return chat_histories except ValueError as e: - RuntimeError("Error parsing JSON response:", e) - return None + logging.error(f"Error during parsing Get_historical_chats status: {e}") + traceback.print_exc() + sys.exit(1) else: - RuntimeError(f"Validation failed. Status code: {response.status_code}, Response: {response.text}") - return None - + logging.error(f"Validation failed. Status code: {response.status_code}, Response: {response.text}") + traceback.print_exc() + sys.exit(1) except requests.exceptions.RequestException as e: - RuntimeError("get_historical_chats:", e) - return None + logging.error("get_historical_chats:", e) + traceback.print_exc() + sys.exit(1) + def submit_data( @@ -89,8 +92,12 @@ def submit_data( response = requests.post(url, json=payload, headers=headers) if response.status_code != 200: - RuntimeError(f"Submission failed. Status code: {response.status_code}, Response: {response.text}") + logging.error(f"Submission failed. Status code: {response.status_code}, Response: {response.text}") + traceback.print_exc() + sys.exit(1) except requests.exceptions.RequestException as e: - RuntimeError("submit_data:", e) + logging.error("submit_data:", e) + traceback.print_exc() + sys.exit(1) diff --git a/psl_proof/utils/validate_data.py b/psl_proof/utils/validate_data.py index 62409f1..b7cd0cb 100644 --- a/psl_proof/utils/validate_data.py +++ b/psl_proof/utils/validate_data.py @@ -45,8 +45,6 @@ def validate_data( source_data : SourceChatData = cargo_data.source_data source_chats = source_data.source_chats - #Patrick_ToCheck score_threshold should be 0.5 - score_threshold = 0.5 total_quality = 0.00 total_uniqueness = 0.00 chat_count = 0 @@ -87,19 +85,17 @@ def validate_data( total_uniqueness += uniqueness #print(f"source_contents: {source_contents}") - # if chat data has meaningful data... - if quality > score_threshold and uniqueness > score_threshold: - # Create a ChatData instance and add it to the list - chat_data = ChatData( - chat_id=source_chat.chat_id, - chat_length=contents_length - ) - #print(f"chat_data: {chat_data}") - cargo_data.chat_list.append( - chat_data - ) - else: - print(f"Extract data skiped - values are below threshold({score_threshold})") + #RL: No longer generate data for sentiment & keywords + # Create a ChatData instance and add it to the list + #chat_data = ChatData( + # chat_length=contents_length, + # chat_start_on = source_chat.chat_start_on, + # chat_ended_on = source_chat.chat_ended_on + #) + #print(f"chat_data: {chat_data}") + #cargo_data.chat_list.append( + # chat_data + #) # Calculate uniqueness if there are chats if chat_count > 0: diff --git a/psl_proof/utils/verification.py b/psl_proof/utils/verification.py index 672d249..255bc6a 100644 --- a/psl_proof/utils/verification.py +++ b/psl_proof/utils/verification.py @@ -34,7 +34,7 @@ def verify_token(config: Dict[str, Any], source_data: SourceData) -> Optional[Ve traceback.print_exc() sys.exit(1) else: - logging.error(f"Error, unexpected verification response: {e}") + logging.error(f"Error, unexpected verification response: Status code: {response.status_code}, Response: {response.text}") traceback.print_exc() sys.exit(1)