Help with computed attributes

socstur7 years ago

Hi Anton,
I am trying to use the new computed attributes to calculate fuel consumption using "Distance" attribute. However its giving me an error. I am trying to update the "Fuel consumption" or "Fuel" attribute using this calculation "Distance*1/(mpg_value)". To test out the computed attributes feature to see if it works for me I tried one of your examples below.

Ignition
flags ? (flags & 2) != 0 : false
Boolean

This also gives me the error below. Do you know what I could be doing wrong? The device I tested on is using gt06 protocol which does report "Battery" attribute.

org.traccar.processing.ComputedAttributesHandler.computeAttribute@70![0,7]: 'Battery < 4.18 && Speed < 1? false : true;' undefined variable Battery - Variable (... < ComputedAttributesHandler:70 < AttributeResource:97 < *:120 < ...)

Anton Tananaev7 years ago

All attributes are in lower-camel-case format. For battery you should use "battery" (all lower case).

socstur7 years ago

thanks for the quick reply. Using lower case now and I'm not getting the error anymore.

What do you recommend for calculating the "spent fuel" column in the trip report if the device does not report it. I'm assuming the "fuel" attribute is what gets reported as "spent fuel" in the reports. The units for the fuel consumption attribute shows l/h...is that liters per hour? and how can that be converted to liter per km?

Anton Tananaev7 years ago

For report you should use "fuel" which is fuel level in litres.

You can find available attribute keys here: Position.java.

socstur7 years ago

Thanks for the response Anton. I'm a little confused about how the "spent fuel" column is calculated in the reports; I am computing the "fuel" attribute using distance and I'm not getting the right "spent fuel" in my reports . If the "fuel" attribute indicates the fuel level in the vehicle how is that used to populate the "spent fuel" column. I am using the "distance" attribute to calculate the "fuel", but this computation gives the fuel used not the fuel level. If you can help me better understand how the "spent fuel" column is derived using the "fuel" attribute I can try to find a way to compute the "spent fuel" using "distance"

Anton Tananaev7 years ago

Currently spent fuel is calculated as a difference between fuel level.

socstur7 years ago

Do you have any recommendation to compute the "fuel" attribute using "distance" and average consumption for devices that do not report it?

I have tried using an attribute to fill an imaginary tank when the vehicle stops(so fuel=1000L if motion is false) and deducting from it when it once it starts moving (so fuel=fuel-distance*(1/mpg)) but it doesn't seem to work. I suppose you don't recommend doing computation on a computed attribute. Do you see any way around this?

Anton Tananaev7 years ago

You can try something like this:

1000000 - totalDistance * [your rate here]
socstur7 years ago

Thanks Anton...it looks like your suggestion will work assuming I can keep the totalDistance accurate and without jumps in gps position when parked. It'll be nice if distance or totalDistance only update with ignition on.

Last question...I promise :) . Can I create a variable in the device attributes and use it in my computations? I'll like to store the device fuel rates in a variable created in the device attributes. I tried but it didn't work...just curious your take on it.

Anton Tananaev7 years ago

It's not possible, but I like the idea. Please create a feature request on GitHub for it.

socstur7 years ago

Ok I'll do that...Thanks for the help.

José Germán6 years ago

Hello Anton, a warm greeting and congratulations for your work and contribution with traccar
I need to show an estimate of fuel consumption in the travel reports.
I'm using computed attributes
Attribute: fuel
Expression:
if (fuel <= 0) fuel = 55
else
fuel = 55- (io65 / 8000)
type: numeric.
where io65 = virtual odometer (meters - Device Ruptela), rate=8km/lts and tank capacity = 55 liters (e.g: my car)
Will this work so that I show the desired value in the trip report? or should I use another attribute or how could I do it?

Anton Tananaev6 years ago

I guess it should work if you have full tank at the beginning of the trip. What does negative fuel mean though?

José Germán6 years ago

I do not know if fuel comes to acquire negative values in the calculations. When you reach zero or acquire a negative value, automatically fill the tank

Anton Tananaev6 years ago

That doesn't make much sense. Attributes don't know anything about previous values.