OSDN Git Service

enhance: LAT&LONの欄の幅を変更
authorhayashi <hayashi.yuu@gmail.com>
Sat, 3 Jun 2017 13:10:29 +0000 (22:10 +0900)
committerhayashi <hayashi.yuu@gmail.com>
Sat, 3 Jun 2017 13:10:29 +0000 (22:10 +0900)
importPicture/AdjustTime.ini
importPicture/AdjustTime.ini.org
importPicture/src/osm/jp/gpx/ImportPicture.java
importPicture/test/osm/jp/gpx/ImportPictureTest.java
importPicture/test/osm/jp/gpx/utils/TarGz.java [moved from importPicture/test/osm/jp/gpx/TarGz.java with 98% similarity]

index ad911f6..f3fed27 100644 (file)
@@ -1,17 +1,17 @@
 #by AdjustTime
-#Sat May 20 20:05:59 JST 2017
+#Sat Jun 03 22:01:29 JST 2017
 GPX.BASETIME=FILE_UPDATE
 IMG.OUTPUT_EXIF=true
 GPX.OUTPUT_WPT=false
-GPX.OUTPUT_SPEED=false
+GPX.OUTPUT_SPEED=true
 IMG.OUTPUT_ALL=false
 GPX.noFirstNode=true
 IMG.OUTPUT=true
 GPX.gpxSplit=true
-IMG.TIME=2017-05-18T09\:20\:30
-GPX.OVERWRITE_MAGVAR=false
+IMG.TIME=2017-05-29T10\:31\:46
+GPX.OVERWRITE_MAGVAR=true
 GPX.REUSE=false
-IMG.BASE_FILE=20170518_092031A.jpg
-IMG.SOURCE_FOLDER=./testdata/cameradata
-GPX.SOURCE_FOLDER=./testdata/cameradata/20170518.gpx
+IMG.BASE_FILE=20170529_103146A.jpg
+IMG.SOURCE_FOLDER=./testdata/cameradata/separate
+GPX.SOURCE_FOLDER=./testdata/cameradata/separate.gpx
 IMG.OUTPUT_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/testdata/output
index 0ca8258..16100cd 100644 (file)
@@ -1,17 +1,17 @@
 #by AdjustTime
-#Sat May 20 20:05:52 JST 2017
-GPX.BASETIME=FILE_UPDATE
+#Sat Jun 03 22:00:34 JST 2017
+GPX.BASETIME=EXIF_TIME
 IMG.OUTPUT_EXIF=true
 GPX.OUTPUT_WPT=false
-GPX.OUTPUT_SPEED=false
-IMG.OUTPUT_ALL=true
+GPX.OUTPUT_SPEED=true
+IMG.OUTPUT_ALL=false
 GPX.noFirstNode=true
 IMG.OUTPUT=true
 GPX.gpxSplit=true
-IMG.TIME=2017-05-18T09\:20\:30
-GPX.OVERWRITE_MAGVAR=false
+IMG.TIME=2017-05-29T10\:31\:46
+GPX.OVERWRITE_MAGVAR=true
 GPX.REUSE=false
-IMG.BASE_FILE=20170518_092031A.jpg
-IMG.SOURCE_FOLDER=./testdata/cameradata
-GPX.SOURCE_FOLDER=./testdata/cameradata/20170518.gpx
+IMG.BASE_FILE=20170529_103146A.jpg
+IMG.SOURCE_FOLDER=./testdata/cameradata/separate
+GPX.SOURCE_FOLDER=./testdata/cameradata/separate.gpx
 IMG.OUTPUT_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/testdata/output
