smort

BCBF

Jun 8th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.69 KB | None | 0 0
  1. flow.set('recipe' , msg.payload.recipe.fermentation)
  2. flow.set('fbeername' , msg.payload.recipe.name)
  3.  
  4. function numberDes(a,b) {
  5. return b-a;
  6. }
  7.  
  8. function stringsort(b,a) {
  9. return (Number(a.match(/(\d+)/g)[0]) - Number((b.match(/(\d+)/g)[0])));
  10. }
  11.  
  12. function time_convert(num)
  13. {
  14. var hours = Math.floor(num / 60);
  15. var minutes = num % 60;
  16. return + hours + ":" + minutes + ":00";
  17. }
  18. var hopstandhoptime=[];
  19. var hopstandhopname=[];
  20. var hopstandhopamount=[];
  21. var hopstand
  22. var hopstandtemp
  23. if (msg.payload.recipe.hops.length > 0){
  24. if (msg.payload.recipe.hopStandMinutes > 0) {
  25. hopstand = true
  26. hopstandtemp = msg.payload.recipe.avgWeightedHopstandTemp
  27. for(var x=0; x<msg.payload.recipe.hops.length; x++){
  28. if (msg.payload.recipe.hops[x].use == "Aroma") {
  29. hopstandhoptime.push(msg.payload.recipe.hops[x].time)
  30. hopstandhopname.push(msg.payload.recipe.hops[x].name)
  31. hopstandhopamount.push(msg.payload.recipe.hops[x].amount)
  32. }
  33. }
  34.  
  35. }
  36. }
  37. else {
  38. hopstandtemp = 0
  39. hopstand = false
  40. }
  41.  
  42. const {
  43. dupstand
  44. } = hopstandhoptime.reduce(
  45. (acc, curr) => {
  46. acc.items[curr] = acc.items[curr] ? acc.items[curr] += 1 : 1
  47. if (acc.items[curr] === 2) acc.dupstand.push(curr)
  48. return acc
  49. }, {
  50. items: {},
  51. dupstand: []
  52. }
  53. )
  54.  
  55. for (x= 0; x<hopstandhoptime.length;x++){
  56. hopstandhopname[x] = hopstandhopamount[x]+"g "+hopstandhopname[x]
  57. }
  58.  
  59.  
  60. if (dupstand.length > 0) {
  61. for (var i = 0; i<dupstand.length; i++) {
  62. for (x = (hopstandhoptime.indexOf(dupstand[i])); x < hopstandhoptime.lastIndexOf(dupstand[i]); x++) {
  63. hopstandhopname[hopstandhoptime.indexOf(dupstand[i])] += " and "+ hopstandhopname[x+1]
  64. delete hopstandhopname[x+1]
  65. delete hopstandhoptime[x+1]
  66. }
  67. }
  68.  
  69. }
  70.  
  71. for (i=0; i<hopstandhoptime.length; i++) {
  72. if (hopstandhoptime[i] == null) {
  73. hopstandhoptime.splice(i,1);
  74. hopstandhopname.splice(i,1);
  75. i -= 1;
  76. }
  77. }
  78. for (i=0; i<hopstandhoptime.length; i++) {
  79. hopstandhopname[i] = hopstandhoptime[i]+"min "+ hopstandhopname[i]
  80. }
  81.  
  82. hopstandhoptime.sort(numberDes);
  83. hopstandhopname.sort(stringsort);
  84.  
  85.  
  86. hopstandhoptime.push(0,0,0,0,0,0,0,0,0,0)
  87. hopstandhoptime.length = 5
  88. hopstandhopname.push("","","","","","","","","","")
  89. hopstandhopname.length = 5
  90.  
  91. var firstwort
  92. var firstworthopname=[];
  93. var firstworthopamount=[];
  94. if (msg.payload.recipe.hops.length > 0){
  95. if (msg.payload.recipe.hops[0].use == "First Wort") {
  96. firstwort = true
  97. for( x=0; x<msg.payload.recipe.hops.length; x++){
  98. if (msg.payload.recipe.hops[x].use == "First Wort") {
  99. firstworthopname.push(msg.payload.recipe.hops[x].name)
  100. firstworthopamount.push(msg.payload.recipe.hops[x].amount)
  101. }
  102. }
  103. for (x= 0; x<firstworthopname.length;x++){
  104. firstworthopname[x] = firstworthopamount[x]+"g "+firstworthopname[x]
  105. }
  106. if (firstworthopname.length > 1) {
  107. for (x = 1; x <firstworthopname.length; x++) {
  108. firstworthopname[0] += " and "+ firstworthopname[x]
  109. //delete firstworthopname[x+1]
  110. }
  111. //for (i=0; i<firstworthopname.length; i++) {
  112. // if (firstworthopname[i] === null) {
  113. // firstworthopname.splice(i,1);
  114. // i -= 1;
  115. // }
  116. //}
  117.  
  118. }
  119. }
  120. }
  121. else {
  122. firstwort = false
  123. }
  124.  
  125.  
  126. var boilhoptime=[];
  127. var boilhopname=[];
  128. var boilhopamount=[];
  129. if (msg.payload.recipe.hops.length > 0){
  130. for( x=0;x<msg.payload.recipe.hops.length;x++){
  131. if (msg.payload.recipe.hops[x].use == "Boil") {
  132. boilhoptime.push(msg.payload.recipe.hops[x].time);
  133. boilhopname.push(msg.payload.recipe.hops[x].name);
  134. boilhopamount.push(msg.payload.recipe.hops[x].amount);
  135. }
  136. }
  137. }
  138. if (msg.payload.batchMiscs.length > 0) {
  139. for ( x=0;x<msg.payload.batchMiscs.length;x++){
  140. if (msg.payload.batchMiscs[x].use == "Boil") {
  141. boilhoptime.push(msg.payload.batchMiscs[x].time)
  142. boilhopname.push(msg.payload.batchMiscs[x].name)
  143. boilhopamount.push(msg.payload.batchMiscs[x].amount)
  144. }
  145. }
  146. }
  147.  
  148. const {
  149. dup
  150. } = boilhoptime.reduce(
  151. (acc, curr) => {
  152. acc.items[curr] = acc.items[curr] ? acc.items[curr] += 1 : 1
  153. if (acc.items[curr] === 2) acc.dup.push(curr)
  154. return acc
  155. }, {
  156. items: {},
  157. dup: []
  158. }
  159. )
  160.  
  161. for (x= 0; x<boilhoptime.length;x++){
  162. boilhopname[x] = boilhopamount[x]+"g "+boilhopname[x]
  163. }
  164.  
  165. if (dup.length > 0) {
  166. for (var i = 0; i<dup.length; i++) {
  167. for (x = (boilhoptime.indexOf(dup[i])); x < boilhoptime.lastIndexOf(dup[i]); x++) {
  168. boilhopname[boilhoptime.indexOf(dup[i])] += " and "+ boilhopname[x+1]
  169. delete boilhopname[x+1]
  170. delete boilhoptime[x+1]
  171. }
  172. }
  173. }
  174.  
  175. for (i=0; i<boilhoptime.length; i++) {
  176. if (boilhoptime[i] == null) {
  177. boilhoptime.splice(i,1);
  178. boilhopname.splice(i,1);
  179. i -= 1;
  180. }
  181. }
  182. for (i=0; i<boilhoptime.length; i++) {
  183. boilhopname[i] = boilhoptime[i]+"min "+ boilhopname[i]
  184. }
  185.  
  186. boilhoptime.sort(numberDes);
  187. boilhopname.sort(stringsort);
  188.  
  189.  
  190. boilhoptime.push(0,0,0,0,0,0,0,0,0,0)
  191. boilhoptime.length = 10
  192. boilhopname.push("","","","","","","","","","")
  193. boilhopname.length = 10
  194.  
  195. var mashtime=[];
  196. for(var y=0;y<msg.payload.mashStepsCount;y++){
  197. mashtime[y]= msg.payload.recipe.mash.steps[y].stepTime;
  198. }
  199. mashtime.push(0,0,0,0,0);
  200. mashtime.length = 5
  201.  
  202. var mashsteps = msg.payload.mashStepsCount - 1;
  203. var mashtemp=[];
  204. for(var z=0;z<msg.payload.mashStepsCount;z++){
  205. mashtemp[z]= msg.payload.recipe.mash.steps[z].stepTemp;
  206. }
  207. mashtemp.push(mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps])
  208. mashtemp.length = 6
  209.  
  210. msg.payload = [
  211.  
  212. { "Name": "Preboil volume", "Value": msg.payload.recipe.boilSize } ,
  213. { "Name": "HLT fillvolume" , "Value": msg.payload.recipe.data.hltWaterAmount } ,
  214. { "Name": "Sparge volume" , "Value": msg.payload.recipe.data.spargeWaterAmount } ,
  215. { "Name": "Strike temp" , "Value": msg.payload.recipe.data.strikeTemp } ,
  216. { "Name": "Mash volume" , "Value": msg.payload.recipe.data.mashWaterAmount } ,
  217. { "Name": "Mash temp" , "Value": mashtemp[0] } ,
  218. { "Name": "Mash temp1" , "Value": mashtemp[1] } ,
  219. { "Name": "Mash temp2" , "Value": mashtemp[2] } ,
  220. { "Name": "Mash temp3" , "Value": mashtemp[3] } ,
  221. { "Name": "Mash temp4" , "Value": mashtemp[4] } ,
  222. { "Name": "Mash temp5" , "Value": mashtemp[5] } ,
  223. { "Name": "Mash time1" , "Value": time_convert(mashtime[0]) } ,
  224. { "Name": "Mash time2" , "Value": time_convert(mashtime[1]) } ,
  225. { "Name": "Mash time3" , "Value": time_convert(mashtime[2]) } ,
  226. { "Name": "Mash time4" , "Value": time_convert(mashtime[3]) } ,
  227. { "Name": "Mash time5" , "Value": time_convert(mashtime[4]) } ,
  228. { "Name": "Hop time0" , "Value": time_convert(boilhoptime[0]) } ,
  229. { "Name": "Hop time1" , "Value": time_convert(boilhoptime[1]) } ,
  230. { "Name": "Hop time2" , "Value": time_convert(boilhoptime[2]) } ,
  231. { "Name": "Hop time3" , "Value": time_convert(boilhoptime[3]) } ,
  232. { "Name": "Hop time4" , "Value": time_convert(boilhoptime[4]) } ,
  233. { "Name": "Hop time5" , "Value": time_convert(boilhoptime[5]) } ,
  234. { "Name": "Hop time6" , "Value": time_convert(boilhoptime[7]) } ,
  235. { "Name": "Hop time8" , "Value": time_convert(boilhoptime[8]) } ,
  236. { "Name": "Hop time9" , "Value": time_convert(boilhoptime[9]) } ,
  237. { "Name": "Boilhopname0" , "Value": boilhopname[0] } ,
  238. { "Name": "Boilhopname1" , "Value": boilhopname[1] } ,
  239. { "Name": "Boilhopname2" , "Value": boilhopname[2] } ,
  240. { "Name": "Boilhopname3" , "Value": boilhopname[3] } ,
  241. { "Name": "Boilhopname4" , "Value": boilhopname[4] } ,
  242. { "Name": "Boilhopname5" , "Value": boilhopname[5] } ,
  243. { "Name": "Boilhopname6" , "Value": boilhopname[6] } ,
  244. { "Name": "Boilhopname7" , "Value": boilhopname[7] } ,
  245. { "Name": "Boilhopname8" , "Value": boilhopname[8] } ,
  246. { "Name": "Boilhopname9" , "Value": boilhopname[9] } ,
  247. { "Name": "Boilsteps" , "Value": msg.payload.boilSteps.length } ,
  248. { "Name": "Hopstandtime0" , "Value": time_convert(hopstandhoptime[0])},
  249. //{ "Name": "Hopstandtime1" , "Value": time_convert(hopstandhoptime[1])},
  250. //{ "Name": "Hopstandtime2" , "Value": time_convert(hopstandhoptime[2])},
  251. //{ "Name": "Hopstandtime3" , "Value": time_convert(hopstandhoptime[3])},
  252. //{ "Name": "Hopstandtime4" , "Value": time_convert(hopstandhoptime[4])},
  253. { "Name": "Hopstandhopname0" , "Value": hopstandhopname[0]},//String(hopstandhopamount[0]) +"g" +" " +String(hopstandhopname[0]) } ,
  254. //{ "Name": "Hopstandhopname2" , "Value": hopstandhopname[1]},//String(hopstandhopamount[1]) +"g" +" " +String(hopstandhopname[1]) } ,
  255. //{ "Name": "Hopstandhopname3" , "Value": hopstandhopname[2]},//String(hopstandhopamount[2]) +"g" +" " +String(hopstandhopname[2]) } ,
  256. //{ "Name": "Hopstandhopname4" , "Value": hopstandhopname[3]},//String(hopstandhopamount[3]) +"g" +" " +String(hopstandhopname[3]) } ,
  257. //{ "Name": "Hopstandhopname5" , "Value": hopstandhopname[4]},//String(hopstandhopamount[4]) +"g" +" " +String(hopstandhopname[4]) } ,
  258. { "Name": "Hopstand" , "Value": true } ,
  259. { "Name": "Boil time" , "Value": time_convert(msg. payload.recipe.boilTime) } ,
  260. { "Name": "Hopstand temp" , "Value": hopstandtemp } ,
  261. { "Name": "First wort" , "Value": firstwort } ,
  262. { "Name": "Status" , "Value": new Date().toDateString()+" "+new Date().getHours()+":"+new Date().getMinutes()+" " +"#"+msg.topic+" "+msg.payload.recipe.name }
  263.  
  264. ];
  265.  
  266. return msg;
Advertisement
Add Comment
Please, Sign In to add comment