How to sum up the duration for last 7 days in TimeFold

I have a reference shift shift1. From the date and time of shift1, we have to calculate the sum of all shift durations for the past 7 days. The explanation of the variables are as follows:

RuleSetting -> It is a problem fact used on or off the rule.

shift1 -> It is a problem fact used as a reference point. From this shift other shift’s work duration is summed up. The shift1 also will be included.

shift2 -> It is a problem fact that has been used for the last 7 days’ shifts which will sum up the duration.

foreignerType-> It is a problem fact that is used for settings for foreign employees.

    Constraint workingHoursGreaterThanMaximumForForeignerPerWeek(ConstraintFactory constraintFactory) {
    
          
          return constraintFactory.forEach(RuleSetting.class)
                .filter(ruleSetting -> ruleSetting.getRuleName().equals("E016") && ruleSetting.getIsActive() == true)
                .join(Shift.class)
                .join(Shift.class)
                .filter((ruleSetting, shift1, shift2) -> shift1.getEmployee() != null
                                            && shift2.getEmployee() != null
                                            && shift1.getEmployee().equals(shift2.getEmployee())
                                            && (shift1.getStartDateTime() != null && shift2.getStartDateTime() != null)
                                            && (shift1.getStartDateTime().isAfter(shift2.getStartDateTime()) || shift1.getStartDateTime().isEqual(shift2.getStartDateTime())) 
                                            && (shift1.getEmployee().getForeignerType() != null)
                                            && Math.abs(ShiftUtil.differenceInDays(shift1, shift2)) < 7)
                .join(ForeignerType.class)
                .filter((ruleSetting, shift1, shift2, foreignerType) -> foreignerType.getForeignerType().equals(shift1.getEmployee().getForeignerType()))
                .groupBy((ruleSetting, shift1, shift2, foreignerType)->ruleSetting,
                            (ruleSetting, shift1, shift2, foreignerType)->shift2.getEmployee(),
                            (ruleSetting, shift1, shift2, foreignerType)->shift1,
// My understanding is the above line is wrong. But I need the shift1 in the later part of the code.
                            ConstraintCollectors.sumLong((ruleSetting, shift1, shift2, foreignerType)->shift2.getWorkMinutes()))
                .map((ruleSetting, employee, shift1, totalDuration) -> new QuadTuple<RuleSetting, Employee, Shift, Long>(ruleSetting, employee, shift1, totalDuration))
                .join(ForeignerType.class)
                .filter((quad, foreignerType) -> quad.getB().getForeignerType() != null
                                            && foreignerType.getForeignerType().equals(quad.getB().getForeignerType())
                                            && quad.getD() > foreignerType.getMaxMinutesInWeek())
                .penalizeConfigurable((quad, foreignerType)->{
                    Double result = Math.abs(((double)quad.getD() / (double) foreignerType.getMaxMinutesInWeek()));
    
                    result = result * Math.abs(quad.getA().getWeight());
                    return result.intValue();
                })
                .indictWith((quad, foreignerType) ->{
                    EmployeeScoreKeyItems res = new EmployeeScoreKeyItems(EmployeeScoreKeyItems.KeyType.BY_DAY,
                            quad.getA().getRuleName(),
                            quad.getB().getEmployeeId(), 
                            null, quad.getC().getBusinessDate(), null, null);
    
                    return List.of(res);    
                })
                .asConstraint("E016");            
        }
  

So, how can we down stream the shift1 to lower part of the code. Please check the commented line inside the code. And also get the summed up duration for the shift for past 7 days.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật