Skip to content

Commit

Permalink
Merge pull request #4 from dfusionai/ScoreCleanup
Browse files Browse the repository at this point in the history
Score cleanup
  • Loading branch information
RicLaiZA authored Dec 16, 2024
2 parents 534df93 + 3f9a94c commit 0bf181c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Build and Release
on:
push:
branches: [main]
pull_request:
branches: [main]

permissions:
contents: write
Expand Down
18 changes: 8 additions & 10 deletions psl_proof/proof.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ...
Expand All @@ -97,20 +98,18 @@ 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,
'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

Expand All @@ -119,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(
Expand Down Expand Up @@ -188,7 +187,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:
Expand Down
16 changes: 10 additions & 6 deletions psl_proof/utils/verification.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 0bf181c

Please sign in to comment.