Skip to content

Commit 70c14c7

Browse files
committed
Added table links to day pages.
1 parent 4b01b56 commit 70c14c7

File tree

6 files changed

+87
-52
lines changed

6 files changed

+87
-52
lines changed

inputscope/conf.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
2121
@author Erki Suurjaak
2222
@created 26.03.2015
23-
@modified 19.05.2015
23+
@modified 21.05.2015
2424
------------------------------------------------------------------------------
2525
"""
2626
try: import ConfigParser as configparser # Py2
@@ -36,8 +36,8 @@
3636

3737
"""Program title, version number and version date."""
3838
Title = "InputScope"
39-
Version = "1.1a"
40-
VersionDate = "19.05.2015"
39+
Version = "1.1b"
40+
VersionDate = "21.05.2015"
4141

4242
"""TCP port of the web user interface."""
4343
WebHost = "localhost"
@@ -63,6 +63,9 @@
6363
"""Physical length of a pixel, in meters."""
6464
PixelLength = 0.00024825
6565

66+
"""Mapping tables to input types."""
67+
InputTables = [("mouse", ["moves", "clicks", "scrolls"]), ("keyboard", ["keys", "combos"])]
68+
6669
"""Key positions in keyboard heatmap."""
6770
KeyPositions = {
6871
"Escape": (12, 12),
@@ -243,8 +246,8 @@
243246
"CREATE TABLE IF NOT EXISTS app_events (id INTEGER NOT NULL PRIMARY KEY, dt TIMESTAMP DEFAULT (DATETIME('now', 'localtime')), type TEXT)",
244247
"CREATE TABLE IF NOT EXISTS screen_sizes (id INTEGER NOT NULL PRIMARY KEY, dt TIMESTAMP DEFAULT (DATETIME('now', 'localtime')), x INTEGER, y INTEGER)",
245248
"CREATE TABLE IF NOT EXISTS counts (id INTEGER NOT NULL PRIMARY KEY, type TEXT, day DATETIME, count INTEGER, UNIQUE(type, day))",
246-
) + tuple(TriggerTemplate.format(x) for x in ["moves", "clicks", "scrolls", "keys", "combos"]
247-
) + tuple(DayIndexTemplate.format(x) for x in ["moves", "clicks", "scrolls", "keys", "combos"])
249+
) + tuple(TriggerTemplate.format(x) for x in [x for k, vv in InputTables for x in vv]
250+
) + tuple(DayIndexTemplate.format(x) for x in [x for k, vv in InputTables for x in vv])
248251

249252

250253
def init(filename=ConfigPath):

inputscope/static/site.css

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* @author Erki Suurjaak
55
* @created 07.04.2015
6-
* @modified 20.05.2015
6+
* @modified 21.05.2015
77
*/
88
* {
99
font-family: Tahoma;
@@ -46,9 +46,6 @@
4646
color: white;
4747
text-decoration: none;
4848
}
49-
#header a:hover {
50-
text-decoration: underline;
51-
}
5249
#headerlinks {
5350
float: left;
5451
position: relative;
@@ -103,9 +100,6 @@
103100
color: white;
104101
font-size: 1em;
105102
}
106-
#content a:visited {
107-
color: blue;
108-
}
109103
#mouse_heatmap {
110104
margin-left: auto;
111105
margin-right: auto;
@@ -183,3 +177,21 @@ label.range_label {
183177
top: -18px;
184178
width: 100%;
185179
}
180+
#header a:hover, #content a:hover {
181+
text-decoration: underline;
182+
}
183+
#tablelinks {
184+
position: absolute;
185+
top: 4px;
186+
left: 4px;
187+
font-weight: bold;
188+
font-size: 0.8em;
189+
}
190+
#tablelinks a {
191+
color: #1abc9c;
192+
margin: 2px;
193+
text-decoration: none;
194+
}
195+
#tablelinks span {
196+
margin: 2px;
197+
}

inputscope/views/base.tpl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ Template arguments:
4040
<span id="daysection">
4141
%dayidx = next((i for i, x in enumerate(days) if x["day"] == day), None)
4242
%prevday, nextday = (days[x]["day"] if 0 <= x < len(days) else None for x in [dayidx-1, dayidx+1]) if dayidx is not None else [None]*2
43+
%prevday = prevday if day else days[-1]["day"]
4344
<a href="{{get_url(http://github.com/%3Cspan%20class=%22pl-s%22%3E%3Cspan%20class=%22pl-pds%22%3E"%3C/span%3E/%s/<table>/<day>%3Cspan%20class=%22pl-pds%22%3E"%3C/span%3E%3C/span%3E%20%3Cspan%20class=%22pl-k%22%3E%%3C/span%3E%20input,%20%3Cspan%20class=%22pl-v%22%3Etable=%3C/span%3Etable,%20%3Cspan%20class=%22pl-v%22%3Eday=%3C/span%3Eprevday)}}">{{"< %s" % prevday if prevday else ""}}</a>
4445

4546
<select id="dayselector">
46-
%if not day:
47+
%if not day or not events:
4748
<option>- day -</option>
4849
%end # if not day
49-
%for d in days:
50-
<option{{' selected="selected"' if day == d["day"] else ""}}>{{d["day"]}}</option>
50+
%for d in days[::-1]:
51+
<option{{!' selected="selected"' if day == d["day"] else ""}}>{{d["day"]}}</option>
5152
%end # for d
5253
</select>
5354

inputscope/views/keyboard.tpl

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Template arguments:
1212

1313
@author Erki Suurjaak
1414
@created 07.04.2015
15-
@modified 20.05.2015
15+
@modified 21.05.2015
1616
%"""
1717
%WEBROOT = get_url(http://github.com/"/")
1818
%title = "%s %s" % (input.capitalize(), table)
@@ -32,6 +32,18 @@ Template arguments:
3232
</span>
3333
</span>
3434

35+
%if day:
36+
<div id="tablelinks">
37+
%for type, tbl in [(k, x) for k, tt in conf.InputTables for x in tt]:
38+
%if tbl == table:
39+
<span>{{tbl}}</span>
40+
%else:
41+
<a href="{{get_url(http://github.com/%3Cspan%20class=%22pl-s%22%3E%3Cspan%20class=%22pl-pds%22%3E"%3C/span%3E/%s/<table>/<day>%3Cspan%20class=%22pl-pds%22%3E"%3C/span%3E%3C/span%3E%20%3Cspan%20class=%22pl-k%22%3E%%3C/span%3E%20type,%20%3Cspan%20class=%22pl-v%22%3Etable=%3C/span%3Etbl,%20%3Cspan%20class=%22pl-v%22%3Eday=%3C/span%3Eday)}}">{{tbl}}</a>
42+
%end # if tbl == table
43+
%end # for type, tbl
44+
</div>
45+
%end # if day
46+
3547
<div id="status">
3648
<span id="statustext"><br /></span>
3749
<span id="progressbar"></span>
@@ -104,7 +116,7 @@ Template arguments:
104116
elm_show_kb = document.getElementById("show_keyboard"),
105117
elm_keyboard = document.getElementById("keyboard");
106118
var myHeatmap = h337.create({container: elm_heatmap, radius: RADIUS});
107-
myHeatmap.setData({data: positions, max: positions.length ? positions[0].value : 0});
119+
if (positions.length) myHeatmap.setData({data: positions, max: positions[0].value});
108120
109121
elm_show_kb.addEventListener("click", function() {
110122
elm_keyboard.style.display = this.checked ? "" : "none";
@@ -113,6 +125,19 @@ Template arguments:
113125
elm_heatmap.getElementsByTagName("canvas")[0].style.display = this.checked ? "" : "none";
114126
});
115127
128+
elm_button.addEventListener("click", function() {
129+
if ("Replay" == elm_button.value) {
130+
myHeatmap.setData({data: [], max: 0});
131+
elm_button.value = "Pause";
132+
replay(0);
133+
} else if ("Continue" != elm_button.value) {
134+
elm_button.value = "Continue";
135+
} else {
136+
elm_button.value = "Pause";
137+
resumeFunc && resumeFunc();
138+
resumeFunc = undefined;
139+
};
140+
});
116141
117142
var replay = function(index) {
118143
if (index <= events.length - 1) {
@@ -139,20 +164,5 @@ Template arguments:
139164
}
140165
};
141166
142-
143-
elm_button.addEventListener("click", function() {
144-
if ("Replay" == elm_button.value) {
145-
myHeatmap.setData({data: [], max: 0});
146-
elm_button.value = "Pause";
147-
replay(0);
148-
} else if ("Continue" != elm_button.value) {
149-
elm_button.value = "Continue";
150-
} else {
151-
elm_button.value = "Pause";
152-
resumeFunc && resumeFunc();
153-
resumeFunc = undefined;
154-
};
155-
});
156-
157167
});
158168
</script>

