-
Notifications
You must be signed in to change notification settings - Fork 0
/
cranach_pairwise_comparison.html
123 lines (111 loc) · 5.03 KB
/
cranach_pairwise_comparison.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lucas Cranach Portrait Pairwise Comparison</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.pair-container {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
.pair-container img {
width: 400px; /* Fixed width */
height: 400px; /* Fixed height */
object-fit: cover; /* Ensure the image covers the area while preserving aspect ratio */
}
.pair-container button {
display: block;
margin-top: 10px;
padding: 10px 20px;
font-size: 16px;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<h1>Lucas Cranach Portrait Pairwise Comparison</h1>
<p>Select your preferred portrait in each pair.</p>
<div id="comparison-container"></div>
<button id="export-results" class="hidden">Export Results as CSV</button>
<script>
let startTime; // Variable to track the time
const pairs = [
{img1: 'images/Portrait_of_a_Lady.jpg', img2: 'images/Portrait_of_Johann_Friedrich.jpg'},
{img1: 'images/Portrait_of_a_Lady.jpg', img2: 'images/Portrait_of_Martin_Luther.jpg'},
{img1: 'images/Portrait_of_a_Lady.jpg', img2: 'images/Portrait_of_a_Young_Girl.jpg'},
{img1: 'images/Portrait_of_a_Lady.jpg', img2: 'images/Portrait_of_a_Saxon_Princess.jpg'},
{img1: 'images/Portrait_of_Johann_Friedrich.jpg', img2: 'images/Portrait_of_Martin_Luther.jpg'},
{img1: 'images/Portrait_of_Johann_Friedrich.jpg', img2: 'images/Portrait_of_a_Young_Girl.jpg'},
{img1: 'images/Portrait_of_Johann_Friedrich.jpg', img2: 'images/Portrait_of_a_Saxon_Princess.jpg'},
{img1: 'images/Portrait_of_Martin_Luther.jpg', img2: 'images/Portrait_of_a_Young_Girl.jpg'},
{img1: 'images/Portrait_of_Martin_Luther.jpg', img2: 'images/Portrait_of_a_Saxon_Princess.jpg'},
{img1: 'images/Portrait_of_a_Young_Girl.jpg', img2: 'images/Portrait_of_a_Saxon_Princess.jpg'}
];
let results = [];
let currentPair = 0;
function shuffle(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
function renderPair(pair) {
startTime = new Date(); // Start the timer when a pair is rendered
const container = document.getElementById('comparison-container');
container.innerHTML = `
<div class="pair-container">
<div>
<img src="${pair.img1}" alt="Portrait 1">
<button onclick="choosePainting('${pair.img1}', 'left')">Choose This</button>
</div>
<div>
<img src="${pair.img2}" alt="Portrait 2">
<button onclick="choosePainting('${pair.img2}', 'right')">Choose This</button>
</div>
</div>
`;
}
function choosePainting(choice, position) {
const endTime = new Date(); // Capture the time of the decision
const timeTaken = (endTime - startTime) / 1000; // Calculate time in seconds
results.push({
pair: `${pairs[currentPair].img1} vs ${pairs[currentPair].img2}`,
choice: choice,
position: position,
time: timeTaken
});
currentPair++;
if (currentPair < pairs.length) {
renderPair(pairs[currentPair]); // Move to the next pair
} else {
document.getElementById('comparison-container').innerHTML = '<h2>Thank you for your participation!</h2>';
document.getElementById('export-results').classList.remove('hidden');
}
}
document.getElementById('export-results').addEventListener('click', () => {
let csvContent = "Pair,Choice,Position,Time\n"; // Include headers for the new fields
results.forEach(result => {
csvContent += `${result.pair},${result.choice},${result.position},${result.time}\n`;
});
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
const link = document.createElement("a");
const url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", "cranach_portrait_results.csv");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
shuffle(pairs); // Shuffle the pairs
renderPair(pairs[currentPair]); // Start with the first pair
</script>
</body>
</html>