VelocityReports question about variable math RESOLVED

Questions and answers on developing, deploying and using plugins and JavaBeans

VelocityReports question about variable math RESOLVED

Postby joe26 » Fri Jun 08, 2018 11:02 pm

What am I doing wrong? (I did say it was a general question...)

I must not be setting up the variables correctly.

I'm just trying to get the milliseconds that the report took to create. $start is from the incoming context object.

thanks,
--Joe.

#set ( $finishT = $number.integer($now.time) )
#set ( $startT = $number.integer($start) )
#set ( $totalTime = $number.integer($finishT) - $number.integer($startT) )
#set ( $totalCalc = $number.integer($totalTime) )
#set ( $timer = \$startT )

finisht $finishT <br></br>
startt $startT <br></br>
totaltime $totalTime <br></br>
totalcalc $totalCalc <br></br>
timer $timer <br></br>
raw $number.integer($finishT) - $number.integer($startT) <br></br>

Returns:

finisht 1,528,491,218,781
startt 1,528,491,216,724
totaltime $totalTime
totalcalc $totalCalc
timer 1,528,491,216,724
raw 1,528,491,218,781 - 1,528,491,216,724
Last edited by joe26 on Tue Jun 19, 2018 11:10 pm, edited 2 times in total.
joe26
 
Posts: 172
Joined: Wed Jun 19, 2013 10:30 pm

Re: General Velocity Apache question on Variables

Postby joe26 » Sat Jun 09, 2018 12:04 am

Even tried to remove commas, my math just doesn't seem to work.

#set ( $finishT = $number.format('####',$now.time) )
#set ( $startT = $number.integer($start) )
#set ( $totalTime = $number.format('####',$finishT) - $number.format('####',$startT) )
#set ( $totalCalc = $number.integer($totalTime) )
#set ( $timer = $startT )
#set ($startFormat = "")
$startFormat.format("$%,d",$number.toInteger($startT))

finisht $finishT <br></br>
startt $startT <br></br>
totaltime $totalTime <br></br>
totalcalc $totalCalc <br></br>
timer $timer <br></br>
raw $number.integer($finishT) - $number.integer($startT) <br></br>
startformatted $startFormat<br></br>
raw2 $number.format('####',$finishT) - $number.format('####',$startT) <br></br>

#set ( $A = 25 )
#set ( $B = 35 )
Sum = $B - $A <br></br>
#set ( $sum = $B - $A ) <br></br>
Sum = $sum <br></br>
#set ( $A = $number.format('####',$finishT) )
#set ( $B = $number.format('####',$startT) )
#set ( $sum2 = $number.format('####',$finishT) - $number.format('####',$startT) )
Time = $sum2 <br></br>
#set ( $sum3 = $B - $A )
B = $B <br></br>
A = $A <br></br>
Time2 (B - A) = $sum3 <br></br>


returns:
$null finisht 1528495291329
startt 1,528,495,289,631
totaltime $totalTime
totalcalc $totalCalc
timer 1,528,495,289,631
raw 1,528,495,291,329 - 1,528,495,289,631
startformatted
raw2 1528495291329 - 1528495289631
Sum = 35 - 25
Sum = 10
Time = $sum2
B = 1528495289631
A = 1528495291329
Time2 (B - A) = $sum3
joe26
 
Posts: 172
Joined: Wed Jun 19, 2013 10:30 pm

Re: VelocityReports question about variable math

Postby joe26 » Mon Jun 18, 2018 5:34 pm

Apparently, there is no need for conversion with $number.integer($now.time) or $start for integer math.

Just adding #set ($calcDur = $now.time - $start) shows the elapsed time for the report where context.start = new Date().getTime()

The sample solution hasn't been updated, so extensions to Velocity probably covered this aspect as well.
joe26
 
Posts: 172
Joined: Wed Jun 19, 2013 10:30 pm


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 15 guests