forked from wismill/amphetype
-
Notifications
You must be signed in to change notification settings - Fork 1
/
StatWidgets.py
99 lines (82 loc) · 3.74 KB
/
StatWidgets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from __future__ import division, with_statement
import time
from Data import DB
from QtUtil import *
from Config import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class WordModel(AmphModel):
def __init__(self, *args):
super(WordModel, self).__init__(*args)
self.words = None
def signature(self):
self.words = []
return (["Item", "Speed", "Accuracy", "Viscosity", "Count", "Mistakes", "Impact"],
[None, "%.1f wpm", "%.1f%%", "%.1f", None, None, "%.1f"])
def populateData(self, idx):
if len(idx) != 0:
return []
return self.words
def setData(self, words):
self.words = map(list, words)
self.reset()
class StringStats(QWidget):
def __init__(self, *args):
super(StringStats, self).__init__(*args)
self.model = WordModel()
tw = AmphTree(self.model)
tw.setIndentation(0)
tw.setUniformRowHeights(True)
tw.setRootIsDecorated(False)
self.stats = tw
ob = SettingsCombo('ana_which', [
('wpm asc', 'slowest'),
('wpm desc', 'fastest'),
('viscosity desc', 'least fluid'),
('viscosity asc', 'most fluid'),
('accuracy asc', 'least accurate'),
('misses desc', 'most mistyped'),
('total desc', 'most common'),
('damage desc', 'most damaging'),
])
wc = SettingsCombo('ana_what', ['keys', 'trigrams', 'words'])
lim = SettingsEdit('ana_many')
s = DB.fetchall("select rowid, name from source")
source = SettingsCombo('ana_source', [
(-1, 'all')
] + s)
self.w_count = SettingsEdit('ana_count')
self.connect(Settings, SIGNAL("change_ana_which"), self.update)
self.connect(Settings, SIGNAL("change_ana_what"), self.update)
self.connect(Settings, SIGNAL("change_ana_many"), self.update)
self.connect(Settings, SIGNAL("change_ana_count"), self.update)
self.connect(Settings, SIGNAL("history"), self.update)
self.setLayout(AmphBoxLayout([
["Display statistics about the", ob, wc, "from ", source, None, AmphButton("Update List", self.update)],
["Limit list to", lim, "items of count ", self.w_count," and older than", SettingsEdit("history"), "hours",
None, AmphButton("Send List to Lesson Generator",
lambda: self.emit(SIGNAL("lessonStrings"), [x[0] for x in self.model.words]))],
(self.stats, 1)
]))
def update(self):
ord = Settings.get('ana_which')
cat = Settings.get('ana_what')
limit = Settings.get('ana_many')
count = Settings.get('ana_count')
hist = time.time() - Settings.get('history') * 3600.0
source = Settings.get('ana_source')
if source == -1:
sourceWhere = ""
else:
sourceWhere = " and source = " + str(source) + " "
sql = """select data, 12.0/time as wpm,
100.0-100.0*misses/cast(total as real) as accuracy,
viscosity, total, misses,
total*time*time*(1.0+misses/total) as damage
from
(select data, agg_median(time) as time, agg_median(viscosity) as viscosity,
sum(count) as total, sum(mistakes) as misses
from statistic where w >= ? and type = ? """+ sourceWhere +""" group by data)
where total >= ?
order by %s limit %d""" % (ord, limit)
self.model.setData(DB.fetchall(sql, (hist, cat, count)))