~lesuisse-dev/joliebulle/outil-alcool

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/python3
#­*­coding: utf­8 -­*­



#JolieBulle 2.7
#Copyright (C) 2010-2012 Pierre Tavares

#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; either version 3
#of the License, or (at your option) any later version.

#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.

#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


import codecs
import PyQt4
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
from base import *
from globals import *
from stepAdjust_ui import *
from brewCalc import *
from preferences_ui import *

class DialogStepAdjust(QtGui.QDialog):
    stepAdjustBrewdayClosed = QtCore.pyqtSignal(float, float, float,list, int, list)
    def __init__(self, parent = None):
        QtGui.QDialog.__init__(self,parent)
        self.ui = Ui_DialogStepBrewday()
        self.ui.setupUi(self)
        self.brewCalc = CalcBrewday()
        
        self.ui.doubleSpinBoxWaterTemp.valueChanged.connect(self.waterTempChanged)
        self.ui.doubleSpinBoxInfuseAmount.valueChanged.connect(self.infuseAmountChanged)
        self.ui.buttonBox.accepted.connect(self.accepted)
        
        
    def setFields (self, targetTemp, targetRatio, infuseAmount, waterTemp, grainWeight, listVol, currentRow, listTemp, strikeTargetTemp) :
        self.ui.doubleSpinBoxInfuseAmount.blockSignals(True)
        self.ui.doubleSpinBoxWaterTemp.blockSignals(True)
        if currentRow == 0 :
            self.ui.labelTargetTemp.setText(str(strikeTargetTemp))
        else :
            self.ui.labelTargetTemp.setText(str(targetTemp))
        self.ui.doubleSpinBoxTargetRatio.setValue(float(targetRatio))
        self.ui.doubleSpinBoxInfuseAmount.setValue(float(infuseAmount))
        self.ui.doubleSpinBoxWaterTemp.setValue(float(waterTemp))
        self.grainWeight = float(grainWeight)
        self.listVol = listVol
        self.currentRow = currentRow
        self.targetTemp = targetTemp
        self.listTemp = listTemp
        self.ui.doubleSpinBoxInfuseAmount.blockSignals(False)
        self.ui.doubleSpinBoxWaterTemp.blockSignals(False)
        self.strikeTemp = strikeTargetTemp
        
    def waterTempChanged(self) :
        waterTemp = self.ui.doubleSpinBoxWaterTemp.value()
        i = self.currentRow
        
        if i != 0 :
            if i == 1 :
                mashTemp = self.strikeTemp
            else :
                mashTemp = self.listTemp[i-2] 
            
            self.brewCalc.calcInfusionStep(self.currentRow-1, self.grainWeight, self.listVol, self.targetTemp, mashTemp, waterTemp, 'Infusion')
#            print('ce qui est passé :',self.currentRow, self.grainWeight, self.listVol, self.targetTemp, mashTemp, waterTemp)
#            print('la liste des temperatures :', self.listTemp)
            self.infuseVol = self.brewCalc.infuseVol
            self.ui.doubleSpinBoxInfuseAmount.blockSignals(True)
            self.ui.doubleSpinBoxInfuseAmount.setValue(float(self.infuseVol))
            self.ui.doubleSpinBoxInfuseAmount.blockSignals(False)
            self.listVol[i] = self.ui.doubleSpinBoxInfuseAmount.value()
            
            newRatio = sum(self.listVol[0:i+1])/(self.grainWeight/1000)
            self.ui.doubleSpinBoxTargetRatio.setValue(newRatio)
            
        #le calcul est différent pour le premier palier d'empatage      
        else :
        #ratio = (0.4*(Ttarget-Tgrain)) / (Tstrike-Ttarget-fudgeFactor)
            Ttarget = float(self.targetTemp)
            Tstrike = self.ui.doubleSpinBoxWaterTemp.value()
            Tgrain = int(settings.conf.value("GrainTemp"))
            fudgeFactor = float(settings.conf.value("FudgeFactor"))
            ratio = (0.4*(Ttarget-Tgrain)) / (Tstrike-Ttarget-fudgeFactor)
            self.infuseVol= ratio * (self.grainWeight/1000)

            self.ui.doubleSpinBoxInfuseAmount.blockSignals(True)
            self.ui.doubleSpinBoxInfuseAmount.setValue(float(self.infuseVol))
            self.ui.doubleSpinBoxInfuseAmount.blockSignals(False)
            self.listVol[i] = self.ui.doubleSpinBoxInfuseAmount.value()
            
            newRatio = sum(self.listVol[0:i+1])/(self.grainWeight/1000)
            self.ui.doubleSpinBoxTargetRatio.setValue(newRatio)            
           
            
        
        
        
    def infuseAmountChanged(self) :
        i = self.currentRow
        if i != 0 :
            if i == 1 :
                mashTemp = self.strikeTemp
            else :
                mashTemp = self.listTemp[i-2] 
            #Vm = Wgrain (0.4 + ratio)
            #Tstrike = (Ttarget*(Vstrike+Vm) - (Vm*Tmash)) / Vstrike
            actualVol = sum(self.listVol[0:i])
            ratio = actualVol / (self.grainWeight/1000)
#            print('actualvol :', actualVol)
            Vm = (self.grainWeight/1000)*(0.4+ratio)
            self.waterTemp = ((self.targetTemp*(self.ui.doubleSpinBoxInfuseAmount.value()+Vm)-(Vm*float(mashTemp))) / self.ui.doubleSpinBoxInfuseAmount.value()) + float(settings.conf.value("FudgeFactor"))
            self.ui.doubleSpinBoxWaterTemp.blockSignals(True)
            self.ui.doubleSpinBoxWaterTemp.setValue(self.waterTemp)
            self.ui.doubleSpinBoxWaterTemp.blockSignals(False)
            
            self.listVol[i] = self.ui.doubleSpinBoxInfuseAmount.value()
            newRatio = sum(self.listVol[0:i+1])/(self.grainWeight/1000)
            self.ui.doubleSpinBoxTargetRatio.setValue(newRatio)
            
        #le calcul est différent pour le premier palier d'empatage   
        else :            
            #Tstrike = [Ttarget + (0.4 * (Ttarget - Tgrain) / ratio)] + FF 
            ratio = self.ui.doubleSpinBoxInfuseAmount.value() / (self.grainWeight/1000)
            Ttarget = float(self.targetTemp)
            Tgrain = int(settings.conf.value("GrainTemp"))
            self.waterTemp = (Ttarget + (0.4 * (Ttarget-Tgrain)/ratio)) + float(settings.conf.value("FudgeFactor"))
            self.ui.doubleSpinBoxWaterTemp.blockSignals(True)
            self.ui.doubleSpinBoxWaterTemp.setValue(self.waterTemp)
            self.ui.doubleSpinBoxWaterTemp.blockSignals(False)
            
            self.listVol[i] = self.ui.doubleSpinBoxInfuseAmount.value()
            newRatio = sum(self.listVol[0:i+1])/(self.grainWeight/1000)
            self.ui.doubleSpinBoxTargetRatio.setValue(newRatio)            
            
        
    def accepted(self) :
        targetRatio = self.ui.doubleSpinBoxTargetRatio.value()
        infuseAmount = self.ui.doubleSpinBoxInfuseAmount.value()
        waterTemp = self.ui.doubleSpinBoxWaterTemp.value()
        listVol = self.listVol
        currentRow = self.currentRow
        listTemp = self.listTemp

        self.stepAdjustBrewdayClosed.emit(targetRatio, infuseAmount, waterTemp,listVol, currentRow, listTemp)