Skip to content

Add root and log filters.#299

Merged
mattcoley merged 8 commits into
masterfrom
root-log-filters
Mar 11, 2019
Merged

Add root and log filters.#299
mattcoley merged 8 commits into
masterfrom
root-log-filters

Conversation

@mattcoley

Copy link
Copy Markdown
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

codecov-io commented Mar 8, 2019

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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