begin process at 2012 02 14 19:28:57
  Trouver un code source :
 
dans
 
Accueil > Forum > 

JAVA / J2EE / J2ME

 > 

Algorithme

 > 

Autre

 > 

J'ai besoin d'aide s’il vous plaît...


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

J'ai besoin d'aide s’il vous plaît...

jeudi 14 août 2008 à 09:20:03 | J'ai besoin d'aide s’il vous plaît...

jorgeflorencio

Bonsoir...

I have some problem with this Script... that it running well by it self...

package spimonitoring;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.lang.reflect.Array;

public class InspectionResults44{

 public static final byte  HEIGHT_AVG_RESULT = 6,
         HEIGHT_RANGE_RESULT = 11,
         AREA_AVG_RESULT = 16,
         AREA_RANGE_RESULT = 22,
         VOLUME_AVG_RESULT = 29,
         VOLUME_RANGE_RESULT = 28,
         HAV_FAILED_FEATURE_RESULT = 35,
         REG_OFF_RESULT = 38,
         BRIDGE_LEN_RESULT = 41;
 
 private String retrievedData[];
 private boolean failed[];
 
 

 /**
  * Constructs this InspectionResult with the data stored in the args.
  * This class expects 44 values within the range of the args.
  */
 public InspectionResults44(String... args){
  retrievedData = args;
  boolean temp[] ={
   ((retrievedData[6].equalsIgnoreCase("F")) ? true: false),//7
   ((retrievedData[11].equalsIgnoreCase("F")) ? true: false),//12
   ((retrievedData[16].equalsIgnoreCase("F")) ? true: false),//15
   ((retrievedData[22].equalsIgnoreCase("F")) ? true: false),//20
   ((retrievedData[29].equalsIgnoreCase("F")) ? true: false),//23
//   ((retrievedData[28].equalsIgnoreCase("F")) ? true: false),//28
//   ((retrievedData[35].equalsIgnoreCase("F")) ? true: false),
//   ((retrievedData[38].equalsIgnoreCase("F")) ? true: false),
//   ((retrievedData[41].equalsIgnoreCase("F")) ? true: false)
  };
  failed = temp;
 }
 static class MyArrays{  
  public static <T> T[] copyOfRange(T[] array, T[] emptyArray, int from, int size){
   ArrayList<T> temp = new ArrayList<T>(0);
   for(int i = from; i < size; i++){
    temp.add(array[i]);
    }    
   return temp.toArray(emptyArray);
   } 
  }

