Exemplo n.º 1
0
 def build_submitions_chart(self, allProblems, head, body):
     points = sumarize_submissions_by_month(allProblems)
     dataPoints = ''
     
     for point in sorted(points):
         dataPoints += ', ["' + point + '",' + str(points[point]) + ']'
     
     script = HtmlElement('script')
     script.addAttr(Attr('type', 'text/javascript'))
     script.addAttr(Attr('src', 'https://www.google.com/jsapi'))
     head.addNode(script)
     
     drawChart = HtmlElement('script')
     drawChart.addAttr(Attr('type', 'text/javascript'))
     head.addNode(drawChart)
     drawChart.addNode("""
     google.load("visualization", "1", {packages:["corechart"]});
     google.setOnLoadCallback(drawChart);
     
     function drawChart() 
     {
         var data = google.visualization.arrayToDataTable([ ['Data', '# tentativas']""" + dataPoints + """]);
         var options = { title: 'Histórico de submissão de problemas', };
         var chart = new google.visualization.AreaChart(document.getElementById('submitions_chart'));
         chart.draw(data, options);
     }
     """)
     
     chartDiv = HtmlElement('div')
     chartDiv.addAttr(Attr('class', 'chartDiv'))
     chartDiv.addNode(HtmlElement('div').addAttr(Attr('id', 'submitions_chart')))
     body.addNode(chartDiv)
Exemplo n.º 2
0
 def create_mainDiv(self, form):    
     div = HtmlElement('div')
     div.addAttr(Attr('class', "maindiv"))
     div.addAttr(Attr('align', "center"))
     form.addNode(div)
     
     return div   
Exemplo n.º 3
0
 def get_query_button(self, spojId):
     query = HtmlElement('input')
     query.addAttr(Attr('id', self.searchInputId))
     query.addAttr(Attr('name', self.searchInputId))
     if spojId != '':
         query.addAttr(Attr('value', spojId))
     query.addAttr(Attr('placeholder', "id de um usuário ou problema do spoj"))
     query.addAttr(Attr('class', "searchInput"))
     return query
Exemplo n.º 4
0
 def get(self, contest, userId):
     database = Database(contest)
     uNameH1 = HtmlElement('h1').addAttr(Attr('class', 'center-align'))
     uNameH1.addNode(userId)
     
     contestH2 = HtmlElement('h2').addAttr(Attr('class', 'center-align'))
     contestH2.addNode(HtmlElement('a').addAttr(Attr('href', SPOJ_URLS[contest])).addNode('SPOJ ' + contest))
     
     head = self.get_head()
     body = HtmlElement('body').addAttr(Attr('style', 'background-color:gray;'))
     body.addNode(uNameH1)
     body.addNode(contestH2)
     self.build_user_info_div(database, userId, body)
     self.build_stats_div(database, userId, head, body)
     self.build_solve_prob_div(database, userId, contest, body)
     self.response.write('<html>' + str(head) + str(body) + '</html>')
Exemplo n.º 5
0
 def build_solve_prob_div(self, database, userId, contest, body):
     title = HtmlElement('h2').addAttr(Attr('class', 'center-align')).addNode('Problemas resolvidos pelo usuário')
     body.addNode(title)
     
     allProblems = parseSignedlist(database.get_problems_of_user_from_db(userId)['data'])
     problems = sumarise_problems_by_column(allProblems, 'PROBLEM')
     body.addNode(self.build_probs_table(problems, contest))
Exemplo n.º 6
0
 def test_combo_box(self):
     combo = HtmlElement('select')
     combo.addAttr(Attr('name', "dif"))
     combo.addAttr(Attr('id', "dif"))
     for dificult in ['Fácil', 'Médio', 'Difícil']:
     	item = HtmlElement('item')
     	item.addAttr(Attr('value', dificult))
     	item.addNode(dificult)
     	combo.addNode(item)
     
     self.assertEqual(str(combo), '<select name="dif" id="dif"><item value="Fácil">Fácil</item><item value="Médio">Médio</item><item value="Difícil">Difícil</item></select>')
     
     searchDiv = HtmlElement('div')
     searchDiv.addAttr(Attr('class', "inner"))
     searchDiv.addNode(combo)
     self.assertEqual(str(searchDiv), '<div class="inner"><select name="dif" id="dif"><item value="Fácil">Fácil</item><item value="Médio">Médio</item><item value="Difícil">Difícil</item></select></div>')
