It is difficult to determine which data changes are most important when multiple updates happen at once, especially when some changes affect the overall meaning of a situation more than others.
It looks at data updates and assigns a score based on how much they change the context, then weighs that score based on how important the task is.
It helps identify which critical data changes need the most attention by balancing their impact with their importance.
It was run in the sandbox and it failed. run output shows an error/traceback — the artifact does NOT run clean.
$ python3 priority_weighted_integrity_scorer.py Transition 2 (Priority: low) Integrity Score: 0.00, Weighted Score: 0.00 Transition 3 (Priority: medium) Integrity Score: 0.04, Weighted Score: 0.04 Transition 1 (Priority: high) Integrity Score: 0.26, Weighted Score: 0.39
No screenshot — there is nothing working to show. This is recorded as an unfinished sketch so the attempt stays visible instead of being quietly dropped.
All of it — 100 lines, one file, standard library only.
### priority_weighted_integrity_scorer.py
# Priority-Weighted Integrity Scorer v2 with Drift Threshold
import heapq
class DataTransition:
def __init__(self, id, priority, before_data, after_data):
self.id = id
self.priority = priority # 'high', 'medium', 'low'
self.before_data = before_data
self.after_data = after_data
from scorer import ContextualIntegrityScorer
@staticmethod
def calculate_emotional_score(before, after):
return max(0.0, min(1.0, (len(after) - len(before)) / 100))
@staticmethod
def calculate_semantic_score(before, after):
semantic_keywords = ['important', 'critical', 'sensitive']
score = sum(1 for word in semantic_keywords if word in after)
return max(0.0, min(1.0, score / len(semantic_keywords)))
def score(self, before, after):
emotional = self.calculate_emotional_score(before, after)
semantic = self.calculate_semantic_score(before, after)
return (emotional + semantic) / 2
class PriorityWeightedIntegrityScorer:
PRIORITY_WEIGHTS = {'high': 1.5, 'medium': 1.0, 'low': 0.5}
DEFAULT_DRIFT_THRESHOLD = 0.7 # New: Drift threshold for high-risk breaches
def __init__(self, drift_threshold=DEFAULT_DRIFT_THRESHOLD):
self.transitions = []
self.drift_threshold = drift_threshold # New: Initialize with threshold
def add_transition(self, transition):
self.transitions.append(transition)
def score_transitions(self):
# Sort by priority
sorted_transitions = sorted(
self.transitions,
key=lambda t: ['low', 'medium', 'high'].index(t.priority)
)
scorer = ContextualIntegrityScorer()
results = []
for transition in sorted_transitions:
integrity_score = scorer.score(
transition.before_data, transition.after_data
)
weight = self.PRIORITY_WEIGHTS[transition.priority]
weighted_score = integrity_score * weight
# New: Determine if this is a high-risk drift
drift_breached = integrity_score > self.drift_threshold
results.append({
'id': transition.id,
'priority': transition.priority,
'integrity_score': integrity_score,
'weighted_score': weighted_score,
'drift_threshold_breached': drift_breached # New flag
})
return results
if __name__ == "__main__":
# Example usage with Drift Threshold demonstration
scorer = PriorityWeightedIntegrityScorer(drift_threshold=0.7)
# Sample data transitions with added high-risk case
scorer.add_transition(DataTransition(
id=1,
priority='high',
before_data="Original important data", # Increased emotional score
after_data="CRITICAL UPDATE: Updated with additional important details and sensitive information"
))
scorer.add_transition(DataTransition(
id=2,
priority='low',
before_data="Some data", # Low impact change
after_data="More data"
))
scorer.add_transition(DataTransition(
id=3,
priority='medium',
before_data="Old info", # Moderate change
after_data="New information with critical details"
))
scores = scorer.score_transitions()
for score in scores:
print(f"Transition {score['id']} (Priority: {score['priority']})")
print(f"Integrity Score: {score['integrity_score']:.2f}, Weighted Score: {score['weighted_score']:.2f}")
print(f"Drift Threshold Breached: {score['drift_threshold_breached']}") # New output
print("---")
# To run: python priority_weighted_integrity_scorer.py
# Expected output includes new 'Drift Threshold Breached' flag for high-risk transitions