Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add quantity CloudCover #883

Closed
wants to merge 5 commits into from
Closed

Add quantity CloudCover #883

wants to merge 5 commits into from

Conversation

MarkCiliaVincenti
Copy link
Contributor

@MarkCiliaVincenti MarkCiliaVincenti commented Dec 29, 2020

Fixes #879

@codecov
Copy link

codecov bot commented Dec 29, 2020

Codecov Report

Merging #883 (9ecac36) into master (f58656c) will decrease coverage by 0.04%.
The diff coverage is 76.92%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #883      +/-   ##
==========================================
- Coverage   82.76%   82.72%   -0.05%     
==========================================
  Files         287      291       +4     
  Lines       43362    43674     +312     
==========================================
+ Hits        35888    36128     +240     
- Misses       7474     7546      +72     
Impacted Files Coverage Δ
UnitsNet/CustomCode/Quantities/CloudCover.extra.cs 0.00% <0.00%> (ø)
UnitsNet/GeneratedCode/UnitAbbreviationsCache.g.cs 100.00% <ø> (ø)
UnitsNet/GeneratedCode/Quantity.g.cs 51.98% <50.00%> (-0.02%) ⬇️
UnitsNet/InternalHelpers/UnitsNetMath.cs 71.42% <71.42%> (ø)
UnitsNet/GeneratedCode/Quantities/CloudCover.g.cs 77.24% <77.24%> (ø)
...ns/GeneratedCode/NumberToCloudCoverExtensions.g.cs 100.00% <100.00%> (ø)
UnitsNet/GeneratedCode/UnitConverter.g.cs 100.00% <100.00%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f58656c...9ecac36. Read the comment docs.

@angularsen angularsen changed the title Cloud cover Add quantity CloudCover Dec 29, 2020
@MarkCiliaVincenti
Copy link
Contributor Author

Not sure what the problem is with regards to the AppVeyor build failing. The code compiles for me and all cloud cover unit tests pass.

@angularsen
Copy link
Owner

Not sure what the problem is with regards to the AppVeyor build failing. The code compiles for me and all cloud cover unit tests pass.

It fails on

C:\projects\unitsnet\UnitsNet.WindowsRuntimeComponent\GeneratedCode\Quantities\CloudCover.g.cs(526,53): error CS0103: The name 'UnitsNetMath' does not exist in the current context

@angularsen
Copy link
Owner

Ah, it's the windows runtime component code generator.
You added a new extension method that is currently not added to the WRC code base.

This is a target that is largely deprecated, but kept around for new units via JSON changes.

Could you please duplicate the extension method to UnitsNet.WindowsRuntimeComponent so that its code also compiles?

@MarkCiliaVincenti
Copy link
Contributor Author

Ah, it's the windows runtime component code generator.
You added a new extension method that is currently not added to the WRC code base.

This is a target that is largely deprecated, but kept around for new units via JSON changes.

Could you please duplicate the extension method to UnitsNet.WindowsRuntimeComponent so that its code also compiles?

Done.

@MarkCiliaVincenti
Copy link
Contributor Author

Bump.

@angularsen
Copy link
Owner

Waiting on #880 to decide on naming. Bumped that thread.

<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.16299.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10586.0</TargetPlatformMinVersion>
<TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to bump up the MinVersion?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Visual Studio makes this change automatically. But yes, best to revert this.

/// <param name="min">The minimum value allowed</param>
/// <param name="max">The maximum value allowed</param>
/// <returns>The clamped value</returns>
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also work for any IQuantity - we could maybe expose it using a more restrictive (IQuantity) version in UnitMath

@angularsen
Copy link
Owner

As discussed in #880, let's go with DecimalFraction.

@lipchev
Copy link
Collaborator

lipchev commented Jan 13, 2021

Sorry I haven't read up much on the Oktas but doesn't it make more sense to have Clamp as a method on the quantity itself, rather than the internally stored value? Currently it seems that we cannot ensure proper addition/subtraction operations give the lossy nature of the internal round. For example isn't the result from (A + B)/2 likely to be (significantly) different from A/2 +B/2?
Anyway, If this is the desired behavior then I would think it is worth a test or two, demonstrating the specific (discrete?) nature of the quantity (like with the PowerRatioTests).

Also, maybe we should think about flagging the json file somehow, to indicate that it is non-linear (like with the Logarithmic flag)

@angularsen
Copy link
Owner

Currently it seems that we cannot ensure proper addition/subtraction operations give the lossy nature of the internal round.

@lipchev Good point, but then I propose we rather disable arithmetic codegen?
I don't think it makes a whole lot sense to do quarter cloud cover + half cloud cover anyway.

"GenerateArithmetic": false,

See Temperature as an example.

@angularsen
Copy link
Owner

angularsen commented Jan 18, 2021

@lipchev As for clamping, a better solution might be to add support in codegen for clamping of a quantity - so you could define that CloudCover should be clamped to say [0,1] of base unit - or some selected unit. Then it would inject clamping where appropriately. However, since this is the first quantity that requires it, I'm fine with doing it per unit for now. I think it should do what we want, to not allow less than 0% and not more than 100% cloud cover.

@angularsen
Copy link
Owner

@MarkCiliaVincenti I believe this is the current status of the PR feedback:

  • Rename to DecimalFraction
  • Don't generate code for arithmetic with "GenerateArithmetic": false, in JSON
  • Move clamp to UnitMath and if possible make it reusable for any IQuantity
  • Revert version change in UnitsNet.WindowsRuntimeComponent.csproj

@stale
Copy link

stale bot commented Mar 19, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 19, 2021
@stale stale bot closed this Jun 2, 2021
@MarkCiliaVincenti
Copy link
Contributor Author

@MarkCiliaVincenti I believe this is the current status of the PR feedback:

  • Rename to DecimalFraction
  • Don't generate code for arithmetic with "GenerateArithmetic": false, in JSON
  • Move clamp to UnitMath and if possible make it reusable for any IQuantity
  • Revert version change in UnitsNet.WindowsRuntimeComponent.csproj

Sorry, I saw this almost 2 years late :)

What did you mean by renaming to DecimalFraction? Instead of CloudCover?

@angularsen
Copy link
Owner

In JSON, rename SingularName/PluralName Fraction/Fractions to DecimalFraction/DecimalFractions to be consistent with Ratio.DecimalFraction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Oktas
3 participants