From 80c4fd27af1c29271d7683db0856583b35fff822 Mon Sep 17 00:00:00 2001 From: Bentley Breithaupt Date: Mon, 14 Dec 2020 07:59:49 -0800 Subject: [PATCH] atlas date (#444) --- docs/checks/constructionCheck.md | 10 ++++++---- .../checks/validation/tag/ConstructionCheck.java | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/checks/constructionCheck.md b/docs/checks/constructionCheck.md index 6bd4c35fc..1b20b7a0b 100644 --- a/docs/checks/constructionCheck.md +++ b/docs/checks/constructionCheck.md @@ -29,15 +29,17 @@ We first validate that the incoming object is: ##### Flagging the Object There are 3 ways we check if the object should be flagged: 1. We get one of the valid date tags (see DATE_TAGS in ConstructionCheck.java) - * If one is present we attempt to parse the date string and compare it to today's date. - * If it is before today's date we flag the object. + * If one is present we attempt to parse the date string and compare it to the atlas generation date. + * If it is before the atlas generation date we flag the object. 2. We check the "check_date" tag - * If present we parse the date string and find how many months it is between the check_date and today's date + * If present we parse the date string and find how many months it is between the check_date and the atlas generation date * If it is more than the oldCheckDateMonths, as defined in the config, we flag the object 3. If all else fails we check the tag "last_edit_time" - * We convert the timestamp to a date and find the days between that and today's date + * We convert the timestamp to a date and find the days between that and the atlas generation date * If it is more than the oldConstructionDays, as defined in the config, we flag the object +In all cases if the atlas generation date in not available, the the current date is used instead. + ##### Parsing the date string While there is one specified way people should be tagging dates, ISO 8601 (yyyy-mm-dd, ie. 2020-01-16), but it is not always in this format, we attempt to account for that by parsing as many date formats as we come across. diff --git a/src/main/java/org/openstreetmap/atlas/checks/validation/tag/ConstructionCheck.java b/src/main/java/org/openstreetmap/atlas/checks/validation/tag/ConstructionCheck.java index c118bbfaa..a83eed756 100644 --- a/src/main/java/org/openstreetmap/atlas/checks/validation/tag/ConstructionCheck.java +++ b/src/main/java/org/openstreetmap/atlas/checks/validation/tag/ConstructionCheck.java @@ -71,6 +71,8 @@ public class ConstructionCheck extends BaseCheck DateTimeFormatter.ofPattern("d-MMM-yyyy"), // 1 January 2020 DateTimeFormatter.ofPattern("d MMMM yyyy")); + private static final DateTimeFormatter ATLAS_DATE_FORMATTER = DateTimeFormatter + .ofPattern("yyyyMMdd"); private static final LocalDate TODAYS_DATE = LocalDate.now(); private static final List DATE_TAGS = Arrays.asList(OpeningDateTag.KEY, OpenDateTag.KEY, ConstructionDateTag.KEY, TemporaryDateOnTag.KEY, "date_on"); @@ -131,6 +133,13 @@ protected CheckFlag createFlag(final AtlasObject object, final String instructio @Override protected Optional flag(final AtlasObject object) { + // Get the date the atlas was generated, or use today's date as a fallback + final Optional atlasDateString = object.getAtlas().metaData().getDataVersion(); + final LocalDate comparisonDate = atlasDateString.isPresent() + && !atlasDateString.get().equals("unknown") + ? LocalDate.parse(atlasDateString.get().split("-")[0], ATLAS_DATE_FORMATTER) + : TODAYS_DATE; + this.markAsFlagged(object.getOsmIdentifier()); final Map tags = object.getTags(); @@ -141,7 +150,7 @@ protected Optional flag(final AtlasObject object) final String tagDate = tags.get(dateTag.get()); final Optional parsedDate = this.parseDate(tagDate); - if (parsedDate.isPresent() && parsedDate.get().isBefore(TODAYS_DATE)) + if (parsedDate.isPresent() && parsedDate.get().isBefore(comparisonDate)) { return Optional.of( this.createFlag(object, this.getLocalizedInstruction(0, dateTag.get()))); @@ -154,7 +163,7 @@ protected Optional flag(final AtlasObject object) if (parseDateChecked.isPresent()) { final long monthsBetween = ChronoUnit.MONTHS.between(parseDateChecked.get(), - TODAYS_DATE); + comparisonDate); if (monthsBetween > this.oldCheckDateMonths) { return Optional.of(this.createFlag(object, @@ -169,7 +178,7 @@ protected Optional flag(final AtlasObject object) final LocalDate lastEditDate = Instant.ofEpochMilli(timestamp) .atZone(ZoneId.systemDefault()).toLocalDate(); - final long numberOfDays = ChronoUnit.DAYS.between(lastEditDate, TODAYS_DATE); + final long numberOfDays = ChronoUnit.DAYS.between(lastEditDate, comparisonDate); if (numberOfDays > this.oldConstructionDays) { return Optional.of(this.createFlag(object,