-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathh2h.sh
More file actions
executable file
·163 lines (153 loc) · 4.85 KB
/
Copy pathh2h.sh
File metadata and controls
executable file
·163 lines (153 loc) · 4.85 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
161
162
163
#!/usr/bin/env bash
#===============================================================================
#
# FILE: h2h.sh
#
# USAGE: ./h2h.sh player1 player2
#
# DESCRIPTION: show bothways whenever p1 has met p2
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: YOUR NAME (),
# ORGANIZATION:
# CREATED: 02/05/2016 23:43
# REVISION: 2016-02-10 15:20
#===============================================================================
cd ~/Downloads/tennis_atp-master
OPT_VERBOSE=
OPT_DEBUG=
OPT_COLS="1,2,11,21,28,30"
while [[ $1 = -* ]]; do
case "$1" in
-V|--verbose) shift
OPT_VERBOSE=1
;;
--raw) shift
OPT_RAW=1
;;
--slam) shift
OPT_SLAM=1
OPT_EVCODE="\-5[2468]0.*"
;;
--masters) shift
OPT_LEVEL=M
OPT_FILTER=1
#OPT_EVCODE="\-5[2468]0.*"
;;
-n|--numbering) shift
OPT_LINE_NUMBER="-l"
;;
--total) shift
OPT_TOTAL=1
;;
--surface) shift
OPT_SURFACE=$1
OPT_FILTER=1
shift
;;
--level) shift
OPT_LEVEL=$1
OPT_FILTER=1
shift
;;
--show-surface) shift
OPT_COLS="${OPT_COLS},3"
;;
--show-level) shift
OPT_COLS="${OPT_COLS},5"
# M - masters, G - slam, A - smaller ones
;;
--debug) shift
OPT_DEBUG=1
;;
-h|--help)
cat <<-! | sed 's|^ ||g'
$0 Version: 0.0.0 Copyright (C) 2016 jkepler
This program prints matches played by two given players.
Data is taken from the csv files on disk.
The output is filtered through csvlook
Usage:
$0 Federer Nadal
$0 -raw Federer Berdych
Options:
--raw Output is not formatted, and is tab delimited. No numbering.
--total Display total matches, and wins for each player
-n --numbering Display line numbering
--slam Display only majors
--surface <surface> Filter on given surface (Hard, Clay, Grass)
--level M G A Show only Masters or Grand Slams or A (Others)
--show-surface Display surface
--show-level Display level (M - Masters, G - Majors, A - others_
-V --verbose Displays wins for each player after the common table
--debug Displays debug information
!
# no shifting needed here, we'll quit!
exit
;;
--edit)
echo "this is to edit the file generated if any "
exit
;;
--source)
echo "this is to edit the source "
vim $0
exit
;;
*)
echo "Error: Unknown option: $1" >&2
echo "Use -h or --help for usage" 1>&2
exit 1
;;
esac
done
if [ $# -lt 2 ]; then
echo -e "Please pass names of two player using Initcaps" 1<&2
exit -1
fi
_format() {
text="$*"
if [[ -z "$OPT_RAW" ]]; then
echo -e "$text" | csvlook -d, -H $OPT_LINE_NUMBER
else
echo "$text" | tr ',' '\t'
fi
}
_filter() {
if [[ -n "$OPT_LEVEL" ]]; then
text=$( echo "$text" | awk -F"," -v level="$OPT_LEVEL" '$5==level {print $0}' )
fi
if [[ -n "$OPT_SURFACE" ]]; then
text=$( echo "$text" | awk -F"," -v level="$OPT_SURFACE" '$3==level {print $0}' )
fi
}
#grep -h "$1" atp_matches_*.csv | grep "$2" | cut -d, -f1,2,11,21,28,30 | csvlook -d, -H -l
#text=$( grep -h "$1" atp_matches_*.csv | grep "$2" | cut -d, -f1,2,11,21,28,30 )
#text=$( grep -h "${OPT_EVCODE}$1" atp_matches_*.csv | grep "$2" | cut -d, -f${OPT_COLS} )
text=$( grep -h "${OPT_EVCODE}$1" atp_matches_*.csv | grep "$2" )
if [[ -n "$OPT_FILTER" ]]; then
_filter "$text"
fi
text=$( echo "$text" | cut -d, -f${OPT_COLS} )
_format "$text"
if [[ -n "$OPT_TOTAL" ]]; then
echo -n "Total: "
echo "$text" | grep -c .
echo -n "$1: "
echo "$text" | grep -c "$1.*$2"
echo -n "$2: "
echo "$text" | grep -c "$2.*$1"
fi
if [[ -n "$OPT_VERBOSE" ]]; then
# This is for when you want to see when p1 has beaten p2
#grep -h "$1.*$2" atp_matches_*.csv | cut -d, -f1,2,11,21,28,30 | csvlook -d, -H -l
#echo "--------------"
#grep -h "$2.*$1" atp_matches_*.csv | cut -d, -f1,2,11,21,28,30 | csvlook -d, -H -l
text=$( grep -h "${OPT_EVCODE}$1.*$2" atp_matches_*.csv | cut -d, -f${OPT_COLS} )
_format "$text"
echo "--------------"
text=$( grep -h "${OPT_EVCODE}$2.*$1" atp_matches_*.csv | cut -d, -f${OPT_COLS} )
_format "$text"
fi