Exemplo n.º 7
0
    def build_probs_table(self, problems, contest):
        table = HtmlElement('table')
        table.addAttr(Attr('style', 'width: 95%;padding: 4px 4px 4px 4px;'))
        
        cnt = 0
        tr = None

        for p in problems:
            if cnt % 10 == 0: #10 colunas
                tr = HtmlElement('tr')
                table.addNode(tr)
                
            td = HtmlElement('td')
            td.addNode(HtmlElement('a').addAttr(Attr('href', SPOJ_URLS[contest] + '/problems/' + p)).addNode(p))
            tr.addNode(td)
            cnt += 1
        
        return table
Exemplo n.º 8
0
 def add_search_div(self, mainDiv, cssclass, spojId, selected, db):
     searchDiv = HtmlElement('div')
     searchDiv.addAttr(Attr('class', cssclass))
     mainDiv.addNode(searchDiv)
     
     searchDiv.addNode(self.get_query_button(spojId))
     searchDiv.addNode(self.get_search_button())
     searchDiv.addNode(self.get_prob_dificult_combo(selected))
     searchDiv.addNode(self.get_db_combo(db))
Exemplo n.º 9
0
 def test_html(self):
     html = HtmlElement('teste')
     self.assertEqual(str(html), '<teste></teste>')
     
     html.addAttr(Attr('teste', 'value'))
     html.addAttr(Attr('tt', 'vv'))
     self.assertEqual(str(html), '<teste teste="value" tt="vv"></teste>')
     
     html1 = HtmlElement('input')
     html.addNode(html1)
     self.assertEqual(str(html), '<teste teste="value" tt="vv"><input></input></teste>')
     
     html2 = HtmlElement('textarea')
     html.addNode(html2)
     self.assertEqual(str(html), '<teste teste="value" tt="vv"><input></input><textarea></textarea></teste>')
     
     html3 = HtmlElement('t')
     html1.addNode(html3)
     self.assertEqual(str(html), '<teste teste="value" tt="vv"><input><t></t></input><textarea></textarea></teste>')
Exemplo n.º 10
0
 def build_problems_stats_table(self, problems):
     problems = sumarise_problems_by_column(problems, 'PROBLEM')
     stats = sumarize_stats_of_user(problems)
     
     probTable = HtmlElement('table')
     probTable.addAttr(Attr('class', 'statTable'))
     th = HtmlElement('tr').addNode(HtmlElement('th').addAttr(Attr('colspan', '2')).addNode('Problemas'))
     probTable.addNode(th)
     
     labels = ['Problemas tentados', 'Resolvidos', 'Não resolvidos', 'Resolvidos na 1ª tentativa', 'Mais tentados', 'Média de tentativas']
     values = [stats['attempted'], stats['solved'], stats['failures'], stats['accepted_1'], stats['most_failures'], '%.2f' % stats['avg_attempted_per_problem']]
     cnt = 0
     
     for label in labels:
         tr = HtmlElement('tr')
         tr.addNode(HtmlElement('td').addNode(label))
         tr.addNode(HtmlElement('td').addNode(values[cnt]))
         cnt += 1
         probTable.addNode(tr)
         
     return probTable
Exemplo n.º 11
0
    def get_head(self):
        head = HtmlElement('head')
        
        meta = HtmlElement('meta')
        meta.addAttr(Attr('http-equiv', 'Content-type'))
        meta.addAttr(Attr('content', 'text/html; charset=utf-8'))
        head.addNode(meta)
        
        links = ['/static/style.css', '//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css']
        for link in links:
		    css = HtmlElement('link')
		    css.addAttr(Attr('rel', 'stylesheet'))
		    css.addAttr(Attr('type', 'text/css'))
		    css.addAttr(Attr('href', link))
		    head.addNode(css)
        
        scripts = ['/static/script.js', '//code.jquery.com/jquery-1.10.2.js', '//code.jquery.com/ui/1.11.2/jquery-ui.js']
        for script in scripts:
		    js = HtmlElement('script')
		    js.addAttr(Attr('src', script))
		    head.addNode(js)
        
        title = HtmlElement('title')
        title.addNode('Spojrec')
        head.addNode(title)
        
        return head
