Cannot convert unit mvarh to unit mvar

#1

On 7.2 I’ve two custom units: mvarh and mvar, defined as follows:

{
  "name" : "megavolt amp reduction hours",
  "symbol" : "MVARh",
  "components" : [ {
    "unit" : {
      "id" : "mvar"
    },
    "order" : "1",
    "multiplier" : "1"
  }, {
    "unit" : {
      "id" : "hour"
    },
    "order" : "1",
    "multiplier" : "1"
  } ],
  "concept" : "power factor correction",
  "id" : "mvarh",
  "meta" : { }
}

and

{
  "name" : "megavolt amp reduction",
  "symbol" : "MVAR",
  "concept" : "power factor correction",
  "id" : "mvar",
  "components" : [ {
    "unit" : {
      "id" : "megawatt"
    },
    "order" : "1",
    "multiplier" : "1"
  } ],
  "meta" : { }
}

Now if I try to covert anyone to the other one I hit:

MetricEngine error : c3.love.exceptions.C3RuntimeException: 
  Error c3.love.units.exceptions.InconvertableException: Cannot convert unit mvarh to unit mvar

Then I check and see that both units are not convertible:

> Unit.isConvertable({id: 'mvarh'}, {id: 'mvar'})
false
> Unit.isConvertable({id: 'varh'}, {id: 'mvarh'})
false

Now I remove one UnitComponent from mvarh, specifically {"unit" : {"id" : "hour"},"order" : "1","multiplier" : "1"} and now the conversion works!

> Unit.isConvertable({id: 'mvarh'}, {id: 'mvar'})
true
> Unit.isConvertable({id: 'mvar'}, {id: 'mvarh'})
true

Is the unit conversion buggy?

Validity of `evalMetric[s]`
#2

@bachr Can you do c3Grid(Cache.list()) and see if the UnitsCache says tenant /tag aware true or false?
There was a bug in the previous versions of the server which was fixed and we experienced this behavior if the cached state was messed up.

As a workaround, you can flush the UnitsCache and try again and it should work.

#3

@rohit.sureka thanks, which one of the cache entries, I see c3.server.love.units and c3.server.love.units-fundamental. Both have enabled set to true!

#4

Just a guess but looking at the error:

Error c3.love.units.exceptions.InconvertableException

I’d say c3.server.love.units

#5

on 7.2, Units cache is not TenantTagAware. I believe this was fixed in 7.6.1.
So after upserting, need to empty caches. BTW, Unit.isConvertable({id: ‘mvarh’}, {id: ‘mvar’}) should be false…

#6

why is that? did the way I’m defining the units incorrect?

#7

did n’t you define . mvarh = mvar * hour… so mvarh unit for different concept than mvar.
isConvertible is true, for units that are measuring same concept as in length, time, energy etc.

1 Like
#8

Converting mvar to mvarh doesn’t make sense, its like converting miles to miles-per-hour.

1 Like
closed #9
archived #10
#11

This seems to be non-obvious. I agree that, by default, one dimension/concept[1] cannot be converted into another. But perhaps the conversion here is context-dependent/aware: you may want to convert mvar into mvarh by multiplying it by a constant in hour, just in some context where it makes sense to you, for whatever purpose. If this is not what is meant, then one should always know it is a bug when an error “cannot convert mvar to mvarh” occurs; one should not say, “please define a conversion” (as it happens).

The dilemma could be removed by using the field concept and augmenting the above error by “because they relate to different concepts.”

[1] https://en.wikipedia.org/wiki/Dimensional_analysis

#12

How do you upsert and/or empty/flush cache? We get "litre not convertible to cubic_meter" from time to time…
Thanks

#13

which version of server, is this. should not happen in 7.7+. If this is 7.7+ please file a ticket. earlier version, if another tag in same tenant, modifes units data, it could cause this error. provision to recreate the units. that should refresh the cache.

Unit Conversion
#14

The server is v7.6.1. Thanks, we will try provisioning.