index c53411a..c3b4f35 100644 (file)
@@ -249,14 +249,15 @@ public class ImportPicture extends Thread {
        if ((paramStr != null) && (paramStr.equals(Boolean.toString(true)))) {\r
                obj.exif = true;\r
        }\r
-\r
+       \r
         System.out.println(" - param: imgDir = '"+ obj.imgDir.getAbsolutePath() +"'");\r
         System.out.println(" - param: outDir = '"+ (obj.outDir == null ? "" : obj.outDir.getAbsolutePath()) +"'");\r
         System.out.println(" - param: gpxDir = '"+ (obj.gpxDir == null ? "" : obj.gpxDir.getAbsolutePath()) +"'");\r
         System.out.println(" - param: number of gpxFiles = '"+ obj.gpxFiles.size() +"'");\r
         System.out.println(" - param: "+ AppParameters.GPX_GPXSPLIT +"="+ obj.param_GpxSplit);\r
         System.out.println(" - param: "+ AppParameters.GPX_NO_FIRST_NODE +"="+ obj.param_GpxNoFirstNode);        \r
-        System.out.println(" - param: "+ AppParameters.GPX_REUSE +"="+ obj.param_GpxReuse);        \r
+        System.out.println(" - param: "+ AppParameters.GPX_REUSE +"="+ obj.param_GpxReuse);\r
+        System.out.println(" - param: "+ AppParameters.IMG_BASE_FILE +"="+ obj.params.getProperty(AppParameters.IMG_BASE_FILE) );\r
         System.out.println(" - param: "+ AppParameters.GPX_BASETIME +"="+ obj.params.getProperty(AppParameters.GPX_BASETIME) );\r
         System.out.println(" - param: "+ AppParameters.IMG_OUTPUT +"="+ obj.params.getProperty(AppParameters.IMG_OUTPUT));     \r
         System.out.println(" - param: "+ AppParameters.IMG_OUTPUT_ALL +"="+ obj.param_ImgOutputAll);\r
@@ -466,11 +467,11 @@ public class ImportPicture extends Thread {
                 \r
                System.out.println("GPX start time: "+ dfjp.format(new Date(gpxStartTime)) + "\t[GMT " + dfuk.format(new Date(gpxStartTime))+"]");\r
                System.out.println("  GPX end time: "+ dfjp.format(new Date(gpxEndTime)) + "\t[GMT " + dfuk.format(new Date(gpxEndTime))+"]");\r
-               System.out.println("------------------------|--------------------|--------------------|------------|------------|--------|------|------|");\r
-               System.out.println(" name                   | UpdateTime         | GPStime            | Latitude   | Longitude  | ele    |magvar| km/h |");\r
-               System.out.println("------------------------|--------------------|--------------------|------------|------------|--------|------|------|");\r
+               System.out.println("------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|");\r
+               System.out.println(" name                   | UpdateTime         | GPStime            |   Latitude   |   Longitude  | ele    |magvar| km/h |");\r
+               System.out.println("------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|");\r
                proc(imgDir, delta, gpxStartTime, gpxEndTime, map, exif, gpx);\r
-               System.out.println("------------------------|--------------------|--------------------|------------|------------|--------|------|------|");\r
+               System.out.println("------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|");\r
 \r
         // 出力\r
         outputFile.getParentFile().mkdirs();\r
@@ -581,7 +582,7 @@ public class ImportPicture extends Thread {
                 if (trkptT.speedStr != null) {\r
                        speedStr = new String(trkptT.speedStr);\r
                 }\r
-                System.out.print(String.format("%12s %12s|", (new Double(latitude)).toString(), (new Double(longitude)).toString()));\r
+                System.out.print(String.format("%-14s %-14s|", (new Double(latitude)).toString(), (new Double(longitude)).toString()));\r
                 System.out.println(String.format("%8s|%6s|%6s|", eleStr, magvarStr, speedStr));\r
             }\r
 \r
index 5eb6292..83bf1f3 100644 (file)
@@ -3,17 +3,24 @@ package osm.jp.gpx;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.*;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.nio.channels.FileChannel;
 
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.*;
 import org.junit.experimental.runners.Enclosed;
 
 import hayashi.tools.files.DeleteDir;
+import osm.jp.gpx.utils.TarGz;
 
 @RunWith(Enclosed.class)
 public class ImportPictureTest {
@@ -34,7 +41,7 @@ public class ImportPictureTest {
                        outDir.mkdir();
                        
                        // カメラディレクトリを作成する
-                       TarGz.uncompress(new File("testdata", "Sony20170518.tar.gz"), dir);
+                       uncompress(new File("testdata", "Sony20170518.tar.gz"), dir);
                        
                        // GPXファイルをセット
                try (   FileInputStream inStream = new FileInputStream(new File("testdata", "20170518.gpx"));
@@ -251,4 +258,166 @@ public class ImportPictureTest {
                        }
                }
        }
+
+       public static class GPXが複数のTRKSEGに分割している場合 {
+               
+               @Before
+               public void setUp() throws Exception {
+                       // カメラディレクトリを削除する
+                       File dir = new File("testdata/cameradata");
+                       if (dir.exists()) {
+                               DeleteDir.delete(dir);
+                       }
+                       File outDir = new File("testdata/output");
+                       if (outDir.exists()) {
+                               DeleteDir.delete(outDir);
+                       }
+                       outDir.mkdir();
+                       
+                       // カメラディレクトリを作成する
+                       TarGz.uncompress(new File("testdata", "separate.tar.gz"), dir);
+                       
+                       // GPXファイルをセット
+               try (   FileInputStream inStream = new FileInputStream(new File("testdata", "separate.gpx"));
+                               FileOutputStream outStream = new FileOutputStream(new File("testdata/cameradata/separate.gpx"));
+                       FileChannel inChannel = inStream.getChannel();
+                       FileChannel outChannel = outStream.getChannel();        )
+               {
+                   inChannel.transferTo(0, inChannel.size(), outChannel);
+               }
+               
+               // プロパティファイルを設定
+                       File iniFile = new File("AdjustTime.ini");
+                       File orgFile = new File("AdjustTime.ini.org");
+                       File testFile = new File("testdata", "AdjustTime.separate.ini");
+                       if (orgFile.exists()) {
+                               orgFile.delete();
+                       }
+                       if (iniFile.exists()) {
+                               iniFile.renameTo(orgFile);
+                       }
+               try (   FileInputStream inStream = new FileInputStream(testFile);
+                               FileOutputStream outStream = new FileOutputStream(new File("AdjustTime.ini"));
+                               FileChannel inChannel = inStream.getChannel();
+                               FileChannel outChannel = outStream.getChannel();        )
+               {
+                   inChannel.transferTo(0, inChannel.size(),outChannel);
+               }
+
+                       AppParameters params = new AppParameters();
+                       params.setProperty(AppParameters.IMG_TIME, "2017-05-29T10:31:46");
+                       params.setProperty(AppParameters.IMG_BASE_FILE, "20170529_103146A.jpg");
+                       params.setProperty(AppParameters.IMG_SOURCE_FOLDER, "./testdata/cameradata/separate");
+                       params.setProperty(AppParameters.GPX_SOURCE_FOLDER, "./testdata/cameradata/separate.gpx");
+                       params.store();
+               }
+
+               @Test
+               public void FILE_UPDATE時間を基準にして時間外のファイルはコピー対象外の時() throws Exception {
+                       AppParameters params = new AppParameters();
+                       params.setProperty(AppParameters.GPX_BASETIME, "FILE_UPDATE");
+                       params.setProperty(AppParameters.IMG_OUTPUT_ALL, "false");
+                       params.store();
+               
+               // 実行する
+                       testdo();
+
+               File gpxfile = new File("./testdata/output/cameradata/separate", "separate_.gpx");
+               assertThat(gpxfile.exists(), is(true));
+               File file0 = new File("./testdata/output/cameradata/separate", "20170529_102305A.jpg");
+               assertThat(file0.exists(), is(false));
+               File file1 = new File("./testdata/output/cameradata/separate", "20170529_103146A.jpg");
+               assertThat(file1.exists(), is(true));
+               File file3 = new File("./testdata/output/cameradata/separate", "20170529_103515A.jpg");
+               assertThat(file3.exists(), is(true));
+               File file4 = new File("./testdata/output/cameradata/separate", "20170529_104119A.jpg");
+               assertThat(file4.exists(), is(true));
+               }
+
+               @Test
+               public void EXIF時間を基準にして時間外のファイルはコピー対象外の時() throws Exception {
+                       AppParameters params = new AppParameters();
+                       params.setProperty(AppParameters.GPX_BASETIME, "EXIF_TIME");
+                       params.setProperty(AppParameters.IMG_OUTPUT_ALL, "false");
+                       params.store();
+               
+               // 実行する
+                       testdo();
+
+               File gpxfile = new File("./testdata/output/cameradata/separate", "separate_.gpx");
+               assertThat(gpxfile.exists(), is(true));
+               File file0 = new File("./testdata/output/cameradata/separate", "20170529_102305A.jpg");
+               assertThat(file0.exists(), is(false));
+               File file1 = new File("./testdata/output/cameradata/separate", "20170529_103146A.jpg");
+               assertThat(file1.exists(), is(true));
+               File file3 = new File("./testdata/output/cameradata/separate", "20170529_103515A.jpg");
+               assertThat(file3.exists(), is(true));
+               File file4 = new File("./testdata/output/cameradata/separate", "20170529_104119A.jpg");
+               assertThat(file4.exists(), is(true));
+               }
+               
+               /**
+                * 実行する
+                * @throws Exception
+                */
+               public void testdo() {
+               try {
+                       String[] argv = {
+                                       "./testdata/cameradata/separate",
+                                       "20170529_103146A.jpg",
+                                       "2017-05-29T10:31:46",
+                                       "./testdata/output",
+                                       "./testdata/cameradata/separate.gpx"
+                       };
+                       ImportPicture.main(argv);
+                       }
+                       catch (Exception e) {
+                               e.printStackTrace();
+                               fail("Exceptionが発生した。");
+                       }
+               }
+       }
+
+    /**
+     * *.tar.gz解凍
+     * ファイル更新日時をオリジナルと同じにします。
+     * @param tazFile 解凍する*.tar.gzファイル
+     * @param dest 解凍先フォルダ
+     * @throws IOException 
+     */
+    public static void uncompress(File tazFile, File dest) throws IOException {
+        dest.mkdir();
+        
+        TarArchiveInputStream tarIn = null;
+        tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tazFile))));
+
+        TarArchiveEntry tarEntry = tarIn.getNextTarEntry();
+        while (tarEntry != null) {
+            File destPath = new File(dest, tarEntry.getName());
+            System.out.println("uncompress: " + destPath.getCanonicalPath());
+            if (tarEntry.isDirectory()) {
+                destPath.mkdirs();
+            }
+            else {
+               File dir = new File(destPath.getParent());
+               if (!dir.exists()) {
+                       dir.mkdirs();
+               }
+                destPath.createNewFile();
+                byte[] btoRead = new byte[1024];
+                BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath));
+                int len = 0;
+
+                while ((len = tarIn.read(btoRead)) != -1) {
+                    bout.write(btoRead, 0, len);
+                }
+
+                bout.close();
+                destPath.setLastModified(tarEntry.getLastModifiedDate().getTime());
+                btoRead = null;
+            }
+            tarEntry = tarIn.getNextTarEntry();
+        }
+        tarIn.close();
+    }
 }
similarity index 98%
rename from importPicture/test/osm/jp/gpx/TarGz.java
rename to importPicture/test/osm/jp/gpx/utils/TarGz.java
index 19559b3..069c02f 100644 (file)
@@ -1,4 +1,5 @@
-package osm.jp.gpx;
+package osm.jp.gpx.utils;
+
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;