1 24 25 26 31 32 package org.objectweb.clif.analyser; 33 34 35 import javax.swing.*; 36 import java.io.*; 37 import java.util.StringTokenizer ; 38 import java.lang.Math .*; 39 import java.util.ArrayList ; 40 import java.lang.Object ; 41 import java.lang.Float ; 42 import java.util.Arrays ; 43 44 public class Fonction { 45 46 public static ArrayList X = new ArrayList (); 47 public static ArrayList Y = new ArrayList (); 48 public static ArrayList time = new ArrayList (); 49 public static ArrayList TableauAug= new ArrayList (); 50 public static ArrayList TableauDim= new ArrayList (); 51 public static ArrayList TableauStation= new ArrayList (); 52 public static ArrayList Pente = new ArrayList (); 53 public static ArrayList PenteReg= new ArrayList (); 54 public static ArrayList Penteaug= new ArrayList (); 55 public static ArrayList Pentedim= new ArrayList (); 56 public static ArrayList Pentestation= new ArrayList (); 57 public static int ifric = 0; 58 59 60 61 public Fonction(){ 66 } 67 68 69 public static void fonctionMax(View vue){ 71 String file = "report/" + vue.getTestId() + "/vues/" + vue.getName() + ".view" ; 72 parseFile(file); 73 float[] res = new float[2]; 74 res = maximum(); 75 String result = "Le maximum pour la vue "+vue.getName()+" est le point: ("+res[1]+","+res[0]+")"; 76 vue.setResult(result); 77 AutomaticAnalyser.updateDecisionTree(vue,0,res[0]); 78 } 79 80 public static void fonctionMin(View vue){ 82 83 String file = "report/" + vue.getTestId() + "/vues/" + vue.getName() + ".view" ; 84 parseFile(file); 85 float[] res = new float[2]; 86 res=minimum(); 87 String result = "Le minimum pour la vue "+vue.getName()+" est le point: ("+res[1]+","+res[0]+")"; 88 vue.setResult(result); 89 AutomaticAnalyser.updateDecisionTree(vue,1,res[0]); 90 } 92 93 public static float[] maximum(){ 95 float[] max = new float[2]; 96 max[0] = ((Float )Y.get(0)).floatValue(); 97 max[1] = ((Float )X.get(0)).floatValue(); 98 int i=0; 99 while(i < Y.size()) 100 { 101 if(max[0] < ((Float )Y.get(i)).floatValue()) 102 { 103 max[0] = ((Float )Y.get(i)).floatValue(); 104 max[1] = ((Float )X.get(i)).floatValue(); 105 } 106 i++; 107 } 108 return max; 109 } 111 public static float[] minimum(){ 113 float[] min = new float[2]; 114 min[0] = ((Float )Y.get(0)).floatValue(); 115 min[1] = ((Float )X.get(0)).floatValue(); 116 int i=0; 117 while(i< Y.size()){ 118 if(min[0] > ((Float )Y.get(i)).floatValue()) 119 { 120 min[0] = ((Float )Y.get(i)).floatValue(); 121 min[1] = ((Float )X.get(i)).floatValue(); 122 } 123 i++; 124 } 125 return min; 126 } 128 129 public static void fonctionEcart(View vue){ 131 132 String file = "report/" + vue.getTestId() + "/vues/" + vue.getName() + ".view" ; 133 parseFile(file); 134 double ecartY=ecartType(); 135 float ecart = (new Float (ecartY)).floatValue(); 136 String result = "l'écart type est de: "+ ecartY; 137 vue.setResult(result); 138 AutomaticAnalyser.updateDecisionTree(vue,3,ecart); 139 140 } 141 142 public static void fonctionPente(View vue){ 144 145 String file = "report/" + vue.getTestId() + "/vues/" + vue.getName() + ".view" ; 146 parseFile(file); 147 Point R= new Point(); 148 float pente = R.Pente(((Float )time.get(0)).floatValue(), ((Float )time.get(time.size()-1)).floatValue()); 149 String result = "la pente de la droite de régression a pour coeficient: "+ pente; 150 vue.setResult(result); 151 AutomaticAnalyser.updateDecisionTree(vue,4,pente); 152 153 } 154 155 156 public static double ecartType(){ 158 int i=0; 159 float SommeCarree = 0.0f; 160 float moy = moyenneY(); 161 while(i< Y.size()){ 162 float diff=(((Float )Y.get(i)).floatValue()-moy)*(((Float )Y.get(i)).floatValue()-moy); 163 SommeCarree= SommeCarree + diff; 164 i++; 165 } 166 return Math.sqrt(SommeCarree/(Y.size())); 167 } 169 170 171 public static void fonctionMoyenne(View vue){ 173 String file = "report/" + vue.getTestId() + "/vues/" + vue.getName() + ".view" ; 174 parseFile(file); 175 float moyY=moyenneY(); 176 String result = "la moyenne est de: "+ moyY ; 177 vue.setResult(result); 178 AutomaticAnalyser.updateDecisionTree(vue,2,moyY); 179 } 180 181 182 public static float moyenneY(){ 184 float somme = 0.0f; 185 int i = 0; 186 while(i< Y.size()){ 187 somme= somme + ((Float )Y.get(i)).floatValue(); 188 i++; 189 } return somme/(Y.size()); 191 } 193 194 195 public static void parseFile(String filelocation){ 197 X.clear(); 199 Y.clear(); 200 time.clear(); 201 try{ 202 String line; 203 FileInputStream fileInput = new FileInputStream(filelocation); 204 BufferedReader file = new BufferedReader(new InputStreamReader(fileInput)); 205 line = file.readLine() ; 206 line = file.readLine() ; 207 while(line!=null){ 208 StringTokenizer st = new StringTokenizer (line,"\t"); 209 X.add(new Float (st.nextToken())); 210 Y.add(new Float (st.nextToken())); 211 time.add(new Float (st.nextToken())); 212 line = file.readLine() ; 213 } 214 } 215 catch (Exception e) { 216 e.printStackTrace() ; 217 System.exit(0) ; 218 } 219 } 221 222 223 public static int rechercheIndiceParam(float valeur, ArrayList param){ 225 for (int i = 0; i< param.size(); i++) 226 if(valeur==((Float )param.get(i)).floatValue()){ 227 return i; 228 } 229 return -1; 230 } 232 233 public static float maximumX(){ 235 236 float max = ((Float )X.get(0)).floatValue(); 237 int i=0; 238 while(i<X.size()){ 239 if(max < ((Float )X.get(i)).floatValue()) 240 max = ((Float )X.get(i)).floatValue(); 241 i++; 242 } 243 return max; 244 } 246 public static float moyenneX(){ 248 249 float somme = 0.0f; 250 int i = 0; 251 while(i< X.size()){ 252 somme= somme + ((Float )X.get(i)).floatValue(); 253 i++; 254 } return somme/(X.size()); 256 } 258 259 260 261 262 263 264 public static String fonctionAugmentReg(View vue,int indice){ 266 267 String file = vue.getTestId() + "_rapport/vues/" + vue.getName() + ".view" ; 268 parseFile(file); 269 Point R=new Point(); 270 271 TableauAug.clear(); 272 float moyx = moyenneX(); 273 float moyy = moyenneY(); 274 float precisionmin = 0.0f; 275 float precisionmax = 1000.0f; 276 float precision = precisionmax; 277 int compteur = 0; 278 long timer = System.currentTimeMillis(); 279 280 while( TableauAug.size() != indice ) 281 { 282 283 if(System.currentTimeMillis() > timer+3000) break; 284 if(TableauAug.size() > indice) precisionmin = precision; 285 else precisionmax = precision; 286 precision = (float) (precisionmin + precisionmax)/2; 287 TableauAug.clear(); 288 R.DecoupageAug(((Float )time.get(0)).floatValue(),((Float )time.get(time.size()-1)).floatValue(), precision, moyx, moyy); 289 compteur++; 290 } 291 float[] tabtab = new float[TableauAug.size()+2]; 292 int i=0; 293 while(i < TableauAug.size()){ 294 tabtab[i] = ((Float )TableauAug.get(i)).floatValue() ; 295 i++; 296 } 297 tabtab[i] = ((Float )time.get(0)).floatValue(); 298 tabtab[i+1] =((Float )time.get(time.size()-1)).floatValue(); 299 Arrays.sort(tabtab); 300 301 302 String result1 = "En "+compteur+" tentatives..." + TableauAug.size() +"coupes: "; 303 i=0; 304 while(i < TableauAug.size()+2){ 305 result1 = result1 + " * " + tabtab[i] ; 306 i++; 307 } 308 vue.setResult(result1); 309 310 return ""; 311 } 313 314 315 316 317 318 319 320 321 322 323 static class Point { float x, y; 325 326 public Point() {x = y = 0.0f;} 327 328 public Point(float x, float y) { 329 this.x = x; 330 this.y = y; 331 } 332 333 public float DistanceEntreDeuxPoints(Point A, Point B,float moyx,float moyy){ 335 float diffx = 100*(B.x-A.x)/moyx; 336 float diffy = 100*(B.y-A.y)/moyy; 337 338 return (float)Math.sqrt(diffx*diffx + diffy*diffy); 339 } 340 341 public void EquationDroite(Point A, Point B){ 343 float coeff =(B.y-A.y)/(B.x-A.x); 344 float origine= B.y-coeff*B.x; 345 346 } 348 349 public Point SolutionSystEquation (Point A, Point B, Point C){ 351 float coef1 = (B.y-A.y)/(B.x-A.x); 352 float b1 = A.y-coef1*A.x; 353 float coef2 = -1/coef1; 354 float b2=C.y+(1/coef1)*C.x; 355 float abs =(b2-b1)/(coef1 - coef2) ; 356 float ord=coef1* abs + b1; 357 Point P= new Point (abs,ord); 358 return P; 359 } 361 362 public float[] couper(float timedeb, float timefin,float moyx, float moyy){ 364 365 float max =0.0f; 366 float [] tab = new float [2]; 367 int d= rechercheIndiceParam(timedeb, time); 368 int f= rechercheIndiceParam(timefin, time); 369 int i=d; 370 Point D = new Point(); 371 Point M = new Point(); 372 Point A =new Point(timedeb,((Float )Y.get(d)).floatValue()); 373 Point B =new Point(timefin,((Float )Y.get(f)).floatValue()); 374 if(f-d < 10) { return tab;} 375 else { i=i+2; f=f-2;} 376 while(i<f){ 377 Point C= new Point(((Float )time.get(i)).floatValue(),((Float )Y.get(i)).floatValue()); 378 if((B.y-A.y)==0) M = new Point(C.x,A.y); 379 else M= SolutionSystEquation (A, B, C); 380 float dist= DistanceEntreDeuxPoints (C, M,moyx,moyy); 381 if(dist > max){ 382 D = C; 383 max = (float) dist; 384 } 385 i++; 386 } 387 tab[0]=D.x; 388 tab[1]=max; 389 return tab; 390 } 392 public ArrayList DecoupageAug(float timedeb, float timefin, float indice, float moyx, float moyy){ 394 396 float[] tab = couper(timedeb, timefin,moyx,moyy); 397 ifric++; 398 399 if(tab[1] > indice){ 400 TableauAug.add(new Float (tab[0])); 401 DecoupageAug(timedeb,tab[0],indice,moyx,moyy); 402 DecoupageAug(tab[0],timefin,indice,moyx,moyy); 403 } 404 return TableauAug; 405 } 407 408 409 public ArrayList TableauFinal(ArrayList tableau){ 411 412 ArrayList TableauFinal= new ArrayList (); 413 int j=0; 414 float [] t = new float [tableau.size()]; 415 while(j<tableau.size()){ 416 t[j]= ((Float )tableau.get(j)).floatValue(); 417 j++; 418 } 419 Arrays.sort(t); 420 int k=1; 421 TableauFinal.add(time.get(0)); 422 while(k < t.length){ 423 TableauFinal.add(new Float (t[k])); 424 k++; 425 } 426 return TableauFinal; 427 } 428 429 430 431 public float PenteEntreDeuxPoints( Point A, Point B){ 433 434 return ((B.y-A.y)/moyenneY())*(moyenneX()/(B.x-A.x)); 435 } 436 437 public float Pente(float deb, float fin){ 439 440 int d = rechercheIndiceParam(deb, time); 441 int f = rechercheIndiceParam(fin, time); 442 int i = d; 443 float p = 0.0f; 444 float carre = 0.0f; 445 while(i <= f){ 446 p=p+ ((Float )X.get(i)).floatValue()*((Float )Y.get(i)).floatValue(); 447 carre=carre+((Float )X.get(i)).floatValue()*((Float )X.get(i)).floatValue(); 448 i++; 449 } 450 float moyParamX = moyenneX(); 451 float moyParamY= moyenneY(); 452 float res = p-((f-d+1)*moyParamX*moyParamY); 453 float res2 = carre-((f-d+1)*moyParamX*moyParamX); 454 return res/res2; 455 } 457 458 public ArrayList StabiliteReg(ArrayList tableau){ 460 461 ArrayList tableauReg = new ArrayList (); 462 PenteReg.clear(); 463 int i=1; 464 int k=0; 465 while(i<tableau.size()){ 466 if(rechercheIndiceParam(((Float )tableau.get(i)).floatValue(), 467 time)-rechercheIndiceParam(((Float )tableau.get(i-1)).floatValue(),time) >=3){ 468 tableauReg.add((Float )tableau.get(i-1)); tableauReg.add((Float )tableau.get(i)); 469 int d = rechercheIndiceParam(((Float )tableau.get(i-1)).floatValue(), time); 470 int f = rechercheIndiceParam(((Float )tableau.get(i)).floatValue(), time); 471 Point A = new Point(((Float )tableau.get(i-1)).floatValue(), ((Float )Y.get(d)).floatValue()); 472 Point B = new Point(((Float )tableau.get(i)).floatValue(), ((Float )Y.get(f)).floatValue()); 473 float pentereg= PenteEntreDeuxPoints(A,B); 474 PenteReg.add(new Float (pentereg)); 475 } 476 i=i+1; 477 k++; 478 } 479 return tableauReg; 480 } 482 public ArrayList AugmentationReg(ArrayList tableau,int indice){ 484 485 ArrayList tableauAug = new ArrayList (); 486 Penteaug.clear(); 487 int i= 0; 488 int j=1; 489 while(j<tableau.size()){ 490 if(((Float )PenteReg.get(i)).floatValue() >= 0.5*50/indice){ 491 tableauAug.add((Float )tableau.get(j-1)); 492 tableauAug.add((Float )tableau.get(j)); 493 Penteaug.add((Float )PenteReg.get(i)); 494 } 495 i++; 496 j=j+2; 497 } 498 return tableauAug; 499 } 501 public ArrayList DimunitionReg(ArrayList tableau, int indice){ 503 504 ArrayList tableauDim= new ArrayList (); 505 Pentedim.clear(); 506 int i=0; 507 int j=1; 508 while(j<tableau.size()){ 509 if(((Float )PenteReg.get(i)).floatValue() <=-0.5*50/indice){ 510 tableauDim.add((Float )tableau.get(j-1)); 511 tableauDim.add((Float )tableau.get(j)); 512 Pentedim.add((Float )PenteReg.get(i)); 513 } 514 i++; 515 j=j+2; 516 } 517 return tableauDim; 518 } 520 public ArrayList StationariteReg(ArrayList tableau, int indice){ 522 523 ArrayList tableauStation = new ArrayList (); 524 Pentestation.clear(); 525 int i=0; 526 int j=1; 527 while(j<tableau.size()){ 528 if((((Float )PenteReg.get(i)).floatValue() < 0.5*50/indice) && ((Float )PenteReg.get(i)).floatValue() > -0.5*50/indice){ 529 tableauStation.add((Float )tableau.get(j-1)); 530 tableauStation.add((Float )tableau.get(j)); 531 Pentestation.add((Float )PenteReg.get(i)); 532 } 533 i++; 534 j=j+2; 535 } 536 return tableauStation; 537 } 539 540 } 542 543 544 545 public static float[] decoupInterval(View vue,int indice){ 547 548 String file = vue.getTestId() + "_rapport/vues/" + vue.getName() + ".view" ; 549 parseFile(file); 550 Point R=new Point(); 551 552 TableauAug.clear(); 553 float moyx = moyenneX(); 554 float moyy = moyenneY(); 555 float precisionmin = 0.0f; 556 float precisionmax = 1000.0f; 557 float precision = precisionmax; 558 int compteur = 0; 559 long timer = System.currentTimeMillis(); 560 561 while( TableauAug.size() != indice ) 562 { 563 564 if(System.currentTimeMillis() > timer+3000) break; 565 if(TableauAug.size() > indice) precisionmin = precision; 566 else precisionmax = precision; 567 precision = (float) (precisionmin + precisionmax)/2; 568 TableauAug.clear(); 569 R.DecoupageAug(((Float )time.get(0)).floatValue(),((Float )time.get(time.size()-1)).floatValue(), precision, moyx, moyy); 570 compteur++; 571 } 572 float[] tabtab = new float[TableauAug.size()+2]; 573 int i=0; 574 while(i < TableauAug.size()){ 575 tabtab[i] = ((Float )TableauAug.get(i)).floatValue() ; 576 i++; 577 } 578 tabtab[i] = ((Float )time.get(0)).floatValue(); 579 tabtab[i+1] =((Float )time.get(time.size()-1)).floatValue(); 580 Arrays.sort(tabtab); 581 582 return tabtab; 583 } 585 586 587 588 589 590 591 592 593 594 595 596 public static String fonctionDiminReg(View vue,int indice){ 598 599 String file = vue.getTestId() + "_rapport/vues/" + vue.getName() + ".view" ; 600 parseFile(file); 601 602 String result1 ="No regular decrease"; 603 604 return result1; 605 } 607 public static String fonctionStationReg(View vue,int indice){ 609 610 String file = vue.getTestId() + "_rapport/vues/" + vue.getName() + ".view" ; 611 parseFile(file); 612 613 String result1 ="No regular stability"; 614 615 return result1; 616 } 617 618 } 619 | Popular Tags |