You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix: Validate VIN & allow vehicles with no transmission
Uses some fancy SQL to remove NULL entries for transmissions when at least one row has a value for the transmission, so that both vehicles with no transmission and with transmissions can properly be decoded. Also adds a few "tests" to validate this.
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# volvo_vida_db
2
2
3
-
This repository contains scripts to extract and work with data from the internal Volvo VIDA database.
3
+
This repository contains scripts to extract and work with data from the internal Volvo VIDA 2014D database.
4
4
5
5
Some SQL statements are based on procedures found in the VIDA SQL Server database and from scripts in [Tigo2000's repository](https://github.com/Tigo2000/Volvo-VIDA/).
# For cases where the VIN represents multiple combinations of engines and transmissions we match the table with itself to create
115
-
# rows with every possible combination of engines and transmissions. However, we also want to allow VINs that only represent a single engine.
122
+
# rows with every possible combination of engines and transmissions.
123
+
# However, we also want to allow VINs where the transmission is not determinable or where no transmission is specified in the database.
116
124
combined=duckdb.sql("""
117
125
SELECT DISTINCT c1.fkVehicleModel, c1.fkModelYear, c1.fkPartnerGroup, c1.fkBodyStyle, c1.fkEngine, c2.fkTransmission FROM components AS c1, components AS c2
118
-
WHERE (c1.fkEngine IS NOT NULL AND c2.fkTransmission IS NOT NULL) OR c1.fkEngine IS NOT NULL
126
+
WHERE (c1.fkEngine IS NOT NULL AND c2.fkTransmission IS NOT NULL) OR (c1.fkEngine IS NOT NULL AND c2.fkTransmission IS NULL AND NOT EXISTS (
127
+
SELECT 1 FROM components WHERE fkTransmission IS NOT NULL
128
+
))
119
129
""").df()
120
130
121
131
# Filter all the engine/transmission combinations for actually valid ones from the VehicleProfile table if more than one exists
122
132
iflen(combined) >1:
133
+
get_csv(DatabaseFile.vehicle_profile)
123
134
filtered=duckdb.sql("""
124
135
SELECT DISTINCT combined.* FROM combined
125
136
INNER JOIN vehicle_profile vp on vp.fkVehicleModel=combined.fkVehicleModel AND vp.fkModelYear=combined.fkModelYear
126
-
WHERE combined.fkEngine=vp.fkEngine AND combined.fkTransmission=vp.fkTransmission
137
+
WHERE (combined.fkEngine=vp.fkEngine AND combined.fkTransmission=vp.fkTransmission) OR combined.fkTransmission IS NULL
127
138
""").df()
128
139
combined=filtered
129
140
130
141
# Replace possible NaN values with 'None' to avoid having float64 columns, and cast everything to int to not use numpy types
0 commit comments