1 24 25 26 30 31 32 33 package org.objectweb.clif.analyser; 34 35 import java.io.*; 36 import java.util.*; 37 import java.lang.Math ; 38 import org.objectweb.clif.analyser.lib.gui.GuiPanelAutomaticAnalyser; 39 40 41 42 public class AutomaticAnalyser 43 { 44 45 46 private static GuiPanelAutomaticAnalyser guipanelautomaticanalyser; 47 private static Rule[] rules = new Rule[100]; 48 private static DecisionTree dt = new DecisionTree(); 49 private static Brain[] brain = new Brain[100]; 50 private static int nbminthread; 51 private static int maxtime; 52 private static String [][] testmachine = new String [100][100]; 53 54 55 public AutomaticAnalyser() 56 { 57 58 59 } 60 61 62 public AutomaticAnalyser(GuiPanelAutomaticAnalyser gpaa) 63 { 64 this.guipanelautomaticanalyser = gpaa; 65 } 66 67 68 69 public void start() 70 { 71 listerFichier(); 72 guipanelautomaticanalyser.updateViewTree(); 73 } 74 75 76 public static String [][] newrule(String name, String hyp, String test, String machine, String thread, int X, int Y, String interval, int fonction, String fresult) 77 { 78 int i,j; 79 String [][] result = new String [100][100]; 80 for(i=0; rules[i] != null; i++) 81 if(rules[i].getName().equals(name)) 82 { 83 rules[i].updateRule(hyp,test,machine,thread,X,Y,interval,fonction,fresult); 84 break; 85 } 86 if(rules[i]==null) 87 { 88 rules[i] = new Rule(name,hyp,test,machine,thread,X,Y,interval,fonction,fresult); 89 brain[i] = new Brain(rules[i],nbminthread,maxtime,testmachine); 90 } 91 for(i=0; rules[i] != null; i++) 92 { 93 result[i][0] = rules[i].getName(); 94 for(j=0; rules[i].hyp[j] != null; j++) result[i][j+1] = rules[i].hyp[j].getName(); 95 result[i][j+1] = null; 96 } 97 result[i][0] = null; 98 99 return result; 100 } 101 102 public static String [][] erase(String name, String hyp) 103 { 104 int i,j; 105 String [][] result = new String [100][100]; 106 for(i=0; rules[i] != null; i++) 107 if(rules[i].getName().equals(name)) 108 { 109 rules[i].eraseHyp(name,hyp); 110 break; 111 } 112 if(rules[i]==null) System.out.println("la regle "+name+" n'existe pas ! impossible de l'effacer..."); 113 for(i=0; rules[i] != null; i++) 114 { 115 result[i][0] = rules[i].getName(); 116 for(j=0; rules[i].hyp[j] != null; j++) result[i][j+1] = rules[i].hyp[j].getName(); 117 result[i][j+1] = null; 118 } 119 result[i][0] = null; 120 121 return result; 122 } 123 124 public void eraseRule(String name) 125 { 126 int i,j; 127 for(i=0; rules[i] != null; i++) 128 if(rules[i].getName().equals(name)) 129 { 130 for(j=i; rules[j] != null; j++) rules[j] = rules[j+1]; 131 } 132 } 133 134 135 136 public void start(String name) 137 { 138 int i; 139 140 for(i=0; rules[i] != null; i++) if(rules[i].getName().equals(name)) break; 141 if(rules[i] == null) System.out.println("la regle "+name+" n'existe pas ! desolé"); 142 else { 143 rules[i].start(); 144 brain[i].start(); 145 } 146 } 147 148 149 public void stop(String name) 150 { 151 int i; 152 for(i=0; rules[i] != null; i++) if(rules[i].getName().equals(name)) break; 153 if(rules[i] == null) System.out.println("la regle "+name+" n'existe pas ! desolé"); 154 else { 155 rules[i].stop(); 156 brain[i].stop(); 157 } 158 } 159 160 public static void updateDecisionTree(View vue, int fonction, float result) 161 { 162 if(fonction > 4) System.out.println("rien pour l'instant"); 163 else { 164 String temp = vue.getDatedebut()+"-"+vue.getDatefin(); 165 int tempbis = vue.getNumthread(); 166 int tempter = 0; int tempquatro = 0; dt.remplirArbre(vue.getTestId(),vue.getNommachine(),tempbis,tempter,tempquatro,temp,fonction,result); 169 } 170 171 } 172 173 public static DecisionTree getDecisionTree() 174 { 175 return dt; 176 } 177 178 179 180 181 182 183 184 public static Hypothesis wichHypNamed(String rule,String hyp) 185 { 186 Rule r = null; 187 Hypothesis h = null;; 188 189 for(int i=0; rules[i] != null ;i++) 190 { 191 if(rules[i].getName().equals(rule)) r = rules[i]; 192 } 193 for(int i=0; r.hyp[i] != null ;i++) 194 { 195 if(r.hyp[i].getName().equals(hyp)) h = r.hyp[i]; 196 } 197 return h; 198 199 } 200 201 202 203 204 205 206 207 208 209 210 211 212 213 public static void listerFichier() 215 { 216 FileInputStream fileInput; 217 BufferedReader file ; 218 String line; 219 StringTokenizer st; 220 String [][] donnees = new String [100][100]; 221 222 File homeDir = new File("./"); 223 String [] contient= new String [100]; 224 contient = homeDir.list(); 225 int j=0; 226 for (int i=0;i<contient.length ; i++) 227 { 228 if(contient[i].endsWith("_rapport")) contient[j++] = contient[i]; 229 } 230 contient[j] = null; 232 int minth = 100000; 233 int maxti = 0; 234 try{ 235 int i; 236 237 for ( i=0;contient[i] != null ;i++) 238 { 239 st = new StringTokenizer(contient[i],"_"); 240 donnees[i][0] = st.nextToken(); 241 fileInput = new FileInputStream(contient[i] + "/description.txt" ); 242 file = new BufferedReader(new InputStreamReader(fileInput)); 243 line = file.readLine() ; 244 int k=1; 245 while (line!=null) 246 { 247 if(line.startsWith("Injector")) 248 { 249 st = new StringTokenizer(line," "); 250 st.nextToken(); 251 donnees[i][k] = st.nextToken(); 252 k++; 253 } 254 if(line.startsWith("argument")) 255 { 256 st = new StringTokenizer(line," "); 257 st.nextToken(); st.nextToken(); 258 int th = (new Integer (st.nextToken())).intValue(); 259 int ti = (new Integer (st.nextToken())).intValue(); 260 ti=ti*1000; 261 if(minth > th) minth = th; 262 if(maxti < ti) maxti = ti; 263 } 264 line = file.readLine() ; 265 } 266 } 267 } 268 catch (Exception e) { 269 e.printStackTrace() ; 270 System.exit(0) ; 271 } 272 273 testmachine = donnees; 274 nbminthread = minth; 275 maxtime = maxti; 276 } 277 278 279 281 282 public static void trier(String nomdemachine) 283 { 284 285 FileInputStream fileInput; 286 BufferedReader file ; 287 PrintStream pfile[] = new PrintStream[3]; 288 StringTokenizer st; 289 String line = null ; 290 int no = 0; 291 int i=0; 292 int j=0; 293 int dateobservee[] = new int[25000]; 294 int datetheorique[] = new int[25000]; 295 int dateecriture[] = new int[25000]; 296 int index = 0; 297 int temp = 0; 298 int tempbis = 0; 299 int tempter = 0; 300 int tempquatro =0; 301 int toto[] = new int[25000]; 302 303 try { 304 305 fileInput = new FileInputStream("toto_rapport/archive.clif"); 306 file = new BufferedReader(new InputStreamReader(fileInput)); 307 line = file.readLine() ; 308 while(line != null) 309 { 310 st = new StringTokenizer(line,";") ; 311 st.nextToken() ; 312 no = (new Integer (st.nextToken())).intValue() ; 313 314 if(no == 2) 315 { st = new StringTokenizer(line,";") ; 317 temp = (new Integer (st.nextToken())).intValue() ; 318 for ( i=0; i<2 ; i++) st.nextToken() ; 319 tempbis = (new Integer (st.nextToken())).intValue() ; 320 if(tempbis == 1) 321 { 322 tempquatro = (new Integer (st.nextToken())).intValue() ; 323 for ( i=0; i<3 ; i++) st.nextToken() ; 324 tempter = (new Integer (st.nextToken())).intValue() ; 325 dateobservee[index] = temp; 326 datetheorique[index] = tempter; 327 dateecriture[index] = tempquatro; 328 index +=1; 329 } 330 331 } 332 333 334 line = file.readLine() ; 335 } 336 } 337 catch (Exception e) { 338 e.printStackTrace() ; 339 System.exit(0) ; 340 } 341 342 343 try { FileOutputStream fileout1 = new FileOutputStream("toto_rapport/vues/toto.view"); 345 int ecartobserver = 0; 346 int ecarttheorique = 0; 347 348 pfile[0] = new PrintStream(fileout1); 349 datetheorique[0] = dateobservee[0] ; 350 for (i=1; i<index ; i++) 351 { 352 toto[i-1] = (dateobservee[i] - dateobservee[i-1] ) - datetheorique[i]; 353 pfile[0].println( toto[i-1] ); 354 355 } 356 357 } 358 catch (Exception e) { 359 e.printStackTrace() ; 360 System.exit(0) ; 361 } 362 363 float moyenne = 0 ; 364 int max = toto[0]; 365 int min = toto[0]; 366 367 for (i=0; i < index-1 ; i++) 368 { 369 if(toto[i] > max) max = toto[i]; 370 if(toto[i] < min) min = toto[i]; 371 moyenne += toto[i]; 372 373 } 374 375 moyenne = moyenne/(index-1); 376 378 float moyennebasse = moyenne - 5*moyenne/100; 379 float moyennehaute = moyenne + 5*moyenne/100; 380 int tititi=0; 381 float resultpc = 0; 382 383 for (i=0; i < index-1 ; i++) 384 { 385 if((toto[i] > moyennehaute)||(toto[i] < moyennebasse)){ 386 tititi++; 387 System.out.println(tititi); 388 389 } 390 } 391 System.out.println(tititi); 392 393 if(tititi == 0) resultpc = 0; 394 else resultpc = 100 - ((float) (tititi*100)/(float) (index-1)); 395 396 int doushka = (index-1) - (95*(index-1)/100); 398 float titi=0; 399 float val = 0; 400 int indicetableau=0; 401 402 while(doushka >0) 403 { 404 405 titi=0; 406 for (i=0; i < index-1 ; i++) 407 { 408 val = java.lang.Math.abs( toto[i] - moyenne); 409 if(val > titi) 410 { 411 412 titi = val; 413 indicetableau = i; 414 } 415 } 416 toto[indicetableau] = (int) moyenne; 417 System.out.println(toto[indicetableau]); 418 419 System.out.println("on vire "+ titi + " a la position "+(indicetableau+1)); 420 doushka--; 421 } 422 423 424 int newmax=(int) moyenne; 425 int newmin=(int) moyenne; 426 for (i=0; i < index-1 ; i++) 427 { 428 if(toto[i] > newmax) newmax = toto[i]; 429 if(toto[i] < newmin) newmin = toto[i]; 430 } 431 float limitebasse = (moyenne - newmin)/moyenne*100; 432 float limitehaute = (newmax - moyenne)/moyenne*100; 433 434 435 System.out.println("moyenne : " + moyenne + "\tmax : " + max + "\tmin : " + min); 436 System.out.println("limite haute : +"+limitehaute+"% de la moyenne" +"limite basse : -"+limitebasse+"% de la moyenne"); 437 System.out.println("% des valeures a + ou - 5% de la moyenne : " + resultpc+"%"); 438 439 440 441 442 } 443 444 } 445 | Popular Tags |