def profile(req, p, remaining): users_db = req.settings[u'users_db'] updates_db = req.settings[u'updates_db'] session = req.environ['beaker.session'] session[u'counter'] = session.get('counter', 0) + 1 session.save() user = session[u'user'] if u'user' in session else None user_profiles = profiles_of_user(users_db, user) p(html.br()) name, id, _ = remaining.split(u'/', 2) updates = updates_db.view('_design/updates/_view/updates_by_profile', startkey=[id], endkey=[id, {}], include_docs=True) p(html.h1(name.replace('_', ' '))) if user is not None: p(u'<form action="%s" method="POST">' % '/say') p(u'%s ' % name.replace('_', ' ')) p(u'<input type="hidden" name="profile" value="%s" />' % id) p(u'<input type="text" name="message" value="is "') if id in user_profiles: p(u'disabled="true"') p(u'/>') p(u'<input type="submit" value="Say"') if id in user_profiles: p(u'disabled="true"') p(u' />') p(u'</form>') if id in user_profiles: p(u'<p style="font-size:smaller"><em>This is your profile</em>. You may not edit your profile.</p>') p(html.br()) p(html.br()) updates = list(updates) updates.reverse() for u in updates: p(u[u'value']) p(u' <b style="font-size:x-small;">') p(webify.templates.helpers.time.fuzzy_time_diff(datetime.datetime.fromtimestamp(u.doc['date']))) p(u' ago') p(u' <a href="/" style="font-size:xx-small">(by Joseph)</a>') p(u'</b>') p(html.br()) friends = users_db.view('_design/users/_view/friends', startkey=[id], endkey=[id, {}], include_docs=True) p(html.h2(u'Friends:')) with html.ul(p): for f in friends: if f[u'key'][1] == 1: url = profile.url(f.doc[u'name'].replace(' ', '_')+u'/'+f.doc.id+u'/') p(html.li(html.a(url, f.doc[u'name']))) p(u'Pageviews: %s' % session['counter']) p(html.br())
def template_equation(p, equation, features): elements = reversed(sorted([(equation[c], c) for c in equation])) p(html.h2(u'Equation:')) with p(html.p_block({u'style': u'font-family:sans;font-size:14pt;font-weight:bold;'})): p(u'= ' + u' + '.join([u'%s×[%s]<br />' % (unicode(weight), html.span_smaller(features[column])) for weight,column in elements if column is not None])) p(u' + %s' % equation[None])
def index(req, p): users_db = req.settings[u'users_db'] p(u'Frishy. Squish your friends!') p(html.br()) p(html.a('/signin', 'sign in')) profiles = users_db.view('_design/users/_view/user_profiles', limit=10, include_docs=True) p(html.h2('Profiles:')) with html.ul(p): for p in profiles: url = profile.url(p.doc[u'name'].replace(' ', '_')+u'/'+p.doc.id+u'/') p(html.li(html.a(url, p.doc[u'name'])))
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))
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))))
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(' ')) 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' ')) 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))
def template_show_data(p, table): p(html.h2(u'Full table:')) with p(html.div({'style':'height:23em;overflow:scroll;'})): p.sub(partial_table(table))
def template_show_features(p, features): p(html.h2(u'All features:')) p.sub(draggable_features(zip(range(len(features)), features), u'all_features'))
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))