Skip to content

Commit

Permalink
Add charge location availability to ChargeLocation and as filter
Browse files Browse the repository at this point in the history
  • Loading branch information
robho committed Dec 9, 2024
1 parent 2077e09 commit 70953af
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ data class GEChargeLocation(
locationDescription,
photos?.map { it.convert(apikey) },
chargecards?.map { it.convert() },
null,
openinghours?.convert(),
cost?.convert(),
null,
Expand Down
23 changes: 22 additions & 1 deletion app/src/main/java/net/vonforst/evmap/api/nobil/NobilApi.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.vonforst.evmap.api.nobil

import android.content.Context
import android.database.DatabaseUtils
import com.car2go.maps.model.LatLng
import com.car2go.maps.model.LatLngBounds
import com.squareup.moshi.JsonDataException
Expand All @@ -21,9 +22,11 @@ import net.vonforst.evmap.model.ChargepointListItem
import net.vonforst.evmap.model.Filter
import net.vonforst.evmap.model.FilterValue
import net.vonforst.evmap.model.FilterValues
import net.vonforst.evmap.model.MultipleChoiceFilter
import net.vonforst.evmap.model.ReferenceData
import net.vonforst.evmap.model.SliderFilter
import net.vonforst.evmap.model.getBooleanValue
import net.vonforst.evmap.model.getMultipleChoiceValue
import net.vonforst.evmap.model.getSliderValue
import net.vonforst.evmap.viewmodel.Resource
import okhttp3.Cache
Expand Down Expand Up @@ -185,6 +188,13 @@ class NobilApiWrapper(
referenceData: ReferenceData,
sp: StringProvider
): List<Filter<FilterValue>> {
val availabilityMap = mapOf(
"Public" to sp.getString(R.string.availability_public),
"Visitors" to sp.getString(R.string.availability_visitors),
"Employees" to sp.getString(R.string.availability_employees),
"By appointment" to sp.getString(R.string.availability_by_appointment),
"Residents" to sp.getString(R.string.availability_residents)
)
return listOf(
BooleanFilter(sp.getString(R.string.filter_free_parking), "freeparking"),
BooleanFilter(sp.getString(R.string.filter_open_247), "open_247"),
Expand All @@ -201,7 +211,10 @@ class NobilApiWrapper(
10,
min = 1
),

MultipleChoiceFilter(
sp.getString(R.string.filter_availability), "availabilities",
availabilityMap, manyChoices = true
)
)
}

Expand Down Expand Up @@ -234,6 +247,14 @@ class NobilApiWrapper(
requiresChargepointQuery = true
}

val availabilities = filters.getMultipleChoiceValue("availabilities")
if (availabilities != null && !availabilities.all) {
val availabilitiesList = availabilities.values.joinToString(",") {
DatabaseUtils.sqlEscapeString(it)
}
result.append(" AND availability IN (${availabilitiesList})")
}

return FiltersSQLQuery(result.toString(), requiresChargepointQuery, false)
}

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/net/vonforst/evmap/api/nobil/NobilModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import net.vonforst.evmap.model.FilterValues
import net.vonforst.evmap.model.OpeningHours
import net.vonforst.evmap.model.ReferenceData
import net.vonforst.evmap.model.getBooleanValue
import net.vonforst.evmap.model.getMultipleChoiceValue
import net.vonforst.evmap.model.getSliderValue
import java.time.Instant
import java.time.LocalDateTime
Expand Down Expand Up @@ -138,6 +139,8 @@ data class NobilChargerStation(
NobilChargerPhotoAdapter(chargerStationData.image)
) else null,
null,
// 2: Availability
chargerStationAttributes.st["2"]?.attrTrans,
// 24: Open 24h
if (chargerStationAttributes.st["24"]?.attrTrans == "Yes") OpeningHours(
twentyfourSeven = true,
Expand All @@ -158,6 +161,11 @@ data class NobilChargerStation(
true
)

val availabilities = filters?.getMultipleChoiceValue("availabilities")
if (availabilities != null && !availabilities.all) {
if (!availabilities.values.contains(chargeLocation.availability)) return null
}

val freeparking = filters?.getBooleanValue("freeparking")
if (freeparking == true && chargeLocation.cost?.freeparking != true) return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ data class OCMChargepoint(
mediaItems?.mapNotNull { it.convert() },
null,
null,
null,
cost?.takeIf { it.isNotBlank() }.let { Cost(descriptionShort = it) },
dataProvider?.let { "© ${it.title}" + if (it.license != null) ". ${it.license}" else "" },
ChargepriceData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ data class OSMChargingStation(
null,
null,
null,
null,
getOpeningHours(),
getCost(),
"© OpenStreetMap contributors",
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/net/vonforst/evmap/model/ChargersModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ sealed class ChargepointListItem
* @param locationDescription Directions on how to find the charger (e.g. "In the parking garage on level 5")
* @param photos List of photos of this charging site
* @param chargecards List of charge cards accepted here
* @param availability Specifies who may use this charge location
* @param openinghours List of times when this charging site can be accessed / used
* @param cost The cost for charging and/or parking
* @param license How the data about this chargepoint is licensed
Expand Down Expand Up @@ -76,6 +77,7 @@ data class ChargeLocation(
val locationDescription: String?,
val photos: List<ChargerPhoto>?,
val chargecards: List<ChargeCardId>?,
val availability: String?,
@Embedded val openinghours: OpeningHours?,
@Embedded val cost: Cost?,
val license: String?,
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/net/vonforst/evmap/storage/Database.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import net.vonforst.evmap.model.*
OCMCountry::class,
OCMOperator::class,
SavedRegion::class
], version = 24
], version = 25
)
@TypeConverters(Converters::class, GeometryConverters::class)
abstract class AppDatabase : RoomDatabase() {
Expand Down Expand Up @@ -75,7 +75,7 @@ abstract class AppDatabase : RoomDatabase() {
MIGRATION_7, MIGRATION_8, MIGRATION_9, MIGRATION_10, MIGRATION_11,
MIGRATION_12, MIGRATION_13, MIGRATION_14, MIGRATION_15, MIGRATION_16,
MIGRATION_17, MIGRATION_18, MIGRATION_19, MIGRATION_20, MIGRATION_21,
MIGRATION_22, MIGRATION_23, MIGRATION_24
MIGRATION_22, MIGRATION_23, MIGRATION_24, MIGRATION_25
)
.addCallback(object : Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
Expand Down Expand Up @@ -483,6 +483,19 @@ abstract class AppDatabase : RoomDatabase() {
db.execSQL("ALTER TABLE `ChargeLocationNew` RENAME TO `ChargeLocation`")
}
}

private val MIGRATION_25 = object : Migration(24, 25) {
override fun migrate(db: SupportSQLiteDatabase) {
// adding availability to ChargeLocation
db.execSQL(
"CREATE TABLE `ChargeLocationNew` (`id` INTEGER NOT NULL, `dataSource` TEXT NOT NULL, `name` TEXT NOT NULL, `coordinates` BLOB NOT NULL, `chargepoints` TEXT NOT NULL, `network` TEXT, `dataSourceUrl` TEXT NOT NULL, `url` TEXT, `editUrl` TEXT, `verified` INTEGER NOT NULL, `barrierFree` INTEGER, `operator` TEXT, `generalInformation` TEXT, `amenities` TEXT, `locationDescription` TEXT, `photos` TEXT, `chargecards` TEXT, `availability` TEXT, `license` TEXT, `timeRetrieved` INTEGER NOT NULL, `isDetailed` INTEGER NOT NULL, `city` TEXT, `country` TEXT, `postcode` TEXT, `street` TEXT, `fault_report_created` INTEGER, `fault_report_description` TEXT, `twentyfourSeven` INTEGER, `description` TEXT, `mostart` TEXT, `moend` TEXT, `tustart` TEXT, `tuend` TEXT, `westart` TEXT, `weend` TEXT, `thstart` TEXT, `thend` TEXT, `frstart` TEXT, `frend` TEXT, `sastart` TEXT, `saend` TEXT, `sustart` TEXT, `suend` TEXT, `hostart` TEXT, `hoend` TEXT, `freecharging` INTEGER, `freeparking` INTEGER, `descriptionShort` TEXT, `descriptionLong` TEXT, `chargepricecountry` TEXT, `chargepricenetwork` TEXT, `chargepriceplugTypes` TEXT, `networkUrl` TEXT, `chargerUrl` TEXT, PRIMARY KEY(`id`, `dataSource`))"
)

db.execSQL("INSERT INTO `ChargeLocationNew` SELECT `id`, `dataSource`, `name`, `coordinates`, `chargepoints`, `network`, `dataSourceUrl`, `url`, `editUrl`, `verified`, `barrierFree`, `operator`, `generalInformation`, `amenities`, `locationDescription`, `photos`, `chargecards`, null, `license`, `timeRetrieved`, `isDetailed`, `city`, `country`, `postcode`, `street`, `fault_report_created`, `fault_report_description`, `twentyfourSeven`, `description`, `mostart`, `moend`, `tustart`, `tuend`, `westart`, `weend`, `thstart`, `thend`, `frstart`, `frend`, `sastart`, `saend`, `sustart`, `suend`, `hostart`, `hoend`, `freecharging`, `freeparking`, `descriptionShort`, `descriptionLong`, `chargepricecountry`, `chargepricenetwork`, `chargepriceplugTypes`, `networkUrl`, `chargerUrl` FROM `ChargeLocation`")
db.execSQL("DROP TABLE `ChargeLocation`")
db.execSQL("ALTER TABLE `ChargeLocationNew` RENAME TO `ChargeLocation`")
}
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<string name="filter_open_247">Available 24/7</string>
<string name="filter_barrierfree">Usable without registration</string>
<string name="filter_exclude_faults">Exclude chargers with reported faults</string>
<string name="filter_availability">Charger availability</string>
<string name="charge_cards">Payment methods</string>
<string name="and_n_others">and %d others</string>
<string name="pref_map_provider">Map provider</string>
Expand Down Expand Up @@ -373,4 +374,9 @@
<string name="pref_chargeprice_native_integration_on">Pricing data will be shown directly in EVMap</string>
<string name="pref_chargeprice_native_integration_off">Price comparison button will refer to the Chargeprice app or website</string>
<string name="auto_zoom_for_details">Zoom in to see details</string>
<string name="availability_public">Public</string>
<string name="availability_visitors">Visitors</string>
<string name="availability_employees">Employees</string>
<string name="availability_by_appointment">By appointment</string>
<string name="availability_residents">Residents</string>
</resources>

0 comments on commit 70953af

Please sign in to comment.