Mapping simple calculations for each hour within the day to use in PiVision

Hi,

 

I am working with production data and would like to calculate tonnes for each hour sending it to attributes to be visualised in PiVision. I have managed to do this by using the following locic and respective hours. It workd but not very efficient. Does anyone know how I can improve on this?

 

For Example:

Hour1 = if BadVal(TagVal('311WIT4191/Weight.MasterTot','t+1h')) or 

  BadVal(TagVal('311WIT4191/Weight.MasterTot','t')) or 

  BadVal(TagVal('311WIT4211/Weight.MasterTot','t+1h')) or 

  BadVal(TagVal('311WIT4211/Weight.MasterTot','t')) 

  then 0 

  else 

  TagVal('311WIT4191/Weight.MasterTot','t+1h')-TagVal('311WIT4191/Weight.MasterTot','t') + 

  TagVal('311WIT4211/Weight.MasterTot','t+1h')-TagVal('311WIT4211/Weight.MasterTot','t')

 

Hour2 = if BadVal(TagVal('311WIT4191/Weight.MasterTot','t+2h')) or BadVal(TagVal('311WIT4191/Weight.MasterTot','t+1h')) or BadVal(TagVal('311WIT4211/Weight.MasterTot','t+2h')) or BadVal(TagVal('311WIT4211/Weight.MasterTot','t+1h')) then 0 else TagVal('311WIT4191/Weight.MasterTot','t+2h')-TagVal('311WIT4191/Weight.MasterTot','t+1h') + TagVal('311WIT4211/Weight.MasterTot','t+2h')-TagVal('311WIT4211/Weight.MasterTot','t+1h')

 

etc.