Tests on SOLR, plottable data out of pazpar2, plot script
[pazpar2-moved-to-github.git] / heikki / solr / test3.sh
1 #!/bin/bash
2 #
3 # Simple script (and config) to get pz2 to run against DBC's OpenSearch, and
4 # calculate rankings. See how they differ for different queries
5 #
6
7 if [ "$1" == "clean" ]
8 then
9   echo "Cleaning up"
10   rm -f $PIDFILE $YAZPIDFILE *.out *.log *.data *~ plot.cmd
11   exit
12 fi
13 killall pazpar2 
14
15 rm -f *.out *.log
16
17 URL="http://localhost:9017/"
18 CFG="test3.cfg"
19
20 PZ="../../src/pazpar2"
21 if [ ! -x $PZ ]
22 then
23   echo "$PZ2 not executable. Panic"
24   exit 1
25 fi
26
27 PIDFILE=pz2.pid
28
29 $PZ -f $CFG  -l pz2.log -p $PIDFILE &
30 sleep 0.2 # make sure it has time to start
31 echo "Init"
32 curl -s "$URL?command=init" > init.out
33 SESSION=`xml_grep --text_only "//session" init.out `
34 # cat init.out; echo
35 echo "Got session $SESSION"
36 SES="&session=$SESSION"
37
38
39 if [ -z "$1" ]
40 then
41   Q="computer"
42 else
43   Q=$1
44 fi
45
46 if [ -z "$2" ]
47 then
48   HEADLINE="$Q"
49 else
50   HEADLINE="$2: $Q"
51 fi
52
53 QRY=`echo $Q | sed 's/ /+/g' `
54
55 #SORT="sort=score"
56 SORT="sort=relevance_h"
57 #SEARCH="command=search$SES&$QRY&rank=1&sort=relevance"
58 #SEARCH="command=search$SES&$QRY"
59 #SEARCH="command=search$SES&query=$QRY&sort=relevance"
60 SEARCH="command=search$SES&query=$QRY&$SORT"
61 echo $SEARCH
62 curl -s "$URL?$SEARCH" > search.out
63 cat search.out | grep search
64 echo
65 sleep 0.5 # let the search start working
66
67 STAT="command=stat&$SES"
68 echo "" > stat.out
69 LOOPING=1
70 while [ $LOOPING = 1 ]
71 do
72   sleep 0.5
73   curl -s "$URL?$STAT" > stat.out
74   ACT=`xml_grep --text_only "//activeclients" stat.out`
75   HIT=`xml_grep --text_only "//hits" stat.out`
76   REC=`xml_grep --text_only "//records" stat.out`
77   echo "$ACT $HIT $REC"
78   if grep -q "<activeclients>0</activeclients>" stat.out
79   then
80     LOOPING=0
81   fi
82   echo >> stats.out
83   cat stat.out >> stats.out
84 done
85
86
87 SHOW="command=show$SES&start=0&num=100&$SORT"
88 echo $SHOW
89 curl -s "http://localhost:9017/?$SHOW" > show.out
90 #grep "relevance" show.out | grep += | grep -v "(0)"
91 #grep "round-robin" show.out
92
93 # Plot the lines created by the code
94 grep plotline show.out > scores.data
95 echo "Client numbers"
96 cat scores.data | cut -d' ' -f2 | sort -u
97 head -10 scores.data
98
99 echo "
100   set term png
101   set out \"plot.png\"
102   set title \"$HEADLINE\"
103 " > plot.cmd
104 echo '
105   plot "scores.data" using 0:($2==0?$6:1/0) with points title "db-1", \
106        "scores.data" using 0:($2==1?$6:1/0) with points title "db-2", \
107        "scores.data" using 0:($2==2?$6:1/0) with points title "db-3", \
108        "scores.data" using 0:($2==3?$6:1/0) with points title "db-4", \
109        "scores.data" using 0:($2==4?$6:1/0) with points title "db-5", \
110        "scores.data" using 0:($2==5?$6:1/0) with points title "db-6" \
111 ' >> plot.cmd
112 cat plot.cmd | gnuplot
113
114
115 exit 1 # The old plotting code
116
117 # Plot it
118 DF=`echo $QRY | sed 's/@//g' | sed 's/[+"]/_/g' | sed s"/'//g "`
119 grep "round-robin" show.out |
120   cut -d' ' -f 6,7 |
121   sed 's/[^0-9 ]//g' |
122   awk '{print FNR,$0}'> $DF.data
123
124
125
126 echo '\
127   set term png
128   set out "plot.png"
129   #set yrange [0:300000]
130   set logscale y
131   plot \' > plot.cmd
132 for F in *.data
133 do
134   BF=`basename $F .data | sed 's/_/ /g' `
135   echo -n " \"$F\" using 1:2  with points  title \"$BF\", " >> plot.cmd
136 done
137 echo "0 notitle" >> plot.cmd
138
139 gnuplot < plot.cmd
140
141 echo
142
143 echo "All done"
144 kill `cat $PIDFILE`
145 rm -f $PIDFILE 
146