Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- flow.set('recipe' , msg.payload.recipe.fermentation)
- flow.set('fbeername' , msg.payload.recipe.name)
- function numberDes(a,b) {
- return b-a;
- }
- function stringsort(b,a) {
- return (Number(a.match(/(\d+)/g)[0]) - Number((b.match(/(\d+)/g)[0])));
- }
- function time_convert(num)
- {
- var hours = Math.floor(num / 60);
- var minutes = num % 60;
- return + hours + ":" + minutes + ":00";
- }
- var hopstandhoptime=[];
- var hopstandhopname=[];
- var hopstandhopamount=[];
- var hopstand
- var hopstandtemp
- if (msg.payload.recipe.hops.length > 0){
- if (msg.payload.recipe.hopStandMinutes > 0) {
- hopstand = true
- hopstandtemp = msg.payload.recipe.avgWeightedHopstandTemp
- for(var x=0; x<msg.payload.recipe.hops.length; x++){
- if (msg.payload.recipe.hops[x].use == "Aroma") {
- hopstandhoptime.push(msg.payload.recipe.hops[x].time)
- hopstandhopname.push(msg.payload.recipe.hops[x].name)
- hopstandhopamount.push(msg.payload.recipe.hops[x].amount)
- }
- }
- }
- }
- else {
- hopstandtemp = 0
- hopstand = false
- }
- const {
- dupstand
- } = hopstandhoptime.reduce(
- (acc, curr) => {
- acc.items[curr] = acc.items[curr] ? acc.items[curr] += 1 : 1
- if (acc.items[curr] === 2) acc.dupstand.push(curr)
- return acc
- }, {
- items: {},
- dupstand: []
- }
- )
- for (x= 0; x<hopstandhoptime.length;x++){
- hopstandhopname[x] = hopstandhopamount[x]+"g "+hopstandhopname[x]
- }
- if (dupstand.length > 0) {
- for (var i = 0; i<dupstand.length; i++) {
- for (x = (hopstandhoptime.indexOf(dupstand[i])); x < hopstandhoptime.lastIndexOf(dupstand[i]); x++) {
- hopstandhopname[hopstandhoptime.indexOf(dupstand[i])] += " and "+ hopstandhopname[x+1]
- delete hopstandhopname[x+1]
- delete hopstandhoptime[x+1]
- }
- }
- }
- for (i=0; i<hopstandhoptime.length; i++) {
- if (hopstandhoptime[i] == null) {
- hopstandhoptime.splice(i,1);
- hopstandhopname.splice(i,1);
- i -= 1;
- }
- }
- for (i=0; i<hopstandhoptime.length; i++) {
- hopstandhopname[i] = hopstandhoptime[i]+"min "+ hopstandhopname[i]
- }
- hopstandhoptime.sort(numberDes);
- hopstandhopname.sort(stringsort);
- hopstandhoptime.push(0,0,0,0,0,0,0,0,0,0)
- hopstandhoptime.length = 5
- hopstandhopname.push("","","","","","","","","","")
- hopstandhopname.length = 5
- var firstwort
- var firstworthopname=[];
- var firstworthopamount=[];
- if (msg.payload.recipe.hops.length > 0){
- if (msg.payload.recipe.hops[0].use == "First Wort") {
- firstwort = true
- for( x=0; x<msg.payload.recipe.hops.length; x++){
- if (msg.payload.recipe.hops[x].use == "First Wort") {
- firstworthopname.push(msg.payload.recipe.hops[x].name)
- firstworthopamount.push(msg.payload.recipe.hops[x].amount)
- }
- }
- for (x= 0; x<firstworthopname.length;x++){
- firstworthopname[x] = firstworthopamount[x]+"g "+firstworthopname[x]
- }
- if (firstworthopname.length > 1) {
- for (x = 1; x <firstworthopname.length; x++) {
- firstworthopname[0] += " and "+ firstworthopname[x]
- //delete firstworthopname[x+1]
- }
- //for (i=0; i<firstworthopname.length; i++) {
- // if (firstworthopname[i] === null) {
- // firstworthopname.splice(i,1);
- // i -= 1;
- // }
- //}
- }
- }
- }
- else {
- firstwort = false
- }
- var boilhoptime=[];
- var boilhopname=[];
- var boilhopamount=[];
- if (msg.payload.recipe.hops.length > 0){
- for( x=0;x<msg.payload.recipe.hops.length;x++){
- if (msg.payload.recipe.hops[x].use == "Boil") {
- boilhoptime.push(msg.payload.recipe.hops[x].time);
- boilhopname.push(msg.payload.recipe.hops[x].name);
- boilhopamount.push(msg.payload.recipe.hops[x].amount);
- }
- }
- }
- if (msg.payload.batchMiscs.length > 0) {
- for ( x=0;x<msg.payload.batchMiscs.length;x++){
- if (msg.payload.batchMiscs[x].use == "Boil") {
- boilhoptime.push(msg.payload.batchMiscs[x].time)
- boilhopname.push(msg.payload.batchMiscs[x].name)
- boilhopamount.push(msg.payload.batchMiscs[x].amount)
- }
- }
- }
- const {
- dup
- } = boilhoptime.reduce(
- (acc, curr) => {
- acc.items[curr] = acc.items[curr] ? acc.items[curr] += 1 : 1
- if (acc.items[curr] === 2) acc.dup.push(curr)
- return acc
- }, {
- items: {},
- dup: []
- }
- )
- for (x= 0; x<boilhoptime.length;x++){
- boilhopname[x] = boilhopamount[x]+"g "+boilhopname[x]
- }
- if (dup.length > 0) {
- for (var i = 0; i<dup.length; i++) {
- for (x = (boilhoptime.indexOf(dup[i])); x < boilhoptime.lastIndexOf(dup[i]); x++) {
- boilhopname[boilhoptime.indexOf(dup[i])] += " and "+ boilhopname[x+1]
- delete boilhopname[x+1]
- delete boilhoptime[x+1]
- }
- }
- }
- for (i=0; i<boilhoptime.length; i++) {
- if (boilhoptime[i] == null) {
- boilhoptime.splice(i,1);
- boilhopname.splice(i,1);
- i -= 1;
- }
- }
- for (i=0; i<boilhoptime.length; i++) {
- boilhopname[i] = boilhoptime[i]+"min "+ boilhopname[i]
- }
- boilhoptime.sort(numberDes);
- boilhopname.sort(stringsort);
- boilhoptime.push(0,0,0,0,0,0,0,0,0,0)
- boilhoptime.length = 10
- boilhopname.push("","","","","","","","","","")
- boilhopname.length = 10
- var mashtime=[];
- for(var y=0;y<msg.payload.mashStepsCount;y++){
- mashtime[y]= msg.payload.recipe.mash.steps[y].stepTime;
- }
- mashtime.push(0,0,0,0,0);
- mashtime.length = 5
- var mashsteps = msg.payload.mashStepsCount - 1;
- var mashtemp=[];
- for(var z=0;z<msg.payload.mashStepsCount;z++){
- mashtemp[z]= msg.payload.recipe.mash.steps[z].stepTemp;
- }
- mashtemp.push(mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps], mashtemp[mashsteps])
- mashtemp.length = 6
- msg.payload = [
- { "Name": "Preboil volume", "Value": msg.payload.recipe.boilSize } ,
- { "Name": "HLT fillvolume" , "Value": msg.payload.recipe.data.hltWaterAmount } ,
- { "Name": "Sparge volume" , "Value": msg.payload.recipe.data.spargeWaterAmount } ,
- { "Name": "Strike temp" , "Value": msg.payload.recipe.data.strikeTemp } ,
- { "Name": "Mash volume" , "Value": msg.payload.recipe.data.mashWaterAmount } ,
- { "Name": "Mash temp" , "Value": mashtemp[0] } ,
- { "Name": "Mash temp1" , "Value": mashtemp[1] } ,
- { "Name": "Mash temp2" , "Value": mashtemp[2] } ,
- { "Name": "Mash temp3" , "Value": mashtemp[3] } ,
- { "Name": "Mash temp4" , "Value": mashtemp[4] } ,
- { "Name": "Mash temp5" , "Value": mashtemp[5] } ,
- { "Name": "Mash time1" , "Value": time_convert(mashtime[0]) } ,
- { "Name": "Mash time2" , "Value": time_convert(mashtime[1]) } ,
- { "Name": "Mash time3" , "Value": time_convert(mashtime[2]) } ,
- { "Name": "Mash time4" , "Value": time_convert(mashtime[3]) } ,
- { "Name": "Mash time5" , "Value": time_convert(mashtime[4]) } ,
- { "Name": "Hop time0" , "Value": time_convert(boilhoptime[0]) } ,
- { "Name": "Hop time1" , "Value": time_convert(boilhoptime[1]) } ,
- { "Name": "Hop time2" , "Value": time_convert(boilhoptime[2]) } ,
- { "Name": "Hop time3" , "Value": time_convert(boilhoptime[3]) } ,
- { "Name": "Hop time4" , "Value": time_convert(boilhoptime[4]) } ,
- { "Name": "Hop time5" , "Value": time_convert(boilhoptime[5]) } ,
- { "Name": "Hop time6" , "Value": time_convert(boilhoptime[7]) } ,
- { "Name": "Hop time8" , "Value": time_convert(boilhoptime[8]) } ,
- { "Name": "Hop time9" , "Value": time_convert(boilhoptime[9]) } ,
- { "Name": "Boilhopname0" , "Value": boilhopname[0] } ,
- { "Name": "Boilhopname1" , "Value": boilhopname[1] } ,
- { "Name": "Boilhopname2" , "Value": boilhopname[2] } ,
- { "Name": "Boilhopname3" , "Value": boilhopname[3] } ,
- { "Name": "Boilhopname4" , "Value": boilhopname[4] } ,
- { "Name": "Boilhopname5" , "Value": boilhopname[5] } ,
- { "Name": "Boilhopname6" , "Value": boilhopname[6] } ,
- { "Name": "Boilhopname7" , "Value": boilhopname[7] } ,
- { "Name": "Boilhopname8" , "Value": boilhopname[8] } ,
- { "Name": "Boilhopname9" , "Value": boilhopname[9] } ,
- { "Name": "Boilsteps" , "Value": msg.payload.boilSteps.length } ,
- { "Name": "Hopstandtime0" , "Value": time_convert(hopstandhoptime[0])},
- //{ "Name": "Hopstandtime1" , "Value": time_convert(hopstandhoptime[1])},
- //{ "Name": "Hopstandtime2" , "Value": time_convert(hopstandhoptime[2])},
- //{ "Name": "Hopstandtime3" , "Value": time_convert(hopstandhoptime[3])},
- //{ "Name": "Hopstandtime4" , "Value": time_convert(hopstandhoptime[4])},
- { "Name": "Hopstandhopname0" , "Value": hopstandhopname[0]},//String(hopstandhopamount[0]) +"g" +" " +String(hopstandhopname[0]) } ,
- //{ "Name": "Hopstandhopname2" , "Value": hopstandhopname[1]},//String(hopstandhopamount[1]) +"g" +" " +String(hopstandhopname[1]) } ,
- //{ "Name": "Hopstandhopname3" , "Value": hopstandhopname[2]},//String(hopstandhopamount[2]) +"g" +" " +String(hopstandhopname[2]) } ,
- //{ "Name": "Hopstandhopname4" , "Value": hopstandhopname[3]},//String(hopstandhopamount[3]) +"g" +" " +String(hopstandhopname[3]) } ,
- //{ "Name": "Hopstandhopname5" , "Value": hopstandhopname[4]},//String(hopstandhopamount[4]) +"g" +" " +String(hopstandhopname[4]) } ,
- { "Name": "Hopstand" , "Value": true } ,
- { "Name": "Boil time" , "Value": time_convert(msg. payload.recipe.boilTime) } ,
- { "Name": "Hopstand temp" , "Value": hopstandtemp } ,
- { "Name": "First wort" , "Value": firstwort } ,
- { "Name": "Status" , "Value": new Date().toDateString()+" "+new Date().getHours()+":"+new Date().getMinutes()+" " +"#"+msg.topic+" "+msg.payload.recipe.name }
- ];
- return msg;
Advertisement
Add Comment
Please, Sign In to add comment