Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 21 15:41
    scala-steward opened #498
  • Oct 20 16:14

    cquiroz on master

    Update sbt-mdoc to 2.2.24 Merge pull request #497 from sc… (compare)

  • Oct 20 16:14
    cquiroz closed #497
  • Oct 20 15:23
    scala-steward opened #497
  • Oct 18 14:22

    cquiroz on master

    Update scala3-library, ... to 3… Merge pull request #496 from sc… (compare)

  • Oct 18 14:22
    cquiroz closed #496
  • Oct 18 13:59
    scala-steward opened #496
  • Oct 14 19:54

    cquiroz on master

    Update scala-library to 2.12.15 Merge pull request #492 from sc… (compare)

  • Oct 14 19:54
    cquiroz closed #492
  • Oct 14 19:54

    cquiroz on master

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

  • Oct 14 19:54
    cquiroz closed #495
  • Oct 14 15:19
    scala-steward opened #495
  • Oct 10 20:41
    sentenza opened #494
  • Oct 06 22:06

    cquiroz on master

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

  • Oct 06 22:06
    cquiroz closed #493
  • Oct 06 20:40
    scala-steward opened #493
  • Oct 05 03:35
    scala-steward opened #492
  • Sep 29 22:50
    cquiroz commented #491
  • Sep 29 22:44

    cquiroz on master

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

  • Sep 29 22:44
    cquiroz closed #490
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
Loránd Szakács
@lorandszakacs

folks, is this a bug or a feature? :D

  test("Bug reproduction - squants.toString depends on ScalaOps.format, which down the stack uses the Locale") {
    IO {
      val quantity        = squants.Seconds(0.0d)
      java.util.Locale.setDefault(java.util.Locale.GERMAN)
      val quantityGerman  = quantity.toString // = 0,0 s
      java.util.Locale.setDefault(java.util.Locale.ENGLISH)
      val quantityEnglish = quantity.toString // 0.0 s
      scala.Console.println(quantityGerman, quantityEnglish)
      assert(clue(quantityEnglish) != clue(quantityGerman))
    }
  }

Basically, I was serializing w/ .toString in some bit of code, then trying to use .parseString to read in another bit of code. This caused a surprising crash out of the blue :smile:

The difference in formatting is given by the use of the format method from StringOps (yay! hidden side effects)
https://github.com/typelevel/squants/blob/master/jvm/src/main/scala/squants/Platform.scala#L12

And the parsing uses only . in its regex:
https://github.com/typelevel/squants/blob/master/shared/src/main/scala/squants/Dimension.scala#L75

Robin Hillyard
@rchillyard
I'd like to contribute. I built a dimensional system in Java a long time ago, and I've been meaning to do something similar in Scala. But I just found this project. I have a somewhat related library that I have built: https://github.com/rchillyard/Number.
garyKeorkunian
@garyKeorkunian
@rchillyard Welcome. Your number library is interesting. One of the things in our backlog is to replace the underlying Double used in Squants with something generic so that any numeric (like your Number or Spire's types) could be used. This would go a long way to improving precision.

I have a fork for the repo here (https://github.com/garyKeorkunian/squants-generic) where I was attempting to remodel the library to support that.

I haven't had time to work on it, but it should at least provide some inspiration towards an elegent solution.

Robin Hillyard
@rchillyard
Great, thanks. I will take a look at that fork.
amahonee
@amahonee

Hi guys, does anyone have experience using the squants lib with Slick? I am trying to add two columns of Rep[Length] together. The thing I'm running into seems like an implicit string conversion is being applied, messing things up. The first value (bow) is lifted and read as Rep[Length], the second (stern) however has anyOptionLift(primitiveShape(stringColumnType)) implicit added to it. Both bow and stern in the for comprehension are read as Rep[Length] but the yield uses the any2stringadd implicit causing a String expected error.

val length: Rep[Option[Length]] = for {
bow <- nearbyVessel.distanceToBow
stern <- nearbyVessel.distanceToStern
} yield bow + stern

AI have also asked the slick room but waiting on a response so any suggestions on how I can solve this would be greatly appreciated, cheers.

marko asplund
@marko_asplund_twitter
Hi! :wave: I'm trying to upgrade from version 1.6.0 to 1.8.0 but running into problems due to a huge increase in the number of dependencies in squants with the new version. Version 1.8.0 seems to depend on 100 jars whereas for 1.6.0 the number was 3. The new dependencies are causing dependency conflict issues for us and I'm wondering if the dependency increase is intentional.
Carlos Quiroz
@cquiroz
Well certainly not intentional, which dependencies are those?
Julien Richard-Foy
@julienrf
I think this is related to typelevel/squants#467
Roberto Bonvallet
@rbonvall
Hi all, is there a reason squants hasn't been published for stable Scala 3? In mvnrepository it's only available for one of the release candidates.
DavidFi1
@DavidFi1
Is there degree radian units?