-
-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "is construction finished" quests for highway=construction and building=construction #920
Merged
+504
−9
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
app/src/androidTest/java/de/westnordost/streetcomplete/quests/AssertUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package de.westnordost.streetcomplete.quests; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.annotation.Nullable; | ||
import android.util.Log; | ||
|
||
import de.westnordost.osmapi.map.data.Element; | ||
import de.westnordost.streetcomplete.data.osm.ElementGeometry; | ||
import de.westnordost.streetcomplete.data.osm.OsmElementQuestType; | ||
import de.westnordost.streetcomplete.data.osm.download.MapDataWithGeometryHandler; | ||
|
||
|
||
import de.westnordost.osmapi.map.data.BoundingBox; | ||
|
||
import static junit.framework.Assert.fail; | ||
|
||
|
||
public class AssertUtil { | ||
public static void verifyYieldsNoQuest(OsmElementQuestType quest, BoundingBox bbox) { | ||
MapDataWithGeometryHandler verifier = (element, geometry) -> | ||
{ | ||
fail("Expected zero elements. Element returned: " + | ||
element.getType().name() + "#" + element.getId()); | ||
}; | ||
quest.download(bbox, verifier); | ||
} | ||
|
||
class ElementCounter implements MapDataWithGeometryHandler{ | ||
int count = 0; | ||
@Override | ||
public void handle(@NonNull Element element, @Nullable ElementGeometry geometry) { | ||
count += 1; | ||
} | ||
} | ||
|
||
public void verifyYieldsQuest(OsmElementQuestType quest, BoundingBox bbox) { | ||
ElementCounter counter = new ElementCounter(); | ||
quest.download(bbox, counter); | ||
if(counter.count == 0) { | ||
fail("Expected nonzero elements. Elements not returned"); | ||
} | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../streetcomplete/quests/construction/MarkCompletedBuildingConstructionIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package de.westnordost.streetcomplete.quests.construction; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import java.text.ParseException; | ||
|
||
import de.westnordost.osmapi.map.data.BoundingBox; | ||
import de.westnordost.streetcomplete.data.OsmModule; | ||
import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao; | ||
import de.westnordost.streetcomplete.quests.AssertUtil; | ||
|
||
public class MarkCompletedBuildingConstructionIntegrationTest extends TestCase { | ||
public void test_matching_candidate_is_accepted() throws ParseException { | ||
//https://www.openstreetmap.org/way/494183785#map=19/50.07671/19.94703 | ||
verifyYieldsQuest( | ||
new BoundingBox(50.07664, 19.94671, 50.07672, 19.94700), | ||
"2018-03-01" | ||
); | ||
} | ||
|
||
public void test_fresh_construction_is_not_accepted() throws ParseException { | ||
//https://www.openstreetmap.org/way/494183785#map=19/50.07671/19.94703 | ||
verifyYieldsNoQuest( | ||
new BoundingBox(50.07664, 19.94671, 50.07672, 19.94700), | ||
"2017-07-30" | ||
); | ||
} | ||
|
||
public void test_relations_are_accepted() throws ParseException { | ||
//https://www.openstreetmap.org/relation/7405013 | ||
verifyYieldsQuest( | ||
new BoundingBox(55.89375, 37.53794, 55.89441, 37.53857), | ||
"2018-03-01" | ||
); | ||
} | ||
|
||
private void verifyYieldsNoQuest(BoundingBox bbox, String date) throws ParseException { | ||
OverpassMapDataDao o = OsmModule.overpassOldMapDataDao(OsmModule::overpassMapDataParser, date); | ||
MarkCompletedBuildingConstructionOldData quest = new MarkCompletedBuildingConstructionOldData(o, date); | ||
AssertUtil.verifyYieldsNoQuest(quest, bbox); | ||
} | ||
|
||
private void verifyYieldsQuest(BoundingBox bbox, String date) throws ParseException { | ||
OverpassMapDataDao o = OsmModule.overpassOldMapDataDao(OsmModule::overpassMapDataParser, date); | ||
MarkCompletedBuildingConstructionOldData quest = new MarkCompletedBuildingConstructionOldData(o, date); | ||
new AssertUtil().verifyYieldsQuest(quest, bbox); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...tnordost/streetcomplete/quests/construction/MarkCompletedBuildingConstructionOldData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package de.westnordost.streetcomplete.quests.construction; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao; | ||
import de.westnordost.streetcomplete.quests.DateUtil; | ||
|
||
public class MarkCompletedBuildingConstructionOldData extends MarkCompletedBuildingConstruction { | ||
private Date date; | ||
MarkCompletedBuildingConstructionOldData(OverpassMapDataDao overpassServer, String dateString) throws ParseException { | ||
super(overpassServer); | ||
date = DateUtil.basicISO8601().parse(dateString); | ||
} | ||
|
||
@Override | ||
protected String getCurrentDateString(){ | ||
return DateUtil.getOffsetDateStringFromDate(0, date) + "T00:00:00Z"; | ||
} | ||
|
||
@Override | ||
protected String getOffsetDateString(int offset){ | ||
return DateUtil.getOffsetDateStringFromDate(offset, date) + "T00:00:00Z"; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...t/streetcomplete/quests/construction/MarkCompletedHighwayConstructionIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package de.westnordost.streetcomplete.quests.construction; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import java.text.ParseException; | ||
|
||
import de.westnordost.osmapi.map.data.BoundingBox; | ||
import de.westnordost.streetcomplete.data.OsmModule; | ||
import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao; | ||
import de.westnordost.streetcomplete.quests.AssertUtil; | ||
|
||
public class MarkCompletedHighwayConstructionIntegrationTest extends TestCase { | ||
public void test_old_highway_construction_triggers_quest() throws ParseException { | ||
//https://www.openstreetmap.org/way/298656945 edited on 2014-08-18 | ||
verifyYieldsQuest( | ||
new BoundingBox(40.01422, -3.02250, 40.01694, -3.02134), | ||
"2018-03-10" | ||
); | ||
} | ||
|
||
public void test_new_highway_construction_is_not_triggering_quest() throws ParseException { | ||
//https://www.openstreetmap.org/way/298656945 edited on 2014-08-18 | ||
verifyYieldsNoQuest( | ||
new BoundingBox(40.01422, -3.02250, 40.01694, -3.02134), | ||
"2014-08-20" | ||
); | ||
} | ||
|
||
public void test_opening_date_tag_used_to_filter_out_active_construction() throws ParseException { | ||
//https://www.openstreetmap.org/way/22462987 - 2017-06-30 not generating, 2017-07-01 generating quest | ||
verifyYieldsNoQuest( | ||
new BoundingBox(47.80952, 12.09730, 47.81005, 12.09801), | ||
"2017-06-30" | ||
); | ||
} | ||
public void test_opening_date_tag_ignored_if_outdated() throws ParseException { | ||
//https://www.openstreetmap.org/way/22462987 - 2017-06-30 not generating, 2017-07-01 generating quest | ||
verifyYieldsQuest( | ||
new BoundingBox(47.80952, 12.09730, 47.81005, 12.09801), | ||
"2017-07-01" | ||
); | ||
} | ||
|
||
|
||
private void verifyYieldsNoQuest(BoundingBox bbox, String date) throws ParseException { | ||
OverpassMapDataDao o = OsmModule.overpassOldMapDataDao(OsmModule::overpassMapDataParser, date); | ||
MarkCompletedHighwayConstructionOldData quest = new MarkCompletedHighwayConstructionOldData(o, date); | ||
AssertUtil.verifyYieldsNoQuest(quest, bbox); | ||
} | ||
|
||
private void verifyYieldsQuest(BoundingBox bbox, String date) throws ParseException { | ||
OverpassMapDataDao o = OsmModule.overpassOldMapDataDao(OsmModule::overpassMapDataParser, date); | ||
MarkCompletedHighwayConstructionOldData quest = new MarkCompletedHighwayConstructionOldData(o, date); | ||
new AssertUtil().verifyYieldsQuest(quest, bbox); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...stnordost/streetcomplete/quests/construction/MarkCompletedHighwayConstructionOldData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package de.westnordost.streetcomplete.quests.construction; | ||
|
||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao; | ||
import de.westnordost.streetcomplete.quests.DateUtil; | ||
|
||
public class MarkCompletedHighwayConstructionOldData extends MarkCompletedHighwayConstruction { | ||
private Date date; | ||
MarkCompletedHighwayConstructionOldData(OverpassMapDataDao overpassServer, String dateString) throws ParseException { | ||
super(overpassServer); | ||
date = DateUtil.basicISO8601().parse(dateString); | ||
} | ||
|
||
@Override | ||
protected String getCurrentDateString(){ | ||
return DateUtil.getOffsetDateStringFromDate(0, date) + "T00:00:00Z"; | ||
} | ||
|
||
@Override | ||
protected String getOffsetDateString(int offset){ | ||
return DateUtil.getOffsetDateStringFromDate(offset, date) + "T00:00:00Z"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
app/src/main/java/de/westnordost/streetcomplete/data/osm/download/OverpassOldMapDataDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
app/src/main/java/de/westnordost/streetcomplete/quests/DateUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package de.westnordost.streetcomplete.quests; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
public class DateUtil { | ||
public static SimpleDateFormat basicISO8601(){ | ||
return new SimpleDateFormat("yyyy-MM-dd"); | ||
|
||
} | ||
public static String getOffsetDateStringFromDate(final int offsetInDays, final Date date){ | ||
Calendar modifiedCalendar = Calendar.getInstance(); | ||
modifiedCalendar.setTime(date); | ||
modifiedCalendar.add(Calendar.DAY_OF_MONTH, offsetInDays); | ||
return basicISO8601().format(modifiedCalendar.getTime()); | ||
} | ||
|
||
public static String getOffsetDateString(int offsetInDays){ | ||
return getOffsetDateStringFromDate(offsetInDays, Calendar.getInstance().getTime()); | ||
} | ||
|
||
public static String getCurrentDateString() { | ||
return getOffsetDateString(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../de/westnordost/streetcomplete/quests/construction/MarkCompletedBuildingConstruction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package de.westnordost.streetcomplete.quests.construction; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.NonNull; | ||
|
||
import java.util.Map; | ||
|
||
import javax.inject.Inject; | ||
|
||
import de.westnordost.osmapi.map.data.BoundingBox; | ||
import de.westnordost.streetcomplete.R; | ||
import de.westnordost.streetcomplete.data.meta.OsmTaggings; | ||
import de.westnordost.streetcomplete.data.osm.changes.StringMapChangesBuilder; | ||
import de.westnordost.streetcomplete.data.osm.download.MapDataWithGeometryHandler; | ||
import de.westnordost.streetcomplete.data.osm.download.OverpassMapDataDao; | ||
import de.westnordost.streetcomplete.data.osm.tql.OverpassQLUtil; | ||
import de.westnordost.streetcomplete.quests.DateUtil; | ||
import de.westnordost.streetcomplete.quests.YesNoQuestAnswerFragment; | ||
|
||
public class MarkCompletedBuildingConstruction extends MarkCompletedConstruction | ||
{ | ||
@Inject | ||
public MarkCompletedBuildingConstruction(OverpassMapDataDao overpassServer) { | ||
super(overpassServer); | ||
} | ||
|
||
@Override public boolean download(BoundingBox bbox, MapDataWithGeometryHandler handler) | ||
{ | ||
return overpassServer.getAndHandleQuota(getOverpassQuery(bbox), handler); | ||
} | ||
|
||
/** @return overpass query string to get buildings marked as under construction but excluding ones | ||
* - with tagged opening date that is in future | ||
* - recently edited (includes adding/updating check_date tags) | ||
* . */ | ||
private String getOverpassQuery(BoundingBox bbox) | ||
{ | ||
String groupName = ".buildings_under_construction"; | ||
String wayGroupName = groupName + "_ways"; | ||
String relationGroupName = groupName + "_relations"; | ||
return OverpassQLUtil.getGlobalOverpassBBox(bbox) + | ||
"way" + getQueryPart("building", wayGroupName, 180) + | ||
"relation" + getQueryPart("building", relationGroupName, 180) + | ||
"(" + wayGroupName + "; " + relationGroupName + ";); out meta geom;"; | ||
} | ||
|
||
public void applyAnswerTo(Bundle answer, StringMapChangesBuilder changes) | ||
{ | ||
if(answer.getBoolean(YesNoQuestAnswerFragment.ANSWER)) { | ||
String constructionValue = changes.getPreviousValue("construction"); | ||
if(constructionValue == null) { | ||
constructionValue = "yes"; | ||
} | ||
changes.modify("building", constructionValue); | ||
removeTagsDescribingConstruction(changes); | ||
} else { | ||
changes.addOrModify(OsmTaggings.SURVEY_MARK_KEY, DateUtil.getCurrentDateString()); | ||
} | ||
} | ||
|
||
@Override | ||
public int getIcon() { | ||
return R.drawable.ic_quest_building_construction; | ||
} | ||
|
||
@Override | ||
public int getTitle() { | ||
return R.string.quest_construction_building_title; | ||
} | ||
|
||
@Override public int getTitle(@NonNull Map<String, String> tags) { | ||
return R.string.quest_construction_building_title; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why you are unhappy about it. Looks like a good integration test setup. I'd perhaps remove the wtf-log, also you could inline the
ElementCounter
(easiest trick to circumvent thefinal
limitation of inner classes/lambdas: use anint[] count = {0};
and count upcount[0]++
)If you think the test should terminate after the first element encountered: Well, this is an architectural problem of osmapi/StreetComplete because the parser was written as a push-parser, not a pull-parser and thus has no mechanism to stop. But what you could do is to throw a custom runtime exception within the handle method and then catch it just after (would perhaps need a comment though why you do that).
But honestly, I think it is fine to let the download run through. Tests are not time critical and the test can choose a bounding box that is small enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ops, that is debug code that I deleted. Maybe I failed to push the changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wtf-log seems to be a weird cache issue. I pushed change removing it - see 041cfbe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rebased and force-pushed what solved the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I though that it can be simplified and I am missing it, but if there are no obvious improvements then it improves my opinion about myself :)