-
Notifications
You must be signed in to change notification settings - Fork 3
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
Filter duplicates #481
Merged
Merged
Filter duplicates #481
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
22ae3f1
Handle encoding issues in MapFromLbe
steffenkleinle 1037ee6
Add FilterDuplicates step
steffenkleinle d73be02
Ignore case and special characters in search for duplicates
steffenkleinle 40a7cc3
Simplify filtering of duplicates
steffenkleinle d10a5c9
Move and extract constants
steffenkleinle fb12e3c
Log duplicated values
steffenkleinle 2c8b13e
Merge branch 'main' into 478-remove-duplicates
steffenkleinle 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
5 changes: 4 additions & 1 deletion
5
...hrenamtskarte/backend/common/constants.kt → ...hrenamtskarte/backend/stores/constants.kt
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package app.ehrenamtskarte.backend.common | ||
package app.ehrenamtskarte.backend.stores | ||
|
||
const val COUNTRY_CODE = "de" | ||
const val STATE = "Bayern" | ||
|
||
// Postal code lookup and address sanitation fails/does not really make sense for a "Postfach" | ||
const val STREET_EXCLUDE_PATTERN = "Postfach" | ||
|
||
const val MISCELLANEOUS_CATEGORY_ID = 9 | ||
const val ALTERNATIVE_MISCELLANEOUS_CATEGORY_ID = 99 | ||
|
4 changes: 2 additions & 2 deletions
4
backend/src/main/kotlin/app/ehrenamtskarte/backend/stores/geocoding/FeatureFetcher.kt
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
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
31 changes: 0 additions & 31 deletions
31
backend/src/main/kotlin/app/ehrenamtskarte/backend/stores/importer/steps/Encode.kt
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
backend/src/main/kotlin/app/ehrenamtskarte/backend/stores/importer/steps/FilterDuplicates.kt
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,70 @@ | ||
package app.ehrenamtskarte.backend.stores.importer.steps | ||
|
||
import app.ehrenamtskarte.backend.stores.importer.PipelineStep | ||
import app.ehrenamtskarte.backend.stores.importer.logRemoveDuplicates | ||
import app.ehrenamtskarte.backend.stores.importer.types.AcceptingStore | ||
import org.slf4j.Logger | ||
|
||
class FilterDuplicates(private val logger: Logger) : PipelineStep<List<AcceptingStore>, List<AcceptingStore>>() { | ||
|
||
override fun execute(input: List<AcceptingStore>): List<AcceptingStore> { | ||
// Group by name + postal code + street to detect duplicates | ||
val groups = input.groupBy { | ||
(it.name + it.postalCode + it.street).toLowerCase().filter { char -> char.isLetterOrDigit() } | ||
} | ||
|
||
return groups.values.map { it.deduplicate() } | ||
} | ||
|
||
private fun List<AcceptingStore>.deduplicate(): AcceptingStore { | ||
if (size == 1) return first() // No duplicates, nothing to do | ||
|
||
// Use the last as that is perhaps the last updated/created one | ||
val store = last() | ||
|
||
logger.logRemoveDuplicates(store, size - 1) | ||
|
||
val location = lastValue("locations") { it.location } | ||
val categoryId = lastValue("categoryIds") { it.categoryId } | ||
val houseNumber = lastValue("house numbers") { it.houseNumber } | ||
val website = lastValue("websites") { it.website } | ||
val email = lastValue("emails") { it.email } | ||
val telephone = lastValue("telephones") { it.telephone } | ||
val additionalAddressInformation = lastValue("additional address information") { it.additionalAddressInformation } | ||
|
||
// The coordinates are often just cut after some digits so use the one with the best precision | ||
val longitude = mapNotNull { it.longitude }.maxBy { it.toString().length } | ||
val latitude = mapNotNull { it.latitude }.maxBy { it.toString().length } | ||
|
||
// Combine all descriptions because we have no way of knowing which is the correct one | ||
val discounts = mapNotNull { it.discount }.toSet().joinToString("\n") | ||
|
||
return AcceptingStore( | ||
store.name, | ||
store.countryCode, | ||
location!!, | ||
store.postalCode, | ||
store.street, | ||
houseNumber, | ||
additionalAddressInformation, | ||
longitude, | ||
latitude, | ||
categoryId!!, | ||
email, | ||
telephone, | ||
website, | ||
discounts | ||
) | ||
} | ||
|
||
private fun <T: Any> List<AcceptingStore>.lastValue(property: String, transform: (AcceptingStore) -> T?): T? { | ||
val uniqueValues = mapNotNull { transform(it) }.toSet() | ||
|
||
if (uniqueValues.size > 1) { | ||
logger.info("$property: ${uniqueValues.joinToString("', '", "'", "'")}") | ||
} | ||
|
||
return uniqueValues.lastOrNull() | ||
} | ||
|
||
} |
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: 1 addition & 1 deletion
2
...nd/src/main/kotlin/app/ehrenamtskarte/backend/stores/importer/steps/PostSanitizeFilter.kt
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: 1 addition & 1 deletion
2
backend/src/main/kotlin/app/ehrenamtskarte/backend/stores/importer/steps/SanitizeAddress.kt
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: 1 addition & 1 deletion
2
backend/src/main/kotlin/app/ehrenamtskarte/backend/stores/importer/steps/SanitizeGeocode.kt
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
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.
Moved from old step
Encode