Repository navigation
Expand file tree
/
Copy pathprofile.js
More file actions
160 lines (118 loc) · 4.03 KB
/
Copy pathprofile.js
File metadata and controls
160 lines (118 loc) · 4.03 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// ================================
// Get username from URL
// ================================
const params = new URLSearchParams(window.location.search);
const userName = params.get("user");
document.getElementById("profile-name").textContent = userName;
// ================================
// Load ascents
// ================================
fetch("ascents.csv")
.then(res => res.text())
.then(csv => {
const ascents = parseCSV(csv);
// Filter this user's ascents
const userAscents = ascents.filter(a => a.userName === userName);
// ================================
// STATS
// ================================
const total = userAscents.length;
const ratings = userAscents
.map(a => Number(a.rating))
.filter(r => !isNaN(r));
const avgRating = ratings.length
? (ratings.reduce((a, b) => a + b, 0) / ratings.length).toFixed(1)
: "—";
// Hardest climb (based on grade string)
// NOTE: This is a simple version
const hardest = getHardest(userAscents);
document.getElementById("profile-stats").innerHTML = `
<p><strong>Total Ascents:</strong> ${total}</p>
<p><strong>Hardest Climb:</strong> ${hardest || "—"}</p>
`;
// ================================
// ASCENTS LIST
// ================================
const container = document.getElementById("profile-ascents");
container.innerHTML = userAscents.map(a => `
<div class="ascent-card">
<h3><a href="climb-details.html?id=${a.climbId}">${a.climbName}</a></h3>
<p><strong>Suggested Grade:</strong> ${a.suggestedGrade}</p>
<div class="ascent-mini-info">
<p><strong>Date:</strong> ${a.date}</p>
<p><strong>Attempts:</strong> ${a.attempts || "—"}</p>
<p class="ascent-card-rating"><strong>Rating:</strong> ⭐ ${a.rating || "—"}</p>
</div>
${a.comments ? `<p class="ascent-comment">${a.comments}</p>` : ""}
</div>
`).join("");
});
// ================================
// SIMPLE grade comparison
// ================================
function getHardest(ascents) {
const order = [
"VB","V0","V1","V2","V3","V4","V5",
"V6","V7","V8","V9","V10"
];
let hardestIndex = -1;
let hardestName = "";
ascents.forEach(a => {
const grade = a.suggestedGrade || "";
const index = order.indexOf(grade);
if (index > hardestIndex) {
hardestIndex = index;
hardestName = `${a.climbName} (${grade})`;
}
});
return hardestName;
}
// ================================
// CSV parser (same as yours)
// ================================
function parseCSV(csv) {
// Remove "sep=;" if it exists
if (csv.startsWith("sep=")) {
csv = csv.split("\n").slice(1).join("\n");
}
const result = Papa.parse(csv, {
header: true,
skipEmptyLines: true
});
const data = result.data;
return data.map(obj => {
let newObj = {};
for (let key in obj) {
let value = obj[key];
if (value !== undefined && value !== null) {
value = value.trim();
}
// Convert numbers (adjust as needed)
if (key === "id" || key === "rating" || key === "attempts") {
value = value ? Number(value) : null;
}
// Optional: handle tags if you use them later
if (key === "tags") {
value = value ? value.split(",").map(t => t.trim()) : [];
}
newObj[key] = value;
}
return newObj;
});
}
// Apply background
function setBackground(imageName) {
document.body.style.backgroundImage = `url('images/${imageName}')`;
document.body.style.backgroundSize = "cover";
document.body.style.backgroundPosition = "center";
// Save to localStorage
localStorage.setItem("selectedBackground", imageName);
}
// Load saved background on page load
function loadBackground() {
const saved = localStorage.getItem("selectedBackground");
if (saved) {
setBackground(saved);
}
}
loadBackground();