package cputils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import common.Combination;
import common.Utils;
public class BaseService {
/**
* @param issueNo
* @param is_not_full 1:full,2:notfull
* @return
* @throws IOException
*/
public Map<String, Map<Integer, Integer>> stat(String issueNo,int is_not_full,String from) throws IOException{
Map<String, Map<Integer, Integer>> res = new HashMap<String, Map<Integer,Integer>>();
String fileName = from + "_" + issueNo;
List<String> list = new ArrayList<String>();
switch (is_not_full) {
case 1:
fileName = fileName+"_full";
list = XmlUtils.getHMData(fileName);
break;
case 2:
fileName = fileName+"_notfull";
list = XmlUtils.getHMData(fileName);
break;
case 100:
list = XmlUtils.getHMData(fileName+"_notfull");
list.addAll(XmlUtils.getHMData(fileName+"_full"));
fileName = fileName+"_all";
break;
default:
break;
}
Utils.print(fileName+" line:"+list.size());
Map<Integer, Integer> bMap = new HashMap<Integer, Integer>();
Map<Integer, Integer> aMap = new HashMap<Integer, Integer>();
initBeforeAndAfterMap(issueNo, bMap, aMap);
Combination comb = new Combination();
for (String s1 : list) {
s1 = s1.replaceAll("<strong class='c_1e50a2'>", "").replaceAll("</strong>", "")
.replaceAll("<strong class='c_ba2636'>", "");
List<String> items = comb.getAll(s1, issueNo);
for (String str : items) {
String[] sArr = str.split("\\:");
if (sArr!=null&&sArr.length==2) {
String[] bArr = sArr[0].split(" ");
String[] aArr = sArr[1].split(" ");
for (int i = 0; i < bArr.length; i++) {
if (StringUtils.isNotBlank(bArr[i])) {
int num = Integer.parseInt(bArr[i].trim());
if (bMap.get(num)!=null) {
bMap.put(num, bMap.get(num)+1);
}
}
}
for (int i = 0; i < aArr.length; i++) {
if (StringUtils.isNotBlank(aArr[i])) {
int num = Integer.parseInt(aArr[i].trim());
if (aMap.get(num)!=null) {
aMap.put(num, aMap.get(num)+1);
}
}
}
}
}
}
res.put("b", bMap);
res.put("a", aMap);
res = XmlUtils.makeSortedMap(res, true);
return res;
}
public void initBeforeAndAfterMap(String issueNo,Map<Integer, Integer> bMap,Map<Integer, Integer> aMap){
int bMax = 0,aMax = 0;
switch (issueNo.length()) {
case 5:
bMax = 35;
aMax = 12;
break;
case 7:
bMax = 33;
aMax = 16;
break;
default:
break;
}
for (int i = 1; i <= bMax; i++) {
bMap.put(i, 0);
}
for (int i = 1; i <= aMax; i++) {
aMap.put(i, 0);
}
}
public String getFullOrNotName(int is_not_full){
String fullOrNotStr = "";
switch (is_not_full) {
case 2:
fullOrNotStr = "notfull";
break;
case 1:
fullOrNotStr = "full";
break;
case 3:
fullOrNotStr = "full";
break;
case 100:
fullOrNotStr = "all";
break;
default:
break;
}
return fullOrNotStr;
}
public String getLotteryType(String issueNo,String from){
String gameName = "";
if(issueNo.length()==7){
if("ac".equals(from)){
gameName = "FC_SSQ";
}else if ("lc".equals(from)) {
gameName = "50";
}else if ("wy".equals(from)) {
gameName = "ssq";
}else if ("tb".equals(from)) {
gameName = "SSQ";
}
}else if (issueNo.length()==5) {
if("ac".equals(from)){
gameName = "TC_DLT";
}else if ("lc".equals(from)) {
gameName = "1";
}else if ("wy".equals(from)) {
gameName = "dlt";
}else if ("tb".equals(from)) {
gameName = "DLT";
}
}
return gameName;
}
}