Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 05 22:41

    cquiroz on master

    Update sbt Signed-off-by: Carl… Merge pull request #461 from cq… (compare)

  • Apr 05 22:41
    cquiroz closed #461
  • Apr 05 13:15
    cquiroz commented #454
  • Apr 05 13:14
    cquiroz synchronize #454
  • Apr 05 01:02
    cquiroz closed #460
  • Apr 05 01:02
    cquiroz opened #461
  • Apr 04 23:46
    scala-steward opened #460
  • Apr 01 09:50

    larsrh on master

    Update scalatest to 3.2.7 Merge pull request #459 from sc… (compare)

  • Apr 01 09:50
    larsrh closed #459
  • Apr 01 07:45
    scala-steward opened #459
  • Mar 31 20:23

    cquiroz on master

    Update sbt-scalajs, scalajs-com… Merge pull request #458 from sc… (compare)

  • Mar 31 20:23
    cquiroz closed #458
  • Mar 31 17:43
    scala-steward opened #458
  • Mar 23 11:10

    cquiroz on master

    Update sbt-ci-release to 1.5.7 Merge pull request #457 from sc… (compare)

  • Mar 23 11:10
    cquiroz closed #457
  • Mar 23 10:27
    scala-steward opened #457
  • Mar 17 11:36
    cquiroz commented #454
  • Mar 17 11:28
    AtelierFox commented #454
  • Mar 17 11:28
    AtelierFox commented #454
  • Mar 11 12:40

    cquiroz on master

    Update sbt-ci-release to 1.5.6 Merge pull request #456 from sc… (compare)

