예제 #1
0
    def updateResultBars( self, canvas ):
        """ Draws summary for the user. """
        canvas.delete( 'all' )
    
        # calculate all necessary values by using functions from diet_delector.py
        user          = diet_selector.normalizeVertically( self.userChoicesMatrix )
        price         = diet_selector.normalizeVertically( diet_selector.price )
        nour          = diet_selector.normalizeVertically( diet_selector.nour )
        time          = diet_selector.normalizeVertically( diet_selector.time )
        digestibility = diet_selector.normalizeVertically( diet_selector.digestibility )
        calorific     = diet_selector.normalizeVertically( diet_selector.calorific )
        simplicity    = diet_selector.normalizeVertically( diet_selector.simplicity )
        s0 = diet_selector.calcMatrixWithAvgRows( user )
        s  = diet_selector.calcMatrixWithAvgRows( price, nour, time, digestibility, calorific, simplicity )
        r  = diet_selector.calcDecisionValues( s0, s )

        offsetY = -110
        offsetX = -100
        #canvas.create_rectangle( self.windowWidth / 2 - 100, 85 + self.beltPosOffset + offsetY,
        #                         self.windowWidth / 2 + 100, 185 + self.beltPosOffset + offsetY, fill = 'light green' )
        canvas.create_text( self.windowWidth / 2 + offsetX, 120 + offsetY, anchor = 'e',
                            text = diet_selector.COURSES[0], font = ( 'Calibri', 10 ), fill = 'black' )
        canvas.create_rectangle( self.windowWidth / 2 + offsetX + 10, 115 + offsetY,
                                 self.windowWidth / 2 + offsetX + r[0] * 1000, 125 + self.beltPosOffset + offsetY, fill = 'light green' )
                            
        canvas.create_text( self.windowWidth / 2 + offsetX, 135 + offsetY, anchor = 'e',
                            text = diet_selector.COURSES[1], font = ( 'Calibri', 10 ), fill = 'black' )
        canvas.create_rectangle( self.windowWidth / 2 + offsetX + 10, 130 + offsetY,
                                 self.windowWidth / 2 + offsetX + r[1] * 1000, 140 + self.beltPosOffset + offsetY, fill = 'light green' )
                            
        canvas.create_text( self.windowWidth / 2 + offsetX, 150 + offsetY, anchor = 'e',
                            text = diet_selector.COURSES[2], font = ( 'Calibri', 10 ), fill = 'black' )
        canvas.create_rectangle( self.windowWidth / 2 + offsetX + 10, 145 + offsetY,
                                 self.windowWidth / 2 + offsetX + r[2] * 1000, 155 + self.beltPosOffset + offsetY, fill = 'light green' )
                            
        canvas.create_text( self.windowWidth / 2 + offsetX, 165 + offsetY, anchor = 'e',
                            text = diet_selector.COURSES[3], font = ( 'Calibri', 10 ), fill = 'black' )
        canvas.create_rectangle( self.windowWidth / 2 + offsetX + 10, 160 + offsetY,
                                 self.windowWidth / 2 + offsetX + r[3] * 1000, 170 + self.beltPosOffset + offsetY, fill = 'light green' )
                            
        canvas.create_text( self.windowWidth / 2 + offsetX, 180 + offsetY, anchor = 'e',
                            text = diet_selector.COURSES[4], font = ( 'Calibri', 10 ), fill = 'black' )
        canvas.create_rectangle( self.windowWidth / 2 + offsetX + 10, 175 + offsetY,
                                 self.windowWidth / 2 + offsetX + r[4] * 1000, 185 + self.beltPosOffset + offsetY, fill = 'light green' )
                                 
        
        consistence = diet_selector.countMatrixConsistency( self.userChoicesMatrix, diet_selector.RI )

        consistencyPercent = 100 - ( consistence / 0.1 * 100.0 )
        if( not diet_selector.isMatrixConsistence( self.userChoicesMatrix, diet_selector.RI ) ):
            consistencyPercent = min( -( 100 - ( consistence / 0.1 * 100.0 ) ), 100 )
            canvas.create_text( self.windowWidth / 2, 200 + offsetY,
                                text = 'The choice is inconsistent! (' + str( int( consistencyPercent ) ) + '%)', font = ( 'Calibri', 13 ), fill = 'red' )
        else:
            canvas.create_text( self.windowWidth / 2, 200 + offsetY,
                                text = 'The choice is consistent. (' + str( int( consistencyPercent ) ) + '%)', font = ( 'Calibri', 13 ), fill = 'dark green' )
예제 #2
0
 def test_makeMatrixWithAvgRows_singleMatrix(self):
     m0 = [
         [0.63, 0.6702127659574468, 0.6176470588235293, 0.45],
         [0.21, 0.22340425531914893, 0.2647058823529412, 0.35],
         [0.09, 0.07446808510638298, 0.08823529411764705, 0.15],
         [0.07, 0.031914893617021274, 0.02941176470588235, 0.05],
     ]
     s = diet_selector.calcMatrixWithAvgRows(m0)
     self.assertEqual(s, [[0.5919649561952441, 0.2620275344180225, 0.1006758448060075, 0.045331664580725906]])
예제 #3
0
 def test_makeMatrixWithAvgRows_multipleMatrices(self):
     diet_selector.normalizeVertically(self.m1)
     diet_selector.normalizeVertically(self.m2)
     diet_selector.normalizeVertically(self.m3)
     diet_selector.normalizeVertically(self.m4)
     s = diet_selector.calcMatrixWithAvgRows(self.m1, self.m2, self.m3, self.m4)
     self.assertEqual(
         s,
         [
             [0.5105339105339105, 0.3893217893217893, 0.10014430014430013],
             [0.1577639751552795, 0.6554865424430641, 0.1867494824016563],
             [0.5105339105339105, 0.3893217893217893, 0.10014430014430013],
             [0.7978093167966587, 0.10531475088437114, 0.09687593231897029],
         ],
     )