by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jul 01 19:20

    cquiroz on master

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

  • Jul 01 18:04
    scala-steward opened #404
  • Jun 28 01:44

    cquiroz on master

    Update sbt to 1.3.13 Merge pull request #403 from sc… (compare)

  • Jun 28 01:44
    cquiroz closed #403
  • Jun 28 01:30
    scala-steward opened #403
  • Jun 23 15:20

    garyKeorkunian on gh-pages

    Update Squants site (compare)

  • Jun 23 15:10

    garyKeorkunian on gh-pages

    Set theme jekyll-theme-cayman (compare)

  • Jun 23 09:51
    txsmith opened #402
  • Jun 19 05:03
    scala-steward opened #401
  • Jun 15 15:24
    scala-steward opened #400
  • May 31 06:35

    cquiroz on master

    Update sbt to 1.3.12 Merge pull request #399 from sc… (compare)

  • May 31 06:35
    cquiroz closed #399
  • May 31 03:35
    scala-steward opened #399
  • May 29 22:49

    cquiroz on master

    Update sbt to 1.3.11 Merge pull request #398 from sc… (compare)

  • May 29 22:49
    cquiroz closed #398
  • May 29 19:39
    scala-steward opened #398
  • May 22 16:01

    cquiroz on master

    Use github actions for CI and r… Upgrade actions Signed-off-by:… Fixes running tests on scala.js… and 1 more (compare)

  • May 22 16:01
    cquiroz closed #375
  • May 18 14:00
    cquiroz synchronize #375
  • May 18 13:20
    cquiroz commented #375
Soren
@srnb_gitlab
can I to compositions (like is to (VUnit / Tick) valid or do I have to do something extra)
garyKeorkunian
@garyKeorkunian
You can also use the map method of quantity to apply a function to the underlying value
val ticks = Tick(100)
val tickA = ticks.map(_ / 2)
If you are doing something beyond what you can do in a map, you can extract the values using double, apply your function and then use the result to create a new quantity.
once you have your unit VUnitsPerTick, you can convert any velocity to that. KilometersPerHour(10) in VUnitsPerTick
something like (VUnit / Tick) is not a valid expression. Something more like VUnit(10) / Tick(20) is what you want.
Soren
@srnb_gitlab
How do I define VUnitsPerTick? @emanresusername
garyKeorkunian
@garyKeorkunian
In a similar way, buy you'll extend the VelocityUnit instead. Your conversion factor should be relative to KilometersPerSecond as that is the base unit of Velocity
garyKeorkunian
@garyKeorkunian
@srnb_gitlab Sorry, that base unit for velocity is actually MetersPerSecond
Soren
@srnb_gitlab
Got it
Przemek Sokół
@falconepl
Hi all! Got a question to you. What's the Squants' most annoying bug (or bugs) that you would like to be fixed in the next release?
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?
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.