Example #1
0
def template_rankings(p, items, rankings):
    with p(html.table()):
        with p(html.tr()):
            with p(html.td_block({u'valign':u'top'})):
                p(html.h2('Rankings:'))
            with p(html.td_block({u'valign':u'top'})):
                p(u' ')
                p(u'<button id="rerank">Re-rank</button>')
            with p(html.td_block({u'valign':u'top'})):
                p(u'<img src="http://www.labmeeting.com/images/upload/spinner.gif" style="display:none;" id="loading" />')
    r = [u'%s (%s)' % (html.b(items[i]), html.span_smaller(u'%s' % score))
                                                    for score,i in rankings]
    p.sub(partial_list(r))
Example #2
0
def template_clean_data(p, clean_data, features, items, cleaners_names, filter_names):
    p(html.h2(u'Clean data:'))
    with p(html.div({u'id':u'clean_data', 
                      u'style':u'height:20em;overflow:scroll;'})):
        with p(html.table()):
            with p(html.tr()):
                p(html.td('&nbsp;'))
                for i,f in enumerate(features):
                    with p(html.td_block()):
                        p(html.b(u'Missing:'))
                        p(html.br())
                        p(u'<select class="cleaners">')
                        for name in cleaner_funcs:
                            p(u'<option')
                            if name == cleaners_names[i]:
                                p(u' SELECTED="SELECTED"')
                            p(u' value="%s"' % name)
                            p(u'>')
                            p(name)
                            p(u'</option>')
                        p(u'</select>')

                        p(html.br())
                        p(html.br())
                        p(html.b(u'Filters:'))
                        p(html.br())
                        with p(html.div({u'class':u'filters'})):
                            for f in filter_funcs:
                                p(u'<input type="checkbox"')
                                if f in filter_names[i]:
                                    p(u' checked="checked"')
                                p(u' name="%s"' % f)
                                p(u'>')
                                p(f)
                                p(u'</input>')
                                p(html.br())
            with p(html.tr()):
                p(html.td(u'&nbsp;'))
                for f in features:
                    with p(html.td_block({u'valign':u'top'})):
                        p(html.b(f))
            for item,row in zip(items, clean_data):
                with p(html.tr()):
                    p(html.td(html.b(item)))
                    for cell in row:
                        if isinstance(cell, ChangedFloat):
                            p(html.td(html.b(u'%.6s ' % cell) + html.span(cell.original, {u'style':u'"font-size:smaller;color:gray;"'})))
                        else:
                            p(html.td('%.6s' % cell))
Example #3
0
def template_view_csv(p, short_code, clean_data, filter_names, cleaners_names, table, features, items, rankings, normalized_equation):
    with p(html.head()):
        p(html.title('%s | AutoRanker' % short_code))
        #p(u'<script src="http://www.google.com/jsapi"></script>')
        p(u'<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>')
        p(u'<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>')
        p(u'<script src="http://www.json.org/json2.js"></script>')
        with p(html.script_block()):
            #p(u'google.load("jquery", "1.3.2");google.load("jqueryui", "1.7.2");')
            p(u'''
               var features = {};
               jQuery(function($) {
                    var send_new_data = function() {
                        var short_code = $('#short_code').val();
                        $.ajax({
                            type: 'POST',
                            url: "''' + new_data.url() + '''",
                            data: {'data':JSON.stringify({'short_code':short_code,
                                   'features':features})},
                            dataType: 'html',
                            success: function(msg) {
                                $('#rankings').html(msg);
                            }});
                    };
                    $('#all_features div').draggable({
                        cursor: 'pointer',
                        opacity: 0.55,
                        distance: 0,
                        zIndex: 2700
                    });
                    $('#all_features').droppable({
                        tolerance: 'fit',
                        hoverClass: 'drophover'
                    });
                    $('#features').droppable({
                        drop: function(event, ui) { 
                            var p = ui.offset;
                            var name = ui.helper.attr('id');
                            features[name] = p.top;
                            send_new_data();
                        },
                        out: function(event, ui) {
                            var name = ui.helper.attr('id');
                            features[name] = null;
                            send_new_data();
                        },
                        tolerance: 'fit',
                        hoverClass: 'drophover'
                    });
                    var get_filters = function() {
                        var filters = [];
                        var f = $('.filters');
                        for(var i=0;i<f.length;i++) {
                            var inputs = f.eq(i).children('input');
                            var current_filters = [];
                            for(var j=0;j<inputs.length;j++) {
                                var current_input = inputs.eq(j);
                                if(current_input .attr('checked')) {
                                    current_filters[current_filters.length] = current_input.attr('name');
                                }
                            }
                            filters[i] = current_filters;
                        }
                        return filters;
                    };
                    var get_cleaners = function() {
                        var cleaners = [];
                        var c = $('.cleaners');
                        for(var i=0;i<c.length;i++) {
                            cleaners[i] = c.eq(i).val();
                        }
                        return cleaners;
                    };
                    var send_properties = function() {
                        var short_code = $('#short_code').val();
                        var properties = {'cleaners':get_cleaners(),
                                          'filters':get_filters()};
                        $.ajax({
                            type: 'POST',
                            url: "''' + new_properties.url() + '''",
                            data: {'data':JSON.stringify({'short_code':short_code,
                                   'properties':properties})},
                            dataType: 'html',
                            success: function(msg) {
                                $('#full_data').html(msg);
                                send_new_data();
                            }});
                    };
                    $('.cleaners').live('change', function(){send_properties();});
                    $('#rerank').live('click', function(){send_new_data();});
                    $('.filters input').live('change', function(){
                        send_properties();
                    });

                    /* #TODO: jperla: this doesn't work for some reason */
                    $("#loading").bind("ajaxStart", function(){
                        $(this).show();
                    }).bind("ajaxStop", function(){
                        $(this).hide();
                    });
               });
            ''')
        p(u'''
            <style type="text/css">
                #features {
                    height:30em;
                    background-color:blue;
                    width:20em;
                }
                #features.drophover {
                    background-color:#1589FF;
                }
                #all_features.drophover {
                    background-color:pink;
                }
                #all_features {
                    background-color:red;
                    padding:10px;
                }
                #all_features div {
                    background-color:#FFCC44;
                    border:1px solid black;
                    padding:5px;
                    cursor:pointer;
                    /* 
                    margin:10 0 10 0;
                    */
                }
                #features div {
                    background-color:yellow;
                }
            </style>
        ''')
    p(u'<input type="hidden" id="short_code" value="%s" />' % short_code)
    with p(html.div({u'id':u'full_data'})):
        p.sub(template_clean_data(clean_data, features, items, cleaners_names, filter_names))
    p(html.br())
    with p(html.table()):
        with p(html.tr()):
            with p(html.td_block({'width':'67%', 'valign':'top'})):
                p(u'<table><tr><td width="34%" valign="top">')
                p.sub(template_show_features(features))
                p(u'</td><td width="66%" valign="top">')
                p(html.h2('Selected Features:'))
                with p(html.div({u'id':u'features'})):
                    pass
                p(u'</td></tr></table>')
                '''
                p(html.br())
                p(u'<table><tr><td width="100%" valign="top">')
                p(template_equation(normalized_equation, features))
                p(u'</td></tr></table>')
                '''
            with p(html.td_block({u'width':u'34%', u'valign':u'top'})):
                with p(html.div({u'id':u'rankings'})):
                    p.sub(template_rankings(items, rankings))
                    p.sub(template_equation(normalized_equation, features))
    p.sub(template_upload_form(short_code))