package worm.esort;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class HandleResult {

	private static final Logger logger = LogManager.getLogger();

	private Integer totalPageCount = 0;

	public List<Integer> handledPages = new ArrayList<Integer>();

	public Integer getTotalPageCount() {
		return totalPageCount;
	}

	public void setTotalPageCount(Integer totalPageCount) {
		this.totalPageCount = totalPageCount;
	}

	public boolean isRepeatHandle() {
		Set<Integer> keys = new HashSet<Integer>();
		for (Integer i : handledPages)
			keys.add(i);
		return keys.size() != handledPages.size();
	}

	public void addHandledPage(Integer pageCount) {
		handledPages.add(pageCount);
	}

	/**
	 * 估算剩余时间
	 * @param pageCostTime 每页耗时（秒）
	 */
	public void expectRemainTime(float pageCostTime) {
		float remainTime = (((totalPageCount - handledPages.size())/2) * pageCostTime);// 剩余时间（秒）
		int hours = (int) (remainTime / 3600);
		int minutes = (int) ((remainTime % 3600f) / 60);
		int seconds = (int) ((remainTime % 3600f) % 60);
		logger.info("进度：{}/{}, 剩余{}小时{}分钟{}秒", handledPages.size(),totalPageCount,hours, minutes, seconds);
	}

//	public static void testExpectRemainTime(){
//		HandleResult rs = new HandleResult();
//		rs.setTotalPageCount(100);
//		int pageCostTime = 61 ;
//		rs.expectRemainTime(pageCostTime);
//	}
//	public static void main(String[] args) {
//		testExpectRemainTime();
//	}
}

@@ -342,16 +342,54 @@
 nt = 0;%0D
+%0A%09%0D%0A%09private float totalCostTime = 0;%0D
 %0A%0D%0A%09publ
@@ -960,24 +960,37 @@
 */%0D%0A%09public 
+synchronized 
 void expectR
@@ -1028,127 +1028,492 @@
 %0D%0A%09%09
-float remainTime = (((totalPageCount - handledPages.size())/2) * pageCostTime);// %E5%89%A9%E4%BD%99%E6%97%B6%E9%97%B4%EF%BC%88%E7%A7%92%EF%BC%89%0D%0A%09%09int hours = (int) (remainT
+totalCostTime+=pageCostTime;%0D%0A%09%09float everyPageCost = totalCostTime/handledPages.size();%0D%0A%09%09float remainTime = everyPageCost*(totalPageCount - handledPages.size());%0D%0A//%09%09float remainTime = (((totalPageCount - handledPages.size())/2) * pageCostTime);// %E5%89%A9%E4%BD%99%E6%97%B6%E9%97%B4%EF%BC%88%E7%A7%92%EF%BC%89%0D%0A%09%09logger.info(%22%E8%BF%9B%E5%BA%A6%EF%BC%9A%7B%7D/%7B%7D,%E5%B7%B2%E8%80%97%E6%97%B6:%7B%7D, %E9%A2%84%E8%AE%A1%E5%89%A9%E4%BD%99:%7B%7D%22, handledPages.size(),totalPageCount,convertSeconds2HMS(totalCostTime),convertSeconds2HMS(remainTime));%0D%0A%09%7D%0D%0A%09%0D%0A%09private String convertSeconds2HMS(float time)%7B%0D%0A%09%09int hours = (int) (t
 ime 
@@ -1538,39 +1538,33 @@
 nutes = (int) ((
-remainT
+t
 ime %25 3600f) / 6
@@ -1592,23 +1592,17 @@
 (int) ((
-remainT
+t
 ime %25 36
@@ -1620,106 +1620,48 @@
 %0D%0A%09%09
-logger.info(%22%E8%BF%9B%E5%BA%A6%EF%BC%9A%7B%7D/%7B%7D, %E5%89%A9%E4%BD%99%7B%7D%E5%B0%8F%E6%97%B6%7B%7D%E5%88%86%E9%92%9F%7B%7D%E7%A7%92%22, handledPages.size(),totalPageCount,hours, 
+return hours+%22%E6%97%B6%22+
 minutes
-, 
++%22%E5%88%86%22+
 seconds
-)
++%22%E7%A7%92%22
 ;%0D%0A%09

修正时间估算算法；