Merge scores, also for DBC output
[pazpar2-moved-to-github.git] / heikki / dbc-os / test2.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 *~ 
11   exit
12 fi
13 killall pazpar2 dbc-opensearch-gw
14
15 rm -f *.out *.log
16
17 URL="http://localhost:9017/"
18 CFG="test2.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 # Start the gateway.
30   ../../../dbc-opensearch-gw/dbc-opensearch-gw.pl -1 \
31       -c dbc-opensearch-gw.cfg \
32       -l dbc-opensearch-gw.log \
33       @:9994 &
34
35
36 $PZ -f $CFG  -l pz2.log -p $PIDFILE &
37 sleep 0.2 # make sure it has time to start
38 echo "Init"
39 curl -s "$URL?command=init" > init.out
40 SESSION=`xml_grep --text_only "//session" init.out `
41 # cat init.out; echo
42 echo "Got session $SESSION"
43 SES="&session=$SESSION"
44
45
46 if [ -z "$1" ]
47 then
48   Q="computer"
49 else
50   Q=$1
51 fi
52 QRY=`echo $Q | sed 's/ /+/g' `
53
54 SORT="sort=relevance_h"
55 #SEARCH="command=search$SES&$QRY&rank=1&sort=relevance"
56 #SEARCH="command=search$SES&$QRY"
57 #SEARCH="command=search$SES&query=$QRY&sort=relevance"
58 SEARCH="command=search$SES&query=$QRY&$SORT"
59 echo $SEARCH
60 curl -s "$URL?$SEARCH" > search.out
61 cat search.out | grep search
62 echo
63 sleep 0.5 # let the search start working
64
65 STAT="command=stat&$SES"
66 echo "" > stat.out
67 LOOPING=1
68 while [ $LOOPING = 1 ]
69 do
70   sleep 0.5
71   curl -s "$URL?$STAT" > stat.out
72   ACT=`xml_grep --text_only "//activeclients" stat.out`
73   HIT=`xml_grep --text_only "//hits" stat.out`
74   REC=`xml_grep --text_only "//records" stat.out`
75   echo "$ACT $HIT $REC"
76   if grep -q "<activeclients>0</activeclients>" stat.out
77   then
78     LOOPING=0
79   fi
80   echo >> stats.out
81   cat stat.out >> stats.out
82 done
83
84
85 SHOW="command=show$SES&start=0&num=100&$SORT"
86 echo $SHOW
87 curl -s "http://localhost:9017/?$SHOW" > show.out
88 #grep "relevance" show.out | grep += | grep -v "(0)"
89 #grep "round-robin" show.out
90 grep '^ <md-title>' show.out | head -11
91 grep 'Received' dbc-opensearch-gw.log | head -1 >> titles.out
92 grep '^ <md-title>' show.out >> titles.out
93
94 # Plot it
95 DF=`echo $QRY | sed 's/@//g' | sed 's/[+"]/_/g' | sed s"/'//g "`
96 grep "round-robin" show.out |
97   cut -d' ' -f 6,7 |
98   sed 's/[^0-9 ]//g' |
99   awk '{print FNR,$0}'> $DF.data
100
101 grep mergeplot show.out > merge.tmp
102 LINENUMBER="1"
103 LAST=""
104 echo "0 0 0" > merge.data
105 for lno in `cat merge.tmp | cut -d ' ' -f2`
106 do
107   if [ "$lno" != "$LAST" ]
108   then
109     echo "Found line $lno at $LINENUMBER"
110     grep "mergeplot $lno " merge.tmp | sed "s/mergeplot/$LINENUMBER/" >> merge.data
111     LAST=$lno
112     LINENUMBER=$(($LINENUMBER + 1))
113   fi
114 done
115 echo "$LINENUMBER 0 0 0" >> merge.data
116
117
118
119 echo '\
120   set term png
121   set out "plot.png"
122   #set yrange [0:300000]
123   set logscale y
124   plot \' > plot.cmd
125 for F in *.data
126 do
127   BF=`basename $F .data | sed 's/_/ /g' `
128   echo -n " \"$F\" using 1:2  with points  title \"$BF\", " >> plot.cmd
129 done
130 echo "0 notitle" >> plot.cmd
131
132 gnuplot < plot.cmd
133
134
135 echo "
136   set term png
137   set out \"cluster.png\"
138   set title \"$HEADLINE\"
139   plot \"merge.data\" using 1:3 with points title \"records\", \
140        \"merge.data\" using 1:4 with points title \"merged score\", \
141        \"merge.data\" using 1:5 with points title \"sum score\", \
142        \"merge.data\" using 1:6 with points title \"avg score\"
143 " > plot.cmd
144 cat plot.cmd | gnuplot
145
146 echo
147
148 echo "All done"
149 kill `cat $PIDFILE`
150 rm -f $PIDFILE 
151