Skip to content
Browse files

Continued cleanups.

* Put connection details in separate file.
* fix db handling enough to view a single statistics page
* Fix some template code to handle computation correctly
  • Loading branch information...
1 parent ad91ab9 commit b1eca37b64358b32b0bc81ec3276938bb27475eb @abelsson committed Dec 15, 2011
Showing with 20 additions and 18 deletions.
  1. +3 −0 web/config.py.template
  2. +9 −10 web/index.py
  3. +8 −8 web/templates/results.html
View
3 web/config.py.template
@@ -0,0 +1,3 @@
+db_host = ''
+db_user = ''
+db_password=''
View
19 web/index.py
@@ -18,7 +18,7 @@
import datetime
from time import time
-
+import config
import web
from web import form
@@ -119,8 +119,7 @@
class base(object):
def __init__(self, *args, **kwargs):
super(base, self).__init__(*args, **kwargs)
- self.db = web.database(dbn='mysql', user='wikistats_reader', pw='wikistats', db='wikistats')
-
+ self.db = web.database(dbn='mysql', host= config.db_host, user= config.db_user , pw=config.db_password, db='wikistats')
class about:
def GET(self):
render = web.template.render('templates/')
@@ -152,7 +151,7 @@ def GET(self, proj=None, year=None, page=None):
render = web.template.render('templates/', base='index')
return render.form(form)
else:
- self.POST(proj, year, page)
+ return self.POST(proj, year, page)
def POST(self, proj=None, year=None, page=None):
search = web.input()
@@ -170,7 +169,7 @@ def POST(self, proj=None, year=None, page=None):
#form = self.init_form()
#return render.form(form)
return render.results(counts, maxcount, total_hits_html, dt, form)
-
+
def results_overview(self, counts, proj, rank, date, page):
cvt = { "commons.m" : "commons.wikimedia.org",
"en.n" : "en.wikinews.org",
@@ -267,28 +266,28 @@ def getalldays(c,date):
rows = c.query("SHOW TABLES like 'pagecounts_%s__';" % date)
#c.execute("SHOW TABLES like 'pagecounts_%s__';" % date)
#rows = c.fetchall()
- all_days = [x[0] for x in rows]
+ all_days = [x.values()[0] for x in rows]
return all_days
def getalldays_new(c,date):
#c.execute("SHOW TABLES like 'pagecounts_%s';" % date)
rows =c.query("SHOW TABLES like 'pagecounts_%s';" % date)
#rows = c.fetchall()
- all_days = [x[0] for x in rows]
+ all_days = [x.values()[0] for x in rows]
return all_days
def getcounts(c,date,proj,page):
all_days = getalldays(c,date)
counts = {}
for day in all_days:
- count = c.query("SELECT sum(hitcount) FROM "+day+" WHERE page=%s AND project=%s;", (page,proj))
+ count = c.query("SELECT sum(hitcount) FROM "+day+" WHERE page=$page AND project=$project;", vars = {'page' : page, 'project' : proj })
#c.execute("SELECT sum(hitcount) FROM "+day+" WHERE page=%s AND project=%s;", (page,proj))
#count = c.fetchone()[0]
if count == None:
count = 0
day = int(day.split("_")[1][-2:])
- counts[day] = int(count)
+ counts[day] = int(count[0].values()[0])
return counts
@@ -385,4 +384,4 @@ def handler(req):
if __name__ == '__main__':
MONTHS, LATESTMONTH = getdates()
app.run()
-
+
View
16 web/templates/results.html
@@ -32,21 +32,21 @@
return "%.1fM" % (n/1000000.0)
$for i in range(0,31):
- <li class="qtr" style="width: 25px; left: $i*20px;">$i</li>
+ <li class="qtr" style="width: 25px; left: ${i*20}px;">$i</li>
$for count in counts:
$#count = counts.get(i+1,0)
- <li class="sent bar" style="height:$count/$max_count)*280px; left: $foopx;">
- <p style="margin-left: -3px;">$humround(count)</p>
+ <li class="sent bar" style="height:${(count/max_count)*280}px; left: ${foo}px;">
+ <p style="margin-left: -3px;">${humround(count)}</p>
</li>
- $foo += 20
- $ssum += int($count)
+ $ foo += 20
+ $ ssum += int(count)
<li id="ticks">
$for i in range(5,0,-1):
<div class="tick" style="height: 59px;">
- $x = ($max_count/5*$i)*1.071)
- <p>$humround(x)</p>
+ $ x = (max_count/5*i)*1.071
+ <p>${humround(x)}</p>
</div>
</li>
</ul>
@@ -64,4 +64,4 @@
<p style="font-size: 0.6em">(took $dt sec)</p>
</body>
-</html>
+</html>

0 comments on commit b1eca37

Please sign in to comment.
Something went wrong with that request. Please try again.