Merge pull request #98 from rootcoma/edits_reports_question_stats

Edits reports question stats
This commit is contained in:
tannn 2013-11-12 20:49:04 -08:00
commit d2697a364d
2 changed files with 56 additions and 26 deletions

View File

@ -117,6 +117,9 @@
<th>Question Answered*</th>
<th>Edits Made</th>
<th>Edits Accepted</th>
<th>Questions Made</th>
<th>Questions Accepted</th>
<th>Reports Made</th>
</tr>
</thead>
<tbody>
@ -135,8 +138,11 @@
) as score,
(select sum(points_made) from triviauserlog t3 where lower(username)=:username) as points,
(select sum(num_answered) from triviauserlog t4 where lower(username)=:username) as q_asked,
(select num_reported from triviausers where lower(username)=:username) as num_r,
(select num_accepted from triviausers where lower(username)=:username) as num_a
(select num_editted from triviausers where lower(username)=:username) as num_e,
(select num_editted_accepted from triviausers where lower(username)=:username) as num_e_accepted,
(select num_questions_added from triviausers where lower(username)=:username) as num_q,
(select num_questions_accepted from triviausers where lower(username)=:username) as num_q_accepted,
(select num_reported from triviausers where lower(username)=:username) as num_r
from (select
tl3.id as id2,
tl3.average_time * 1.0 as t,
@ -160,8 +166,11 @@
echo '<td>' . number_format($res['score'],2) . '</td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '<td>' . number_format($res['q_asked'],0) . '</td>';
echo '<td>' . number_format($res['num_e'],0) . '</td>';
echo '<td>' . number_format($res['num_e_accepted'],0) . '</td>';
echo '<td>' . number_format($res['num_q'],0) . '</td>';
echo '<td>' . number_format($res['num_q_accepted'],0) . '</td>';
echo '<td>' . number_format($res['num_r'],0) . '</td>';
echo '<td>' . number_format($res['num_a'],0) . '</td>';
echo '</tr>';
}
}
@ -193,14 +202,3 @@
</body>
</html>
<!--
select
sum(tl2.t * (tl2.n / (select sum(num_answered) from triviauserlog where username='rootcoma')))
from (select tl3.id as id2, tl3.average_time * 1.0 as t, tl3.num_answered * 1.0 as n
from triviauserlog tl3
) tl2
inner join triviauserlog tl
on tl.username='rootcoma'
and id=tl2.id2
-->

View File

