Example #1
0
def template_ask_matrix(p, id, figure, answer, choices):
    with p(html.html()):
        with p(html.head()):
            p(html.title('Answer a matrix'))
    with p(html.body()):
        p(html.p(html.img(matrix_guess.url(id))))
        choice_html = [helper_choice(figure, c) 
                        for c in choices] + [helper_choice(figure, answer)]
        numpy.random.shuffle(choice_html)
        with p(html.form()):
            for c in choice_html:
                p.sub(c)
            p(html.input_submit(value='Answer'))
Example #2
0
def template_answered_matrix(p, matrix_id, f, answer, guessed):
    with p(html.html()):
        with p(html.head()):
            p(html.title('Answered a matrix'))
    with p(html.body()):
        if answer == guessed:
            p(html.h1('Correct!'))
        else:
            p(html.h1('Sorry, wrong answer :('))
        p(html.h2('You guessed: '))
        p(html.p(html.img(figure_image.url(guessed))))
        p(html.p(html.a(ask_matrix.url(matrix_id), 'Back to this matrix')))
        p(html.p(html.a(generate_random_matrix.url(), 'or Generate a new matrix')))
        p(html.p(html.img(matrix_guess.url(matrix_id))))
Example #3
0
def page_layout(p, title, inside):
    with p(html.html()):
        with p(html.head()):
            p(html.title(title))
        with p(html.body()):
            p.sub(inside)
Example #4
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))