PierreMarcil

PIData.Summary with astAverage and no value in datetime range

Discussion created by PierreMarcil on Dec 12, 2012
Latest reply on Dec 18, 2012 by PierreMarcil

Hello,

 

I figure this function trigger my try/catch since it might try to divide by 0 since there no data in the datetime range.  Using astCount instead go trough same condition without fail and just return 0.

 

My quesiton is there any other proper way to handle this than create a sub try/catch or test with astCount then do astAverage if count > 0?  When i first write up my code, I though it would be handle after all using .IsGood() function.

 
var avg = pot.Data.Summary(startTime, endTime, ArchiveSummaryTypeConstants.astAverage);

// => trigger try/catch

//idea #1

var result = (double)0;

try {

var avg = pot.Data.Summary(startTime, endTime, ArchiveSummaryTypeConstants.astAverage);

if(avg.IsGood())
result = avg.Value

}
catch 
(COMException ex)
{
result = null;
}

//idea #2 :

var cnt = pot.Data.Summary(startTime, endTime, ArchiveSummaryTypeConstants.astCount);

if(cnt.value > 0)

var avg = pot.Data.Summary(startTime, endTime, ArchiveSummaryTypeConstants.astAverage);

 

Outcomes