 public static void main(String... args){

  String line = null;
  
  String Height = null;
  String Area = null;
  String Volume = null;
  String RegOffset = null;
  String Bridging = null;
  
  int countHeight = 0,
   countArea = 0,
   countVolume = 0,
   countRegOffset = 0,
   countBridging = 0;
  
  int countline = 0;
  int startAtLineNo = 7;
  
  FileReader fr = null;
  BufferedReader br = null;
  try{
   fr = new FileReader(new File("K:\\Spi5\\240-25-04-B-02-R1.F.T.#10.489a5f8e.spi.csv"));
   br = new BufferedReader(fr);
  }catch(Exception e){e.printStackTrace();}


  String dwArray[][] ={ {""}, {""}, {""} };

  try {
   while ((line = br.readLine()) != null) {
      if (countline >= startAtLineNo) {
   
       for(int i = 0; i < dwArray.length; i++){
        String temp[] = null;

        try{ temp = br.readLine().split(",");
        }
        catch(Exception f){f.printStackTrace();
        System.exit(1);
        };
        String empty[] = {};
        temp = InspectionResults44.MyArrays.<String>copyOfRange(temp, empty, 1, temp.length);   

        dwArray[i] = temp;
       }


       InspectionResults44 ir[] =
       {
         new InspectionResults44(dwArray[0]),
         new InspectionResults44(dwArray[1]),
         new InspectionResults44(dwArray[2])
       };

       System.out.println(ir[1]); // as an example
       spacer(1);

       try{
      
        System.out.println(ir[0].hasFailed(InspectionResults32.HEIGHT_AVG_RESULT));
        System.out.println(ir[0].getAdjacentValue(InspectionResults32.HEIGHT_AVG_RESULT));
        System.out.println(ir[0].hasFailed(InspectionResults32.AREA_AVG_RESULT));
        System.out.println(ir[0].getAdjacentValue(InspectionResults32.AREA_AVG_RESULT));
        System.out.println(ir[0].hasFailed(InspectionResults32.VOLUME_AVG_RESULT));
        System.out.println(ir[0].getAdjacentValue(InspectionResults32.VOLUME_AVG_RESULT));
        System.out.println(ir[0].hasFailed(InspectionResults32.REG_OFF_RESULT));
        System.out.println(ir[0].getAdjacentValue(InspectionResults32.REG_OFF_RESULT));
        System.out.println(ir[0].hasFailed(InspectionResults32.BRIDGE_LEN_RESULT));
        System.out.println(ir[0].getAdjacentValue(InspectionResults32.BRIDGE_LEN_RESULT));
       }catch(Exception e){
        System.out.println(e);
       }
      }countline++;
   }
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }

 private static void spacer(int lines){
  for(int i = 0; i < lines; i++)
   System.out.println();
 }
 
 /**
  * Returns true if the given value has failed, returns false otherwise.
  * It's preferred to use the constants defined within this class to get the
  * desired information, and not regular ints.
  */
 public boolean hasFailed(byte result) throws Exception{
  switch(result){
   case HEIGHT_AVG_RESULT:
    return failed[0];
   case HEIGHT_RANGE_RESULT:
    return failed[1];
   case AREA_AVG_RESULT:
    return failed[2];
   case AREA_RANGE_RESULT:
    return failed[3];
   case VOLUME_AVG_RESULT:
    return failed[4];
   case VOLUME_RANGE_RESULT:
    return failed[5];
   case HAV_FAILED_FEATURE_RESULT:
    return failed[6];
   case REG_OFF_RESULT:
    return failed[7];
   case BRIDGE_LEN_RESULT:
    return failed[8];
   default :
    throw new Exception("Attempt to access invalid result type! Use the Result Constants to avoid this error!");
  }
 }

 /**
  * Returns the value next to the specified result.
  */
 public String getAdjacentValue(byte result) throws Exception{
  if(result >= 0 && result < retrievedData.length - 1)
   return retrievedData[result + 1];
  else throw new Exception("Error! Attempt to access column with either no adjacent value or outside of data-range!");
 }

 /**
  * Simply returns a String representing the data for each value in this class.
  */
 @Override
 public String toString(){
  String temp = "";
  for(String element : retrievedData){
   if(element.toString() != retrievedData[retrievedData.length - 1])
    temp += element + ", ";
   else temp += element;
  }
  return temp;
 }}

______________________

when reading a csv file with this structure:

,SRFF File: F:\MSA070808\240-25-04-B-02-R1.srf
,Panel Name: Panel Description
,Units: Millimeters

,Date,Time,PanelId,Board,Location,Feature,HeightResult,Height,HeightUpFail,HeightLowFail,HeightTarget,AreaResult,Area,AreaUpFail,AreaLowFail,AreaTarget,VolumeResult,Volume,VolumeUpFail,VolumeLowFail,VolumeTarget,Valid,RegResult,XOffset,YOffset,RegShort%,RegLong%,RegShort%Fail,RegLong%Fail,BridgeResult,BridgeLength,BridgeFail

,08/07/2008,10:28:29,#1,Module 1,U38,Pad1 ,F,0.011466,0.238000,0.084000,0.140000,F,0.027715,0.184884,0.061628,0.123256,F,-0.000145,0.031061,0.008628,0.017256,P,P,-0.027090,-0.011130,10.923388,2.239437,40.000000,40.000000,P,0.000000,0.500000
,08/07/2008,10:28:29,#1,Module 1,U38,Pad2 ,F,0.012471,0.238000,0.084000,0.140000,F,0.028455,0.184884,0.061628,0.123256,F,0.000230,0.031061,0.008628,0.017256,P,P,0.019590,-0.033550,7.899194,6.750503,40.000000,40.000000,P,0.000000,0.500000
,08/07/2008,10:28:29,#1,Module 1,U38,Pad3 ,F,0.020914,0.238000,0.084000,0.140000,W,0.097200,0.184884,0.061628,0.123256,F,0.001631,0.031061,0.008628,0.017256,P,W,0.094300,-0.019680,38.024193,3.959759,40.000000,40.000000,P,0.000000,0.500000

_____________________________

but when i'm using a recursive method:

public  void listRecursively(File fdir, int depth) throws IOException {

  /*Transform milliseconds time to gregorian time */
  long datefiles = fdir.lastModified();
  SimpleDateFormat Date = new SimpleDateFormat (" dd/MM/yyyy , HH:mm:ss aaa");
  Date nDate = new Date(datefiles);

  String F = ",F,";
  String Height = null;
  String Area = null;
  String Volume = null;
  String RegOffset = null;
  String Bridging = null;
  
  String line = null;
  int countline = 0;
  int startAtLineNo = 7; 
  
  int count = 0;
   
  int countHeight = 0,
   countArea = 0,
   countVolume = 0,
   countRegOffset = 0,
   countBridging = 0;

  /*Line counter*/
  try
  {
   RandomAccessFile File = new RandomAccessFile(fdir,"r");
   long lastline=File.length();
   File.close();
   
   FileReader fileRead = new FileReader(fdir);
   BufferedReader bufferReader = new BufferedReader(fileRead);
   String dwArray[][] ={ {""}, {""}, {""} };
   Scanner scan = new Scanner(fdir);
   
   while(scan.hasNextLine())
   {
    if(scan.nextLine().contains(F))
     count++;
   }
   
   fileRead.close();
   bufferReader.close();//___________________________original
   
  InspectionResults44 inspectionResults = new InspectionResults44(line.split(","));
   
   while ((line = bufferReader.readLine()) != null) {
    if (countline >= startAtLineNo) {
     
     if (line.split(",").length == 32){
      HEIGHT_AVG_RESULT = 6;
      AREA_AVG_RESULT = 11;
      VOLUME_AVG_RESULT = 16;
      REG_OFF_RESULT = 22;
      BRIDGE_LEN_RESULT = 29;
     }else{//File with 44
      HEIGHT_AVG_RESULT = 7;
      HEIGHT_RANGE_RESULT = 12;
      AREA_AVG_RESULT = 15;
      AREA_RANGE_RESULT = 20;
      VOLUME_AVG_RESULT = 23;
      VOLUME_RANGE_RESULT = 28;
      HAV_FAILED_FEATURE_RESULT = 35;
      REG_OFF_RESULT = 38;
      BRIDGE_LEN_RESULT = 41;
     }   
     
     try {
      if(inspectionResults.hasFailed(InspectionResults44.HEIGHT_AVG_RESULT)){
       Height = inspectionResults.getAdjacentValue(InspectionResults44.HEIGHT_AVG_RESULT);
       countHeight++;
      }
      if(inspectionResults.hasFailed(InspectionResults44.AREA_AVG_RESULT)){
       Area = inspectionResults.getAdjacentValue(InspectionResults44.AREA_AVG_RESULT);
       countArea++;
      }
      if(inspectionResults.hasFailed(InspectionResults44.VOLUME_AVG_RESULT)){
       Area = inspectionResults.getAdjacentValue(InspectionResults44.VOLUME_AVG_RESULT);
       countVolume++;
      }
      if(inspectionResults.hasFailed(InspectionResults44.REG_OFF_RESULT)){
       Area = inspectionResults.getAdjacentValue(InspectionResults44.REG_OFF_RESULT);
       countRegOffset++;
      }
      if(inspectionResults.hasFailed(InspectionResults44.BRIDGE_LEN_RESULT)){
       Area = inspectionResults.getAdjacentValue(InspectionResults44.BRIDGE_LEN_RESULT);
       countBridging++;
      }}
     catch (Exception e) {
      e.printStackTrace();
     }
     fileRead.close();
     bufferReader.close();
    }}

//   /*Start Line counter mode2*/
//   LineNumberReader lineRead = new LineNumberReader(fileRead);
//   lineRead.skip(lastline);
//   int countline = lineRead.getLineNumber()-6; //number of default lines = 6
//   fileRead.close();
//   lineRead.close();
//   /*End Line counter mode2*/

   /* Output1 */
   if (fdir.getPath().endsWith(".csv") /*&& fdir.lastModified() > HostFile.lastModified()*/)
    System.out.println(INDENTS[depth] + x +", "+fdir.getName() +", "+ count +","+Date.format(nDate) + "," + countHeight + "," + countArea + "," + countVolume + "," + countRegOffset + "," + countBridging);
   /* Output2 */
   if (fdir.getPath().endsWith(".csv") /*&& fdir.lastModified() > HostFile.lastModified()*/)
    fw.write( INDENTS[depth] + x +", "+ fdir.getName() +", "+ count +","+ Date.format(nDate)+ System.getProperty("line.separator"));
   fw.flush();
   //if (fdir.getPath().endsWith(".csv") && (fdir.length()/512 )>= 1 && fdir.length()/512 <= 3) 
  }
  catch(IOException e){
  }
  if (fdir.isDirectory() && !fdir.isHidden() && depth < MAX_DEPTH) {
   for (File f : fdir.listFiles()){  // Go over each file/subdirectory.
    listRecursively(f, depth+1);
   }}}

Its giving me an error in this line

InspectionResults44 inspectionResults = new InspectionResults44(line.split(","));


java.lang.NullPointerException
 at spimonitoring.SpimonitoringFrame.listRecursively(SpimonitoringFrame.java:4984)
 at spimonitoring.SpimonitoringFrame.listRecursively(SpimonitoringFrame.java:5056)
 at spimonitoring.SpimonitoringFrame$Start.doInBackground(SpimonitoringFrame.java:418)
 at spimonitoring.SpimonitoringFrame$Start.doInBackground(SpimonitoringFrame.java:1)
 at org.jdesktop.swingworker.SwingWorker$1.call(Unknown Source)
 at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
 at java.util.concurrent.FutureTask.run(Unknown Source)
 at org.jdesktop.swingworker.SwingWorker.run(Unknown Source)
 at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)