@ -33,11 +33,11 @@ class TriviaTime(callbacks.Plugin):
self.__parent = super(TriviaTime, self)
self.__parent.__init__(irc)
""" games info """
# games info
self.games = {} # separate game for each channel
self.skips = {}
""" connections """
# connections
dbLocation = self.registryValue('sqlitedb')
# tuple head, tail ('example/example/', 'filename.txt')
dbFolder = os.path.split(dbLocation)
@ -161,6 +161,7 @@ class TriviaTime(callbacks.Plugin):
irc.error('Could not find that temp question')
else:
q = q[0]
self.storage.updateUser(q[1], 0, 0, 0, 0, 1)
self.storage.insertQuestionsBulk([(q[3], q[3])])
self.storage.removeTemporaryQuestion(q[0])
irc.reply('Question accepted!')
@ -176,6 +177,7 @@ class TriviaTime(callbacks.Plugin):
if charMask not in question:
irc.error(' The question must include the separating character %s ' % (charMask))
return
self.storage.updateUser(username, 0, 0, 0, 1)
self.storage.insertTemporaryQuestion(username, channel, question)
irc.reply(' Thank you for adding your question to the question database, it is awaiting approval. ')
addquestion = wrap(addquestion, ['text'])
@ -439,10 +441,10 @@ class TriviaTime(callbacks.Plugin):
question = self.storage.getQuestionByRound(roundNum, channel)
if len(question) > 0:
question = question[0]
self.storage.updateUser(username, 1, 0)
if inp[:2] == 's/':
regex = inp[2:].split('/')
if len(regex) > 1:
self.storage.updateUser(username, 1, 0)
newOne = regex[1]
oldOne = regex[0]
newQuestionText = question[2].replace(oldOne, newOne)
@ -451,6 +453,7 @@ class TriviaTime(callbacks.Plugin):
irc.sendMsg(ircmsgs.notice(username, 'NEW: %s' % (newQuestionText)))
irc.sendMsg(ircmsgs.notice(username, 'OLD: %s' % (question[2])))
return
self.storage.updateUser(username, 0, 0, 1)
self.storage.insertReport(channel, username, text, question[0])
irc.reply('Your report has been submitted!')
else:
@ -1993,12 +1996,22 @@ class TriviaTime(callbacks.Plugin):
self.conn.commit()
c.close()
def insertUser(self, username, numReported=0, numAccepted=0):
def insertUser(self, username, numEditted=0, numEdittedAccepted=0, numReported=0, numQuestionsAdded=0, numQuestionsAccepted=0):
usernameCanonical = ircutils.toLower(username)
if self.userExists(username):
return self.updateUser(username)
return self.updateUser(username, numEditted, numEdittedAccepted, numReported, numQuestionsAdded, numQuestionsAccepted)
c = self.conn.cursor()
c.execute('insert into triviausers values (NULL, ?, ?, ?, ?)', (username,numReported,numAccepted,usernameCanonical))
c.execute('insert into triviausers values (NULL, ?, ?, ?, ?, ?, ?, ?)',
(
username,
numEditted,
numEdittedAccepted,
usernameCanonical,
numReported,
numQuestionsAdded,
numQuestionsAccepted
)
)
self.conn.commit()
c.close()
@ -2071,9 +2084,12 @@ class TriviaTime(callbacks.Plugin):
c.execute('''create table triviausers (
id integer primary key autoincrement,
username text not null unique,
num_editted integer,
num_editted_accepted integer,
username_canonical,
num_reported integer,
num_accepted integer,
username_canonical
num_questions_added integer,
num_questions_accepted integer
)''')
except:
pass
@ -2387,16 +2403,29 @@ class TriviaTime(callbacks.Plugin):
self.conn.commit()
c.close()
def updateUser(self, username, numReported=0, numAccepted=0):
def updateUser(self, username, numEditted=0, numEdittedAccepted=0, numReported=0, numQuestionsAdded=0, numQuestionsAccepted=0):
if not self.userExists(username):
return self.insertUser(username, numReported, numAccepted)
return self.insertUser(username, numEditted, numEdittedAccepted, numReported, numQuestionsAdded, numQuestionsAccepted)
usernameCanonical = ircutils.toLower(username)
c = self.conn.cursor()
c.execute('''update triviausers set
username=?,
num_editted=num_editted+?,
num_editted_accepted=num_editted_accepted+?,
num_reported=num_reported+?,
num_accepted=num_accepted+?
where username_canonical=?''', (username, numReported, numAccepted, usernameCanonical))
num_questions_added=num_questions_added+?,
num_questions_accepted=num_questions_accepted+?
where username_canonical=?''',
(
username,
numEditted,
numEdittedAccepted,
numReported,
numQuestionsAdded,
numQuestionsAccepted,
usernameCanonical
)
)
self.conn.commit()
c.close()
@ -2608,6 +2637,7 @@ class TriviaTime(callbacks.Plugin):
if rows > 0:
return True
return False
def getVersion(self):
c = self.conn.cursor();
try:
@ -2615,6 +2645,7 @@ class TriviaTime(callbacks.Plugin):
return c.fetchone()
except:
pass
def makeInfoTable(self):
c = self.conn.cursor()
try:
@ -2623,5 +2654,6 @@ class TriviaTime(callbacks.Plugin):
)''')
except:
pass
Class = TriviaTime
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: