Example #1
0
 def result(self,data=None):
     if not data:
         return self.header+'''Введите <a href="/hw5">данные</a>'''+self.footer
     circuits=hw2.buildCircuits(data.split('\n'))
     elements=set()
     html='''<b>Исходные данные</b><br /><br />'''
     for i in range(1,len(circuits)+1):
         if len(circuits[i])<=1:
             del circuits[i]
             html+='Цепь №%i пустая <br />' % i
             continue
         html+='Цепь №%i %s<br />' % (i,str(circuits[i]))
         for el in circuits[i]:
             elements.add(el)
     elements=list(elements)
     elements.sort()
     matrix1=hw2.buildComplexMatrix(circuits,elements)
     width=int(100/(len(circuits)+1))
     html+='''<br />
     <b>Матрица комплексов</b><br /><br />
     <table cellspacing="0">
     <tr class="gray">
         <td width="%i%%" class="white">&nbsp;</td>
         ''' % width
     for key in circuits:
         html+='<td width="%i%%"><b>%i</b></td>\n' % (width,key)
     html+='</tr>\n'
     lgray=False
     i=0
     for row in matrix1:
         if lgray:
             html+='<tr class="lightGray">\n'
         else:
             html+='<tr>\n'
         html+='<td class="gray"><b>%i</b></td>\n' % elements[i]
         for el in row:
             if el==0:
                 html+='<td>%i</td>\n' % el
             else:
                 html+='<td><b>%i</b></td>\n' % el
         html+='</tr>\n'
         i+=1
         lgray=not lgray
     width=int(100/(len(elements)+1))
     matrix2=hw2.buildConnMatrix(circuits,elements)
     html+='''</table><br />
     <b>Матрица соединений</b><br /><br />
     <table cellspacing="0">
     <tr class="gray">
     <td width="%i%%" class="white">&nbsp;</td>
     ''' % width
     for el in elements:
         html+='<td width="%i%%"><b>%i</b></td>\n' % (width,el)
     html+='</tr>\n'
     i=0
     lgray=False
     for row in matrix2:
         if lgray:
             html+='<tr class="lightGray">\n'
         else:
             html+='<tr>\n'
         html+='<td class="gray"><b>%i</b></td>\n' % elements[i]
         k=0
         for val in row:
             if k==i:
                 html+='<td><b>%i</b></td>\n' % val
             else:
                 html+='<td>%i</td>\n' % val
             k+=1
         html+='</tr>\n'
         i+=1
         lgray=not lgray
     html+='''</table><br /><br />
     <b>Гамильтонов цикл</b><br/><br/>'''
     for line in hw5.hamiltonChain(matrix2,elements):
         html+=line+'<br/>'
     return self.header+html+self.footer
Example #2
0
 def result(self, data=None, boring=None):
     if not data:
         return self.header + """Введите <a href="/hw2">данные</a>""" + self.footer
     if boring == "on":
         boring = False
     else:
         boring = True
     circuits = hw2.buildCircuits(data.split("\n"))
     elements = set()
     html = """<b>Исходные данные</b><br /><br />"""
     for i in range(1, len(circuits) + 1):
         if len(circuits[i]) <= 1:
             del circuits[i]
             html += "Цепь №%i пустая <br />" % i
             continue
         html += "Цепь №%i %s<br />" % (i, str(circuits[i]))
         for el in circuits[i]:
             elements.add(el)
     elements = list(elements)
     elements.sort()
     matrix1 = hw2.buildComplexMatrix(circuits, elements)
     width = int(100 / (len(circuits) + 1))
     html += (
         """<br />
     <b>Матрица комплексов</b><br /><br />
     <table cellspacing="0">
     <tr class="gray">
         <td width="%i%%" class="white">&nbsp;</td>
         """
         % width
     )
     for key in circuits:
         html += '<td width="%i%%"><b>%i</b></td>\n' % (width, key)
     html += "</tr>\n"
     lgray = False
     i = 0
     for row in matrix1:
         if boring:
             if lgray:
                 html += '<tr class="lightGray">\n'
             else:
                 html += "<tr>\n"
             html += '<td class="gray"><b>%i</b></td>\n' % elements[i]
         else:
             html += """<tr class="%s">
             <td class="%s"><b>%i</b></td>\n""" % (
                 self.funnyColors[random.randint(0, len(self.funnyColors) - 1)],
                 self.funnyColors[random.randint(0, len(self.funnyColors) - 1)],
                 elements[i],
             )
         for el in row:
             if el == 0:
                 html += "<td>%i</td>\n" % el
             else:
                 html += "<td><b>%i</b></td>\n" % el
         html += "</tr>\n"
         i += 1
         lgray = not lgray
     width = int(100 / (len(elements) + 1))
     matrix2 = hw2.buildConnMatrix(circuits, elements)
     html += (
         """</table><br />
     <b>Матрица соединений</b><br /><br />
     <table cellspacing="0">
     <tr class="gray">
     <td width="%i%%" class="white">&nbsp;</td>
     """
         % width
     )
     for el in elements:
         html += '<td width="%i%%"><b>%i</b></td>\n' % (width, el)
     html += "</tr>\n"
     i = 0
     lgray = False
     for row in matrix2:
         if boring:
             if lgray:
                 html += '<tr class="lightGray">\n'
             else:
                 html += "<tr>\n"
             html += '<td class="gray"><b>%i</b></td>\n' % elements[i]
         else:
             html += """<tr class="%s">
             <td class="%s"><b>%i</b></td>\n""" % (
                 self.funnyColors[random.randint(0, len(self.funnyColors) - 1)],
                 self.funnyColors[random.randint(0, len(self.funnyColors) - 1)],
                 elements[i],
             )
         k = 0
         for val in row:
             if k == i:
                 html += "<td><b>%i</b></td>\n" % val
             else:
                 html += "<td>%i</td>\n" % val
             k += 1
         html += "</tr>\n"
         i += 1
         lgray = not lgray
     html += (
         """</table><br /><br />
     <b>Раскраска графа</b><br /><br />
     <table cellspacing="0">
     <tr class="gray">
     <td width="%i%%">Вершина</td>"""
         % width
     )
     for el in elements:
         html += '<td width="%i%%"><b>%i</b></td>\n' % (width, el)
     html += """</tr>
     <tr><td class="gray">Кол-во смежных</td>
     """
     graph = hw2.buildGraph(matrix2, elements)
     for key in graph:
         html += "<td>%i</td>\n" % len(graph[key])
     html += "</tr></table>\n<br /><br />"
     colored = hw2.colorGraph(graph)
     for key in colored:
         html += "j=%i: %s\n<br />" % (key, str(colored[key]))
     if not boring:
         html += """<br /><h1>Эти нескучные цвета как бы намекают, что не стоит всем сдавать
         одинаковые отчёты</h1>
         """
     return self.header + html + self.footer