Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

Sujet : J'ai besoin d'aide s’il vous plaît... [ Algorithme / Autre ] (jorgeflorencio)

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é dans : string, result, area, avg, inspectionresults44


Répondre à ce message

Sujets en rapport avec ce message

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 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 une banque en java [ par shadowcat1 ] bonjour a tousj'ai un probleme d'appel de methode. j'ai tout essayé mais ca ne marche pas.ca concerne la creation d'un compte pour une personne(soit m Vercor [ par mariam1987 ] Salut a tous.je commence a programmer en java et j'ai ecrit un morceau de code  qui ne marche pas et je ne sais pas ou est le probleme::  import java. convertir String en monetaire [ par kam81 ] Bonjour,Je voudrais convertir le contenu d'un jTextField en type monetaire pour l'inserer dans une base access.Merci. Souci de comparaison entre 2 String avec substring [ par Boowiss ] Bien le bonjour à vous :Donc je voudrais avoir quelques renseignements actuellement, je développe une sorte de "msn" perso, en java, dont les trames s java jdbc mysql [ par paranouya ] bonjours;je suis entraine de la réalisation d'une application mais pour la classe de l'authentification j'ai réalisé le code suivant import java.awt.* comprarer 2 date [ par simeone1 ] salut tt le mondeje suis vraiement un débutant en java et je viens vers vous afin de bien vouloir m'aider pour resoudre mon probleme, vous en remercia Classe connection pour mysql [ par mimi1255 ] Bonjour, je veux créer une classe permettant de se connecter ou se déconnecter de ma base de donnée.J'ai fait ceci, mais je ne suis pas du tout sur de difference entre parseint et integer.valueof [ par sikove ] salut,il y'a une difference entre parseint(string) et Integer.valueof(string).intvalue() ? j'entend souvent parler de parseint pour la convertion vers


Nos sponsors

Sondage...

CalendriCode

Décembre 2008
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

Téléchargements



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, 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
Temps d'éxécution de la page : 0,234 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.