Florin Pop
Florin Pop

Reputation: 5135

Xpages view string type ratio

I have a view with 2 columns, both type of String. One is always "08:00" and one depends on the user input. It could be 02:30 or 13:45, etc...

I want to convert all the column of 08:00's and all the other column of values, add them together and then divide the total...

Example:

Column 1 | Column 2
02:50    | 08:00
05:15    | 08:00
15:25    | 08:00
03:15    | 08:00

It would be something like:(~26)/(8*4)=~0.8%. It's a timekeeping application. I have the normal-time of 8 hours and the time the employee worked, and I want to add a button that will calculate the ratio between the 2 columns.

Thank you,

Florin

Upvotes: 0

Views: 67

Answers (1)

Florin Pop
Florin Pop

Reputation: 5135

This is the code I used to calculate the ration between 2 columns of strings:

var vec:NotesViewEntryCollection = viewSearch.getAllEntries();
var c = vec.getCount()
var data = @DbColumn(@DbName(),"vwSearch",4);

var totalH = 0;
var totalM = 0;

for(var i=0;i<c;i++){
var str = data[i].toString();
var a = str.split(":",2)[0];
var b = str.split(":",2)[1]; 
var hour = parseInt(a);
var minutes = parseInt(b);
totalH += hour;
totalM += minutes;

if(totalM >= 60)
{
    totalH++;
    totalM-=60;
}
}

var h_necesare = c*8;

getComponent("h_lucrate").setValue(totalH+" ore, si "+totalM+" minute.");
getComponent("h_necesare").setValue(h_necesare);
getComponent("raport").setValue(totalH-h_necesare);

Upvotes: 1

Related Questions