www/js/global.js

changeset 463
0efdafd23753
parent 462
c91175610f8a
child 465
dc3e14b976be
equal deleted inserted replaced
462:c91175610f8a 463:0efdafd23753
869 function ebc_to_color(ebc){return srm_to_color(ebc_to_srm(ebc));} 869 function ebc_to_color(ebc){return srm_to_color(ebc_to_srm(ebc));}
870 function srm_to_color(srm){ 870 function srm_to_color(srm){
871 var i = Math.round(srm * 10); 871 var i = Math.round(srm * 10);
872 if(i<0)i=0; 872 if(i<0)i=0;
873 if(i>299)i=299; 873 if(i>299)i=299;
874
875 /* Table copied from Brouwhulp/BrewBuddy */ 874 /* Table copied from Brouwhulp/BrewBuddy */
876 var R=[ 875 var R=[
877 250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,//0 876 250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,//0
878 250,250,250,250,250,249,248,247,246,245,244,243,242,241,240,239,238,237,236,235,//2 877 250,250,250,250,250,249,248,247,246,245,244,243,242,241,240,239,238,237,236,235,//2
879 234,233,232,231,230,229,228,227,226,225,224,223,222,221,220,219,218,217,216,215,//4 878 234,233,232,231,230,229,228,227,226,225,224,223,222,221,220,219,218,217,216,215,//4
881 197,197,196,196,195,195,194,194,193,193,192,192,192,192,192,192,192,192,192,192,//8 880 197,197,196,196,195,195,194,194,193,193,192,192,192,192,192,192,192,192,192,192,//8
882 192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,//10 881 192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,192,//10
883 192,192,192,192,192,192,192,192,191,190,189,188,187,186,185,184,183,182,181,180,//12 882 192,192,192,192,192,192,192,192,191,190,189,188,187,186,185,184,183,182,181,180,//12
884 179,178,177,175,174,172,171,169,168,167,195,164,162,161,159,158,157,155,154,152,//14 883 179,178,177,175,174,172,171,169,168,167,195,164,162,161,159,158,157,155,154,152,//14
885 151,149,148,147,145,144,142,141,139,138,137,135,134,132,131,129,128,127,125,124,//16 884 151,149,148,147,145,144,142,141,139,138,137,135,134,132,131,129,128,127,125,124,//16
886 122,121,119,118,117,115,114,112,111,109,108,107,105,104,102,101, 99, 98, 97, 95,//18 885 122,121,119,118,117,115,114,112,111,109,108,107,105,104,102,101,99,98,97,95,//18
887 94, 92, 91, 89, 88, 87, 85, 84, 82, 81, 79, 78, 77, 75, 74, 72, 71, 69, 68, 67,//20 886 94,92,91,89,88,87,85,84,82,81,79,78,77,75,74,72,71,69,68,67,//20
888 65, 64, 62, 61, 59, 58, 57, 55, 54, 52, 51, 49, 48, 47, 45, 44, 43, 41, 39, 38,//22 887 65,64,62,61,59,58,57,55,54,52,51,49,48,47,45,44,43,41,39,38,//22
889 37, 37, 36, 36, 35, 35, 34, 34, 33, 33, 32, 32, 31, 31, 30, 30, 29, 29, 28, 28,//24 888 37,37,36,36,35,35,34,34,33,33,32,32,31,31,30,30,29,29,28,28,//24
890 27, 27, 26, 26, 25, 25, 24, 24, 23, 23, 22, 22, 21, 21, 20, 20, 19, 19, 18, 18,//26 889 27,27,26,26,25,25,24,24,23,23,22,22,21,21,20,20,19,19,18,18,//26
891 17, 17, 16, 16, 15, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8]; 890 17,17,16,16,15,15,14,14,13,13,12,12,11,11,10,10,9,9,8,8];
892
893 var G=[ 891 var G=[
894 250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250, 892 250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,
895 250,250,250,250,250,250,249,248,247,246,245,244,242,240,238,236,234,232,230,228, 893 250,250,250,250,250,250,249,248,247,246,245,244,242,240,238,236,234,232,230,228,
896 226,224,222,220,218,216,214,212,210,208,206,204,202,200,198,196,194,192,190,188, 894 226,224,222,220,218,216,214,212,210,208,206,204,202,200,198,196,194,192,190,188,
897 186,184,182,180,178,176,174,172,170,168,166,164,162,160,158,156,154,152,150,148, 895 186,184,182,180,178,176,174,172,170,168,166,164,162,160,158,156,154,152,150,148,
898 146,144,142,141,140,139,139,138,137,136,136,135,134,133,133,132,131,130,130,129, 896 146,144,142,141,140,139,139,138,137,136,136,135,134,133,133,132,131,130,130,129,
899 128,127,127,126,125,124,124,123,122,121,121,120,119,118,118,117,116,115,115,114, 897 128,127,127,126,125,124,124,123,122,121,121,120,119,118,118,117,116,115,115,114,
900 113,112,112,111,110,109,109,108,107,106,106,105,104,103,103,102,101,100,100, 99, 898 113,112,112,111,110,109,109,108,107,106,106,105,104,103,103,102,101,100,100,99,
901 98, 97, 97, 96, 95, 94, 94, 93, 92, 91, 91, 90, 89, 88, 88, 87, 86, 85, 85, 84, 899 98,97,97,96,95,94,94,93,92,91,91,90,89,88,88,87,86,85,85,84,
902 83, 82, 82, 81, 80, 79, 78, 77, 76, 75, 75, 74, 73, 72, 72, 71, 70, 69, 69, 68, 900 83,82,82,81,80,79,78,77,76,75,75,74,73,72,72,71,70,69,69,68,
903 67, 66, 66, 65, 64, 63, 63, 62, 61, 60, 60, 59, 58, 57, 57, 56, 55, 54, 54, 53, 901 67,66,66,65,64,63,63,62,61,60,60,59,58,57,57,56,55,54,54,53,
904 52, 51, 51, 50, 49, 48, 48, 47, 46, 45, 45, 44, 43, 42, 42, 41, 40, 39, 39, 38, 902 52,51,51,50,49,48,48,47,46,45,45,44,43,42,42,41,40,39,39,38,
905 37, 36, 36, 35, 34, 33, 33, 32, 31, 30, 30, 29, 28, 27, 27, 26, 25, 24, 24, 23, 903 37,36,36,35,34,33,33,32,31,30,30,29,28,27,27,26,25,24,24,23,
906 22, 22, 22, 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 17, 17, 17, 16, 16, 904 22,22,22,21,21,21,20,20,20,19,19,19,18,18,18,17,17,17,16,16,
907 16, 15, 15, 15, 14, 14, 14, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 905 16,15,15,15,14,14,14,13,13,13,12,12,12,11,11,11,10,10,10,9,
908 9, 9, 8, 8, 8, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3]; 906 9,9,8,8,8,7,7,7,6,6,6,5,5,5,4,4,4,3,3,3];
909
910 var B=[ 907 var B=[
911 210,204,199,193,188,182,177,171,166,160,155,149,144,138,133,127,122,116,111,105, 908 210,204,199,193,188,182,177,171,166,160,155,149,144,138,133,127,122,116,111,105,
912 100, 94, 89, 83, 78, 72, 67, 61, 56, 50, 45, 45, 45, 46, 46, 46, 46, 47, 47, 47, 909 100,94,89,83,78,72,67,61,56,50,45,45,45,46,46,46,46,47,47,47,
913 47, 48, 48, 48, 48, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 910 47,48,48,48,48,49,49,49,49,50,50,50,50,51,51,51,51,52,52,52,
914 52, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 56, 911 52,53,53,53,53,54,54,54,54,55,55,55,55,56,56,56,56,56,56,56,
915 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 912 56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,
916 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 913 56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,
917 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 914 56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,
918 56, 56, 56, 55, 55, 55, 55, 54, 54, 54, 54, 53, 53, 53, 53, 52, 52, 52, 52, 51, 915 56,56,56,55,55,55,55,54,54,54,54,53,53,53,53,52,52,52,52,51,
919 51, 51, 51, 50, 50, 50, 50, 49, 49, 48, 47, 47, 46, 45, 45, 44, 43, 43, 42, 41, 916 51,51,51,50,50,50,50,49,49,48,47,47,46,45,45,44,43,43,42,41,
920 41, 40, 39, 39, 38, 37, 37, 36, 35, 34, 33, 32, 31, 29, 28, 27, 26, 25, 24, 23, 917 41,40,39,39,38,37,37,36,35,34,33,32,31,29,28,27,26,25,24,23,
921 21, 20, 19, 18, 17, 16, 15, 13, 12, 11, 10, 9, 8, 9, 9, 10, 10, 11, 11, 12, 918 21,20,19,18,17,16,15,13,12,11,10,9,8,9,9,10,10,11,11,12,
922 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 919 12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21,22,
923 21, 21, 21, 20, 20, 20, 19, 19, 19, 18, 18, 18, 17, 17, 17, 17, 16, 16, 15, 15, 920 21,21,21,20,20,20,19,19,19,18,18,18,17,17,17,17,16,16,15,15,
924 15, 14, 14, 14, 13, 13, 13, 12, 12, 12, 11, 11, 11, 10, 10, 10, 9, 9, 9, 8, 921 15,14,14,14,13,13,13,12,12,12,11,11,11,10,10,10,9,9,9,8,
925 8, 8, 7, 7, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2]; 922 8,8,7,7,7,6,6,6,5,5,5,4,4,4,3,3,3,2,2,2];
926
927 var color=R[i]*65536+G[i]*256+B[i]; 923 var color=R[i]*65536+G[i]*256+B[i];
928 var result=color.toString(16).toUpperCase(); 924 var result=color.toString(16).toUpperCase();
929 if(result.length<6) { 925 if(result.length<6)result='0'+result;
930 result='0'+result; 926 return '#'+result;
931 }
932 result='#'+result;
933 return result;
934 } 927 }
935 928
936 929
937 930
938 function sg_to_plato(sg){return ((135.997*sg-630.272)*sg+1111.14)*sg-616.868;} 931 function sg_to_plato(sg){return ((135.997*sg-630.272)*sg+1111.14)*sg-616.868;}
939 function plato_to_sg(plato){return 1+(plato/(258.6-((plato/258.2)*227.1)));} 932 function plato_to_sg(plato){return 1+(plato/(258.6-((plato/258.2)*227.1)));}
940 function brix_to_sg(brix){if(my_brix_correction>0)return plato_to_sg(brix/my_brix_correction);else return plato_to_sg(brix);} 933 function brix_to_sg(brix){if(my_brix_correction>0)return plato_to_sg(brix/my_brix_correction);else return plato_to_sg(brix);}
941 function sg_to_brix(sg){return sg_to_plato(sg)*my_brix_correction;} 934 function sg_to_brix(sg){return sg_to_plato(sg)*my_brix_correction;}
942 935
943
944
945 function estimate_sg(sugars,batch_size){ 936 function estimate_sg(sugars,batch_size){
946 var plato = 100 * sugars / batch_size; 937 var plato=100*sugars/batch_size;
947 var sg = plato_to_sg(plato); 938 var sg=plato_to_sg(plato);
948 for (var i = 0; i < 20; i++) { 939 for(var i=0;i<20;i++){if(sg>0)plato=100*sugars/(batch_size*sg);sg=plato_to_sg(plato);}
949 if (sg > 0) 940 return Round(sg,4);
950 plato = 100 * sugars / (batch_size * sg); 941 }
951 sg = plato_to_sg(plato); 942
952 } 943
953 return Round(sg,4); 944
954 } 945 function estimate_fg(percSugar,percCara,WGratio,TotTme,Temp,attenuation,og){
955 946
956 947 var BD;
957 948
958 function estimate_fg(percSugar, percCara, WGratio, TotTme, Temp, attenuation, og) { 949 if(percSugar>40)percSugar=0;
959 950 if(percCara>50)percCara=0;
960 var BD; 951 if((WGratio>0)&&(TotTme>0)){
961 952 BD=WGratio;
962 if (percSugar > 40) 953 if(BD<2)BD=2;
963 percSugar = 0; 954 if(BD>5.5)BD=5.5;
964 if (percCara > 50) 955 if(Temp<60)Temp=60;
965 percCara = 0; 956 if(Temp>72)Temp=72;
966 if ((WGratio > 0) && (TotTme > 0)) { 957 }else{
967 BD = WGratio; 958 BD=3.5;
968 if (BD < 2) 959 Temp=67;
969 BD = 2; 960 TotTme=75;
970 if (BD > 5.5) 961 }
971 BD = 5.5; 962 if(attenuation<30)attenuation=77;
972 if (Temp < 60) 963
973 Temp = 60; 964 // 0.00825 Attenuation factor yeast
974 if (Temp > 72) 965 // 0.00817 Attenuation factor water/grain ration
975 Temp = 72; 966 // -0.00684 Attenuation factor mash temperature
976 } else { 967 // 0.00026 Attenuation factor total mash time (at some places this is 0.0026 this is wrong!)
977 BD = 3.5; 968 // -0.00356 Attenuation factor percentage crystal malt
978 Temp = 67; 969 // 0.00553 Attenuation factor percentage simple sugars
979 TotTme = 75; 970 // 0.547 Attenuation factor constant
980 } 971 var AttBeer=0.00825*attenuation+0.00817*BD-0.00684*Temp+0.00026*TotTme-0.00356*percCara+0.00553*percSugar+0.547;
981 if (attenuation < 30) 972 var fg=Round(1+(1-AttBeer)*(og-1),4);
982 attenuation = 77; 973
983 974 console.log("estimate_fg("+percSugar+","+percCara+","+BD+","+TotTme+","+Temp+","+attenuation+","+og+") AttBeer:"+AttBeer+" fg:"+fg);
984 // 0.00825 Attenuation factor yeast 975 return fg;
985 // 0.00817 Attenuation factor water/grain ration
986 // -0.00684 Attenuation factor mash temperature
987 // 0.00026 Attenuation factor total mash time (at some places this is 0.0026 this is wrong!)
988 // -0.00356 Attenuation factor percentage crystal malt
989 // 0.00553 Attenuation factor percentage simple sugars
990 // 0.547 Attenuation factor constant
991 var AttBeer = 0.00825 * attenuation + 0.00817 * BD - 0.00684 * Temp + 0.00026 * TotTme - 0.00356 * percCara + 0.00553 * percSugar + 0.547;
992 var fg = Round(1 + (1 - AttBeer) * (og - 1),4);
993
994 console.log("estimate_fg("+percSugar+","+percCara+","+BD+","+TotTme+","+Temp+","+attenuation+","+og+") AttBeer:"+AttBeer+" fg:"+fg);
995 return fg;
996 } 976 }
997 977
998 978
999 979
1000 function CalcFrac(TpH, pK1, pK2, pK3) { 980 function CalcFrac(TpH, pK1, pK2, pK3) {

mercurial