-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvin_decoding_models.go
More file actions
474 lines (446 loc) · 16.7 KB
/
vin_decoding_models.go
File metadata and controls
474 lines (446 loc) · 16.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
//nolint:tagliatelle
package models
import (
"encoding/json"
"fmt"
"strings"
"github.com/aarondl/null/v8"
)
type DecodeProviderEnum string
const (
DrivlyProvider DecodeProviderEnum = "drivly"
VincarioProvider DecodeProviderEnum = "vincario"
AutoIsoProvider DecodeProviderEnum = "autoiso"
DATGroupProvider DecodeProviderEnum = "dat"
AllProviders DecodeProviderEnum = ""
TeslaProvider DecodeProviderEnum = "tesla"
Japan17VIN DecodeProviderEnum = "japan17vin"
CarVXVIN DecodeProviderEnum = "carvxvin"
ElevaKaufmannProvider DecodeProviderEnum = "eleva"
)
type VINDecodingInfoData struct {
VIN string
Make string
Model string
SubModel string
Year int32
StyleName string
Source DecodeProviderEnum
ExternalID string
MetaData null.JSON
Raw []byte
FuelType string
}
// VINDecodingVendorExtra extra information from decoding process to store for failures
type VINDecodingVendorExtra struct {
VendorsTried []string
DrivlyRaw []byte
VincarioRaw []byte
AutoIsoRaw []byte
DATGroupRaw []byte
Japan17VINRaw []byte
CarVXVINRaw []byte
}
type AutoIsoVINResponse struct {
Version string `json:"version"`
Vin string `json:"vin"`
APIStatus string `json:"apiStatus"`
ResponseDate string `json:"responseDate"`
FunctionName string `json:"functionName"`
FunctionResponse struct {
Data struct {
API struct {
CoreVersion string `json:"core_version"`
EndpointVersion int `json:"endpoint_version"`
JSONVersion string `json:"json_version"`
APIType string `json:"api_type"`
APICache string `json:"api_cache"`
DataPrecision int `json:"data_precision"`
DataMatching string `json:"data_matching"`
LexLang string `json:"lex_lang"`
} `json:"api"`
Analyze struct {
VinOrginal struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"vin_orginal"`
VinCorrected struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"vin_corrected"`
VinYear struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"vin_year"`
VinSerial struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"vin_serial"`
Checkdigit struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"checkdigit"`
} `json:"analyze"`
Decoder struct {
Make struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"make"`
Model struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"model"`
ModelYear struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"model_year"`
Body struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"body"`
FuelType struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"fuel_type"`
VehicleType struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"vehicle_type"`
Doors struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"doors"`
EngineDisplCm3 struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_displ_cm3"`
EngineDisplL struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_displ_l"`
EnginePowerHp struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_power_hp"`
EnginePowerKw struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_power_kw"`
EngineConf struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_conf"`
EngineType struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_type"`
EngineVersion struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_version"`
EngineHead struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_head"`
EngineValves struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_valves"`
EngineCylinders struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_cylinders"`
EngineDisplCid struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_displ_cid"`
EngineTurbo struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"engine_turbo"`
DriveType struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"drive_type"`
GearboxType struct {
Desc string `json:"desc"`
Value string `json:"value"`
} `json:"gearbox_type"`
EmissionStd struct {
Desc string `json:"desc"`
Value string `json:"value"`
Co2Gkm string `json:"co2_gkm"`
} `json:"emission_std"`
} `json:"decoder"`
} `json:"data"`
} `json:"functionResponse"`
LicenseInfo struct {
LicenseNumber string `json:"licenseNumber"`
ValidTo string `json:"validTo"`
RemainingCredits int `json:"remainingCredits"`
RemainingMonthlyLimit int `json:"remainingMonthlyLimit"`
RemainingDailyLimit int `json:"remainingDailyLimit"`
} `json:"licenseInfo"`
}
// GetStyle returns a standard style string built from the data we have
func (v *AutoIsoVINResponse) GetStyle() string {
s := ""
// eg. Diesel
if len(v.FunctionResponse.Data.Decoder.FuelType.Value) > 0 {
s += v.FunctionResponse.Data.Decoder.FuelType.Value + " "
}
// eg. TDI
if len(v.FunctionResponse.Data.Decoder.EngineVersion.Value) > 0 {
s += v.FunctionResponse.Data.Decoder.EngineVersion.Value + " "
}
// eg. Manual
if len(v.FunctionResponse.Data.Decoder.GearboxType.Value) > 0 {
s += v.FunctionResponse.Data.Decoder.GearboxType.Value + " "
}
// eg. FWD / AWD
if len(v.FunctionResponse.Data.Decoder.DriveType.Value) > 0 {
s += v.FunctionResponse.Data.Decoder.DriveType.Value + " "
}
return strings.TrimSpace(s)
}
// GetSubModel returns the Body type, which we can use as the sub model.
func (v *AutoIsoVINResponse) GetSubModel() string {
return strings.TrimSpace(v.FunctionResponse.Data.Decoder.Body.Value)
}
type VincarioInfoResponse struct {
VIN string `key:"VIN"`
VehicleID int `key:"Vehicle ID"`
Make string `key:"Make"`
Model string `key:"Model"`
ModelYear int `key:"Model Year"`
ProductType string `key:"Product Type"`
Body string `key:"Body"`
Series string `key:"Series"`
Drive string `key:"Drive"`
EngineDisplacement int `key:"Engine Displacement (ccm)"`
FuelType string `key:"Fuel Type - Primary"`
EngineCode string `key:"Engine Code"`
Transmission string `key:"Transmission"`
NumberOfGears int `key:"Number of Gears"`
EmissionStandard string `key:"Emission Standard"`
PlantCountry string `key:"Plant Country"`
ProductionStopped int `key:"Production Stopped"`
EngineManufacturer string `key:"Engine Manufacturer"`
EngineType string `key:"Engine Type"`
AverageCO2Emission float64 `key:"Average CO2 Emission (g/km)"`
NumberOfWheels int `key:"Number Wheels"`
NumberOfAxles int `key:"Number of Axles"`
NumberOfDoors int `key:"Number of Doors"`
FrontBrakes string `key:"Front Brakes"`
RearBrakes string `key:"Rear Brakes"`
BrakeSystem string `key:"Brake System"`
SteeringType string `key:"Steering Type"`
WheelSize string `key:"Wheel Size"`
WheelSizeArray []string `key:"Wheel Size Array"`
Wheelbase int `key:"Wheelbase (mm)"`
WheelbaseArray []int `key:"Wheelbase Array (mm)"`
Height int `key:"Height (mm)"`
Length int `key:"Length (mm)"`
Width int `key:"Width (mm)"`
RearOverhang int `key:"Rear Overhang (mm)"`
FrontOverhang int `key:"Front Overhang (mm)"`
TrackFront int `key:"Track Front (mm)"`
TrackRear int `key:"Track Rear (mm)"`
MaxSpeed int `key:"Max Speed (km/h)"`
WeightEmpty int `key:"Weight Empty (kg)"`
MaxWeight int `key:"Max Weight (kg)"`
MaxRoofLoad int `key:"Max roof load (kg)"`
TrailerLoadWithoutBrakes int `key:"Permitted trailer load without brakes (kg)"`
CheckDigit string `key:"Check Digit"`
SequentialNumber string `key:"Sequential Number"`
}
// GetStyle returns a standard style string built from the data we have
func (v *VincarioInfoResponse) GetStyle() string {
s := ""
if len(v.FuelType) > 0 {
s += v.FuelType + " "
}
if len(v.EngineType) > 0 {
s += v.EngineType + " "
}
if len(v.Transmission) > 0 {
s += v.Transmission + " "
}
if v.NumberOfGears > 0 {
s += fmt.Sprintf("%d-speed", v.NumberOfGears)
}
return strings.TrimSpace(s)
}
// GetSubModel returns the Body type from Vincario, which we can use as the sub model.
func (v *VincarioInfoResponse) GetSubModel() string {
return strings.TrimSpace(v.Body)
}
// GetMetadata returns a map of metadata for the vehicle, in standard format.
func (v *VincarioInfoResponse) GetMetadata() (null.JSON, error) {
metadata := map[string]interface{}{
"fuel_type": v.FuelType,
"driven_wheels": v.Drive,
"number_of_doors": v.NumberOfDoors,
"base_msrp": nil,
"epa_class": v.EmissionStandard,
"vehicle_type": v.Body,
"mpg_highway": nil,
"mpg_city": nil,
"fuel_tank_capacity_gal": nil,
"battery_capacity_kwh": nil,
"mpg": nil,
}
bytes, err := json.Marshal(metadata)
if err != nil {
return null.JSON{}, err
}
return null.JSONFrom(bytes), nil
}
type DrivlyVINResponse struct {
Vin string `json:"vin"`
WindowSticker string `json:"windowSticker"`
Year string `json:"year"`
Make string `json:"make"`
Model string `json:"model"`
SubModel string `json:"subModel"`
Trim string `json:"trim"`
Generation int `json:"generation"`
SubGeneration int `json:"subGeneration"`
ManufacturerCode string `json:"manufacturerCode"`
Body string `json:"body"`
Style string `json:"style"`
Type string `json:"type"`
Drive string `json:"drive"`
Transmission string `json:"transmission"`
TransmissionDetails string `json:"transmissionDetails"`
Engine string `json:"engine"`
EngineDetails string `json:"engineDetails"`
Doors int `json:"doors"`
PaintColor string `json:"paintColor"`
PaintName string `json:"paintName"`
PaintCode string `json:"paintCode"`
Interior string `json:"interior"`
Options []string `json:"options"`
OptionCodes string `json:"optionCodes"`
MsrpBase float64 `json:"msrpBase"`
MsrpDiscount float64 `json:"msrpDiscount"`
MsrpOptions float64 `json:"msrpOptions"`
MsrpDelivery float64 `json:"msrpDelivery"`
Msrp float64 `json:"msrp"`
WarrantyBasicMonths int `json:"warrantyBasicMonths"`
WarrantyCorrosionMonths int `json:"warrantyCorrosionMonths"`
WarrantyEmissionsMonths int `json:"warrantyEmissionsMonths"`
WarrantyFullMonths int `json:"warrantyFullMonths"`
WarrantyFullMiles int `json:"warrantyFullMiles"`
WarrantyDrivetrainMonths int `json:"warrantyDrivetrainMonths"`
WarrantyPowertrainMonths int `json:"warrantyPowertrainMonths"`
WarrantyPowertrainMiles int `json:"warrantyPowertrainMiles"`
WarrantyRoadsideMonths int `json:"warrantyRoadsideMonths"`
WarrantyRoadsideMiles int `json:"warrantyRoadsideMiles"`
Wheelbase string `json:"wheelbase"`
Fuel string `json:"fuel"`
FuelTankCapacityGal float64 `json:"fuelTankCapacityGal"`
BatteryCapacityKwh float64 `json:"batteryCapacityKwh"`
Mpg int `json:"mpg"`
MpgCity int `json:"mpgCity"`
MpgHighway int `json:"mpgHighway"`
LastOdometer int `json:"lastOdometer"`
LastOdometerDate string `json:"lastOdometerDate"`
EstimatedOdometer int `json:"estimatedOdometer"`
Salvage bool `json:"salvage"`
PreviousOwners int `json:"previousOwners"`
TotalLoss bool `json:"totalLoss"`
Branded bool `json:"branded"`
LastTitleState string `json:"lastTitleState"`
TitleIssueDate string `json:"titleIssueDate"`
TitleNumber string `json:"titleNumber"`
Confidence float64 `json:"confidence"`
VehicleHistory []string `json:"vehicleHistory"`
InstalledEquipment []string `json:"installedEquipment"`
Dimensions []string `json:"dimensions"`
}
// GetExternalID builds something we can use as an external ID that is drivly specific, at the MMY level (not for style)
func (vir *DrivlyVINResponse) GetExternalID() string {
// cant use shared.SlugString due to import cycle
return strings.ReplaceAll(strings.ToLower(fmt.Sprintf("%s-%s-%s", vir.Make, vir.Model, vir.Year)), " ", "")
}
type DATGroupInfoResponse struct {
VIN string `json:"vin"`
DatECode string `json:"datecode"`
SalesDescription string `json:"salesDescription"`
VehicleTypeName string `json:"vehicleTypeName"`
// make
ManufacturerName string `json:"manufacturerName"`
BaseModelName string `json:"baseModelName"`
SubModelName string `json:"subModelName"`
// this is the model name we want to use
MainTypeGroupName string `json:"mainTypeGroupName"`
VinAccuracy int `json:"vinAccuracy"`
// when we're unable to get exact year
YearLow int `json:"yearLow"`
YearHigh int `json:"yearHigh"`
// we don't always get the exact year
Year int `json:"year"`
SeriesEquipment []DATGroupEquipment `json:"seriesEquipment"`
SpecialEquipment []DATGroupEquipment `json:"specialEquipment"`
DATECodeEquipment []DATGroupEquipment `json:"datECodeEquipment"`
VINEquipment []DATGroupEquipment `json:"vinEquipments"`
}
// nolint
type DATGroupEquipment struct {
DatEquipmentId string `json:"datEquipmentId"`
ManufacturerEquipmentId string `json:"manufacturerEquipmentId"`
// if Vin Equipment, this comes from ShortName
ManufacturerDescription string `json:"manufacturerDescription"`
Description string `json:"description"`
}
// nolint
type Japan17MMY struct {
VIN string `json:"vin"`
ManufacturerName string `json:"manufacturerName"`
ManufacturerLowerCase string `json:"manufacturerLowerCase"`
ModelName string `json:"modelName"`
Year int `json:"year"`
}
// nolint
type CarVxResponse struct {
Data []struct {
Make string `json:"make"`
Model string `json:"model"`
Grade string `json:"grade"`
Body string `json:"body"`
Engine string `json:"engine"`
Drive string `json:"drive"`
Transmission string `json:"transmission"`
Fuel string `json:"fuel"`
ManufactureDate struct {
Year string `json:"year"`
Month string `json:"month"`
} `json:"manufacture_date"`
} `json:"data"`
Error string `json:"error"`
}
// nolint
type ElevaVINResponse struct {
Error int `json:"error"`
Message string `json:"message"`
Data struct {
Client struct {
Rut string `json:"rut"`
ClientId int `json:"clientId"`
Name string `json:"name"`
Lastname string `json:"lastname"`
Email string `json:"email"`
Phone string `json:"phone"`
BusinessName string `json:"businessName"`
} `json:"client"`
Vehicle struct {
Plate string `json:"plate"`
Chassis string `json:"chassis"`
Model string `json:"model"`
Kms int `json:"kms"`
Baumuster string `json:"baumuster"`
Brand string `json:"brand"`
} `json:"vehicle"`
} `json:"data"`
}