-
Notifications
You must be signed in to change notification settings - Fork 4
/
segmentLeaderboard.pl
executable file
·141 lines (113 loc) · 4.02 KB
/
segmentLeaderboard.pl
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
#!/usr/bin/perl -w
# by Torben Menke https://entorb.net
# DESCRIPTION
# Download Segment Leaderboard as Excel Sheet
# TODO
# IDEAS
# Filter by my clubs
# Fetch Segment infos
# DONE
# Modules: My Default Set
use strict;
use warnings;
use 5.010; # say
use Data::Dumper;
use utf8; # this script is written in UTF-8
binmode STDOUT, ':utf8'; # default encoding for linux print STDOUT
# Modules: Perl Standard
use Encode qw(encode decode);
# use File::Path qw/remove_tree/;
# Modules: Web
use CGI;
my $cgi = CGI->new;
#use CGI ":all";
#use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
# Modules: My Strava Module Lib
use lib ('.');
use lib ('/var/www/virtual/entorb/perl5/lib/perl5');
use lib "C:\\Users\\menketrb\\Documents\\Hacken\\Perl\\Strava-Web"
; # just for making Visual Studio Code happy
use lib "d:\\files\\Hacken\\Perl\\Strava-Web";
use TMsStrava qw( %o %s);
# at entorb.net some modules require use local::lib!!!
TMsStrava::htmlPrintHeader( $cgi, 'Segment Leaderboard', 1 );
TMsStrava::initSessionVariables( $cgi->param("session") );
TMsStrava::htmlPrintNavigation();
my %formparam;
if ( $cgi->param('segment_id') and $cgi->param('segment_id') =~ m /^\d+$/ ) {
$formparam{'segment_id'} = $cgi->param('segment_id') + 0;
}
if ( $cgi->param('date_range') ) {
$formparam{'date_range'} = $cgi->param('date_range');
}
if ( $cgi->param('club_id') and $cgi->param('club_id') =~ m /^\d+$/ ) {
$formparam{'club_id'} = $cgi->param('club_id') + 0;
}
if ( $cgi->param('gender') ) { $formparam{'gender'} = $cgi->param('gender'); }
if ( $cgi->param('age_group') ) {
$formparam{'age_group'} = $cgi->param('age_group');
}
say
"<p>A segment ID looks like 17204908 in https://www.strava.com/segments/17204908</p>";
$formparam{'segment_id'} = 17204908 unless $formparam{'segment_id'};
my @clubs = TMsStrava::fetchClubs( $s{'token'} );
# display the form
say "<form action=\"segmentLeaderboard.pl\" method=\"post\">
<input type=\"hidden\" name=\"session\" value=\"$s{ 'session' }\">
<input type=\"text\" id=\"durationMin\" name=\"segment_id\" style=\"width: 100px\" value=\""
. $formparam{'segment_id'} . "\" >";
say "<select name=\"date_range\">";
for my $s (qw( all_time this_year this_month this_week today)) {
say "<option value=\"$s\" "
. ( $formparam{'date_range'} eq $s ? 'selected' : '' )
. ">$s</option>";
}
say "</select>";
say "<select name=\"club_id\">";
say "<option value=\"0\" "
. ( $formparam{'club_id'} eq 0 ? 'selected' : '' )
. ">any_club</option>";
for my $ref (@clubs) {
my @l = @{$ref}; # id, name, member_count, sport_type, city
say "<option value=\"$l[0]\" "
. ( $formparam{'club_id'} eq $l[0] ? 'selected' : '' )
. ">$l[1]</option>";
} ## end for my $ref (@clubs)
say "</select>";
say "<select name=\"gender\">";
for my $s (qw( men_and_women men women )) {
say "<option value=\"$s\" "
. ( $formparam{'gender'} eq $s ? 'selected' : '' )
. ">$s</option>";
}
say "</select>";
say "<select name=\"age_group\">";
for my $s (
qw( all_age 0_19 20_24 25_34 35_44 45_54 55_64 65_69 70_74 75_plus ))
{
say "<option value=\"$s\" "
. ( $formparam{'age_group'} eq $s ? 'selected' : '' )
. ">$s</option>";
} ## end for my $s (...)
say "</select>*";
say "<input type=\"submit\" name=\"submit\" value=\"Submit\">
</form>";
say "<p>* age filtering requires Strava 'Summit' subscription</p>";
# form was submitted, so the search is performed
# TODO: all -> gender variable
if ( $cgi->param('submit') ) {
my @list = TMsStrava::fetchSegmentLeaderboard(
$s{'token'}, $formparam{'segment_id'},
$formparam{'date_range'}, $formparam{'club_id'},
$formparam{'gender'}, $formparam{'age_group'}
);
say "<table>";
say "<tr><th>Rank</th><th>Time (s)</th><th>Name</th><th>Date</th></tr>";
foreach my $ref (@list) {
my @l = @{$ref};
say "<tr><td>$l[0]</td><td>$l[1]</td><td>$l[2]</td><td>$l[3]</td></tr>";
}
say "</table>";
} ## end if ( $cgi->param('submit'...))
TMsStrava::htmlPrintFooter($cgi);