inputscope/views/mouse.tpl

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Template arguments:
1212

1313
@author Erki Suurjaak
1414
@created 07.04.2015
15-
@modified 20.05.2015
15+
@modified 21.05.2015
1616
%"""
1717
%WEBROOT = get_url(http://github.com/"/")
1818
%title = "%s %s" % (input.capitalize(), table)
@@ -32,6 +32,18 @@ Template arguments:
3232
</span>
3333
</span>
3434

35+
%if day:
36+
<div id="tablelinks">
37+
%for type, tbl in [(k, x) for k, tt in conf.InputTables for x in tt]:
38+
%if tbl == table:
39+
<span>{{tbl}}</span>
40+
%else:
41+
<a href="{{get_url(http://github.com/%3Cspan%20class=%22pl-s%22%3E%3Cspan%20class=%22pl-pds%22%3E"%3C/span%3E/%s/<table>/<day>%3Cspan%20class=%22pl-pds%22%3E"%3C/span%3E%3C/span%3E%20%3Cspan%20class=%22pl-k%22%3E%%3C/span%3E%20type,%20%3Cspan%20class=%22pl-v%22%3Etable=%3C/span%3Etbl,%20%3Cspan%20class=%22pl-v%22%3Eday=%3C/span%3Eday)}}">{{tbl}}</a>
42+
%end # if tbl == table
43+
%end # for type, tbl
44+
</div>
45+
%end # if day
46+
3547
<div id="status">
3648
<span id="statustext"><br /></span>
3749
<span id="progressbar"></span>
@@ -74,6 +86,19 @@ Template arguments:
7486
var myHeatmap = h337.create({container: elm_heatmap, radius: RADIUS});
7587
myHeatmap.setData({data: positions, max: positions.length ? positions[0].value : 0});
7688
89+
elm_button.addEventListener("click", function() {
90+
if ("Replay" == elm_button.value) {
91+
myHeatmap.setData({data: [], max: positions.length ? positions[0].value : 0});
92+
elm_button.value = "Pause";
93+
replay(0);
94+
} else if ("Continue" != elm_button.value) {
95+
elm_button.value = "Continue";
96+
} else {
97+
elm_button.value = "Pause";
98+
resumeFunc && resumeFunc();
99+
resumeFunc = undefined;
100+
};
101+
});
77102
78103
var replay = function(index) {
79104
if (index <= events.length - 1) {
@@ -99,20 +124,5 @@ Template arguments:
99124
}
100125
};
101126
102-
103-
elm_button.addEventListener("click", function() {
104-
if ("Replay" == elm_button.value) {
105-
myHeatmap.setData({data: [], max: positions.length ? positions[0].value : 0});
106-
elm_button.value = "Pause";
107-
replay(0);
108-
} else if ("Continue" != elm_button.value) {
109-
elm_button.value = "Continue";
110-
} else {
111-
elm_button.value = "Pause";
112-
resumeFunc && resumeFunc();
113-
resumeFunc = undefined;
114-
};
115-
});
116-
117127
});
118128
</script>

inputscope/webui.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
@author Erki Suurjaak
88
@created 06.04.2015
9-
@modified 20.05.2015
9+
@modified 21.05.2015
1010
"""
1111
import collections
1212
import datetime
@@ -79,10 +79,9 @@ def inputindex(input):
7979
@route("/")
8080
def index():
8181
"""Handler for showing the GUI index page."""
82-
stats = {"mouse": {"count": 0}, "keyboard": {"count": 0}}
82+
stats = dict((k, {"count": 0}) for k, tt in conf.InputTables)
8383
countminmax = "SUM(count) AS count, MIN(day) AS first, MAX(day) AS last"
84-
tables = {"keyboard": ("keys", "combos"), "mouse": ("moves", "clicks", "scrolls")}
85-
for input, table in [(x, t) for x, tt in tables.items() for t in tt]:
84+
for input, table in [(x, t) for x, tt in conf.InputTables for t in tt]:
8685
row = db.fetchone("counts", countminmax, type=table)
8786
if not row["count"]: continue # for input, table
8887
stats[input]["count"] += row["count"]

0 commit comments

Comments
 (0)