Implemented merging banks with same bank code and pin tan address in BankList.json

This commit is contained in:
dankito 2020-11-17 01:36:43 +01:00
parent 6b0504feb3
commit 18035203b7
8 changed files with 66 additions and 4 deletions

View File

@ -8,7 +8,8 @@ open class BankInfo(
open val postalCode: String,
open val city: String,
open val pinTanAddress: String?,
open val pinTanVersion: String?
open val pinTanVersion: String?,
open var branchesInOtherCities: List<String> = listOf() // to have only one entry per bank its branches's cities are now stored in branchesInOtherCities so that branches' cities are still searchable
) {
protected constructor() : this("", "", "", "", "", null, "") // for object deserializers

View File

@ -40,6 +40,7 @@ open class InMemoryBankFinder() : BankFinderBase(), IBankFinder {
protected open fun checkIfQueryMatchesBankNameOrCity(bankInfo: BankInfo, queryLowerCase: String): Boolean {
return bankInfo.name.toLowerCase().contains(queryLowerCase)
|| bankInfo.city.toLowerCase().startsWith(queryLowerCase)
|| bankInfo.branchesInOtherCities.any { it.toLowerCase().startsWith(queryLowerCase) }
}

View File

@ -35,7 +35,8 @@ actual class BankListDeserializer {
bankInfoDict.getStringOrEmpty("postalCode"),
bankInfoDict.getStringOrEmpty("city"),
bankInfoDict.getString("pinTanAddress"),
bankInfoDict.getString("pinTanVersion")
bankInfoDict.getString("pinTanVersion"),
bankInfoDict.mutableArrayValueForKey("branchesInOtherCities").mapNotNull { it as? String }
)
}

View File

@ -20,6 +20,10 @@ open class BankListPrettifier {
prettifiedList = removeBanksWithSameBankCodeAndCity(prettifiedList)
}
if (options.contains(BankListPrettifierOption.MergeAllBranchesOfBankIntoOne)) {
prettifiedList = mergeAllBranchesOfBankIntoOne(prettifiedList)
}
if (options.contains(BankListPrettifierOption.MapBankNamesToWellKnownNames)) {
prettifiedList = mapBankNamesToWellKnownNames(prettifiedList)
}
@ -105,4 +109,40 @@ open class BankListPrettifier {
return prettifiedList
}
open fun mergeAllBranchesOfBankIntoOne(banks: List<BankInfo>): List<BankInfo> {
val groupedByBankCodeAndPinTanAddress = banks.groupBy { it.bankCode + "_" + it.pinTanAddress }
val banksToRemove = groupedByBankCodeAndPinTanAddress.values.flatMap { banksWithSameBankCodeAndPinTanAddress ->
if (banksWithSameBankCodeAndPinTanAddress.size > 1) {
val banksToRemove = banksWithSameBankCodeAndPinTanAddress.toMutableList()
val mainBranch = findMainBranch(banksWithSameBankCodeAndPinTanAddress)
banksToRemove.remove(banksWithSameBankCodeAndPinTanAddress.first())
mainBranch.branchesInOtherCities = banksToRemove.map { it.city }.toSet().toList()
return@flatMap banksToRemove
}
listOf<BankInfo>()
}
val prettifiedList = banks.toMutableList()
prettifiedList.removeAll(banksToRemove)
return prettifiedList
}
private fun findMainBranch(banksWithSameBankCodeAndPinTanAddress: List<BankInfo>): BankInfo {
// banksWithSameBankCodeAndPinTanAddress.forEach { bank ->
// if (bank.name.contains(bank.city)) {
// println("${bank.name}: Picked ${bank.city} from ${banksWithSameBankCodeAndPinTanAddress.map { it.city }}")
// return bank
// }
// }
// in most cases this turned out to be the best one
return banksWithSameBankCodeAndPinTanAddress.first()
}
}

View File

@ -18,6 +18,11 @@ enum class BankListPrettifierOption {
*/
RemoveBanksWithSameBankCodeAndCity,
/**
* By default each branch has its own BankInfo. With this option only main branch keeps its BankInfo and all branches get added to branchesInOtherCities.
*/
MergeAllBranchesOfBankIntoOne,
/**
* Removes banks like 'Deutsche Bank (Gf intern)' or 'UniCredit Bank - HVB Settlement EAC01' etc.
*/

View File

@ -180,7 +180,7 @@ open class LuceneBankFinder(indexFolder: File) : BankFinderBase(), IBankFinder {
}
protected open fun createDocumentForBank(bank: BankInfo, writer: DocumentsWriter): Document {
return writer.createDocumentForNonNullFields(
val indexableFields = mutableListOf(
fields.fullTextSearchField(BankInfoNameFieldName, bank.name, true),
fields.keywordField(BankInfoBankCodeFieldName, bank.bankCode, true),
fields.keywordField(BankInfoBicFieldName, bank.bic, true),
@ -191,6 +191,12 @@ open class LuceneBankFinder(indexFolder: File) : BankFinderBase(), IBankFinder {
fields.nullableStoredField(BankInfoPinTanServerAddressFieldName, bank.pinTanAddress),
fields.nullableStoredField(BankInfoPinTanVersionFieldName, bank.pinTanVersion)
)
bank.branchesInOtherCities.forEach { branchCity ->
indexableFields.add(fields.storedField(BankInfoCityStoredFieldName, branchCity))
}
return writer.createDocumentForNonNullFields(indexableFields)
}

View File

@ -71,11 +71,19 @@ android {
pickFirst 'META-INF/ktor-http-cio.kotlin_module'
pickFirst 'META-INF/atomicfu.kotlin_module'
pickFirst 'META-INF/common.kotlin_module'
pickFirst 'META-INF/fints4k.kotlin_module'
pickFirst 'META-INF/BankFinder.kotlin_module'
pickFirst 'META-INF/BankFinder.kotlin_module'
pickFirst 'META-INF/DEPENDENCIES'
pickFirst 'META-INF/NOTICE'
pickFirst 'META-INF/LICENSE'
pickFirst 'META-INF/LICENSE.txt'
pickFirst 'META-INF/NOTICE.txt'
pickFirst 'BankList.json'
exclude 'DetailedBankList.json'
}
lintOptions {

View File

@ -59,7 +59,7 @@ struct BankInfoListItem: View {
struct BankInfoListItem_Previews: PreviewProvider {
static var previews: some View {
BankInfoListItem(BankInfo(name: "Abzockbank Berlin", bankCode: "12345678", bic: "ABZODEBBXXX", postalCode: "12345", city: "Berlin", pinTanAddress: nil, pinTanVersion: "FinTS 3.0"))
BankInfoListItem(BankInfo(name: "Abzockbank Berlin", bankCode: "12345678", bic: "ABZODEBBXXX", postalCode: "12345", city: "Berlin", pinTanAddress: nil, pinTanVersion: "FinTS 3.0", branchesInOtherCities: []))
}
}