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 root and log filters. #299

Merged
merged 8 commits into from
Mar 11, 2019
Merged

Add root and log filters. #299

merged 8 commits into from
Mar 11, 2019

Conversation

mattcoley
Copy link
Collaborator

Adds a root and a log filter as requested here #292 similar to https://ansible-docs.readthedocs.io/zh/stable-2.0/rst/playbooks_filters.html#math.

Complications: supporting BigDecimal and exact values requires adding a dependency on https://github.com/eobermuhlner/big-math

@mattcoley mattcoley requested a review from boulter March 8, 2019 16:18
@codecov-io
Copy link

codecov-io commented Mar 8, 2019

Codecov Report

Merging #299 into master will decrease coverage by 0.19%.
The diff coverage is 62.36%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master     #299     +/-   ##
===========================================
- Coverage     71.98%   71.78%   -0.2%     
- Complexity     1526     1558     +32     
===========================================
  Files           237      239      +2     
  Lines          4769     4881    +112     
  Branches        757      789     +32     
===========================================
+ Hits           3433     3504     +71     
- Misses         1071     1093     +22     
- Partials        265      284     +19
Impacted Files Coverage Δ Complexity Δ
...a/com/hubspot/jinjava/interpret/InvalidReason.java 100% <100%> (ø) 3 <0> (ø) ⬇️
...java/com/hubspot/jinjava/lib/filter/LogFilter.java 58.69% <58.69%> (ø) 13 <13> (?)
...ava/com/hubspot/jinjava/lib/filter/RootFilter.java 64.44% <64.44%> (ø) 16 <16> (?)
...ubspot/jinjava/objects/date/StrftimeFormatter.java 87.05% <0%> (-2.42%) 19% <0%> (ø)
...main/java/com/hubspot/jinjava/lib/tag/FromTag.java 86% <0%> (-2.1%) 10% <0%> (+1%)
...n/java/com/hubspot/jinjava/lib/tag/IncludeTag.java 82.14% <0%> (-1.86%) 6% <0%> (+2%)

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 9105778...021c9a5. Read the comment docs.

import ch.obermuhlner.math.big.BigDecimalMath;

@JinjavaDoc(
value = "Return the log of the input.",
Copy link
Contributor

Choose a reason for hiding this comment

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

"return the natural log value of the input"


@Test
public void itCalculatesNthRootOfBigDecimal() {
BigDecimal result = ((BigDecimal) filter.filter(new BigDecimal(9765625d), interpreter, "5.0"));
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be computationally expensive with large values?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Performance is largely a function of precision in this case set to 50 digits. With such a low precision operations are in the nanoseconds range. The goal of this library we are using is for performance remain stable as the input grows so we should be safe http://obermuhlner.ch/wordpress/2016/06/02/bigdecimalmath/


@Override
public String getName() {
return "log";
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not thrilled about the very generic name of this, but it makes sense to be compatible with ansible.

@mattcoley mattcoley merged commit c9010dc into master Mar 11, 2019
@mattcoley mattcoley deleted the root-log-filters branch March 11, 2019 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants