程式碼
import java.io.*;
class NumberStat3
{
public static void main(String[] args)
{
// Define data file name and statistical file name
String DEFAULTDATAFN = "number-data.txt";
String DATAFN = DEFAULTDATAFN;
String STATFN = "number-stat.txt";
String STATFN2 = "number-stat2.txt";
String STATFN3 = "number-stat3.txt";
String STATFN3p = "number-stat3p.txt";
String FIRSTLINE = "";
String READLINE = "";
// Define data row number, main region count, special region count, max of main, max of special
int ROW = 0, MAINNUM = 0, SPNUM = 0, MAINMAX = 0, SPMAX = 0;
// Define read counter
int ReadCount = 0;
// Define line length
int LineLen = 0;
// Define read number
int ReadNum = -1;
// Define lookup line
int LOOKUP = 15;
//Define BASE lookup sum
int BASE = 3;
//Define row number which begin to show statistical data
int BEGINROW = 0;
//Define add string to statistical file name
String STATFNADD = "";
// Read data file
if(args.length > 0){ DATAFN = args[0]; }
try{
// Buffered reader and read count
BufferedReader br = new BufferedReader(new FileReader(DATAFN));
FIRSTLINE = br.readLine();
ReadCount++;
// Split first line for setup array
String[] LINE = FIRSTLINE.split(",");
LineLen = FIRSTLINE.length();
for(int i = 0; i < LINE.length; i++){
if(i != 8){
ReadNum = -1;
ReadNum = Integer.parseInt(LINE[i]);
}
//For debug
//System.out.print(LINE[i] + " " + ReadNum + " ");
switch(i){
case 0: ROW = ReadNum; System.out.println("設定資料筆數 " + ROW);
break;
case 1: MAINNUM = ReadNum; System.out.println("設定主要區號碼個數 " + MAINNUM);
break;
case 2: SPNUM = ReadNum; System.out.println("設定特別區號碼個數 " + SPNUM);
break;
case 3: MAINMAX = ReadNum; System.out.println("設定主要區最大數字 " + MAINMAX);
break;
case 4: SPMAX = ReadNum; System.out.println("設定特別區最大數字 " + SPMAX);
break;
case 5: LOOKUP = ReadNum; System.out.println("設定前後查看期數 ");
break;
case 6: BASE = ReadNum; System.out.println("設定統計期數基底數 ");
break;
case 7: BEGINROW = ReadNum-1; System.out.println("設定從 " + (BEGINROW+1) + " 期開始顯示統計資料");
break;
case 8: STATFNADD = LINE[i]; System.out.println("設定附加檔名字串 " + STATFNADD);
break;
default: System.out.println("超過數量的參數不予理會.");
}
}
System.out.print("\n");
System.out.print("初始化陣列 : 資料陣列 ");
int[][] data = new int[ROW][MAINNUM+SPNUM];
for(int i = 0; i < ROW; i++){
for(int j = 0; j < MAINNUM+SPNUM; j++){
data[i][j] = 0;
}
System.out.print(".");
}
System.out.print("\n");
System.out.print("初始化陣列 : 統計陣列 ");
int[][][] anabe = new int[ROW][LOOKUP][MAINMAX+1];
int[][][] anaaf = new int[ROW][LOOKUP][MAINMAX+1];
int[][][] anaspbe = new int[ROW][LOOKUP][SPMAX+1];
int[][][] anaspaf = new int[ROW][LOOKUP][SPMAX+1];
int[][] statMAINp3be = new int[ROW][MAINMAX+1];
int[][] statMAINp3af = new int[ROW][MAINMAX+1];
int[][] statSPp3be = new int[ROW][SPMAX+1];
int[][] statSPp3af = new int[ROW][SPMAX+1];
char[][] statMAINp3beS = new char[ROW][MAINMAX+1];
char[][] statSPp3beS = new char[ROW][SPMAX+1];
for(int i = 0; i < ROW; i++){
for(int j = 0; j < LOOKUP; j++){
for(int k = 0; k < MAINMAX+1; k++){
anabe[i][j][k] = 0;
}
}
System.out.print(".");
}
for(int i = 0; i < ROW; i++){
for(int j = 0; j < LOOKUP; j++){
for(int k = 0; k < MAINMAX+1; k++){
anaaf[i][j][k] = 0;
}
}
System.out.print(".");
}
for(int i = 0; i < ROW; i++){
for(int j = 0; j < LOOKUP; j++){
for(int k = 0; k < SPMAX+1; k++){
anaspbe[i][j][k] = 0;
}
}
System.out.print(".");
}
for(int i = 0; i < ROW; i++){
for(int j = 0; j < LOOKUP; j++){
for(int k = 0; k < SPMAX+1; k++){
anaspaf[i][j][k] = 0;
}
}
System.out.print(".");
}
for(int i = 0; i < ROW; i++){
for(int j = 0; j < MAINMAX+1; j++){
statMAINp3be[i][j] = 0;
}
System.out.print(".");
}
for(int i = 0; i < ROW; i++){
for(int j = 0; j < MAINMAX+1; j++){
statMAINp3af[i][j] = 0;
}
System.out.print(".");
}
for(int i = 0; i < ROW; i++){
for(int j = 0; j < SPMAX+1; j++){
statSPp3be[i][j] = 0;
}
System.out.print(".");
}
for(int i = 0; i < ROW; i++){
for(int j = 0; j < SPMAX+1; j++){
statSPp3af[i][j] = 0;
}
System.out.print(".");
}
for(int i = 0; i < ROW; i++){
for(int j = 0; j < MAINMAX+1; j++){
statMAINp3beS[i][j] = '*';
}
System.out.print(".");
}
for(int i = 0; i < ROW; i++){
for(int j = 0; j < SPMAX+1; j++){
statSPp3beS[i][j] = '*';
}
System.out.print(".");
}
System.out.print("\n");
System.out.print("讀入資料並統計 ");
READLINE = br.readLine();
ReadCount++;
while(READLINE != null && ReadCount <= ROW+1){
//System.out.println(READLINE);
LINE = READLINE.split(",");
for(int i = 0; i < LINE.length; i++){
ReadNum = -1;
ReadNum = Integer.parseInt(LINE[i]);
//System.out.print(ReadNum + " ");
data[ReadCount-2][i] = ReadNum;
}
System.out.print(".");
READLINE = br.readLine();
ReadCount++;
}
System.out.print("\n");
//Close data file
br.close();
//For debug
/*for(int i = 0; i < ROW; i++){
for(int j = 0; j < MAINNUM+SPNUM; j++){
System.out.print(data[i][j] + " ");
}
System.out.print("\n");
}*/
for(int i = 0; i < ROW; i++){
for(int j = 0; j < MAINNUM+SPNUM; j++){
for(int l = 0; l < LOOKUP; l++){
if(j < MAINNUM+SPNUM-1){
//Main forward lookup
if( i-l-1 >=0 ){
anaaf[i-l-1][l][data[i][j]]++;
anaaf[i-l-1][l][0]++;
}
//Main backward lookup
if( i+l+1 < ROW ){
anabe[i+l+1][l][data[i][j]]++;
anabe[i+l+1][l][0]++;
}
}else{
//Special forward lookup
if( i-l-1 >=0 ){
anaspaf[i-l-1][l][data[i][j]]++;
anaspaf[i-l-1][l][0]++;
}
//Special backward lookup
if( i+l+1 < ROW ){
anaspbe[i+l+1][l][data[i][j]]++;
anaspbe[i+l+1][l][0]++;
}
}
}
}
}
System.out.println("顯示統計結果並輸出檔案 ");
//Define seperate string
String SPSTR = "------ ------ ------ ------ ------ ------";
//
// Part III AdvSummary
//
//Define if fix BEGINROW
boolean BRstatus = false;
try{
if(STATFNADD != ""){ STATFN3 = "number-stat3-" + STATFNADD + ".txt"; }
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(STATFN3)));
System.out.println("分析三 依數字加總次數觀察");
pw.println("分析三 依數字加總次數觀察");
//Define summary count
int asum = 0;
if(BEGINROW -3 >= 0){ BEGINROW-=3; BRstatus = true; }
System.out.println("一 主要區");
pw.println("一 主要區");
System.out.println("(一) 前期出現次數");
pw.println("(一) 前期出現次數");
for(int i = 0; i < MAINMAX+1; i++){
if(i == 0){
System.out.print("Total\t");
pw.print("Total\t");
} else {
System.out.printf("%3d",i);
pw.printf("%3d",i);
}
}
System.out.print("\n");
pw.print("\n");
for(int i = BEGINROW; i < ROW; i++){
for(int k = 0, j = 0; k < MAINMAX+1; k++){
if(k == 0){
System.out.printf("%5d\t",i+1);
pw.printf("%5d\t",i+1);
} else if(k == data[i][j] && j < MAINNUM){
System.out.printf("%3s"," +");
pw.printf("%3s"," +");
j++;
} else {
System.out.printf("%3s"," ");
pw.printf("%3s"," ");
}
}
System.out.print("\n");
pw.print("\n");
for(int j = 0; j < MAINMAX+1; j++){
asum = 0;
for(int r = 0; r < LOOKUP/BASE; r++){
for(int l = 0; l < BASE*(r+1); l++){
asum+=anabe[i][l][j];
}
}
if(j == 0){
System.out.printf("%5d\t",asum);
pw.printf("%5d\t",asum);
} else {
System.out.printf("%3d",asum);
pw.printf("%3d",asum);
}
statMAINp3be[i][j] = asum;
}
System.out.print("\n");
pw.print("\n");
}
System.out.print("\n\n");
pw.print("\n\n");
System.out.print("統計分析\n");
pw.print("統計分析\n");
int MAXSCORE = 100;
int DISTSCORE = 10;
int BASESCALE = -1;
int[] statBingo = new int[MAXSCORE/DISTSCORE];
int[] statBASE = new int[MAXSCORE/DISTSCORE];
for(int i = 0; i < statBingo.length; i++){ statBingo[i] = 0; }
for(int i = 0; i < statBASE.length; i++){ statBASE[i] = 0; }
for(int i = BEGINROW; i < ROW; i++){
for(int j = 0; j < MAINNUM; j++){
if(i > 0){
if(statMAINp3be[i-1][data[i][j]] >= MAXSCORE){
statBingo[statBingo.length-1]++;
} else {
statBingo[statMAINp3be[i-1][data[i][j]]/DISTSCORE]++;
}
}
}
}
for(int i = BEGINROW; i < ROW-1; i++){
for(int j = 1; j < MAINMAX+1; j++){
BASESCALE = statMAINp3be[i][j]/DISTSCORE;
if(BASESCALE >= MAXSCORE/DISTSCORE){
statBASE[statBASE.length-1]++;
} else {
statBASE[BASESCALE]++;
}
}
}
System.out.print("Range ");
pw.print("Range ");
for(int i = 0; i < statBingo.length; i++){
System.out.printf(" %3d~%3d",i*DISTSCORE,(i+1)*DISTSCORE-1);
pw.printf(" %3d~%3d",i*DISTSCORE,(i+1)*DISTSCORE-1);
}
System.out.print("\n");
pw.print("\n");
System.out.print("Count ");
pw.print("Count ");
for(int i = 0; i < statBingo.length; i++){
System.out.printf(" %3d/%3d",statBingo[i],statBASE[i]);
pw.printf(" %3d/%3d",statBingo[i],statBASE[i]);
}
System.out.print("\n");
pw.print("\n");
System.out.print("Prob ");
pw.print("Prob ");
for(int i = 0; i < statBingo.length; i++){
if(statBASE[i] == 0){
System.out.printf(" N/A");
pw.printf(" N/A");
} else {
System.out.printf(" %.3f",(float)statBingo[i]/(float)statBASE[i]);
pw.printf(" %.3f",(float)statBingo[i]/(float)statBASE[i]);
}
}
System.out.print("\n\n");
pw.print("\n\n");
System.out.println("(二) 後期出現次數");
pw.println("(二) 後期出現次數");
for(int i = 0; i < MAINMAX+1; i++){
if(i == 0){
System.out.print("Total\t");
pw.print("Total\t");
} else {
System.out.printf("%3d",i);
pw.printf("%3d",i);
}
}
System.out.print("\n");
pw.print("\n");
for(int i = BEGINROW; i < ROW; i++){
for(int k = 0, j = 0; k < MAINMAX+1; k++){
if(k == 0){
System.out.printf("%5d\t",i+1);
pw.printf("%5d\t",i+1);
} else if(k == data[i][j] && j < MAINNUM){
System.out.printf("%3s"," +");
pw.printf("%3s"," +");
j++;
} else {
System.out.printf("%3s"," ");
pw.printf("%3s"," ");
}
}
System.out.print("\n");
pw.print("\n");
for(int j = 0; j < MAINMAX+1; j++){
asum = 0;
for(int r = 0; r < LOOKUP/BASE; r++){
for(int l = 0; l < BASE*(r+1); l++){
asum+=anaaf[i][l][j];
}
}
if(j == 0){
System.out.printf("%5d\t",asum);
pw.printf("%5d\t",asum);
} else {
System.out.printf("%3d",asum);
pw.printf("%3d",asum);
}
statMAINp3af[i][j] = asum;
}
System.out.print("\n");
pw.print("\n");
}
System.out.print("\n\n");
pw.print("\n\n");
System.out.println("二 特別區號碼");
pw.println("二 特別區號碼");
System.out.println("(一) 前期出現次數");
pw.println("(一) 前期出現次數");
for(int i = 0; i < SPMAX+1; i++){
if(i == 0){
System.out.print("Total\t");
pw.print("Total\t");
} else {
System.out.printf("%3d",i);
pw.printf("%3d",i);
}
}
System.out.print("\n");
pw.print("\n");
for(int i = BEGINROW; i < ROW; i++){
for(int k = 0, j = MAINNUM; k < SPMAX+1; k++){
if(k == 0){
System.out.printf("%5d\t",i+1);
pw.printf("%5d\t",i+1);
} else if(j < MAINNUM+SPNUM && k == data[i][j]){
System.out.printf("%3s"," +");
pw.printf("%3s"," +");
j++;
} else {
System.out.printf("%3s"," ");
pw.printf("%3s"," ");
}
}
System.out.print("\n");
pw.print("\n");
for(int j = 0; j < SPMAX+1; j++){
asum = 0;
for(int r = 0; r < LOOKUP/BASE; r++){
for(int l = 0; l < BASE*(r+1); l++){
asum+=anaspbe[i][l][j];
}
}
if(j == 0){
System.out.printf("%5d\t",asum);
pw.printf("%5d\t",asum);
} else {
System.out.printf("%3d",asum);
pw.printf("%3d",asum);
}
statSPp3be[i][j] = asum;
}
System.out.print("\n");
pw.print("\n");
}
System.out.print("\n\n");
pw.print("\n\n");
System.out.print("統計分析\n");
pw.print("統計分析\n");
MAXSCORE = 100;
DISTSCORE = 10;
BASESCALE = -1;
int[] statBingoSP = new int[MAXSCORE/DISTSCORE];
int[] statBASESP = new int[MAXSCORE/DISTSCORE];
for(int i = 0; i < statBingoSP.length; i++){ statBingoSP[i] = 0; }
for(int i = 0; i < statBASESP.length; i++){ statBASESP[i] = 0; }
for(int i = BEGINROW; i < ROW; i++){
for(int j = MAINNUM; j < MAINNUM+SPNUM; j++){
if(i > 0){
if(statSPp3be[i-1][data[i][j]] >= MAXSCORE){
statBingoSP[statBingoSP.length-1]++;
} else {
statBingoSP[statSPp3be[i-1][data[i][j]]/DISTSCORE]++;
}
}
}
}
for(int i = BEGINROW; i < ROW-1; i++){
for(int j = 1; j < SPMAX+1; j++){
BASESCALE = statSPp3be[i][j]/DISTSCORE;
if(BASESCALE >= MAXSCORE/DISTSCORE){
statBASESP[statBASE.length-1]++;
} else {
statBASESP[BASESCALE]++;
}
}
}
System.out.print("Range ");
pw.print("Range ");
for(int i = 0; i < statBingoSP.length; i++){
System.out.printf(" %3d~%3d",i*DISTSCORE,(i+1)*DISTSCORE-1);
pw.printf(" %3d~%3d",i*DISTSCORE,(i+1)*DISTSCORE-1);
}
System.out.print("\n");
pw.print("\n");
System.out.print("Count ");
pw.print("Count ");
for(int i = 0; i < statBingoSP.length; i++){
System.out.printf(" %3d/%3d",statBingoSP[i],statBASESP[i]);
pw.printf(" %3d/%3d",statBingoSP[i],statBASESP[i]);
}
System.out.print("\n");
pw.print("\n");
System.out.print("Prob ");
pw.print("Prob ");
for(int i = 0; i < statBingoSP.length; i++){
if(statBASESP[i] == 0){
System.out.printf(" N/A");
pw.printf(" N/A");
} else {
System.out.printf(" %.3f",(float)statBingoSP[i]/(float)statBASESP[i]);
pw.printf(" %.3f",(float)statBingoSP[i]/(float)statBASESP[i]);
}
}
System.out.print("\n\n");
pw.print("\n\n");
System.out.println("(二) 後期出現次數");
pw.println("(二) 後期出現次數");
for(int i = 0; i < SPMAX+1; i++){
if(i == 0){
System.out.print("Total\t");
pw.print("Total\t");
} else {
System.out.printf("%3d",i);
pw.printf("%3d",i);
}
}
System.out.print("\n");
pw.print("\n");
for(int i = BEGINROW; i < ROW; i++){
for(int k = 0, j = MAINNUM; k < SPMAX+1; k++){
if(k == 0){
System.out.printf("%5d\t",i+1);
pw.printf("%5d\t",i+1);
} else if(j < MAINNUM+SPNUM && k == data[i][j]){
System.out.printf("%3s"," +");
pw.printf("%3s"," +");
j++;
} else {
System.out.printf("%3s"," ");
pw.printf("%3s"," ");
}
}
System.out.print("\n");
pw.print("\n");
for(int j = 0; j < SPMAX+1; j++){
asum = 0;
for(int r = 0; r < LOOKUP/BASE; r++){
for(int l = 0; l < BASE*(r+1); l++){
asum+=anaspaf[i][l][j];
}
}
if(j == 0){
System.out.printf("%5d\t",asum);
pw.printf("%5d\t",asum);
} else {
System.out.printf("%3d",asum);
pw.printf("%3d",asum);
}
statSPp3af[i][j] = asum;
}
System.out.print("\n");
pw.print("\n");
}
System.out.print("\n\n");
pw.print("\n\n");
//Close file
pw.close();
} catch(IOException e){
System.out.println("無法開啟檔案 " + STATFN3);
System.exit(1);
}
//
// Part III plus : Trend
//
//Fix BEGINROW
if(BRstatus){ BEGINROW+=3; }
try{
if(STATFNADD != ""){ STATFN3p = "number-stat3p-" + STATFNADD + ".txt"; }
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(STATFN3p)));
System.out.println("分析三+ 趨勢分析");
pw.println("分析三+ 趨勢分析");
System.out.println("一 主要區");
pw.println("一 主要區");
System.out.println("(一) 前期出現次數");
pw.println("(一) 前期出現次數");
for(int i = 0; i < MAINMAX+1; i++){
if(i == 0){
System.out.print("Num \t");
pw.print("Num \t");
} else {
System.out.printf("%3d",i);
pw.printf("%3d",i);
}
}
System.out.print("\n");
pw.print("\n");
for(int i = BEGINROW; i < ROW; i++){
for(int k = 0, j = 0; k < MAINMAX+1; k++){
if(k == 0){
System.out.printf("%5d\t",i+1);
pw.printf("%5d\t",i+1);
} else if(k == data[i][j] && j < MAINNUM){
System.out.printf("%3s"," +");
pw.printf("%3s"," +");
j++;
} else {
System.out.printf("%3s"," ");
pw.printf("%3s"," ");
}
}
System.out.print("\n");
pw.print("\n");
if(i >= 3){
for(int j = 0; j < MAINMAX+1; j++){
if( j == 0){
System.out.printf("%5s\t","");
pw.printf("%5s\t","");
} else {
if((statMAINp3be[i-3][j] > statMAINp3be[i-2][j])&&(statMAINp3be[i-2][j] > statMAINp3be[i-1][j])){
System.out.printf("%3s"," -");
pw.printf("%3s"," -");
statMAINp3beS[i][j] = '-';
} else if((statMAINp3be[i-3][j] < statMAINp3be[i-2][j])&&(statMAINp3be[i-2][j] < statMAINp3be[i-1][j])){
System.out.printf("%3s"," +");
pw.printf("%3s"," +");
statMAINp3beS[i][j] = '+';
} else if(((statMAINp3be[i-3][j] < statMAINp3be[i-2][j])&&(statMAINp3be[i-2][j] == statMAINp3be[i-1][j]))||((statMAINp3be[i-3][j] == statMAINp3be[i-2][j])&&(statMAINp3be[i-2][j] < statMAINp3be[i-1][j]))){
System.out.printf("%3s"," !");
pw.printf("%3s"," !");
statMAINp3beS[i][j] = '!';
} else if(((statMAINp3be[i-3][j] > statMAINp3be[i-2][j])&&(statMAINp3be[i-2][j] == statMAINp3be[i-1][j]))||((statMAINp3be[i-3][j] == statMAINp3be[i-2][j])&&(statMAINp3be[i-2][j] > statMAINp3be[i-1][j]))){
System.out.printf("%3s"," _");
pw.printf("%3s"," _");
statMAINp3beS[i][j] = '_';
} else if(((statMAINp3be[i-3][j] > statMAINp3be[i-2][j])&&(statMAINp3be[i-2][j] < statMAINp3be[i-1][j]))||((statMAINp3be[i-3][j] < statMAINp3be[i-2][j])&&(statMAINp3be[i-2][j] > statMAINp3be[i-1][j]))){
System.out.printf("%3s"," <");
pw.printf("%3s"," <");
statMAINp3beS[i][j] = '<';
} else if(((statMAINp3be[i-3][j] == statMAINp3be[i-2][j])&&(statMAINp3be[i-2][j] == statMAINp3be[i-1][j]))||((statMAINp3be[i-3][j] == 0)&&(statMAINp3be[i-2][j] == 0)&&(statMAINp3be[i-1][j] == 0))){
System.out.printf("%3s"," ?");
pw.printf("%3s"," ?");
statMAINp3beS[i][j] = '?';
} else {
System.out.printf("%3s"," ");
pw.printf("%3s"," ");
statMAINp3beS[i][j] = ' ';
}
}
}
}
System.out.print("\n");
pw.print("\n");
}
System.out.print("\n\n");
pw.print("\n\n");
System.out.print("統計分析\n");
pw.print("統計分析\n");
// '+' 0 '!' 1 '-' 2 '_' 3 '<' 4 '?' 5 ' ' 6
char[] SYM = {'+', '!', '-', '_', '<', '?', ' ', 'U'};
int[] statBingoSYM = new int[SYM.length];
int[] statBASESYM = new int[SYM.length];
for(int i = 0; i < statBingoSYM.length; i++){ statBingoSYM[i] = 0; }
for(int i = 0; i < statBASESYM.length; i++){ statBASESYM[i] = 0; }
int SYMID = 7;
for(int i = BEGINROW; i < ROW; i++){
for(int j = 0; j < MAINNUM; j++){
SYMID = 7;
if(i > 0){
switch(statMAINp3beS[i-1][data[i][j]]){
case '+': SYMID = 0;
break;
case '!': SYMID = 1;
break;
case '-': SYMID = 2;
break;
case '_': SYMID = 3;
break;
case '<': SYMID = 4;
break;
case '?': SYMID = 5;
break;
case ' ': SYMID = 6;
break;
default: SYMID = 7;
}
statBingoSYM[SYMID]++;
}
}
}
for(int i = BEGINROW; i < ROW-1; i++){
for(int j = 1; j < MAINMAX+1; j++){
switch(statMAINp3beS[i][j]){
case '+': SYMID = 0;
break;
case '!': SYMID = 1;
break;
case '-': SYMID = 2;
break;
case '_': SYMID = 3;
break;
case '<': SYMID = 4;
break;
case '?': SYMID = 5;
break;
case ' ': SYMID = 6;
break;
default: SYMID = 7;
}
statBASESYM[SYMID]++;
}
}
System.out.print("Symbol ");
pw.print("Symbol ");
for(int i = 0; i < SYM.length; i++){
System.out.printf(" %c",SYM[i]);
pw.printf(" %c",SYM[i]);
}
System.out.print("\n");
pw.print("\n");
System.out.print("Count ");
pw.print("Count ");
for(int i = 0; i < SYM.length; i++){
System.out.printf("%3d/%3d",statBingoSYM[i],statBASESYM[i]);
pw.printf("%3d/%3d",statBingoSYM[i],statBASESYM[i]);
}
System.out.print("\n");
pw.print("\n");
System.out.print("Prob ");
pw.print("Prob ");
for(int i = 0; i < SYM.length; i++){
if(statBASESYM[i] == 0){
System.out.printf(" N/A");
pw.printf(" N/A");
} else {
System.out.printf(" %.3f",(float)statBingoSYM[i]/(float)statBASESYM[i]);
pw.printf(" %.3f",(float)statBingoSYM[i]/(float)statBASESYM[i]);
}
}
System.out.print("\n\n");
pw.print("\n\n");
System.out.println("二 特別區號碼");
pw.println("二 特別區號碼");
System.out.println("(一) 前期出現次數");
pw.println("(一) 前期出現次數");
for(int i = 0; i < SPMAX+1; i++){
if(i == 0){
System.out.print("Num \t");
pw.print("Num \t");
} else {
System.out.printf("%3d",i);
pw.printf("%3d",i);
}
}
System.out.print("\n");
pw.print("\n");
for(int i = BEGINROW; i < ROW; i++){
for(int k = 0, j = MAINNUM; k < SPMAX+1; k++){
if(k == 0){
System.out.printf("%5d\t",i+1);
pw.printf("%5d\t",i+1);
} else if(j < MAINNUM+SPNUM && k == data[i][j]){
System.out.printf("%3s"," +");
pw.printf("%3s"," +");
j++;
} else {
System.out.printf("%3s"," ");
pw.printf("%3s"," ");
}
}
System.out.print("\n");
pw.print("\n");
if( i > 3 ){
for(int j = 0; j < SPMAX+1; j++){
if( j == 0){
System.out.printf("%5s\t","");
pw.printf("%5s\t","");
} else {
if((statSPp3be[i-3][j] > statSPp3be[i-2][j])&&(statSPp3be[i-2][j] > statSPp3be[i-1][j])){
System.out.printf("%3s"," -");
pw.printf("%3s"," -");
statSPp3beS[i][j] = '-';
} else if((statSPp3be[i-3][j] < statSPp3be[i-2][j])&&(statSPp3be[i-2][j] < statSPp3be[i-1][j])){
System.out.printf("%3s"," +");
pw.printf("%3s"," +");
statSPp3beS[i][j] = '+';
} else if(((statSPp3be[i-3][j] < statSPp3be[i-2][j])&&(statSPp3be[i-2][j] == statSPp3be[i-1][j]))||((statSPp3be[i-3][j] == statSPp3be[i-2][j])&&(statSPp3be[i-2][j] < statSPp3be[i-1][j]))){
System.out.printf("%3s"," !");
pw.printf("%3s"," !");
statSPp3beS[i][j] = '!';
} else if(((statSPp3be[i-3][j] > statSPp3be[i-2][j])&&(statSPp3be[i-2][j] == statSPp3be[i-1][j]))||((statSPp3be[i-3][j] == statSPp3be[i-2][j])&&(statSPp3be[i-2][j] > statSPp3be[i-1][j]))){
System.out.printf("%3s"," _");
pw.printf("%3s"," _");
statSPp3beS[i][j] = '_';
} else if(((statSPp3be[i-3][j] > statSPp3be[i-2][j])&&(statSPp3be[i-2][j] < statSPp3be[i-1][j]))||((statSPp3be[i-3][j] < statSPp3be[i-2][j])&&(statSPp3be[i-2][j] > statSPp3be[i-1][j]))){
System.out.printf("%3s"," <");
pw.printf("%3s"," <");
statSPp3beS[i][j] = '<';
} else if(((statSPp3be[i-3][j] == statSPp3be[i-2][j])&&(statSPp3be[i-2][j] == statSPp3be[i-1][j]))||((statSPp3be[i-3][j] == 0)&&(statSPp3be[i-2][j] == 0)&&(statSPp3be[i-1][j] == 0))){
System.out.printf("%3s"," ?");
pw.printf("%3s"," ?");
statSPp3beS[i][j] = '?';
} else {
System.out.printf("%3s"," ");
pw.printf("%3s"," ");
statSPp3beS[i][j] = ' ';
}
}
}
}
System.out.print("\n");
pw.print("\n");
}
System.out.print("\n\n");
pw.print("\n\n");
System.out.print("統計分析\n");
pw.print("統計分析\n");
int[] statBingoSYMSP = new int[SYM.length];
int[] statBASESYMSP = new int[SYM.length];
for(int i = 0; i < statBingoSYMSP.length; i++){ statBingoSYMSP[i] = 0; }
for(int i = 0; i < statBASESYMSP.length; i++){ statBASESYMSP[i] = 0; }
for(int i = BEGINROW; i < ROW; i++){
for(int j = MAINNUM; j < MAINNUM+SPNUM; j++){
SYMID = 7;
if(i > 0){
switch(statSPp3beS[i-1][data[i][j]]){
case '+': SYMID = 0;
break;
case '!': SYMID = 1;
break;
case '-': SYMID = 2;
break;
case '_': SYMID = 3;
break;
case '<': SYMID = 4;
break;
case '?': SYMID = 5;
break;
case ' ': SYMID = 6;
break;
default: SYMID = 7;
}
statBingoSYMSP[SYMID]++;
}
}
}
for(int i = BEGINROW; i < ROW-1; i++){
for(int j = 1; j < SPMAX+1; j++){
switch(statSPp3beS[i][j]){
case '+': SYMID = 0;
break;
case '!': SYMID = 1;
break;
case '-': SYMID = 2;
break;
case '_': SYMID = 3;
break;
case '<': SYMID = 4;
break;
case '?': SYMID = 5;
break;
case ' ': SYMID = 6;
break;
default: SYMID = 7;
}
statBASESYMSP[SYMID]++;
}
}
System.out.print("Symbol ");
pw.print("Symbol ");
for(int i = 0; i < SYM.length; i++){
System.out.printf(" %c",SYM[i]);
pw.printf(" %c",SYM[i]);
}
System.out.print("\n");
pw.print("\n");
System.out.print("Count ");
pw.print("Count ");
for(int i = 0; i < SYM.length; i++){
System.out.printf("%3d/%3d",statBingoSYMSP[i],statBASESYMSP[i]);
pw.printf("%3d/%3d",statBingoSYMSP[i],statBASESYMSP[i]);
}
System.out.print("\n");
pw.print("\n");
System.out.print("Prob ");
pw.print("Prob ");
for(int i = 0; i < SYM.length; i++){
if(statBASESYMSP[i] == 0){
System.out.printf(" N/A");
pw.printf(" N/A");
} else {
System.out.printf(" %.3f",(float)statBingoSYMSP[i]/(float)statBASESYMSP[i]);
pw.printf(" %.3f",(float)statBingoSYMSP[i]/(float)statBASESYMSP[i]);
}
}
System.out.print("\n\n");
pw.print("\n\n");
System.out.println("程式分析完畢.");
//Close file
pw.close();
} catch(IOException e){
System.out.println("無法開啟檔案 " + STATFN3p);
System.exit(1);
}
} catch(IOException e){
System.out.println("找不到資料來源檔案 " + DATAFN);
System.out.println("使用預設檔名 " + DEFAULTDATAFN + "\t請使用 java NumberStat3");
System.out.println("使用指定檔案 PATH/to/FN\t\t請使用 java NumberStat3 PATH/to/FN");
System.exit(1);
}
}
}
資料檔格式
[[[ Setting ]]]
Row 1
ROW,MAINNUM,SPNUM,MAINMAX,SPMAX,LOOKUP,BASE,BEGINROW,STATFNADD
------------------------------- ++++++++++++++++++++++++++++++
Essential Parameter Optional Parameter
ROW data row number = total row number - 1
MAINNUM Main area number
SPNUM Special area number
MAINMAX Max value of main area
SPMAX Max value of special area
LOOKUP default : 15 (rows)
BASE default : 3 (rows)
BEGINROW default : 0 (row number)
STATFNADD default : empty
[[[ Data ]]]
Row 2
MainNum_1,MainNum_2,...,MainNum_MAINNUM,SPNum_1,...,SPNum_SPNUM
...
Row ROW+1
MainNum_1,MainNum_2,...,MainNum_MAINNUM,SPNum_1,...,SPNum_SPNUM
測試資料
12,6,1,38,8,12,2,10,20120928test
3,4,16,18,36,37,2
2,14,15,16,28,29,8
6,9,11,13,19,23,2
2,6,10,18,23,26,5
6,20,26,33,34,35,5
2,4,11,22,23,25,8
7,13,28,33,35,38,6
5,7,15,28,35,37,6
1,20,22,23,29,38,3
9,15,16,34,36,37,5
6,13,16,29,33,36,4
13,14,24,25,26,35,3
輸出的分析結果
number-stat3-20120928test.txt
分析三 依數字加總次數觀察
一 主要區
(一) 前期出現次數
Total 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
7 + + + + + +
180 0 15 4 10 0 16 0 0 5 5 11 0 5 4 4 8 0 9 5 6 0 6 16 0 6 11 0 4 4 0 0 0 6 6 6 4 4 0
8 + + + + + +
198 0 15 3 9 0 14 6 0 4 5 10 0 10 4 4 7 0 8 4 5 0 6 15 0 6 10 0 10 4 0 0 0 11 5 11 3 3 6
9 + + + + + +
216 0 12 3 8 6 13 12 0 4 4 9 0 10 3 9 6 0 7 4 5 0 5 13 0 5 9 0 15 3 0 0 0 11 5 17 3 9 6
10 + + + + + +
228 6 12 2 7 6 11 11 0 3 4 8 0 8 3 9 5 0 6 3 10 0 11 18 0 5 8 0 14 9 0 0 0 9 4 15 2 8 11
11 + + + + + +
240 6 9 2 6 5 10 10 0 9 3 7 0 8 2 13 10 0 5 3 10 0 10 16 0 4 7 0 12 8 0 0 0 9 10 14 8 13 11
12 + + + + + +
246 5 9 1 5 5 14 9 0 8 3 6 0 12 2 13 15 0 4 2 8 0 9 14 0 4 6 0 11 13 0 0 0 13 9 12 13 12 9
統計分析
Range 0~ 9 10~ 19 20~ 29 30~ 39 40~ 49 50~ 59 60~ 69 70~ 79 80~ 89 90~ 99
Count 33/146 3/ 44 0/ 0 0/ 0 0/ 0 0/ 0 0/ 0 0/ 0 0/ 0 0/ 0
Prob 0.226 0.068 N/A N/A N/A N/A N/A N/A N/A N/A
(二) 後期出現次數
Total 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
7 + + + + + +
156 6 0 0 0 6 5 6 0 5 0 0 0 9 4 11 10 0 0 0 6 0 6 6 4 4 4 0 6 11 0 0 0 5 5 10 10 11 6
8 + + + + + +
132 6 0 0 0 0 5 0 0 6 0 0 0 10 5 6 11 0 0 0 6 0 6 6 5 5 5 0 0 11 0 0 0 5 6 5 11 6 6
9 + + + + + +
102 0 0 0 0 0 6 0 0 6 0 0 0 11 5 6 12 0 0 0 0 0 0 0 5 5 5 0 0 6 0 0 0 6 6 5 12 6 0
10 + + + + + +
72 0 0 0 0 0 6 0 0 0 0 0 0 12 6 0 6 0 0 0 0 0 0 0 6 6 6 0 0 6 0 0 0 6 0 6 6 0 0
11 + + + + + +
36 0 0 0 0 0 0 0 0 0 0 0 0 6 6 0 0 0 0 0 0 0 0 0 6 6 6 0 0 0 0 0 0 0 0 6 0 0 0
12 + + + + + +
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
二 特別區號碼
(一) 前期出現次數
Total 1 2 3 4 5 6 7 8
7 +
30 0 9 0 0 11 0 0 10
8 +
33 0 7 0 0 10 6 0 10
9 +
36 0 7 0 0 9 12 0 8
10 +
38 0 5 6 0 8 11 0 8
11 +
40 0 5 6 0 13 10 0 6
12 +
41 0 3 5 6 12 9 0 6
統計分析
Range 0~ 9 10~ 19 20~ 29 30~ 39 40~ 49 50~ 59 60~ 69 70~ 79 80~ 89 90~ 99
Count 6/ 32 0/ 8 0/ 0 0/ 0 0/ 0 0/ 0 0/ 0 0/ 0 0/ 0 0/ 0
Prob 0.188 0.000 N/A N/A N/A N/A N/A N/A N/A N/A
(二) 後期出現次數
Total 1 2 3 4 5 6 7 8
7 +
26 0 0 10 5 5 6 0 0
8 +
22 0 0 11 5 6 0 0 0
9 +
17 0 0 5 6 6 0 0 0
10 +
12 0 0 6 6 0 0 0 0
11 +
6 0 0 6 0 0 0 0 0
12 +
0 0 0 0 0 0 0 0 0
number-stat3p-20120928test.txt
分析三+ 趨勢分析
一 主要區
(一) 前期出現次數
Num 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
10 + + + + + +
? _ _ - ! - + ? _ _ - ? ! _ ! - ? - _ _ ? _ - ? _ - ? + _ ? ? ? ! _ + _ < !
11 + + + + + +
! _ _ - ! - < ? _ _ - ? _ _ ! - ? - _ ! ? < < ? _ - ? < < ? ? ? _ _ < _ < !
12 + + + + + +
! _ _ - _ - - ? < _ - ? _ _ ! < ? - _ ! ? < < ? _ - ? - < ? ? ? _ < - < < !
統計分析
Symbol + ! - _ < ? U
Count 0/ 3 2/ 10 3/ 13 5/ 23 1/ 8 1/ 19 0/ 0 6/ 0
Prob 0.000 0.200 0.231 0.217 0.125 0.053 N/A N/A
二 特別區號碼
(一) 前期出現次數
Num 1 2 3 4 5 6 7 8
10 +
? _ ? ? - + ? _
11 +
? _ ! ? - < ? _
12 +
? _ ! ? < - ? _
統計分析
Symbol + ! - _ < ? U
Count 0/ 1 1/ 1 0/ 2 0/ 4 0/ 1 1/ 7 0/ 0 1/ 0
Prob 0.000 1.000 0.000 0.000 0.000 0.143 N/A N/A
No comments:
Post a Comment