File: stats.html

package info (click to toggle)
python-cyclone 1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,388 kB
  • ctags: 1,372
  • sloc: python: 8,823; sh: 183; makefile: 13; sql: 12
file content (87 lines) | stat: -rw-r--r-- 2,587 bytes parent folder | download | duplicates (2)
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
<!DOCTYPE html>
<html>
<head>
  <script src="http://yandex.st/jquery/1.7.1/jquery.min.js"></script>
  <script src="http://yandex.st/jquery/flot/0.7/jquery.flot.min.js"></script>
  <script>
    $(document).ready(function() {
        updater.start();
    });

    $(document).unload(function() {
    });

    updater = {
        socket: null,

        plot: null,
        visits: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
        chatters: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ],
        points: 10,

        options: {
            legend: { show: true }
        },

        start: function() {
            if ("WebSocket" in window) {
                socket = new WebSocket("ws://localhost:8888/statssocket");
            } else {
                socket = new MozWebSocket("ws://localhost:8888/statssocket");
            }
            socket.onmessage = function(event) {
                data = JSON.parse(event.data);
                updater.update_plot(data);
            }
            updater.plot = $.plot($('#placeholder'),
                                  [ updater.visits, updater.chatters ],
                                  updater.options);
        },

        append_data: function(visits, chatters) {
            if (updater.visits.length > updater.points) {
                updater.visits = updater.visits.slice(1);
                updater.chatters = updater.chatters.slice(1);
            }
            updater.visits.push(visits);
            updater.chatters.push(chatters);
        },

        prepare_data: function(arr) {
            var len = arr.length;
            var res = [];
            for (var i=0; i < len; i++) {
                res.push([i, arr[i]]);
            }
            return res;
        },

        update_plot: function(data) {
            updater.append_data(data.visits, data.chatters);
            var visits = updater.prepare_data(updater.visits);
            var chatters = updater.prepare_data(updater.chatters);
            updater.plot = $.plot($('#placeholder'),
                                  [ {label: 'Global visits', data: visits},
                                    {label: 'Active users', data: chatters}
                                  ], updater.options);
        },

        plot: function(visits, chatters) {
        },

        stop: function() {
            updater.socket.close();
            updater.socket = null;
        }
    };
  </script>
<title> Site statistics </title>
</head>
<body>
  <div>
   <div id="placeholder" style="width:920px;height:400px;float:left;"></div>
   <div id="table"></div>
  </div>
</body>
</html>