-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate.js
More file actions
136 lines (101 loc) · 4.38 KB
/
evaluate.js
File metadata and controls
136 lines (101 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const PATTERN_WEIGHTS = {
"bait and switch": 30,
"pre-selected checkbox": 5,
"confirmshaming": 5,
};
const CAP_PER_PATTERN = 3;
const MAX_SCORE = 100;
export function calculateUnethicalScore(patternCounts) {
const patterns = Object.keys(patternCounts);
if (patterns.length === 0) return 0;
let totalWeighted = 0;
let maxPossible = 0;
patterns.forEach(pattern => {
const count = Math.min(patternCounts[pattern], CAP_PER_PATTERN);
const weight = PATTERN_WEIGHTS[pattern] || 5;
totalWeighted += count * weight;
maxPossible += CAP_PER_PATTERN * weight;
});
const score = (totalWeighted / maxPossible) * 100;
console.log(`Calculated score: ${score} (Total Weighted: ${totalWeighted}, Max Possible: ${maxPossible})`);
return Math.round(score);
}
// const PATTERN_WEIGHTS = {
// 'pre-selected checkbox': 1, // baseline
// 'confirmshaming': 2, // 比 checkbox 严重一些
// 'bait and switch': 5, // 很严重
// // Add more as needed
// };
// const MAX_COUNT_PER_PATTERN = 5;
// const MAX_SCORE = 100;
// export function calculateUnethicalScore(patternCounts) {
// let totalScore = 0;
// Object.keys(patternCounts).forEach(pattern => {
// const count = Math.min(patternCounts[pattern], MAX_COUNT_PER_PATTERN);
// const weight = PATTERN_WEIGHTS[pattern] || 1; // default weight is 1
// totalScore += count * weight;
// });
// return Math.min(totalScore, MAX_SCORE);
// }
// // Define weights for different patterns
// const PATTERN_WEIGHTS = {
// 'pre-selected checkbox': 10,
// 'confirmshaming': 10,
// 'bait and switch': 50
// // Add other patterns with their weights as needed
// };
// // Maximum possible score
// const MAX_SCORE = 100;
// // Function to calculate the unethical score based on patterns
// export function calculateUnethicalScore(patternCounts) {
// // let totalScore = 0;
// // let maxPossibleScore = 0;
// // // Calculate the theoretical maximum possible score
// // // Assuming each pattern could occur up to 5 times on a page (arbitrary choice, adjust as needed)
// // const maxOccurrencesPerPattern = 5;
// // Object.keys(PATTERN_WEIGHTS).forEach(pattern => {
// // maxPossibleScore += PATTERN_WEIGHTS[pattern] * maxOccurrencesPerPattern;
// // });
// // // Calculate weighted score for each detected pattern
// // Object.keys(patternCounts).forEach(pattern => {
// // const count = patternCounts[pattern];
// // const weight = PATTERN_WEIGHTS[pattern] || 5; // Default weight of 5 if pattern not defined
// // // Add to total score (pattern weight * count)
// // totalScore += weight * count;
// // });
// // // Calculate proportional score out of MAX_SCORE
// // const proportionalScore = Math.round((totalScore / maxPossibleScore) * MAX_SCORE);
// // return proportionalScore;
// let totalScore = 0;
// // Calculate weighted score for each pattern
// Object.keys(patternCounts).forEach(pattern => {
// const count = patternCounts[pattern];
// const weight = PATTERN_WEIGHTS[pattern] || 5; // Default weight of 5 if pattern not defined
// // Add to total score (pattern weight * count)
// totalScore += weight * count;
// });
// // Cap the score at MAX_SCORE
// return Math.min(totalScore, MAX_SCORE);
// }
// // Function to update the score display
// export function updateScoreDisplay(score) {
// const scoreElement = document.querySelector('.score-section p:first-child');
// const progressBar = document.querySelector('.score-section progress');
// const descriptionElement = document.querySelector('.score-section p:last-child');
// // Update score text
// scoreElement.textContent = `Unethical Score: ${score}/${MAX_SCORE}`;
// // Update progress bar
// progressBar.value = score;
// // Update description based on score ranges
// if (score < 20) {
// descriptionElement.textContent = 'A level';
// } else if (score < 40) {
// descriptionElement.textContent = 'B level';
// } else if (score < 60) {
// descriptionElement.textContent = 'C level';
// } else if (score < 80) {
// descriptionElement.textContent = 'D level';
// } else {
// descriptionElement.textContent = 'E level';
// }
// }