Example #1
0
def main(file):
    lines = []
    '''with fileinput.input(files=(file)) as f:
        for line in f:
            lines.append(line)
    '''
    finp = fileinput.input(files=(sys.argv[2]))
    for line in finp:
        lines.append(line)
    circuits = hw2.buildCircuits(lines)
    elements = hw2.getElements(circuits)
    connMatrix = hw2.buildConnMatrix(circuits, elements)
    for line in hw5.hamiltonChain(connMatrix, elements):
        print(line)
Example #2
0
def main(file):
    lines=[]
    '''with fileinput.input(files=(file)) as f:
        for line in f:
            lines.append(line)
    '''
    finp=fileinput.input(files=(sys.argv[2]))
    for line in finp:
        lines.append(line)
    circuits=hw2.buildCircuits(lines)    
    elements=hw2.getElements(circuits)
    connMatrix=hw2.buildConnMatrix(circuits,elements)
    for line in hw5.hamiltonChain(connMatrix,elements):
        print(line)
Example #3
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 #4
0
 def result(self, data=None, rows=None, cols=None):
     if not data or not rows or not cols:
         return self.header + '''Введите <a href="/hw3">данные</a>''' + self.footer
     try:
         rows = int(rows)
         cols = int(cols)
         if rows < 1 or cols < 1:
             raise ValueError()
     except ValueError:
         return self.header + '''Некорректное число строк или столбцов<br/>
         <a href="javascript:history.back()">Назад</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()
     width = int(100 / (len(elements) + 2))
     connMatrix = hw2.buildConnMatrix(circuits, elements)
     result = hw3.buildGraph(connMatrix, elements, rows, cols)
     html += '''<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>' % (width, el)
     html += '<td width="%i%%"><b>r<sub>i</sub></b></td></tr>' % width
     i = 0
     lgray = False
     for row in connMatrix:
         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 += '<td><b>%i</b></td></tr>\n' % result['ri'][i]
         i += 1
         lgray = not lgray
     html += '''</table><br/><br/>'''
     width = int(100 / (len(result['d']) + 2))
     html += '''<b>Матрица расстояний</b><br/><br/>
     <table cellspacing="0">
     <tr class="gray">
     <td width="%i%%" class="white">&nbsp;</td>
     ''' % width
     for el in range(len(result['d'])):
         html += '<td width="%i%%"><b>%i</b></td>\n' % (width, el + 1)
     html += '<td width="%i%%"><b>d<sub>i</sub></b></td>\n</tr>\n' % width
     lgray = False
     i = 0
     for row in result['d']:
         if lgray:
             html += '<tr class="lightGray">\n'
         else:
             html += '<tr>\n'
         html += '<td class="gray"><b>%i</b></td>\n' % (i + 1)
         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 += '<td><b>%i</b></td>\n</tr>\n' % result['di'][i]
         i += 1
         lgray = not lgray
     html += '''</table>\n<br/><br/>'''
     width = int(100 / (len(elements) + 1))
     html += '''<b>Упорядоченные элементы и позиции</b><br/><br/>
     <table cellspacing="0">
     <tr class="lightGray">
     <td width="%i%%" class="gray"><b>l<sub>i</sub></b></td>
     ''' % width
     for el in result['es']:
         html += '<td width="%i%%">%i</td>\n' % (width, el)
     html += '''</tr>\n</table>\n<br/>'''
     width = int(100 / (len(result['ps']) + 1))
     html += '''<table cellspacing="0">
     <tr class="lightGray"><td class="gray"><b>p<sub>i</sub></b></td>
     '''
     for p in result['ps']:
         html += '<td>%i</td>\n' % (p + 1)
     html += '''</tr>
     </table><br/>
     <b>Расположение элементов</b><br/><br/>
     <table cellspacing="0" border="1">'''
     width = int(100 / cols)
     for row in result['graph']:
         html += '<tr>'
         for el in row:
             html += '<td width="%i%%">' % width
             if el == 0:
                 html += '&nbsp;'
             else:
                 html += str(el)
             html += '</td>\n'
         html += '</tr>\n'
     html += '</table>\n<br/>'  #F(p)='+str(result['f'])
     width = int(100 / (len(elements) + 1))
     html += '''<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)
     i = 0
     html += '</tr>\n'
     lgray = False
     for row in result['dm']:
         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
         i += 1
         lgray = not lgray
         html += '</tr>\n'
     html += '''</table>
     <br /><br />
     <b>Матрица весов и пропускных способностей</b><br/><br/>
     <table cellspacing="0" border="1">
     <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>'
     weightMatrix = hw3.buildWeightMatrix(connMatrix, result['dm'])
     lgray = False
     i = 0
     for row in weightMatrix:
         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
             elif val != -1:
                 html += '<td>%i</td>\n' % val
             else:
                 html += '<td>&nbsp;</td>\n'
             k += 1
         i += 1
         lgray = not lgray
         html += '</tr>\n'
     html += '''</table>
     <br/><br/>
     <b>Алгоритм Дейкстры</b><br/><br/>
     Исходная вершина: l<sub>%i</sub>
     <br/><br/>''' % result['graph'][0][0]
     # choosing left-upper node
     pathMatrix = hw3.buildPathMatrix(result['graph'][0][0], elements,
                                      weightMatrix)
     lGray = False
     html += '''
     <table cellspacing="0">
     <tr class="gray">
     <td class="white">&nbsp;</td>'''
     for i in range(len(pathMatrix)):
         html += '<td width="%i%%"><b>%i</b></td>' % (width, i + 1)
     html += '</tr>\n'
     for i in range(len(pathMatrix)):
         if lgray:
             html += '<tr class="lightGray">'
         else:
             html += '<tr>'
         html += '<td width="%i%%" class="gray"><b>x%i</b></td>' % (
             width, elements[i])
         for k in range(len(pathMatrix)):
             html += '<td>'
             if pathMatrix[k][i] == 100500:
                 html += '∞'
             elif pathMatrix[k][i] == -1:
                 html += '&nbsp;'
             else:
                 html += str(pathMatrix[k][i])
             html += '</td>\n'
         html += '</tr>\n'
         lgray = not lgray
     html += '''</table>\n'''
     return self.header + html + self.footer