Can Anyone help me please...

 

Thank you Very much... Mercy!

 

Regards,
jorge



Cette discussion est classée dans : string, result, area, avg, inspectionresults44


Répondre à ce message

Sujets en rapport avec ce message

connexion à une base de données à chaque intervalle de temps [ par irann ] Bonjour à tous!Salut !je veus faire une connexion à la base de données à chaque intervale de temps (par exemple chaque 2 secondes).j'ai une  procédure smylies-html-url-chat [ par deiz21 ] Bonjour a tous,actuellement j'essai d'améliorer une application de chat que j'ai développé il y a déjà un bout de temps.mon problème se situe au nivea Logiciel de gestion d'une association. Demande d'aide et de conseils [ par lamarmaille ] Bonjour à tous. Avant toute chose, je tiens à préciser que je suis en général plutôt du genre à me débrouiller tout seul, en faisant des erreurs et e Au secours [ par Sabola ] Bonjour, je suis débutant en JAVA POO et on me demande d'écrire une Class Livre avec les attributs suivants: - titre : Le titre du livre, - auteur convertire string en date en gardant la même format [ par tunisiano22 ] Bonjour, SVp est ce qu'il ya qq qui peut me dire comment je peux convertire un String en une date tout en gardant la même format: "jour.mois.année" requete ne fonctionne pas [ par 208893 ] bonjour mes amies; j'ai un problème au niveau du requête sql elle affiche un message d'erreur lorsque je l'exécute voila le code [code=java]savebtn.a les vars String dans les .class [ par nethacker ] Bonjour, Je me demande comment peut-on cacher ou éventuellement crypter les variables de type String, ou tout autre solution qui pourrait éviter que dechiffrement aes [ par assoumaomri ] salut, je veux faire un algorithme de chiffrement AES.c'est le code que j'ai utilisé: import java.io.IOException; import java.io.UnsupportedEncoding besoin d'aide [ par zaeinouba ] salut j suis une debutante en programation voici mon code j'arrive pas à le compiler si c possible aidez moi merci d'avance import javax.swing.*; Programme calculateur de temps [ par coulva ] Bonjour, J'ai un programme a réaliser qui calcul le temps d'utilisation d'une salle. J'ai mis à peu près tout ce qu'il fallait mais je ne trouve pas m


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,388 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales