~ubuntuone-control-tower/software-center/trunk

« back to all changes in this revision

Viewing changes to test/graph/plot-reviews-spread.py

  • Committer: Michael Vogt
  • Date: 2011-07-19 15:55:27 UTC
  • Revision ID: michael.vogt@ubuntu.com-20110719155527-y3ekllx1a2m6yjbq
test/graph/plot-reviews-spread.py: add tool to draw distribution graphs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import simplejson
 
4
import subprocess
 
5
import sys
 
6
 
 
7
from softwarecenter.backend.piston.rnrclient import RatingsAndReviewsAPI
 
8
 
 
9
if __name__ == "__main__":
 
10
 
 
11
    rnrclient = RatingsAndReviewsAPI()
 
12
    piston_review_stats = rnrclient.review_stats(origin="ubuntu")
 
13
 
 
14
    # means            1  2  3  4  5 stars
 
15
    histogram_total = [0, 0, 0, 0, 0]
 
16
    for s in piston_review_stats:
 
17
        histogram = simplejson.loads(s.histogram)
 
18
        for i in range(5):
 
19
            histogram_total[i] += histogram[i]
 
20
    print "overall distribution: ", histogram_total
 
21
 
 
22
    # write out data file
 
23
    f=open("reviews-spread.dat", "w")
 
24
    for i in range(5):
 
25
        f.write("%i %i\n" % (i+1, histogram_total[i]))
 
26
    f.close()
 
27
 
 
28
    # write out gnuplot
 
29
    f=open("reviews-spread.gnuplot", "w")
 
30
    f.write("""
 
31
set title "Reviews spread"
 
32
set xlabel "Stars"
 
33
set ylabel "Nr ratings"
 
34
set boxwidth 0.75
 
35
set term png size 1600,1200
 
36
set out 'review-spread.png'
 
37
 
 
38
plot "reviews-spread.dat" using 1:2 with boxes fs solid 0.2 title "Star distribution"
 
39
""")
 
40
    f.close()
 
41
 
 
42
    # run it
 
43
    res = subprocess.call(["gnuplot", "reviews-spread.gnuplot"])
 
44
    sys.exit(res)