1762 dataRecord.sparge_acid_amount = Acid / 1000; |
1762 dataRecord.sparge_acid_amount = Acid / 1000; |
1763 $("#sparge_acid_amount").val(Acid); |
1763 $("#sparge_acid_amount").val(Acid); |
1764 } |
1764 } |
1765 |
1765 |
1766 function calcFermentation(){ |
1766 function calcFermentation(){ |
1767 if(dataRecord.brew_fermenter_sg<1.020)return; |
1767 if(dataRecord.brew_fermenter_sg<1.020)return; |
1768 var obrix=sg_to_brix(dataRecord.brew_fermenter_sg); |
1768 var obrix=sg_to_brix(dataRecord.brew_fermenter_sg); |
1769 if ((dataRecord.primary_end_sg>0.990)&&(dataRecord.primary_end_sg<dataRecord.brew_fermenter_sg)){ |
1769 if((dataRecord.primary_end_sg>0.990)&&(dataRecord.primary_end_sg<dataRecord.brew_fermenter_sg)){ |
1770 var primary_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.primary_end_sg)/(dataRecord.brew_fermenter_sg-1),1); |
1770 var primary_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.primary_end_sg)/(dataRecord.brew_fermenter_sg-1),1); |
1771 $("#primary_svg").val(primary_svg); |
1771 $("#primary_svg").val(primary_svg); |
1772 if((dataRecord.secondary_end_sg>0.990)&&(dataRecord.secondary_end_sg<dataRecord.brew_fermenter_sg)){ |
1772 if((dataRecord.secondary_end_sg>0.990)&&(dataRecord.secondary_end_sg<dataRecord.brew_fermenter_sg)){ |
1773 var secondary_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.secondary_end_sg)/(dataRecord.brew_fermenter_sg-1),1); |
1773 var secondary_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.secondary_end_sg)/(dataRecord.brew_fermenter_sg-1),1); |
1774 $("#secondary_svg").val(secondary_svg); |
1774 $("#secondary_svg").val(secondary_svg); |
1775 if((dataRecord.fg>0.990)&&(dataRecord.fg<dataRecord.brew_fermenter_sg)){ |
1775 if((dataRecord.fg>0.990)&&(dataRecord.fg<dataRecord.brew_fermenter_sg)){ |
1776 var final_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.fg)/(dataRecord.brew_fermenter_sg-1),1); |
1776 var final_svg=Round(100*(dataRecord.brew_fermenter_sg-dataRecord.fg)/(dataRecord.brew_fermenter_sg-1),1); |
1777 $("#final_svg").val(final_svg); |
1777 $("#final_svg").val(final_svg); |
1778 var ABV=Round(abvol(dataRecord.brew_fermenter_sg,dataRecord.fg),2); |
1778 var ABV=Round(abvol(dataRecord.brew_fermenter_sg,dataRecord.fg),2); |
1779 $("#final_abv").val(ABV); |
1779 $("#final_abv").val(ABV);}}} |
1780 } |
|
1781 } |
|
1782 } |
|
1783 } |
1780 } |
1784 |
1781 |
1785 function ResCO2(CO2, T) { |
1782 function ResCO2(CO2,T){ |
1786 //var resco2 = 0.000849151 * T * T - 0.0587512 * T + 1.71137; // brouwhulp |
1783 var F=T*1.8+32; |
1787 var F = T * 1.8 + 32; |
1784 return 3.0378-0.050062*F+0.00026555*F*F; |
1788 var resco2 = 3.0378 - 0.050062 * F + 0.00026555 * F * F; // most of the rest |
1785 } |
1789 //console.log("CO2: "+resco2); |
1786 |
1790 return resco2; |
1787 function CarbCO2toS(CO2,T,SFactor){ |
1791 } |
1788 var sugar=SFactor*(CO2-ResCO2(CO2,T))/0.286; |
1792 |
1789 if(sugar<0)sugar=0; |
1793 function CarbCO2toS(CO2, T, SFactor) { |
1790 return Round(sugar,3); |
1794 var sugar = SFactor * (CO2 - ResCO2(CO2, T)) / 0.286; |
1791 } |
1795 if (sugar < 0) |
|
1796 sugar = 0; |
|
1797 return Math.round(sugar * 1000) / 1000; |
|
1798 } |
|
1799 |
1792 |
1800 function GetPressure(CO2, T1, T2) { |
1793 function GetPressure(CO2, T1, T2) { |
1801 var F = T2 * 1.8 + 32; |
|
1802 var V = CO2 - ResCO2(CO2, T1); |
1794 var V = CO2 - ResCO2(CO2, T1); |
1803 if (V < 0) |
1795 if (V < 0) |
1804 return 0; |
1796 return 0; |
1805 var P = -1.09145427669121 + 0.00800006989646477 * T2 + 0.000260276315484684 * T2 * T2 + 0.0215142075945119 * T2 * V + |
1797 var P = -1.09145427669121 + 0.00800006989646477 * T2 + 0.000260276315484684 * T2 * T2 + 0.0215142075945119 * T2 * V + |
1806 0.674996600795854 * V + -0.00471757220150754 * V * V; |
1798 0.674996600795854 * V + -0.00471757220150754 * V * V; |
1807 //console.log("CO2: "+CO2+" "+V+" Temp: "+T1+" "+T2+" Pressure: "+P); |
1799 //console.log("CO2: "+CO2+" "+V+" Temp: "+T1+" "+T2+" Pressure: "+P); |
1808 if (P < 0) |
1800 if (P < 0) |
1809 P = 0; |
1801 P = 0; |
1810 P = P * 1.01325; // atm to bar |
1802 P = P * 1.01325; // atm to bar |
1811 P = Math.round(P * 10) / 10; |
1803 return Round(P,1); |
1812 return P; |
|
1813 } |
1804 } |
1814 |
1805 |
1815 function CarbCO2ToPressure(CO2, T) { |
1806 function CarbCO2ToPressure(CO2, T) { |
1816 return (CO2 - (-0.000005594056 * Math.pow(T, 4) + 0.000144357886 * Math.pow(T, 3) + |
1807 return (CO2-(-0.000005594056*Math.pow(T,4)+0.000144357886*Math.pow(T,3)+0.000362999168*T*T-0.064872987645*T+1.641145175049)) / |
1817 0.000362999168 * T * T - 0.064872987645 * T + 1.641145175049)) / |
1808 (0.00000498031*Math.pow(T,4)-0.00024358267*Math.pow(T,3)+0.00385867329*T*T-0.05671206825*T+1.53801423376); |
1818 (0.00000498031 * Math.pow(T, 4) - 0.00024358267 * Math.pow(T, 3) + |
1809 } |
1819 0.00385867329 * T * T - 0.05671206825 * T + 1.53801423376); |
1810 |
1820 } |
1811 function calcCarbonation() { |
1821 |
1812 var TSec=dataRecord.secondary_temp; |
1822 function calcCarbonation() { |
1813 if(TSec<1)TSec=dataRecord.primary_end_temp; |
1823 |
1814 if(TSec<1)TSec=18; |
1824 var TSec = dataRecord.secondary_temp; // End fermentation temperature. |
1815 if(dataRecord.fg==0.000) |
1825 if (TSec < 1) |
1816 var ABV=abvol(dataRecord.brew_fermenter_sg,parseFloat($("#est_fg").jqxNumberInput('decimal'))); |
1826 TSec = dataRecord.primary_end_temp; // Fallback |
1817 else |
1827 if (TSec < 1) |
1818 var ABV=abvol(dataRecord.brew_fermenter_sg,dataRecord.fg); |
1828 TSec = 18; // Fallback to room temperature. |
1819 /* Calculate new volume and alcohol. */ |
1829 |
1820 var bvol=dataRecord.package_volume-(ABV*dataRecord.package_volume)/100; |
1830 if (dataRecord.fg == 0.000) |
1821 var balc=dataRecord.package_volume-bvol; |
1831 var ABV = abvol(dataRecord.brew_fermenter_sg, parseFloat($("#est_fg").jqxNumberInput('decimal'))); |
1822 var mvol=dataRecord.package_infuse_amount-(dataRecord.package_infuse_abv*dataRecord.package_infuse_amount)/100; |
1832 else |
1823 var malc=dataRecord.package_infuse_amount-mvol; |
1833 var ABV = abvol(dataRecord.brew_fermenter_sg, dataRecord.fg); |
1824 var talc=balc+malc; |
1834 |
1825 var tvol=bvol+mvol; |
1835 /* |
1826 ABV = Round(talc/(tvol+talc)*100,2); |
1836 * Calculate new volume and alcohol. |
1827 dataRecord.package_abv=ABV; |
1837 */ |
1828 $("#package_abv").val(ABV); |
1838 var bvol = dataRecord.package_volume - (ABV * dataRecord.package_volume) / 100; |
1829 |
1839 var balc = dataRecord.package_volume - bvol; |
1830 // console.log("calcCarbonation() TSec:"+TSec+" ABV:"+ABV); |
1840 var mvol = dataRecord.package_infuse_amount - (dataRecord.package_infuse_abv * dataRecord.package_infuse_amount) / 100; |
1831 if(!(rows = $('#fermentableGrid').jqxGrid('getrows'))){return;} |
1841 var malc = dataRecord.package_infuse_amount - mvol; |
1832 |
1842 var talc = balc + malc; |
1833 // Bottles |
1843 var tvol = bvol + mvol; |
1834 dataRecord.bottle_priming_amount=0; |
1844 ABV = Math.round(talc / (tvol + talc) * 10000) / 100; |
1835 dataRecord.bottle_priming_total=0; |
1845 //console.log("bvol:"+bvol+" balc:"+balc+" mvol:"+mvol+" malc:"+malc+" tvol:"+tvol+" talc:"+talc+" abv:"+ABV+" vol:"+(tvol + talc)); |
1836 for (var i=0;i<rows.length;i++){ |
1846 dataRecord.package_abv = ABV; |
1837 var row=rows[i]; |
1847 $("#package_abv").val(ABV); |
1838 if(row.f_added==4){ |
1848 |
1839 var SFactor=1/((row.f_yield/100)*(1-row.f_moisture/100)); |
1849 console.log("calcCarbonation() TSec:"+TSec+" ABV:"+ABV); |
1840 dataRecord.bottle_priming_amount=CarbCO2toS(dataRecord.bottle_carbonation,TSec,SFactor); |
1850 if (!(rows = $('#fermentableGrid').jqxGrid('getrows'))) { |
1841 dataRecord.bottle_priming_total=Round(dataRecord.bottle_amount*dataRecord.bottle_priming_amount,2); |
1851 return; // grid not yet loaded. |
1842 $("#fermentableGrid").jqxGrid('setcellvalue',i,'f_amount',dataRecord.bottle_priming_total/1000); |
1852 } |
1843 }} |
1853 |
1844 $("#bottle_priming_amount").val(Round(dataRecord.bottle_priming_amount,1)); |
1854 // Bottles |
1845 $("#bottle_priming_total").val(dataRecord.bottle_priming_total); |
1855 dataRecord.bottle_priming_amount = 0; |
1846 var pabv=ABV+dataRecord.bottle_priming_amount*0.47/7.907; |
1856 dataRecord.bottle_priming_total = 0; |
1847 var pvol=dataRecord.bottle_amount-(pabv*dataRecord.bottle_amount)/100; |
1857 for (var i = 0; i < rows.length; i++) { |
1848 var talc=dataRecord.bottle_amount-pvol; |
1858 var row = rows[i]; |
1849 var tvol=pvol+dataRecord.bottle_priming_water; |
1859 if (row.f_added == 4) { |
1850 var babv = Round(talc/(tvol+talc)*100,2); |
1860 var SFactor = 1 / ((row.f_yield / 100) * (1 - row.f_moisture / 100)); |
1851 //console.log("bottle pabv:"+pabv+" pvol:"+pvol+" wvol:"+dataRecord.bottle_priming_water+" tvol:"+tvol+" talc:"+talc+" abv:"+babv); |
1861 dataRecord.bottle_priming_amount = CarbCO2toS(dataRecord.bottle_carbonation, TSec, SFactor); |
1852 $("#bottle_abv").val(babv); |
1862 dataRecord.bottle_priming_total = Math.round(dataRecord.bottle_amount * dataRecord.bottle_priming_amount * 100) / 100; |
1853 $("#bottle_pressure").val(GetPressure(dataRecord.bottle_carbonation,TSec,dataRecord.bottle_carbonation_temp)); |
1863 $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', dataRecord.bottle_priming_total / 1000); |
1854 |
1864 } |
1855 // Kegs |
1865 } |
1856 var Pressure=CarbCO2ToPressure(dataRecord.keg_carbonation,dataRecord.keg_carbonation_temp); |
1866 $("#bottle_priming_amount").val(Math.round(dataRecord.bottle_priming_amount * 10) / 10); |
1857 if(Pressure<0)Pressure=0; |
1867 $("#bottle_priming_total").val(dataRecord.bottle_priming_total); |
1858 dataRecord.keg_pressure=Pressure; |
1868 var pabv = ABV + dataRecord.bottle_priming_amount * 0.47 / 7.907; |
1859 $("#keg_pressure").val(Round(Pressure,1)); |
1869 var pvol = dataRecord.bottle_amount - (pabv * dataRecord.bottle_amount) / 100; |
1860 |
1870 var talc = dataRecord.bottle_amount - pvol; |
1861 dataRecord.keg_priming_amount=0; |
1871 var tvol = pvol + dataRecord.bottle_priming_water; |
1862 dataRecord.keg_priming_total=0; |
1872 var babv = Math.round(talc / (tvol + talc) * 10000) / 100; |
1863 if(!dataRecord.keg_forced_carb){ |
1873 //console.log("bottle pabv:"+pabv+" pvol:"+pvol+" wvol:"+dataRecord.bottle_priming_water+" tvol:"+tvol+" talc:"+talc+" abv:"+babv); |
1864 for(var i=0;i<rows.length;i++){ |
1874 $("#bottle_abv").val(babv); |
1865 var row=rows[i]; |
1875 $("#bottle_pressure").val(GetPressure(dataRecord.bottle_carbonation, TSec, dataRecord.bottle_carbonation_temp)); |
1866 if(row.f_added==5){ |
1876 |
1867 var SFactor=1/((row.f_yield/100)*(1-row.f_moisture/100)); |
1877 // Kegs |
1868 dataRecord.keg_priming_amount=CarbCO2toS(dataRecord.keg_carbonation,TSec,SFactor); |
1878 var Pressure = CarbCO2ToPressure(dataRecord.keg_carbonation, dataRecord.keg_carbonation_temp); |
1869 dataRecord.keg_priming_total=Round(dataRecord.keg_amount*dataRecord.keg_priming_amount,2); |
1879 if (Pressure < 0) |
1870 $("#fermentableGrid").jqxGrid('setcellvalue',i,'f_amount',dataRecord.keg_priming_total/1000); |
1880 Pressure = 0; |
1871 } |
1881 dataRecord.keg_pressure = Pressure; |
1872 } |
1882 $("#keg_pressure").val(Math.round(Pressure * 10) / 10); |
1873 $("#keg_priming_amount").val(Round(dataRecord.keg_priming_amount,1)); |
1883 |
1874 $("#keg_priming_total").val(dataRecord.keg_priming_total); |
1884 dataRecord.keg_priming_amount = 0; |
1875 var pabv=ABV+dataRecord.keg_priming_amount*0.47/7.907; |
1885 dataRecord.keg_priming_total = 0; |
1876 var pvol=dataRecord.keg_amount-(pabv*dataRecord.keg_amount)/100; |
1886 if (! dataRecord.keg_forced_carb) { |
1877 var talc=dataRecord.keg_amount-pvol; |
1887 for (var i = 0; i < rows.length; i++) { |
1878 var tvol=pvol+dataRecord.keg_priming_water; |
1888 var row = rows[i]; |
1879 var kabv=Round(talc/(tvol+talc)*100,2); |
1889 if (row.f_added == 5) { |
1880 //console.log("kegs pabv:"+pabv+" pvol:"+pvol+" wvol:"+dataRecord.keg_priming_water+" tvol:"+tvol+" talc:"+talc+" abv:"+kabv); |
1890 var SFactor = 1 / ((row.f_yield / 100) * (1 - row.f_moisture / 100)); |
1881 $("#keg_abv").val(kabv); |
1891 dataRecord.keg_priming_amount = CarbCO2toS(dataRecord.keg_carbonation, TSec, SFactor); |
1882 } else { |
1892 dataRecord.keg_priming_total = Math.round(dataRecord.keg_amount * dataRecord.keg_priming_amount * 100) / 100; |
1883 $("#keg_priming_amount").val(0); |
1893 $("#fermentableGrid").jqxGrid('setcellvalue', i, 'f_amount', dataRecord.keg_priming_total / 1000); |
1884 $("#keg_priming_total").val(0); |
1894 } |
1885 $("#keg_abv").val(ABV); |
1895 } |
1886 } |
1896 $("#keg_priming_amount").val(Math.round(dataRecord.keg_priming_amount * 10) / 10); |
1887 } |
1897 $("#keg_priming_total").val(dataRecord.keg_priming_total); |
|
1898 var pabv = ABV + dataRecord.keg_priming_amount * 0.47 / 7.907; |
|
1899 var pvol = dataRecord.keg_amount - (pabv * dataRecord.keg_amount) / 100; |
|
1900 var talc = dataRecord.keg_amount - pvol; |
|
1901 var tvol = pvol + dataRecord.keg_priming_water; |
|
1902 var kabv = Math.round(talc / (tvol + talc) * 10000) / 100; |
|
1903 //console.log("kegs pabv:"+pabv+" pvol:"+pvol+" wvol:"+dataRecord.keg_priming_water+" tvol:"+tvol+" talc:"+talc+" abv:"+kabv); |
|
1904 $("#keg_abv").val(kabv); |
|
1905 } else { |
|
1906 $("#keg_priming_amount").val(0); |
|
1907 $("#keg_priming_total").val(0); |
|
1908 $("#keg_abv").val(ABV); |
|
1909 } |
|
1910 } |
|
1911 |
1888 |
1912 function calcStage() { |
1889 function calcStage() { |
1913 |
1890 |
1914 var newstage = dataRecord.stage; |
1891 var newstage = dataRecord.stage; |
1915 /* parseFloat$("#brew_date_start").val()) returns the year if it is a valid mysql style date. */ |
1892 /* parseFloat$("#brew_date_start").val()) returns the year if it is a valid mysql style date. */ |