Example #5
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 #6
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
Example #7
0
 def result(self,data=None,rows=None,cols=None):
     if not data or not rows or not cols:
         return self.header+'''Введите <a href="/hw3">данные</a>'''+self.footer
     try:
         rows=int(rows)
         cols=int(cols)
         if rows<1 or cols<1:
             raise ValueError()
     except ValueError:
         return self.header+'''Некорректное число строк или столбцов<br/>
         <a href="javascript:history.back()">Назад</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()
     width=int(100/(len(elements)+2))
     connMatrix=hw2.buildConnMatrix(circuits,elements)
     result=hw3.buildGraph(connMatrix,elements,rows,cols)
     html+='''<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>' % (width,el)
     html+='<td width="%i%%"><b>r<sub>i</sub></b></td></tr>' % width
     i=0
     lgray=False
     for row in connMatrix:
         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+='<td><b>%i</b></td></tr>\n' % result['ri'][i]
         i+=1
         lgray=not lgray
     html+='''</table><br/><br/>'''
     width=int(100/(len(result['d'])+2))
     html+='''<b>Матрица расстояний</b><br/><br/>
     <table cellspacing="0">
     <tr class="gray">
     <td width="%i%%" class="white">&nbsp;</td>
     ''' % width
     for el in range(len(result['d'])):
         html+='<td width="%i%%"><b>%i</b></td>\n' % (width,el+1)
     html+='<td width="%i%%"><b>d<sub>i</sub></b></td>\n</tr>\n' % width
     lgray=False
     i=0
     for row in result['d']:
         if lgray:
             html+='<tr class="lightGray">\n'
         else:
             html+='<tr>\n'
         html+='<td class="gray"><b>%i</b></td>\n' % (i+1)
         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+='<td><b>%i</b></td>\n</tr>\n' % result['di'][i]
         i+=1
         lgray=not lgray
     html+='''</table>\n<br/><br/>'''
     width=int(100/(len(elements)+1))
     html+='''<b>Упорядоченные элементы и позиции</b><br/><br/>
     <table cellspacing="0">
     <tr class="lightGray">
     <td width="%i%%" class="gray"><b>l<sub>i</sub></b></td>
     ''' % width
     for el in result['es']:
         html+='<td width="%i%%">%i</td>\n' % (width,el)
     html+='''</tr>\n</table>\n<br/>'''
     width=int(100/(len(result['ps'])+1))
     html+='''<table cellspacing="0">
     <tr class="lightGray"><td class="gray"><b>p<sub>i</sub></b></td>
     '''
     for p in result['ps']:
         html+='<td>%i</td>\n' % (p+1)
     html+='''</tr>
     </table><br/>
     <b>Расположение элементов</b><br/><br/>
     <table cellspacing="0" border="1">'''
     width=int(100/cols)
     for row in result['graph']:
         html+='<tr>'
         for el in row:
             html+='<td width="%i%%">' % width
             if el==0:
                 html+='&nbsp;'
             else:
                 html+=str(el)
             html+='</td>\n'
         html+='</tr>\n'
     html+='</table>\n<br/>'#F(p)='+str(result['f'])
     width=int(100/(len(elements)+1))
     html+='''<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)
     i=0
     html+='</tr>\n'
     lgray=False
     for row in result['dm']:
         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
         i+=1
         lgray=not lgray
         html+='</tr>\n'
     html+='''</table>
     <br /><br />
     <b>Матрица весов и пропускных способностей</b><br/><br/>
     <table cellspacing="0" border="1">
     <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>'
     weightMatrix=hw3.buildWeightMatrix(connMatrix,result['dm'])
     lgray=False
     i=0
     for row in weightMatrix:
         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
             elif val!=-1:
                 html+='<td>%i</td>\n' % val
             else:
                 html+='<td>&nbsp;</td>\n'
             k+=1
         i+=1
         lgray=not lgray
         html+='</tr>\n'
     html+='''</table>
     <br/><br/>
     <b>Алгоритм Дейкстры</b><br/><br/>
     Исходная вершина: l<sub>%i</sub>
     <br/><br/>''' % result['graph'][0][0]
     # choosing left-upper node
     pathMatrix=hw3.buildPathMatrix(result['graph'][0][0],elements,weightMatrix)
     lGray=False
     html+='''
     <table cellspacing="0">
     <tr class="gray">
     <td class="white">&nbsp;</td>'''
     for i in range(len(pathMatrix)):
         html+='<td width="%i%%"><b>%i</b></td>' % (width,i+1)
     html+='</tr>\n'
     for i in range(len(pathMatrix)):
         if lgray:
             html+='<tr class="lightGray">'
         else:
             html+='<tr>'
         html+='<td width="%i%%" class="gray"><b>x%i</b></td>' % (width,elements[i])
         for k in range(len(pathMatrix)):
             html+='<td>'
             if pathMatrix[k][i]==100500:
                 html+='∞'
             elif pathMatrix[k][i]==-1:
                 html+='&nbsp;'
             else:
                 html+=str(pathMatrix[k][i])
             html+='</td>\n'
         html+='</tr>\n'
         lgray=not lgray
     html+='''</table>\n'''
     return self.header+html+self.footer
Example #8
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