Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Feature: PPL command - WMA Trendline #3293
base: main
Are you sure you want to change the base?
Feature: PPL command - WMA Trendline #3293
Changes from 8 commits
927fbfa
3836f31
0fcd688
898d3a6
ab58370
51d8395
e4c25b3
f6c82ae
d0cf898
ce94ca9
f32e5ad
4d95529
df3c666
3ed8fa8
7fc4075
3b7902f
47f9cec
b8cf496
4a56b57
0b50637
b8e3983
8dc96c9
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to have been quite an explosion of classes here! Some ideas:
Evaluator
class with a singleevaluate
method, would it make sense to instead store a reference to aevaluate
method that takes a List ofExprValue
s and returns the resultingExprValue
? Don't know what is more common, but it seems like a lot to have seven separateEvaluator
classes; perhaps sevenEvaluator
method would be more manageable?List<ExprValue>
instead of anArrayList
?LinkedList
might be more efficient for this purpose -- but not if we iterator over it like this! Are we able to use an iterator to do so? Then we would getO(1)
access for both aLinkedList
or anArrayList
. See below for how I think this could look.evaluate
signature so that it takes aList<ExprValue>
and aList<Double>
of weights? i.e.evaluate(List<ExprValue> values, List<Double> weights)
? This would have the added advantage that, in the case of WMA, we wouldn't need to re-calculate the weights every time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the point for too many Evaluator, however indeed these are two distinct types of
Evaluator
, in the case of SMA,Evaluator
not just take the new item, but also read therunning-total
in order to avoid re-computation, and all evaluators under the SMA umbrella take this into consideration especially on the API signature level, ex:Also the method calculateFirstTotal is unique to SMA:
However in contrast, WMA don't share the same characteristic, which re-computation is required upon every update, also, the concept of
running-total
is not applicable here.Regarding the concern of too many evaluators, I have updated to move all WMA related evaludator inside of class
WeightedMovingAverageAccumulator
in order to further narrow down the scope.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Good explanation for why SMA and WMA accumulators should be separate - thanks for that!
For WMA, I still think there is opportunity to combine some common logic. The weights should only need to be calculated once - can we pass them directly to the Evaluator from the Accumulator? Moreover, as I (tried to) describe in this comment, can we extract the common logic from all the WMA accumulators (related applying the weights to the values), and only have the different parts (mapping each value to a number, mapping the result back to the right
ExprValue
) split out into the different implementations.As mentioned elsewhere, I think we should also use an iterator for these loops, so that we can get O(1) access for a linked list or queue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above make sense, and I have now using
BiFunction
to replace original usage of custom interface ofwmaEvalulator
along with the static class creation.Also I have moved out the logic of
totalWeight
calculation out from respective function call, as that is common to all calculation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. This looks good to me.
I like that you have moved the
totalWeight
(the denominator) so that it doesn't need to be re-calculated each time. However, I think it is possible to move all the weight calculations out of these functions, and just pass a list containing all the weights to the function (i.e. to storen
"complete" weights values as aWeightedMovingAverageAccumulator
member).I also think it is possible to extract a the common logic for determining
sum
into another helper function: as mentioned in a previous comment, that logic is the same, except for mapping theExprValue
list to longs.Let me know if you want to discuss either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At it's heart, most of the logic between
NumericWmaEvaluator
,TimeWmaEvaluator
, andTimeStampWmaEvaluator
seems to be common: all the logic for determining the weights and calculating the weights average is the same, the only differences are (a) the type (double vs. long), and (b) how we get the numerical value from theExprValue
, and (c) how we convert the resulting weighted average back into anExprValue
.Would it be possible to extract all of this common logic to
WmaTrendlineEvaluator
in a helper method likeLong evaluateHelper(Collection<Long> values)
, and then have each sub-class only (i) convert a collection ofExprValue
to a collection ofLong
, (ii) callevaluateHelper
(pick a better name, obviously) to get the weighted average as aLong
, and then (iii) convert thatLong
back into anExprValue
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in another comment, still think there is common logic that can be extracted. Please let me know if you want to discuss.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As alluded to in other comments, I'm not sure we need separate
Evaluators
for simple and weights moving averages, if we design the interface right.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for explanation of this in another comments. Please resolve. ✅