From: hayashi Date: Fri, 23 Jun 2017 06:53:37 +0000 (+0900) Subject: green: X-Git-Tag: release_2017-07-09~23 X-Git-Url: http://git.sourceforge.jp/view?a=commitdiff_plain;h=4e406a5a2ffc441971dd2593792664b8ca32a8fd;p=importpicture%2Fimportpicture.git green: --- diff --git a/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java b/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java index 0c8bd06..296254c 100644 --- a/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java +++ b/importPicture/src/osm/jp/gpx/ElementMapTRKPT.java @@ -2,8 +2,6 @@ package osm.jp.gpx; import java.text.ParseException; import java.util.Date; -import java.util.Iterator; -import java.util.Set; import java.util.TreeMap; import org.w3c.dom.DOMException; @@ -55,10 +53,16 @@ public class ElementMapTRKPT extends TreeMap { * @throws ParseException */ public Element getValue(Date jptime) throws ParseException { - Element imaE = getTrkpt(jptime); + System.out.println("jptime="+ ImportPicture.dfuk.format(jptime)); + + Element imaE = getTrkpt(jptime); if (imaE != null) { - Element maeE = getMaeTrkpt(new TagTrkpt(imaE)); + System.out.println("\timaTime="+ ImportPicture.dfuk.format((new TagTrkpt(imaE)).time)); + + Element maeE = getMaeTrkpt((new TagTrkpt(imaE)).time); if (maeE != null) { + System.out.println("\t\tmaeTime="+ ImportPicture.dfuk.format((new TagTrkpt(maeE)).time)); + Complementation comp = new Complementation(imaE, maeE); // がなければ、 @@ -75,68 +79,76 @@ public class ElementMapTRKPT extends TreeMap { return (Element)(comp.imaTag.trkpt.cloneNode(true)); } + return imaE; } return null; } /** * [map]から指定した時刻のエレメントを取り出す。 - * GPX時刻との差が10分以上は無効 + * 取り出すエレメントは、指定した時刻と同一時刻、もしくは、直近・直前の時刻のエレメントとする。 + * 指定した時刻以前のエレメントが存在しない場合は null を返す。 + * 指定した時刻と直近・直前のエレメントの時刻との乖離が プロパティ[OVER_TIME_LIMIT=3000(ミリ秒)]より大きい場合には null を返す。 * - * @param mapTRKPT * @param jptime - * @return エレメント + * @return エレメント。対象のエレメントが存在しなかった場合には null。 * @throws ParseException */ private Element getTrkpt(Date jptime) throws ParseException { - long sa = 2L * 3600000L; - long jpt = jptime.getTime(); - - Element ret = null; - - Set keySet = this.keySet(); //すべてのキー値を取得 - Iterator keyIte = keySet.iterator(); - while (keyIte.hasNext()) { - Date time = keyIte.next(); - long t = time.getTime(); - - if (Math.abs(jpt - t) < sa) { - sa = Math.abs(jpt - t); - ret = this.get(time); - } - } - - // GPX時刻との差が10分以内なら有効 - if (sa < (60000L * 10L)) { - return ret; - } - return null; + Date keyTime = null; + for (Date key : this.keySet()) { + int flag = jptime.compareTo(key); + if (flag < 0) { + if (keyTime != null) { + return this.get(keyTime); + } + return null; + } + else if (flag == 0) { + return this.get(key); + } + else if (flag > 0) { + keyTime = new Date(key.getTime()); + } + } + if (keyTime != null) { + if (Math.abs(keyTime.getTime() - jptime.getTime()) <= OVER_TIME_LIMIT) { + return this.get(keyTime); + } + } + return null; } - private Element getMaeTrkpt(TagTrkpt imaTrkpt) throws ParseException { - Element ret = null; - long diffTime = 2L * 3600000L; // 2時間 - long jpt = imaTrkpt.time.getTime() - DIFF_MAE_TIME; - - Set keySet = this.keySet(); //すべてのキー値を取得 - Iterator keyIte = keySet.iterator(); - while (keyIte.hasNext()) { //ループ。反復子iteratorによる キー 取得 - Date time = keyIte.next(); - long t = time.getTime(); - - if (Math.abs(jpt - t) < diffTime) { - diffTime = Math.abs(jpt - t); - ret = this.get(time); - } - } - - // GPX時刻との差が10分以内なら有効 - if (diffTime < (60000L * 10L)) { - // 元の時刻との差が1秒以上あること - if (diffTime < (imaTrkpt.time.getTime() - 1000)) { - return ret; - } - } + /** + * ロガーの最終取得時刻を超えた場合、どこまでを有効とするかを設定する。 + * この設定がないと、最終取得時刻を超えたものは全て有効になってしまう。 + * OVER_TIME_LIMITは、GPSロガーの位置取得間隔()よりも長くする必要がある。長すぎても良くない。 + */ + public static long OVER_TIME_LIMIT = 3000; // ミリ秒(msec) + + private Element getMaeTrkpt(Date time) throws ParseException { + Date maeTime = null; + for (Date key : this.keySet()) { + int flag = time.compareTo(key); + if (flag < 0) { + maeTime = new Date(key.getTime()); + } + else if (flag == 0) { + if (maeTime == null) { + return null; + } + return this.get(maeTime); + } + else { + if (maeTime == null) { + return null; + } + if (Math.abs(maeTime.getTime() - time.getTime()) > OVER_TIME_LIMIT) { + return null; + } + return this.get(maeTime); + } + } return null; } } diff --git a/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java b/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java index 89606f6..1e39f28 100644 --- a/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java +++ b/importPicture/test/osm/jp/gpx/ElementMapTRKPTTest.java @@ -131,34 +131,98 @@ public class ElementMapTRKPTTest { } @Test - public void get_一番先頭の1秒前() throws ParseException { + public void get_17() throws ParseException { Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:17Z")); assertThat(ret, is(nullValue())); } @Test - public void get_一番先頭のTRKPTと同時刻() throws ParseException { + public void get_18() throws ParseException { Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:18Z")); - assertThat(ret, is(nullValue())); + TagTrkpt tag = new TagTrkpt(ret); + assertThat(sdf.format(tag.time), is("2017-05-29T01:23:18Z")); } @Test - public void get_一番から二番の間() throws ParseException { + public void get_19() throws ParseException { Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:19Z")); TagTrkpt tag = new TagTrkpt(ret); assertThat(sdf.format(tag.time), is("2017-05-29T01:23:18Z")); } @Test - public void get_最後と同時刻() throws ParseException { + public void get_20() throws ParseException { + Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:20Z")); + TagTrkpt tag = new TagTrkpt(ret); + assertThat(sdf.format(tag.time), is("2017-05-29T01:23:18Z")); + } + + @Test + public void get_21() throws ParseException { + Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:21Z")); + TagTrkpt tag = new TagTrkpt(ret); + assertThat(sdf.format(tag.time), is("2017-05-29T01:23:21Z")); + } + + @Test + public void get_22() throws ParseException { + Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:22Z")); + TagTrkpt tag = new TagTrkpt(ret); + assertThat(sdf.format(tag.time), is("2017-05-29T01:23:21Z")); + } + + @Test + public void get_23() throws ParseException { + Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:23Z")); + TagTrkpt tag = new TagTrkpt(ret); + assertThat(sdf.format(tag.time), is("2017-05-29T01:23:21Z")); + } + + @Test + public void get_24() throws ParseException { + Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:24Z")); + TagTrkpt tag = new TagTrkpt(ret); + assertThat(sdf.format(tag.time), is("2017-05-29T01:23:24Z")); + } + + @Test + public void get_25() throws ParseException { + Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:25Z")); + TagTrkpt tag = new TagTrkpt(ret); + assertThat(sdf.format(tag.time), is("2017-05-29T01:23:24Z")); + } + + @Test + public void get_26() throws ParseException { + Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:26Z")); + TagTrkpt tag = new TagTrkpt(ret); + assertThat(sdf.format(tag.time), is("2017-05-29T01:23:24Z")); + } + + @Test + public void get_27() throws ParseException { Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:27Z")); TagTrkpt tag = new TagTrkpt(ret); assertThat(sdf.format(tag.time), is("2017-05-29T01:23:27Z")); } @Test - public void get_最後の1秒後() throws ParseException { + public void get_28() throws ParseException { Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:28Z")); + TagTrkpt tag = new TagTrkpt(ret); + assertThat(sdf.format(tag.time), is("2017-05-29T01:23:27Z")); + } + + @Test + public void get_30() throws ParseException { + Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:30Z")); + TagTrkpt tag = new TagTrkpt(ret); + assertThat(sdf.format(tag.time), is("2017-05-29T01:23:27Z")); + } + + @Test + public void get_31() throws ParseException { + Element ret = map.getValue(ImportPicture.dfuk.parse("2017-05-29T01:23:31Z")); assertThat(ret, is(nullValue())); } }