diff --git a/.gitignore b/.gitignore index 5fa362b..b903b59 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ node_modules/ .env .cache/ -*.log \ No newline at end of file +*.log +*.db \ No newline at end of file diff --git a/courses.html b/courses.html deleted file mode 100644 index 3ecd07b..0000000 --- a/courses.html +++ /dev/null @@ -1,612 +0,0 @@ - - -
- - -Error loading courses. Please try again.
'); + } +}); + +router.get('/partials/course-layouts/:courseId', async (req, res) => { + try { + const { courseId } = req.params; + const layouts = await getLayoutsForCourse(courseId); + res.render('../partials/course-layouts', { layouts, courseId }); + } catch (error) { + console.error('Error loading course layouts:', error.message); + res.status(500).send('Error loading ratings. Please try again.
'); + } +}); + +router.get('/partials/player-history/:pdgaNumber', async (req, res) => { + try { + const { pdgaNumber } = req.params; + + let history = await getRatingHistoryFromDB(pdgaNumber); + if (!history || history.length === 0) { + const html = await fetchRatingHistory(pdgaNumber); + history = parseRatingHistory(html); + try { + await saveRatingHistoryToDB(pdgaNumber, history); + } catch (dbErr) { + console.error('Failed to save rating history:', dbErr.message); + } + } + + const formattedHistory = (history || []).map(row => ({ + date: row.date, + rating: row.rating, + displayDate: new Date(row.date).toLocaleDateString('en-US', { day: '2-digit', month: 'short', year: 'numeric' }) + })); + + res.render('../partials/player-history', { pdgaNumber, history: formattedHistory }); + } catch (error) { + console.error('Error loading player history:', error.message); + res.status(500).send('No courses found. Click "Scrape Courses" to load Swedish courses from PDGA.
+<% } else { %> +| Course Name | +City | +Last Updated | +Actions | +
|---|---|---|---|
|
+ <%= course.name %>
+ <%= course.city %>
+ |
+ <%= course.city %> | +<%= lastUpdated %> | ++ '); event.stopPropagation();" title="Scrape layouts for this course"> + | +
|
+
+
+ Click to load layouts...
+ |
+ |||
No ratings found.
+<% } else { %> +| Rank | +Player Name | +PDGA # | +Rating | +Change | +Predicted | +
|---|---|---|---|---|---|
| <%= index + 1 %> | +
+ <%= player.name %>
+ PDGA #<%= player.pdgaNumber %>
+ |
+ #<%= player.pdgaNumber %> | +
+
+
+
+
+
+
+ |
+ <%= ratingChangeText %> | +
+
+ <%= player.predictedRating || 'N/A' %>
+
+
+
+
+ |
+
|
+
+
+
+ Rating History for <%= player.name %>
+
+
+
+
+ Click to load rating history...
+ |
+ |||||