2013/7/16 Cédric Krier <[email protected]> > On 16/07/13 12:17 +0200, Robert Schöftner wrote: > > Am 2013-07-16 11:41, schrieb Cédric Krier: > > > On 16/07/13 12:12 +0300, Giedrius Slavinskas wrote: > > >> > 2013/7/15 Cédric Krier <[email protected]> > > >>> > > On 15/07/13 10:25 +0300, Giedrius Slavinskas wrote: > > >>> > > So let's introduce it. > > >>> > > > > >>> > > > > >>> > > class Measure(namedtuple('Measure', ['quantity', 'unit'])): > > >>> > > __slots__ = () > > >>> > > > > >>> > > def convert_to(self, uom, round=True): > > >>> > > Uom = Pool().get('product.uom') > > >>> > > return Measure(Uom.compute_qty(self.unit, self.quantity, > uom, > > >>> > > round=round), uom) > > >>> > > > > >>> > > > > >>> > > Which will make: > > >>> > > > > >>> > > Measure(1000, gr).convert_to(kg) == Measure(1, kg) > > >> > > > >> > > > >> > I suggest more intuitive interface/naming. Here is just the idea, > > >> > nothing mean to work. > > >> > > > >> > class Quantity(namedtuple('Quantity', ['units', 'uom'])): > > > I don't understand why using "units" ? For me, it sounds wrong. > > > unit is what is called uom == Unit of Measure. > > > > > > Quantity sounds like it is a scalar, when measure sounds better > > > especially because we already use "Unit of Measure". > > nitpicking: > > > > uom should be "unit of measurement". > > > > "measure" is something different than "measurement", see [1], I would > > associate it with set-theory and calculus. > > Yes probably I'm confuse with the french. > But it doesn't seem to be incorrect: > https://en.wikipedia.org/wiki/Unit_of_measure > > > "quantity" seems to be the correct term (according to wikipedia). Thus I > > propose: > > > > class Quantity(namedtuple('Quantity', ['amount', 'uom'])): >
Quantity must be expressed by units and unit_of_measurement, where unit_of_measurement is the measurement of a single unit and units is how many UoMs the quantity containts. > > For me, the definition is not so clear about what is the quantity. Is it > the couple or the part in front of the unit? > When someone is talking about quantity he refer not only to numeric value, but also the meaning of this numeric value (UoM). Quantity is a combination of unit of measurement and amount of these units. UoM is a standard of measurement. For example the standard of kg is 1 liter of water (in specific conditions). By 5 kg, we refer that, it weights the same as 5 units of standard. Unit of measure == Unit of measurement == measure == standard for measurement For money this can be used: <Amount(amount, currency)> > Anyway, I'm in favor of consistency and as quantity is already used in > many places. It will be confusing to introduce a new Object with the > same name for something different. > So for me, this new object must be named to describe the result of a > measurement (and not generate collisions). > > -- Giedrius
