2015-01-08 5 views
0

내 안드로이드 애플리케이션에서 그래프로 나타낼 데이터 포인트가 포함 된 텍스트 파일을 읽으려고합니다. 각 파일의 데이터 포인트 수는 24,000에서 150,000 사이 여야합니다.GraphView를 사용하여 텍스트 파일의 데이터를 읽고 그래프로 표시

현재 압축 텍스트 파일에서 데이터를 읽고 로컬 벡터에 저장하는 비동기 작업을 구현했습니다. 작업이 완료되면 데이터 포인트가 그래프로 표시되도록 데이터 세트에 추가됩니다.

class ReadFileService extends AsyncTask<Void, String, Boolean> { 

    @Override 
    protected Boolean doInBackground(Void... args) {   
     Scanner strings = null; 
     InputStream stream = null; 
     ZipInputStream zipInput = null; 
     try { 
      System.out.println(externalStorageDirectory + Constants.APP_DIRECTORY + recordingName + Constants.ZIP_FILE_EXTENTION); 
      File file = new File(externalStorageDirectory + Constants.APP_DIRECTORY, recordingName + Constants.ZIP_FILE_EXTENTION); 
      ZipFile zipFile = new ZipFile(file); 
      Enumeration<? extends ZipEntry> entries = zipFile.entries(); 

      while (entries.hasMoreElements()) { 
       ZipEntry zipEntry = entries.nextElement(); 
       stream = zipFile.getInputStream(zipEntry); 
       strings = new Scanner(stream); 

       // Extract the value of sampling frequency from header 
       System.out.println("Extracting value of sampling frequency."); 
       String regexPattern = "\"ColumnLabels\""; 
       strings.useDelimiter(regexPattern); 
       String extracted = strings.next(); 
       Pattern pattern = Pattern.compile("\"SamplingFrequency\": \"(\\d+)\""); 
       Matcher matcher = pattern.matcher(extracted); 
       if (matcher.find()) { 
        samplingFrequency = Integer.parseInt(matcher.group(1)); 
        System.out.println(samplingFrequency); 
       } 

       // Locate the end of the header and use tabs as the delimiter 
       strings.findWithinHorizon(endOfHeader,0);   
       strings.useDelimiter("\t *"); 
       strings.next(); 
      } 
     } 
     catch (FileNotFoundException error) { 
      System.out.println("@IOERROR: " + error); 
      return false; 
     } 
     catch (IOException error) { 
      System.out.println("@IOERROR: " + error); 
      return false; 
     } 
     while (strings.hasNext()) 
     { 
      // Get raw value of data point 
      double dataPoint = Double.parseDouble(strings.next()); 
      // Convert data point into the proper scale 
      dataSet.add(SensorDataConverter.scaleEMG(dataPoint)); 
      // Skip the index value if it exists and break from loop if it does not 
      if (strings.hasNext()) 
       strings.next(); 
      else 
       break; 
     } 
     System.out.println("Closing strings."); 
     try { 
      stream.close(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     strings.close();    
     return true; 
    } 

    protected void onProgressUpdate(String...progress) { 
     //called when the background task makes any progress 
    } 

    protected void onPreExecute() { 
     //called before doInBackground() is started 
     super.onPreExecute(); 
     // Show Progress Bar Dialog before calling doInBackground method 
     prgDialog.setTitle("Opening File"); 
     prgDialog.setMessage("Opening " + recordingName + "\nPlease wait..."); 
     prgDialog.show(); 
    } 

    //called after doInBackground() has finished 
    protected void onPostExecute(Boolean readFileSuccess) { 
     // If unable to read from file, print error and generate a random set of sample data 
     if(!readFileSuccess) { 
      Random randomGenerator = new Random();   
      System.out.println("@IOERROR: Unable to read from file. Creating random dataset"); 
      for(int i=0; i<100; i++) 
      { 
       dataSet.add(randomGenerator.nextDouble()); 
      } 
     } 
     // Create a set of graph data to use with GraphView 
     exampleSeries1 = new GraphViewSeries(new GraphViewData[] { 
     }); 
     for (int i=0; i<dataSet.size(); i++) { 
      double pointX = i; 
      double pointY = dataSet.get(i); 
      exampleSeries1.appendData(new GraphViewData(pointX, pointY), true, dataSet.size()); 
     } 
     // Plot the data points 
     graphData(); 
     prgDialog.dismiss(); 
     prgDialog = null; 
    } 
} 

이 약 10,000 개의 데이터 포인트를 저장하고로드 할 때 작업 표시 및로드 약 15 초 정도 소요 다음과 같이

비동기 작업에 대한 코드의 구현입니다. 그러나 데이터 포인트 수가 20,000 개로 증가하면로드하는 데 최대 45 초가 소요됩니다.

내 주요 질문 : 데이터를로드하는 데 필요한 시간을 최소화하기 위해이 모든 데이터를보다 효율적으로 처리하는 또 다른 방법이 있습니까? 예를 들어,보기 포트 범위에 따라 데이터 포인트를 동적으로 그래프로 표시 할 수 있습니까?

도움과 제안을 많이 주시면 감사하겠습니다.

답변

0

데이터 포인트를 더 적게 사용하려면 데이터를 리샘플링해야합니다. 일반적으로 단일 뷰포트에 100 개 이상의 데이터 포인트를 플롯하는 것은 의미가 없습니다.

과 성능을 개선하기 위해 수동 뷰포트 및 수동 라벨 너비/높이를 사용

나는 이러한 경우가있는 것을 두려워
+0

는 ...이있는에서 사용자를 제한하는 것처럼 이러한 불편을이 작업을 수행 할 것으로 보인다 그래프를 수동으로 스크롤하고 크기를 조정할 수있는 유연성. 그러나 입력 내용에 감사드립니다. 현재 파일 읽기 속도를 향상시키기 위해 노력하고 있지만 도움이되지 않는다면 제안을 시도 할 것입니다. – oruok