typelevel / squants Goto Github PK
View Code? Open in Web Editor NEWThe Scala API for Quantities, Units of Measure and Dimensional Analysis
Home Page: https://www.squants.com
License: Apache License 2.0
The Scala API for Quantities, Units of Measure and Dimensional Analysis
Home Page: https://www.squants.com
License: Apache License 2.0
I wanted to check if this is a bug or is it by design. On Irradiance we can divide by power as in here
We can see that the function is defined as
def /(that: Power): Area
however irradiance is power/area
and dividing by power doesn't give you area but 1/area
.
Am I missing something?
For cases like 1 minute
.
Hi @garyKeorkunian,
I would like to use squants in a type-class based setting where it is important to keep track on a type level if e.g. two values of two different types can be multiplied to get a value of a third type.
I would like to derive something like the CanMultiply
class in the following (hugely simplified) example:
implicit def createMultiplication[InDim1, InDim2, OutDim](implicit canMultiply: CanMultiply[InDim1, InDim2, OutDim]) = new Multiplication[InDim1, InDim2, OutDim](...)
val areaMultiplication: Multiplication[Length, Length, Area] = implicitly
val areaDensityMultiplication: Multiplication[Density, Length, AreaDensity] = implicitly
Skimming through the code I haven't found any hint that dimensions are actually tracked on a type level.
Is something like this planned?
Would you accept a PR if I find the time to create one?
why does the following custom DataRateUnit lead to the wrong result?
object GibibytesPerDay extends DataRateUnit {
val symbol = "GiB/d"
val conversionFactor = Gibibytes.conversionFactor / Days.conversionFactor
}
manual test code:
val averageDataRate: DataRate = MebibytesPerSecond(4096)
println(averageDataRate in MebibytesPerSecond)
println(averageDataRate in GibibytesPerSecond)
println(averageDataRate in GibibytesPerDay)
println( 4 * 60 * 60 * 24)
The third line (GibibytesPerDay) is off by a factor of 1000.
It can be corrected by
object GibibytesPerDay extends DataRateUnit {
val symbol = "GiB/d"
val conversionFactor = Gibibytes.conversionFactor / (Days.conversionFactor / Seconds.conversionFactor)
}
but it is a bit counterintuitive.
Is there a better way to create custom DataRateUnits ?
It would be nice if Squants provided a parallel set of generic types for working with other kinds of numbers besides Double
, or supported generic types in some other way.
I'm not sure exactly what this would look like, or if this is a realistic goal for the project, but there are definitely types in Spire (Rational
, Real
, Complex[_]
, Interval[_]
, and so on) that would be really useful for dimensional analysis.
Hi, I'm working on a project that uses your preliminary support for storage units of measurement. When I started using same, the package was named squants.storage. Now it is squants.information.
When I try to use your snapshot builds for my own project, https://github.com/LoyolaChicagoCode/blockperf-scala, which does builds for 2.10 and 2.11 of Scala against your 0.6.1-SNAPSHOT, it seems like the 2.10 build for squants has not been updated. This might be because your 2.10 build didn't get pushed to bintray.
Here is where my own build is getting tripped up when trying to build the 2.10.6 version:
$ sbt '+ package'
[info] Loading project definition from /Users/gkt/Work/blockperf-scala/project
[info] Set current project to blockperf (in build file:/Users/gkt/Work/blockperf-scala/)
[info] Setting version to 2.10.6
[info] Reapplying settings...
[info] Set current project to blockperf (in build file:/Users/gkt/Work/blockperf-scala/)
[info] Compiling 1 Scala source to /Users/gkt/Work/blockperf-scala/target/scala-2.10/classes...
[error] /Users/gkt/Work/blockperf-scala/src/main/scala/blockperf/Performance.scala:2: object information is not a member of package squants
[error] import squants.information._
[error] ^
[error] /Users/gkt/Work/blockperf-scala/src/main/scala/blockperf/Performance.scala:16: not found: value Bytes
[error] val used = Bytes(m) in Megabytes
[error] ^
[error] /Users/gkt/Work/blockperf-scala/src/main/scala/blockperf/Performance.scala:17: not found: value Bytes
[error] val free = Bytes(Runtime.getRuntime.freeMemory) in Gigabytes
[error] ^
[error] /Users/gkt/Work/blockperf-scala/src/main/scala/blockperf/Performance.scala:18: not found: value Bytes
[error] val total = Bytes(Runtime.getRuntime.totalMemory) in Gigabytes
[error] ^
[error] four errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 1 s, completed Mar 10, 2016 3:38:48 PM
Factor is the term most widely used for these values in the context of dimensional analysis.
Evaluate and implement one of the experimental strategies for applying conversions to support multiply, divide and dotProduct operations between QuantityVectors and other quantity types.
The goal is to allow for the following type of operation:
val lengthVector = QuantityVector(Meters(1), Meters(2), Meters(3))
val areaVector = lengthVector * Meters(2)
assert (areaVector ==
QuantityVector(
SquareMeters(2),
SquareMeters(4),
SquareMeters(6)))
There are currently three strategies partially implemented with tests and marked as experimental. These can be found in Vector.scala and VectorSpec.scala.
In the UK, the stone (14 pounds) is commonly used to express body weight. Squants should support this unif of mass. A PR is forthcoming.
To better reflect its open source nature, the organizational domain for the package will be migrated to org.squants.
scala> val foo: Double = 4
foo: Double = 4.0
scala> foo C
res1: squants.thermal.Celsius = 4.0°C
scala> val foo: Int = 4
foo: Int = 4
scala> foo C
<console>:199: error: value C is not a member of Int
foo C
^
Refactor case classes with component values to final class with single value and QuantityCompanion
Currently the thermal package does not support the Rankine scale. While Rankine isn't very popular, I gather it is still used in some areas, and supporting it is straightforward.
[error] /Users/nornagon/work/squants/src/main/scala/squants/space/Volume.scala:27: illegal cyclic reference involving class VolumeFlowRate
[error] with TimeIntegral[VolumeFlowRate] {
[error] ^
Add tests to ensure that all types support basic JSON marshalling / serialization
This may reveal the need (or desire) to create companion projects for specific JSON frameworks (ie, squants-json4s)
Many industries measure mass of precious metals and gemstones in troy units and carats. We should support those units. A PR is forthcoming.
The recent introduction of the ScalaJS, broke the publish and console features.
This needs to be corrected so that new versions can be properly published and the Squants REPL returns to normal operation.
Refactor case classes with component values to final class with single value and QuantityCompanion
Refactor to use single value and QuantityCompanion
Hey! I'm replacing another measures library internally with squants, and we use microliters a lot (for biology). It'd be great to have that included by default in squants!
For example:
Kilowatts(1000) mustBe Kilowatts(1000)
fails with
1.0 MW was not equal to 1.0 MW
I feel like 12.C - 3.C < 20.K
should work.
Related to #145 . The JVM has a class and method to find the decimals for each currency:
https://docs.oracle.com/javase/7/docs/api/java/util/Currency.html#getDefaultFractionDigits()
Should the decimals defined on https://github.com/typelevel/squants/blob/master/shared/src/main/scala/squants/market/Money.scala#L379 be read using this method?
I'm not sure if I want to depend on an old java class but perhaps is the correct thing
The Currencies JPY and KRW should have zero decimal places (they are incorrectly set to 2 decimal places).
We should figure out if any of the remaining tickets need to be addressed before an official 1.0.0 release is made. I'd prefer to get this done ASAP to avoid depending on a SNAPSHOT.
Are there any tickets that specifically need to be addressed before the current status is considered "stable"?
The site at www.squants.com
still references the old organization and version. The gh-pages
branch contains raw html for the pages instead of a jekyll site
What do you think about migrating to sbt-microsites
I'd really like the documentation to be typechecked with tut
. This is also suggested by typelevel at
https://github.com/typelevel/general/blob/master/governance/membership.md
I'm not sure how to keep the nice layout of the current site with sbt-microsites
though
I'd like to make the master branch protected. This way accidental commits are avoided and all the changes must come through a PR and tests must pass as well as requiring at least one approval:
https://help.github.com/articles/about-protected-branches/
What do you think?
You don't notice this with squants itself because it squants only has the 1 AreaDensity type, but I made a couple custom ones for my app and noticed the issue.
I've submitted a pull request for the fix.https://github.com/garyKeorkunian/squants/pull/115
$ sbt console
scala> Kilowatts(1200)
res3: squants.energy.Power = 1.2 MW
scala> Microlitres(20000)
res2: squants.space.Volume = 2.0E-5 m³
This is causing havoc with serialization tests in my project (since things don't round-trip from JSON back to JSON).
The README claims that "Quantity values are based in the units used to create them", but this does not seem to be the case.
Hi,
I was going to code a TimeSeries class for the Energy domain enforcing that values in the timeseries must be of type [A <: Quantity[A]]
. So far so good but then I tried to create a TimeSeries of Price[Energy]
and it happens that a Ratio
is not a quantity. Digging deeper I see other "Ratio" quantities like Velocity having its own non-derived types.
Is this something by design or something that could be improved in current implementation? Should I create an EnergyPrice type like the one in Velocity? Is it something maybe related to #127 ?
Regards.
scala> val ok = 10.metres / second / second
ok: squants.motion.Acceleration = 10.0 m/s²
scala> val o2k = EarthGravities(10.metres / second / second)
o2k: squants.motion.Acceleration = 10.0 g
EarthGravities(ok)
res8: squants.motion.Acceleration = 10.0 g
Shouldn't this result in ~1g ? I've only just picked up the library just now, please excuse me if I'm misunderstanding something fundamental here.
The current POM metadata reflects the old git repo:
<scm>
<url>[email protected]:garyKeorkunian/squants.git</url>
<connection>scm:git:[email protected]:garyKeorkunian/squants.git</connection>
</scm>
This should reflect the current typelevel git repo.
Following up on #137, this is a call for new maintainers under the typelevel github organization. Other than @garyKeorkunian the current contributors are listed as,
and it'd be good to see one or more of them step forward. I imagine that everyone who has commented on #137 is also a stakeholder in some sense so they would be very welcome to step forward too.
Given that @garyKeorkunian approached Typelevel for member status I think it's appropriate to continue the project in the Typelevel organization. That being the case I think it would be good if volunteer maintainers shared that commitment.
scala> Kilowatts(10)
res0: squants.energy.Power = 10.0 kW
scala> Kilowatts(20
| )
res1: squants.energy.Power = 20.0 kW
scala> List(res0, res1)
res2: List[squants.energy.Power] = List(10.0 kW, 20.0 kW)
scala> res2.sum
:156: error: could not find implicit value for parameter num: Numeric[squants.energy.Power]
res2.sum
Hi,
I'm trying to use squants to do some kinetic energy calculations :
val v1 = Meters(1.0)/Seconds(1.0)
val m1 = Kilograms(1.0)
val ek1 = 1/2 * m1 * v1 * v1
val ek2 = 1/2 * m1 * (v1 * v1)
But the last two lines don't compile (ek1 because operator * is not define between one momentum and one velocity and ek2 because operator * is not define between two velocities).
Maybe I did something wrong, but I'm wondering if there is a way to do some kinetic energy calculations without define new operator *.
Adding information in different units is a part of many user-interfaces and is often validated on a frontend. I wonder, do you have any plans of cross-releasing to ScalaJS?
please
Refactor case classes with component values to final class with single value and QuantityCompanion
Would it be possible to support multiplication with a TimeDerivative like Frequency ?
here is an example:
val averageMessageSize: Information = Bytes(600)
println(averageMessageSize)
val messageRate: Frequency = Each(7000) / Seconds(1)
println(messageRate)
// A * Frequency is not supported
// following doesn't compile:
// val averageDataRate: DataRate = averageMessageSize * messageRate
// But A / Time is supported, so convert Frequency to Time and divide
val averageDataRate: DataRate = averageMessageSize / (Each(1) / messageRate)
println(averageDataRate in MebibytesPerSecond)
Thanks for this great library.
I kindly request to publish it cross-compiled to Scala.js so that it can be used in hybrid (Scala/Scala.js) projects.
Thank you!
Money types don't have a Numeric implicit object. This seems to be hindered by the fact that AbstractQuantityNumeric
requires a valueUnit
instance that can apply from an Int, while money can be created from Double or BigDecimal. Alternately, I'm just missing something trivial :)
Hi,
I'm trying to tweak the MoneyContext but being a case class make it really hard.
Could we create an abstraction ?
The snapshot release JAR on Sonatype Snapshots is empty apart from the META-INF directory.
I believe the conversion factor for bars in Pressure should be 100000d, rather than 100d. This is consistent with the definition given in http://en.wikipedia.org/wiki/Bar_%28unit%29.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.