Skip to content

Commit

Permalink
atlas date (osmlab#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bentleysb authored Dec 14, 2020
1 parent 352643b commit 80c4fd2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 6 additions & 4 deletions docs/checks/constructionCheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public class ConstructionCheck extends BaseCheck<Long>
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<String> DATE_TAGS = Arrays.asList(OpeningDateTag.KEY, OpenDateTag.KEY,
ConstructionDateTag.KEY, TemporaryDateOnTag.KEY, "date_on");
Expand Down Expand Up @@ -131,6 +133,13 @@ protected CheckFlag createFlag(final AtlasObject object, final String instructio
@Override
protected Optional<CheckFlag> flag(final AtlasObject object)
{
// Get the date the atlas was generated, or use today's date as a fallback
final Optional<String> 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<String, String> tags = object.getTags();
Expand All @@ -141,7 +150,7 @@ protected Optional<CheckFlag> flag(final AtlasObject object)
final String tagDate = tags.get(dateTag.get());

final Optional<LocalDate> 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())));
Expand All @@ -154,7 +163,7 @@ protected Optional<CheckFlag> 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,
Expand All @@ -169,7 +178,7 @@ protected Optional<CheckFlag> 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,
Expand Down

0 comments on commit 80c4fd2

Please sign in to comment.