Exemplo n.º 12
0
 def build_submission_stats_table(self, problems):
     subTable = HtmlElement('table')
     subTable.addAttr(Attr('class', 'statTable'))
     th = HtmlElement('tr').addNode(HtmlElement('th').addAttr(Attr('colspan', '2')).addNode('Submissões'))
     subTable.addNode(th)
     
     totalTr = HtmlElement('tr')
     subTable.addNode(totalTr)
     total = 0
     
     for result in sorted(problems):
         n = len(problems[result])
         total += n
         tr = HtmlElement('tr')
         subTable.addNode(tr)
         tr.addNode(HtmlElement('td').addNode(result))
         tr.addNode(HtmlElement('td').addNode(n))
     
     
     totalTr.addNode(HtmlElement('td').addNode('Total'))
     totalTr.addNode(HtmlElement('td').addNode(total))
     return subTable
Exemplo n.º 13
0
 def get(self):
     form = self.create_form()
     mainDiv = self.create_mainDiv(form)
     self.add_logo_div(mainDiv, 'top')
     
     mainDiv.addNode(self.create_aboutDiv())
     mainDiv.addNode(self.create_aboutText())
     
     self.add_search_div(mainDiv, 'inner', '', 'Normal', 'BR')
     
     body = HtmlElement('body')
     body.addAttr(Attr('style', 'background-image:url(static/balloon-release.jpg);background-size: cover;'))
     body.addNode(form)
     
     self.response.write('<html>' + str(self.get_head()) + str(body) + '</html>')
Exemplo n.º 14
0
 def build_stats_div(self, database, userId, head, body):
     allProblems = parseSignedlist(database.get_problems_of_user_from_db(userId)['data'])
     
     problems = sumarise_problems_by_column(allProblems, 'RESULT')
     subTable = self.build_submission_stats_table(problems)
     probTable = self.build_problems_stats_table(allProblems)
     table = HtmlElement('table')
     table.addAttr(Attr('class', 'allStats'))
     body.addNode(table)
     tr = HtmlElement('tr')
     table.addNode(tr)
     tr.addNode(HtmlElement('td').addNode(probTable))
     tr.addNode(HtmlElement('td').addNode(subTable))
     
     self.build_submitions_chart(allProblems, head, body)
Exemplo n.º 15
0
 def post(self):
     spojId = self.request.get(self.searchInputId)
     dificult = self.request.get(self.difId)
     database = self.request.get(self.spojDB)
     recommendedProblems = rec(spojId, database, dificult)
     
     form = self.create_form()
     mainDiv = self.create_mainDiv(form)
     
     self.add_logo_div(mainDiv, 'top1')
     
     mainDiv.addNode(self.create_aboutDiv())
     mainDiv.addNode(self.create_aboutText())
     
     self.add_search_div(mainDiv, 'innerPost', spojId, dificult, database)
     
     if len(recommendedProblems) > 0:
         resultDiv = HtmlElement('div')
         resultDiv.addAttr(Attr('class', 'resultDiv'))
         
         linkToUser = HtmlElement('a').addAttr(Attr('href', '/users/' + database + '/' + spojId))
         linkToUser.addAttr(Attr('style', 'color:red;'))
         linkToUser.addNode(spojId)
         
         tableTop = HtmlElement('h3').addAttr(Attr('class', 'text-warning'))
         tableTop.addNode('Porque recomendamos esses problemas para ' + str(linkToUser))
         resultDiv.addNode(tableTop)
         
         for problem in recommendedProblems:
             problemH3 = HtmlElement('h3')
             
             if isinstance(problem['title'], unicode):
                 problem['title'] = problem['title'].encode('utf-8','ignore')
             
             if isinstance(problem['snippet'], unicode):
                 problem['snippet'] = problem['snippet'].encode('utf-8','ignore')
             
             l = HtmlElement('a').addAttr(Attr('href', problem['url'])).addNode(str(problem['spojId']) + ' - ' + str(problem['title']))
             problemH3.addNode(HtmlElement('img').addAttr(Attr('src', 'static/ballon' + str(random.randint(1,7)) + '.png')))
             problemH3.addNode(l)
             resultDiv.addNode(problemH3)
             resultDiv.addNode(HtmlElement('p').addNode(problem['snippet']))
             
         mainDiv.addNode(resultDiv)
     
     body = HtmlElement('body')
     body.addAttr(Attr('style', 'background-image:url(static/balloon-release.jpg);background-size: cover;'))
     body.addNode(form)
     
     self.response.write('<html>' + str(self.get_head()) + str(body) + '</html>')
