随机分配效果在task中的应用,公司内部代码片

本文介绍了一种算法,用于从一组测试人员中筛选出待测试任务最少的人选,以便更合理地分配测试任务。该算法首先确定了候选测试者的范围,然后通过统计每位测试者待处理的任务数量来找出最合适的人员。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//3.找出这些测试人员中需要进行的待测试的测试任务最少的
CondSetBean taskAndCSB = new CondSetBeanJustAnd();
taskAndCSB.addCondBean(new CondBeanEqual("CR_STATUS", statusId));
String columnName = null;
if (roleId.equals(TaskDefinition.ROLE_DEVELOP_TESTER)) {
columnName = "CR_DEVELOP_TESTER";
} else if (roleId.equals(TaskDefinition.ROLE_INTEGRATION_TESTER)) {
columnName = "CR_INTEGRATION_TESTER";
}
CondBeanIn taskTesterCBIforTaskAndCSB = new CondBeanIn(columnName);
taskAndCSB.addCondBean(taskTesterCBIforTaskAndCSB);
for (int i = 0; i < userRoleTB.size(); i++) {
RowBean userRoleRowBean = userRoleTB.get(i);
String userId = userRoleRowBean.getCellBeanValue("CR_USER_ID");
taskTesterCBIforTaskAndCSB.addValue(userId);
if (!testerIdArray.contains(userId)) {
testerIdArray.add(userId);//把所有测试人员全部放入集合中,通过后面的算法移除不符合要求的;
}
}
TableBean taskTB = this.baseDAO.queryForTableBean(new ClassPOJO("TN_TASK"), taskAndCSB);
Bag testerBag = new HashBag();
if (taskTB.size() > 0) {
for (int i = 0; i < taskTB.size(); i++) {
testerBag.add(taskTB.get(i).getCellBeanValue(columnName));//开发测试人员放入HashBag中统计数量
}
}
int lastTesterTaskCount = -1;
Iterator<String> iterator = testerIdArray.iterator();
ArrayList<String> theLeastTesterIdList = new ArrayList<String>();
while (iterator.hasNext()) {
String tempTesterId = (String) iterator.next();
int testerTaskCount = testerBag.getCount(tempTesterId);//读取当前测试人的待测试task数量
if (lastTesterTaskCount == -1) {
lastTesterTaskCount = testerTaskCount;
theLeastTesterIdList.add(tempTesterId);
continue;
}
//如果当前开发测试人的待测试task数量小于之前开发测试人员的待测试task数量,将之前的测试人员清空,当前测试人加入集合
if (testerTaskCount < lastTesterTaskCount) {
theLeastTesterIdList.clear();
theLeastTesterIdList.add(tempTesterId);
lastTesterTaskCount = testerTaskCount;
}else if(testerTaskCount == lastTesterTaskCount){
theLeastTesterIdList.add(tempTesterId);
}else if(testerTaskCount > lastTesterTaskCount){
}
}
//如果有多个测试人员有相同的待测试task数量,则为当前task在这些测试人员中随机分配一个
if (theLeastTesterIdList.size() > 1) {
Random random = new Random(System.currentTimeMillis());
testUserId = theLeastTesterIdList.get(random.nextInt(theLeastTesterIdList.size()));

}else if (theLeastTesterIdList.size() == 1) {
testUserId = theLeastTesterIdList.get(0);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值