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
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);
Related
I am trying to get my power bi data from my HRIS platform to calculate hours worked - hours on lunch, to get a total of hours worked in a day.
I have tried grouping, pivots, formulas, and because my HRIS platform send the "check-in" time at the start of a shift and the "check-in" time when they clock back in from lunch, as the same "check-in" classification, I cannot associate it with one or the other, it picks the most recent one, if I say return "check-in" (My data set is intraday and updates every hour so I can get all Clock events for the current day)
I have included an example of what my data looks like right from the HRIS into Power Bi
Sample Data Set
Full Data Sheet Columns
Formula's Used in Order:
Check In =
IF(AND(Merge1[Current Day]=Merge1[Day of the
Week],Merge1[Clock_Event_Type]="Check-in"),
Merge1[Clock_Event_Time_-_No_Time_Zone])
Check Out (Lunch) =
IF(Merge1[Day of the Week]= Merge1[Current Day],
IF(Merge1[Clock_Event_Type]= "Check-out
(meal)",Merge1[Clock_Event_Time_-_No_Time_Zone],BLANK()))
Check in (Lunch) = IF(Merge1[Current Day]=Merge1[Day of the
Week],
VAR checkin = Merge1[Check In]
VAR outlunch = Merge1[Check Out (Lunch)]
VAR timeinfromlunch = IF(checkin>outlunch,checkin)
return timeinfromlunch)
Check Out = IF(Merge1[Day of the Week]= Merge1[Current Day],
IF(Merge1[Clock_Event_Type] = "Check-out",
Merge1[Clock_Event_Time_-_No_Time_Zone]),BLANK())
Current Time = IF(AND(Merge1[Current Day]=Merge1[Day of the
Week],Merge1[Clock_Event_Type]="Check-in"),
NOW()
)
CPH Calc (Intraday Shift) = IF(Merge1[Current Time]<Merge1[Shift
End Today],Merge1[Current Time],Merge1[Check Out])
Hours Worked =
IF(AND(Merge1[Current Day]=Merge1[Day of the
Week],Merge1[Clock_Event_Type]="Check-in"),
VAR totalsecondsinbreak = DATEDIFF(Merge1[Check Out
(Lunch)],Merge1[Check in (Lunch)],SECOND)
VAR total_secondsworking = DATEDIFF(Merge1[Check In],Merge1[CPH
Calc (Intraday Shift)],SECOND)
VAR totalseconds = total_secondsworking-totalsecondsinbreak
VAR DAXHours = (totalseconds/60)/60
RETURN IF(Merge1[Clock_Event_Time_-
_No_Time_Zone]=0,BLANK(),DAXHours))
Shift Start Today = IF(Merge1[Current Day]=Merge1[Day of the
Week],TODAY() + Merge1[Start Shift])
Shift End Today = IF(Merge1[Current Day]=Merge1[Day of the
Week],TODAY() + Merge1[End Shift])
On Queue (Milliseconds) = IF(AND(Merge1[Current Day]=Merge1[Day
of the Week],Merge1[Clock_Event_Type]="Check-in"),
VAR onqueueseconds = RELATED('Table (2)'[On Queue])
VAR milliseconds = onqueueseconds
VAR total_second = milliseconds/1000
VAR minutes = total_second/60
VAR hours_decimal = minutes/60
VAR hours = INT(hours_decimal)
return onqueueseconds)
Utilization =
IF(AND(Merge1[Current Day]=Merge1[Day of the
Week],Merge1[Clock_Event_Type]="Check-in"),
VAR productivetime = Merge1[Hours Productive Time]
VAR workedtime = Merge1[Hours Worked]
VAR Ult = IFERROR(productivetime/workedtime,BLANK())
return Ult
)
Hours Productive Time =
IF(AND(Merge1[Current Day]=Merge1[Day of the
Week],Merge1[Clock_Event_Type]="Check-in"),
VAR milliseconds = Merge1[On Queue (Milliseconds)]
VAR total_second = milliseconds/1000
//VAR minutes = total_second/60
//VAR hours_decimal = minutes/60
//VAR hours = INT(hours_decimal)
VAR DAXHours = (total_second/60)/60
return DAXHours+.5)
My current project need to customisely showing some extra information base on calculations of the dates that has been selected. I have writen a function, and I can't find the AJAX code that the booking system returns the data and calculations base on the valid date to trigger my function.
My function is easy:
function calculate_date_duration() {
var year_1 = document.querySelector('.selection-start-date').getAttribute('data-year');
var month_1 = document.querySelector('.selection-start-date').getAttribute('data-month');
var date_1 = document.querySelector('.selection-start-date a').textContent;
var year_2 = document.querySelector('.selection-end-date').getAttribute('data-year');
var month_2 = document.querySelector('.selection-end-date').getAttribute('data-month');
var date_2 = document.querySelector('.selection-end-date a').textContent;
var day_1 = new Date(year_1, month_1, date_1);
var day_2 = new Date(year_2, month_2, date_2);
console.log(day_1);
console.log(day_2);
var day_selected = day_2.getTime() - day_1.getTime();
var date_duration = parseInt(day_selected / (1000 * 60 * 60 * 24)) +1;
console.log(date_duration);
var display_pane = document.querySelector('.wc-bookings-booking-cost');
display_pane.innerHTML = display_pane.innerHTML + '<br>Total booking cost:<strong><span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">$</span>' + (date_duration*120) + '</bdi></span></strong>';}
The date select duration ajax is in wp-content/plugins/woocommerce-bookings/dist/frontend.js, search success, the last one in this file is the codes after validating the selected duration.
I'm fetching rows from excel sheet in my application that holds attendance records from the bio metric machine. In order to get the best result i have to remove the redundant data. For that I have to manage check in and checkout timings at regular intervals. For instance, First check in time for entering, and then checkout time for lunch, then again check in for returning back, and last check out for going home. Meanwhile the rows in excel contains multiple check ins and check outs as the employee tends to do more that once for both.
I have managed to get records from excel and added to data table. Now for the sequence and sorting part I'm struggling to achieve my desired result. Below is my code.
protected void btnSaveAttendance_Click(object sender, EventArgs e)
{
try
{
if (FileUpload1.HasFile && Path.GetExtension(FileUpload1.FileName) == ".xls")
{
using (var excel = new OfficeOpenXml.ExcelPackage(FileUpload1.PostedFile.InputStream))
{
var tbl = new DataTable();
var ws = excel.Workbook.Worksheets.First();
var hasHeader = true; // adjust accordingly
// add DataColumns to DataTable
foreach (var firstRowCell in ws.Cells[1, 1, 1, ws.Dimension.End.Column])
tbl.Columns.Add(hasHeader ? firstRowCell.Text
: String.Format("Column {0}", firstRowCell.Start.Column));
// add DataRows to DataTable
int startRow = hasHeader ? 2 : 1;
for (int rowNum = startRow; rowNum <= ws.Dimension.End.Row; rowNum++)
{
var wsRow = ws.Cells[rowNum, 1, rowNum, ws.Dimension.End.Column];
DataRow row = tbl.NewRow();
foreach (var cell in wsRow)
row[cell.Start.Column - 1] = cell.Text;
tbl.Rows.Add(row);
}
var distinctNames = (from row in tbl.AsEnumerable()
select row.Field<string>("Employee Code")).Distinct();
DataRow[] dataRows = tbl.Select().OrderBy(u => u["Employee Code"]).ToArray();
var ss = dataRows.Where(p => p.Field<string>("Employee Code") == "55").ToArray();
}
}
}
catch (Exception ex) { }
}
The result i'm getting is:
Employee Code Employee Name Date Time In / Out
55 Alex 12/27/2018 8:59 IN
55 Alex 12/27/2018 8:59 IN
55 Alex 12/27/2018 13:00 OUT
55 Alex 12/27/2018 13:00 OUT
55 Alex 12/27/2018 13:48 IN
55 Alex 12/27/2018 13:49 IN
55 Alex 12/27/2018 18:08 OUT
And I want to have first In and then out and then in and then out. This would iterate four times to generate the result.
Expected result is:
Employee Code Employee Name Date Time In / Out
55 Alex 12/27/2018 8:59 IN
55 Alex 12/27/2018 13:00 OUT
55 Alex 12/27/2018 13:48 IN
55 Alex 12/27/2018 18:08 OUT
Can you try to do groupby in the result like below
ss=ss.GroupBy(x=>x.DateTime).ToArray();
Build a logic, if your result have 2 successive In/Out as a sample like below.
Here In I considered as field name
var tt;
for(int i=0;i<ss.Count();i++)
{
if(ss[i].In=="In" && (tt!=null || tt.LastOrDefault().In!="In"))
tt=ss[i];
else if(ss[i].In=="Out" && (tt!=null || tt.LastOrDefault().In!="Out"))
tt=ss[i];
}
I would like to make a change of image say every 15 days. Or twice a month. When the date is between the 1 and 15 is an image, and if it is from 16 to 30 another, so on, are 24 images in the year. I would like it to be the typoscript that manages the change of the image.
I took the following typosript:
lib.headerlogo1 = COA
lib.headerlogo1 {
10 = LOAD_REGISTER
10 {
divSem.cObject = TEXT
divSem.cObject {
data = date:U
strftime = %U
current = 1
setCurrent.data = date:U
setCurrent.wrap = |/2
prioriCalc = 1
}
}
20 = FILES
20 {
references {
data = levelmedia: -1, slide
}
renderObj = IMAGE
renderObj {
file.import.dataWrap = {file:current:storage}:{file:current:identifier}
#file.import.listNum = 0
altText.data = file:current:title
# Affiche bien la valeur de : divSem
#stdWrap.insertData = 1
#stdWrap.wrap = <div class="banner{register:divSem}">|</div>
}
# insertData = 1
insertData = 1
# IT'S FAILLED !!
begin = {register:divSem}
maxItems = 1
}
30 = TEXT
30 {
stdWrap.insertData = 1
stdWrap.wrap = <div class="{register:divSem}">|</div>
}
}
The problem is that I can not start the value of the registry begin = {register:divSem} ... It always starts at 0! Do you have an idea ? The display of the registers in 30 = TEXT is correct.
Do you have a good idea to modify the typoscript?
I just found the solution, instead of begin = {register: divSem}, I did this:
begin.cObject = TEXT
begin.cObject {
value = 0
value.override.cObject = CASE
value.override.cObject {
key.data = register:divSem
1 = TEXT
1.value = 1
2 = TEXT
2.value = 2
...
24 = TEXT
24.value = 24
default = TEXT
default.value = 2
}
}
Maybe there is more simple, if you have an idea, I'm interested.
Best regards.
You found the important detail: you need a .cObject to fill in any data in the simple property.
Why so complicated with a CASE that outputs the same as the key?
So the simplest way would be:
begin.cObject = TEXT
begin.cObject.data = register:divSem
maybe this also worked like you do in .30:
begin = {register:divSem}
begin.insertData = 1
and a more direct way of your .30:
instead of an .insertData for a .wrap use .dataWrap
begin.stdWrap.dataWrap = {register:divSem}
:
30 = TEXT
30.dataWrap = <div class="{register:divSem}">|</div>
I can get the date in de date picker, calculate the time left and put in a label. This gives seconds:
let timeLeft = datePicker.dateValue.timeIntervalSinceNow
countingLabel.stringValue = "seconds left: \(timeLeft)"
How to format "timeLeft"?
I tried this and it does not work:
var formatter = NSDateFormatter()
formatter.dateFormat = "EEEE, yyyy-MM-dd hh:mm:ss"
let timeLeft2 = formatter.stringFromDate(timeLeft)
You can use NSDateComponentsFormatter. From the
documentation:
An NSDateComponentsFormatter object takes quantities of time and
formats them as a user-readable string. Use a date components
formatter to create strings for your app’s interface.
Example:
let formatter = NSDateComponentsFormatter()
formatter.unitsStyle = .Full
formatter.allowedUnits = .CalendarUnitSecond | .CalendarUnitMinute | .CalendarUnitHour
let pickedDate = datePicker.dateValue
let now = NSDate()
let formattedTimeLeft = formatter.stringFromDate(now, toDate: pickedDate)!
// Example result : 1:06:50
There are some more output formats available, e.g.
.Abbreviated : 1h 6m 50s
.Short : 1 hr, 6 min, 50 secs
.Full : 1 hour, 6 minutes and 50 seconds
Update for Swift 4 and later:
let formatter = DateComponentsFormatter()
formatter.unitsStyle = .full // or .short or .abbreviated
formatter.allowedUnits = [.second, .minute, .hour]
let pickedDate = datePicker.date
let now = Date()
let formattedTimeLeft = formatter.string(from: now, to: pickedDate)!
To get timeLeft you should use two time components and get their differnece as follow:
let todayComponents = NSCalendar.currentCalendar().components(.DayCalendarUnit | .MonthCalendarUnit | .YearCalendarUnit | .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond | , fromDate : NSDate())
var pickedDateComponents = NSCalendar.currentCalendar().components(.DayCalendarUnit | .MonthCalendarUnit | .YearCalendarUnit | .CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond | , fromDate : datePicker.dateValue)
pickedDateComponents.second = pickedDateComponents.second - todayComponents.second
pickedDateComponents.minute = pickedDateComponents.minute - todayComponents.minute
pickedDateComponents.hour = pickedDateComponents.hour - todayComponents.hour
pickedDateComponents.day =pickedDateComponents.day - todayComponents.day
pickedDateComponents.month = pickedDateComponents.month - todayComponents.month
pickedDateComponents.year = pickedDateComponents.year - todayComponents.year
let timeLeft = NSCalendar.currentCalendar().dateFromComponents(pickedDateComponents)!