Roberto Leibman
@rleibman
Hey... hi... thanks for the wonderful library! I wrote some extra utilities to deal with cooking issues. I don't know if it's useful at all to anyone and if it is, I can incorporate it more thoroughly and create a pull request:
https://gist.github.com/rleibman/aae13e38ae0d3490c3b5e5ec3b47bc68
In particular, I use this to parse recipes, so it's capable of figuring out the ingredients and units, figure out what's the optimal measurement to display ingredients in (depending on the size of containers used for cooking), etc.
garyKeorkunian
@garyKeorkunian
@rleibman That looks pretty cool. It seems to be more application specific, however, it could make a great companion project. It may make sense to add the units you created to Squants, but I'm not sure. I'm not an expert on cooking and don't know how precise things like a "dash" really is. What do others think?
Soren
@srnb_gitlab
We learned about angular momentum, acceleration, velocity, and torque this week in physics class, and I was looking for them in Squants and could only find angular velocity
Shadaj Laddad
@shadaj
@srnb_gitlab my high-school robotics team contributed torque and angular acceleration some time back, we needed it for our own physics simulations (https://github.com/typelevel/squants/pull/227/files)
Soren
@srnb_gitlab
Huh
Guess it just has to be added to the table
Roberto Leibman
@rleibman
Ok... so I have a Quantity... but I have no clue what kind of quantity (I parsed these from recipe ingredients, so I know I have something, just don't know what).
val qty: Quantity[_ <: Quantity[_]] = parse(str)
Now... I have a Seq of these... I group them by qty.dimension:
val groups = quantities.groupBy(_.dimension)
So that I know that within a group they're all the same dimension.
How do I add them? I can't seem to get the types right, something like this:
quanties.foldLeft(unit(0))((a, b) => b.plus(a))
Roberto Leibman
@rleibman
This is the first time in my life I wish for laxer types :)
garyKeorkunian
@garyKeorkunian
Abstracting over the quantity type in many use cases defeats the purpose of the type-safety that Squants provides. Once you have a quantity you need to know what you can do with it. One suggestion I would have for your use case is to split the ingredient list into those that are by mass vs volume. Then creating and scaling the actual quantities should be trivial.
To split the list compare each ingredients unit to those available from Mass and Volume. I'd have to look, but I don't think there are any overlaps.
Roberto Leibman
@rleibman
Ounces, though it's a corner case... in essence that's what I'm doing, grouping by dimension, yes, I could do copy and paste, and then do a whole section casted by mass, another section by volume, another by length (e.g. an inch of ginger) and yet another by dimensionless (a clove of garlic, a head of lettuce, one apple).
I did something super ugly and casted everything to things like Quantity[Nothing]. It's ugly, and it works, but in essence it's exactly what I mean: I know the dimensions match (I grouped, so they must!) and I don't care what they are, just process them.
garyKeorkunian
@garyKeorkunian
Ah, yes. Ounces. How did I overlook that? Quanity[Nothing]. That's interesting. Don't you end up losing the type and therefore some of the scaling features (ounces to cups, etc)?
I say "scaling" because when you want to scale up a recipe (4 servings to 100 servings) I assume you will want to show ingredients in larger units.
.... ounces. It's funny how recipes don't differentiate between them (liquid vs dry). They just assume we have the context to know which applies based on the ingredient. So, the questions is, how do you give your application that context?
Roberto Leibman
@rleibman
I just assume fluid oz vs weight oz. If you look at my gist above (which I've changed a bit), I have a method per Dimension on the CookingUnitGroup that gives me the quanity "inBestUnit", using the available containers.
And yes, with Nothing I lose the type, but I never had it in the first place, which is what Nothing implies, so I think it's all good.
garyKeorkunian
@garyKeorkunian
nice. looking at it again, I think there would be some value to the synonyms concept. That could make the built in parser more useful for use cases like this.
Soren
@srnb_gitlab
Is https://gitlab.com/srnb/nose workable into Squants? I have so many cases where I want to use it but the Squants way of doing things is so much easier
I'd like to rewrite nose at some point to actually extend Squants but I'm fresh out of time at the moment
garyKeorkunian
@garyKeorkunian
I don't know much about nose. What use cases did you have in mind? What do you mean by "workable into Squants"?
Soren
@srnb_gitlab
I wrote nose because I wanted to do some color operations, like dithering, in the CIELab space and not the sRGB space
I'm wondering if Squants could have Color as a dimension and Srgb, CIELab, HSV, etc as units
My new usecase is integrating with A frame where all colors need to be rgb style
The way nose does it right now is very limited, you have to know the units at compile time and conversion is handled very weirdly
The only problem I can forsee is the way conversions are handled in Squants, i.e. with Squants, converting from CIELab to CIEXYZ might go CIELab -> sRGB -> CIEXYZ if sRGB were to be the base unit
garyKeorkunian
@garyKeorkunian
I would suggest starting out by creating the Quantity, Dimension and Units (extending from Squants types) you need within your project (or a companion project). This isn't too difficult. Once you have validated that it works for your use-case, we can take look to ensure it is general enough to be included in Squants.
Yes, conversions from one non-base unit to another do need to "pass-through" the base, which is essentially calculating a new conversion factor from the two-non base factors. That can be "precision-lossy".
Soren
@srnb_gitlab
It's also time intensive because the calculations aren't as simple as multiplying by constants
It takes a significantly nonzero amount of time to convert from CIELAB -> sRGB -> CIELAB on my machine
Napas (Tian) Udomsak
@tian000
Is there a method for parsing "$5.00" as Money(5, USD)
garyKeorkunian
@garyKeorkunian
@tian000 There is not a parser for that directly. One reason is that many currencies use the "$" symbol, so no way to tell which one. The only parsing available now would support strings like "5 USD"
Howy Perrin
@howyp
Hey! Is there a way in squants to specify the unit of a Dimensionless at the type level? I'd like to do something like: case class InterestRate(r: Percentage). As far as I can see, that's not possible - Dimensionless just holds the unit as a runtime value?
2 replies
Julien Richard-Foy
@julienrf

Hello, I’m using squants 1.6.0 and I see this:

scala> squants.thermal.Kelvin(300).toCelsiusDegrees
res4: Double = 300.0

What I try to do is to convert 300 K into °C. It should return 26.85 but I get 300. Did I do something wrong?

I’ve found the following workaround:
scala> squants.thermal.Kelvin(300).toCelsiusScale
res9: Double = 26.850000000000023
But that’s still surprising.
garyKeorkunian
@garyKeorkunian
@julienrf Yes, naming things is hard. We did need a way to support both types of conversions: "Thermometer" conversions as well as a "Quantity of Degrees" conversion.
It's the only Dimension in squants where the units don't share a Zero.
garyKeorkunian
@garyKeorkunian
Interestingly sometimes temperature ranges are quoted like this -> 75F (+/- 2C). So we need to convert a quantity of 2C to a quantity of F to get the actual range in F (75F (+/- 3.6F)). With only the thermometer conversion, we'd get 75F (+/- 35.6F).
Tim Pigden
@TimPigden
Hi Guys. I've just upgraded to latest version of squants and I'm having trouble writing/parsing money values.
GBP(5000).toFormattedString gives me £5000. How do I read that back? GBP(5000).toString gives me 5E3 GBP. How do I read that back? I can read 5000 GBP but the other two seem to fail. I can't figure the trick from the docs.
Tim Pigden
@TimPigden
btw if this is a currently known issue, I'm happy to have a crack at fixing. Is there an active PR review process?
Tim Pigden
@TimPigden

ok, I forked and cloned and added this test to MoneySpec

  it should "read its own output from formatted strings given an implicit MoneyContext in scope" in {
    implicit val moneyContext = MoneyContext(USD, defaultCurrencySet, Nil)
    Money("500 USD").get should be(USD(500))
    Money(Money("500 USD").toString) should be(USD(500))
  }

Gives

Failure(squants.QuantityParseException: Unable to parse Money:Success(5E+2 USD)) was not equal to 5E+2 USD
as far as I can see it's down to this:
  def apply(s: String)(implicit fxContext: MoneyContext): Try[Money] = {
    val regex = ("([-+]?[0-9]*\\.?[0-9]+) *(" + fxContext.currencies.map(_.code).reduceLeft(_ + "|" + _) + ")").r
    s match {
      case regex(value, currency) ⇒ Currency(currency).map(Money(value.toDouble, _))
      case _                      ⇒ Failure(QuantityParseException("Unable to parse Money", s))
    }
  }
Tim Pigden
@TimPigden
which clearly excludes E from the number portion of the string. 2 obvious solutions are:
  1. since people don't really use E in money constants, change the default toString to always write out as decimal
  2. change the above, to include E on LHS of the parsing.
    What do people think?
Carlos Quiroz
@cquiroz
There has been a slew of PRs lately, we should make a release
Carlos Quiroz
@cquiroz
I’ll produce a release today
Thijs Broersen
@ThijsBroersen
Is Squants following any convention regarding serialization? E.g. I am interested in using Squants datatypes directly in protobuf definitions and generated classes. So far I could not find any protobuf related thing for either Squants or other units of measure data models. Any suggestions?
Carlos Quiroz
@cquiroz
Not really, squants is independent of any serialization format