summaryrefslogtreecommitdiff
path: root/python/gras/stats/main.js
blob: 9659024371d260e14f8356591fe4e4f85a4d57fd (plain)
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
/***********************************************************************
 * Query stats
 **********************************************************************/
var gras_query_stats = function(registry)
{
    $.ajax({
        type: "GET",
        async: true,
        url: "/stats.xml",
        dataType: "xml",
        success: function(xml)
        {
            if (registry.overall_active)
            {
                if ($(xml, "gras_stats") !== undefined)
                {
                    registry.appendPoint(xml);
                    gras_update_throughput_chart(registry);
                    gras_update_per_block_charts(registry);
                }

                registry.timeout_handle = window.setTimeout(function()
                {
                    gras_query_stats(registry);
                }, Math.round(1000/registry.overall_rate));
            }
        }
    });
}

/***********************************************************************
 * Init
 **********************************************************************/
var gras_stats_main = function()
{
    var registry = new GrasStatsRegistry();
    var overall_config = $('#overall_config').get(0);

    gras_setup_overall_chart(registry);

    //init overall config gui element for rate
    var overall_rate = $('input[name="rate"]', overall_config);
    overall_rate.val(registry.overall_rate);
    overall_rate.change(function()
    {
        registry.overall_rate = overall_rate.val();
    });

    //init overall config gui element for activity
    registry.overall_active = true;
    var overall_active = $('input[name="active"]', overall_config);
    overall_active.attr('checked', registry.overall_active);
    overall_active.change(function()
    {
        registry.overall_active = overall_active.is(':checked');
        if (registry.overall_active) gras_query_stats(registry);
        else window.clearInterval(registry.timeout_handle);
    });

    //init overall config gui element for showing
    var overall_show = $('input[name="show"]', overall_config);
    overall_show.attr('checked', false);
    overall_show.change(function()
    {
        var chart = $('#overall_chart');
        gras_animate_show_hide(chart, overall_show.is(':checked'));
    });
    overall_show.change();

    gras_query_stats(registry);
}