coddingtonbear / django-measurement

Easily store, retrieve, and convert measurements of weight, volume, distance, area and more.
MIT License
145 stars 33 forks source link

Calculation based on external model value #68

Closed synnack closed 4 years ago

synnack commented 6 years ago

Hi,

Is it possible to have the measurement conversion look at a different field for the conversion?

What I'm looking for a way to convert different types of fuel between metric, imperial, but also between volume and weight. :)

Essentially, things like gallons per hour, litres per hour, grams per second, grams per hour.

For 1 type of fuel this is simple, just create a custom Fuel measure class and define the conversions there, then create a bi-dimensional measurement that has Fuel over time.

Now, the problem is that I have 2 main types of fuel: one at 0.721 kg/l, and one at 0.804 kg/l.

For multiple types of fuel, it needs to find the conversion somewhere else in the model class..

From the point of view of the field, it'll be in the parent (model) and there in a field with the value stored there.

codingjoe commented 6 years ago

Hi @synnack I don't think using a value from another field is a wise idea. I would recommend to just add a new metric and a new field. The metric you seem to be looking for is volumetric flow rate. Would that help you? Maybe you can explain in a bit more detail what data you want to store.

JackAtOmenApps commented 4 years ago

@codingjoe now that we have volumetric flow in python-measurement and the poster didn't add any new details in over 2 years, this issue can probably be closed out.

synnack commented 4 years ago

Damn, I forgot about this issue :)

Volumetric flow rate is exactly what I do not want, it's flow rate.. but the input may be volumetric or mass.

synnack commented 4 years ago

Essentially, I want to use mass as a base for all calculations, but it may store volume+fuel.. for instance, 20 US Gallon per hour of JetA, Jet B, 100LL Avgas or Diesel. Those have different masses, so the conversion is dependent on the fuel, but you want to input the values that you have, which may be in GPH, LPH or (better) g/s

codingjoe commented 4 years ago

I think in this case I would recommend doing the calculation in your form or view on a model mutation method. Not inside the field. Besides, this use case is too uncommon to implement it in the package itself. If you want to implement such behavior inside the field, you'd need to subclass it. Best. Joe