Exemplo n.º 16
0
    def get_head(self):
        head = HtmlElement('head')
        
        meta = HtmlElement('meta')
        meta.addAttr(Attr('http-equiv', 'Content-type'))
        meta.addAttr(Attr('content', 'text/html; charset=utf-8'))
        head.addNode(meta)
        
        links = ['static/style.css', '//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css']
        for link in links:
		    css = HtmlElement('link')
		    css.addAttr(Attr('rel', 'stylesheet'))
		    css.addAttr(Attr('type', 'text/css'))
		    css.addAttr(Attr('href', link))
		    head.addNode(css)
        
        scripts = ['static/script.js', '//code.jquery.com/jquery-1.10.2.js', '//code.jquery.com/ui/1.11.2/jquery-ui.js']
        for script in scripts:
		    js = HtmlElement('script')
		    js.addAttr(Attr('src', script))
		    head.addNode(js)
        
        dilogScript = HtmlElement('script')
        dilogScript.addNode('''$(function() {
    $( "#dialog" ).dialog({
      autoOpen: false,
      show: {
        effect: "blind",
        duration: 100
      },
      hide: {
        effect: "blind",
        duration: 100
      }
    });
 
    $( "#opener" ).click(function() {
      $( "#dialog" ).dialog( "open" );
    });
  });''')
        head.addNode(dilogScript)
        
        title = HtmlElement('title')
        title.addNode('Spojrec')
        head.addNode(title)
        
        return head
Exemplo n.º 17
0
 def get_db_combo(self, db):
     span = HtmlElement('span').addNode('SPOJ contest:')
     div = HtmlElement('div').addAttr(Attr('class', 'contestDiv'))
     div.addNode(span)
     for contest in self.contests:
         radio = HtmlElement('input')
         radio.addAttr(Attr('type', 'radio'))
         radio.addAttr(Attr('name', self.spojDB))
         radio.addAttr(Attr('id', contest))
         radio.addAttr(Attr('value', contest))
         
         if contest == db:
             radio.addAttr(Attr('checked', ''))
         
         div.addNode(radio)
         div.addNode(contest)
         
     return div
Exemplo n.º 18
0
 def get_prob_dificult_combo(self, selected):
     combo = HtmlElement('select')
     combo.addAttr(Attr('name', self.difId))
     combo.addAttr(Attr('id', self.difId))
     combo.addAttr(Attr('value', selected))
     for dificult in self.dificulties:
     	item = HtmlElement('option')
     	item.addAttr(Attr('value', dificult))
     	if dificult == selected:
     	    item.addAttr(Attr('SELECTED', ''))
     	item.addNode(dificult)
     	combo.addNode(item)
     
     span = HtmlElement('span').addNode('Dificuldade dos problemas:')
     div = HtmlElement('div').addAttr(Attr('class', 'difdiv'))
     div.addNode(span)
     div.addNode(combo)
     return div
Exemplo n.º 19
0
 def create_form(self):
     form = HtmlElement('form')
     form.addAttr(Attr('action', "/"))
     form.addAttr(Attr('method', "post"))
     form.addAttr(Attr('name', "form1"))
     return form
Exemplo n.º 20
0
 def add_logo_div(self, mainDiv, cssClass):
     logoDiv = HtmlElement('div')
     logoDiv.addNode(HtmlElement('img').addAttr(Attr('src', 'static/logo.png')))
     logoDiv.addAttr(Attr('class', cssClass))
     mainDiv.addNode(logoDiv)
Exemplo n.º 21
0
 def create_aboutDiv(self):
     aboutDiv = HtmlElement('div')
     aboutDiv.addNode(HtmlElement('img').addAttr(Attr('src', 'static/about.jpg')).addAttr(Attr('id', 'opener')).addAttr(Attr('title', 'Sobre o site')))
     aboutDiv.addAttr(Attr('class', "abouttop"))
     return aboutDiv
Exemplo n.º 22
0
 def test_attr(self):
     attr = Attr('teste', 'value')
     self.assertEqual(str(attr), 'teste="value"')
Exemplo n.º 23
0
 def create_aboutText(self):
     aboutDiv = HtmlElement('div')
     aboutDiv.addNode('<p>Spojrec é uma aplicação web, que tem como intuito fornecer recomendações de problemas para o spoj.</p>')
     aboutDiv.addAttr(Attr('id', "dialog"))
     aboutDiv.addAttr(Attr('title', "Sobre"))
     return aboutDiv
Exemplo n.º 24
0
 def get_search_button(self):
     search = HtmlElement('input')
     search.addAttr(Attr('type', "submit"))
     search.addAttr(Attr('value', "Buscar"))
     search.addAttr(Attr('class', "searchButton"))
     return search