Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Nov 25 17:13
    smarter commented #412
  • Nov 23 14:51

    larsrh on master

    Update sbt to 1.4.4 (#430) Co-… (compare)

  • Nov 23 14:51
    larsrh closed #430
  • Nov 23 11:59
    larsrh synchronize #430
  • Nov 23 11:59
    larsrh commented #431
  • Nov 23 11:59

    larsrh on bump-actions

    (compare)

  • Nov 23 11:59

    larsrh on master

    bump action versions Merge pull request #431 from ty… (compare)

  • Nov 23 11:59
    larsrh closed #431
  • Nov 23 11:17
    cquiroz commented #431
  • Nov 23 07:15
    larsrh opened #431
  • Nov 23 07:14

    larsrh on bump-actions

    bump action versions (compare)

  • Nov 23 04:59
    scala-steward opened #430
  • Nov 16 11:20

    cquiroz on master

    Update sbt to 1.4.3 Merge pull request #429 from sc… (compare)

  • Nov 16 11:20
    cquiroz closed #429
  • Nov 16 06:12
    scala-steward opened #429
  • Nov 15 19:13

    cquiroz on master

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

  • Nov 15 19:13
    cquiroz closed #428
  • Nov 15 17:14
    scala-steward opened #428
  • Nov 09 07:14

    larsrh on master

    Update scalatest to 3.2.3 Merge pull request #427 from sc… (compare)

  • Nov 09 07:14
    larsrh closed #427
garyKeorkunian
@garyKeorkunian
Well, not sure it's a bug exactly, but one of the main goals of the project is to make the underlying value type generic instead of the hard Double that it is. I have a fork here https://github.com/garyKeorkunian/squants-generic that is my attempt to work through that. I haven't had much time to do that so contributors are certainly welcome. Of course, there's also a number of open items on the issues list.
Przemek Sokół
@falconepl
I will take a look. Thanks!
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