mirror of
https://github.com/tobiasehlert/teslamateapi.git
synced 2026-02-27 09:54:18 +08:00
chore: reordering sql query slightly (#364)
This commit is contained in:
@@ -143,9 +143,6 @@ func TeslaMateAPICarsDrivesV1(c *gin.Context) {
|
||||
COALESCE( NULLIF ( GREATEST ( start_rated_range_km - end_rated_range_km, 0 ), 0 ),0 ) as range_diff_rated_km,
|
||||
outside_temp_avg,
|
||||
inside_temp_avg,
|
||||
(SELECT unit_of_length FROM settings LIMIT 1) as unit_of_length,
|
||||
(SELECT unit_of_temperature FROM settings LIMIT 1) as unit_of_temperature,
|
||||
cars.name,
|
||||
CASE
|
||||
WHEN (start_rated_range_km - end_rated_range_km) > 0
|
||||
THEN (start_rated_range_km - end_rated_range_km) * cars.efficiency
|
||||
@@ -155,7 +152,10 @@ func TeslaMateAPICarsDrivesV1(c *gin.Context) {
|
||||
WHEN (duration_min > 1 AND distance > 1 AND ( start_position.usable_battery_level IS NULL OR end_position.usable_battery_level IS NULL OR ( end_position.battery_level - end_position.usable_battery_level ) = 0 )) AND NULLIF(distance, 0) IS NOT NULL
|
||||
THEN (start_rated_range_km - end_rated_range_km) * cars.efficiency / NULLIF(distance, 0) * 1000
|
||||
ELSE NULL
|
||||
END as consumption_net
|
||||
END as consumption_net,
|
||||
(SELECT unit_of_length FROM settings LIMIT 1) as unit_of_length,
|
||||
(SELECT unit_of_temperature FROM settings LIMIT 1) as unit_of_temperature,
|
||||
cars.name
|
||||
FROM drives
|
||||
LEFT JOIN cars ON car_id = cars.id
|
||||
LEFT JOIN addresses start_address ON start_address_id = start_address.id
|
||||
@@ -236,11 +236,11 @@ func TeslaMateAPICarsDrivesV1(c *gin.Context) {
|
||||
&drive.RangeRated.RangeDiff,
|
||||
&drive.OutsideTempAvg,
|
||||
&drive.InsideTempAvg,
|
||||
&drive.EnergyConsumedNet,
|
||||
&drive.ConsumptionNet,
|
||||
&UnitsLength,
|
||||
&UnitsTemperature,
|
||||
&CarName,
|
||||
&drive.EnergyConsumedNet,
|
||||
&drive.ConsumptionNet,
|
||||
)
|
||||
|
||||
// converting values based of settings UnitsLength
|
||||
|
||||
@@ -160,9 +160,6 @@ func TeslaMateAPICarsDrivesDetailsV1(c *gin.Context) {
|
||||
COALESCE( NULLIF ( GREATEST ( start_rated_range_km - end_rated_range_km, 0 ), 0 ),0 ) as range_diff_rated_km,
|
||||
outside_temp_avg,
|
||||
inside_temp_avg,
|
||||
(SELECT unit_of_length FROM settings LIMIT 1) as unit_of_length,
|
||||
(SELECT unit_of_temperature FROM settings LIMIT 1) as unit_of_temperature,
|
||||
cars.name,
|
||||
CASE
|
||||
WHEN (start_rated_range_km - end_rated_range_km) > 0
|
||||
THEN (start_rated_range_km - end_rated_range_km) * cars.efficiency
|
||||
@@ -172,7 +169,10 @@ func TeslaMateAPICarsDrivesDetailsV1(c *gin.Context) {
|
||||
WHEN (duration_min > 1 AND distance > 1 AND ( start_position.usable_battery_level IS NULL OR end_position.usable_battery_level IS NULL OR ( end_position.battery_level - end_position.usable_battery_level ) = 0 )) AND NULLIF(distance, 0) IS NOT NULL
|
||||
THEN (start_rated_range_km - end_rated_range_km) * cars.efficiency / NULLIF(distance, 0) * 1000
|
||||
ELSE NULL
|
||||
END as consumption_net
|
||||
END as consumption_net,
|
||||
(SELECT unit_of_length FROM settings LIMIT 1) as unit_of_length,
|
||||
(SELECT unit_of_temperature FROM settings LIMIT 1) as unit_of_temperature,
|
||||
cars.name
|
||||
FROM drives
|
||||
LEFT JOIN cars ON car_id = cars.id
|
||||
LEFT JOIN addresses start_address ON start_address_id = start_address.id
|
||||
@@ -214,11 +214,11 @@ func TeslaMateAPICarsDrivesDetailsV1(c *gin.Context) {
|
||||
&drive.RangeRated.RangeDiff,
|
||||
&drive.OutsideTempAvg,
|
||||
&drive.InsideTempAvg,
|
||||
&drive.EnergyConsumedNet,
|
||||
&drive.ConsumptionNet,
|
||||
&UnitsLength,
|
||||
&UnitsTemperature,
|
||||
&CarName,
|
||||
&drive.EnergyConsumedNet,
|
||||
&drive.ConsumptionNet,
|
||||
)
|
||||
|
||||
switch err {
|
||||
|
||||
Reference in New Issue
Block a user