Use result even when results is empty in sim #5
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.
Right now if you run a sim you can get the following result:
$ curl https://35.221.121.54.sslip.io/simulate/solana/mainnet-beta/4Hmd6PdjVA9auCoScE12iaBogfwS4ZXQ6VZoBeqanwWW [{"feed":"4Hmd6PdjVA9auCoScE12iaBogfwS4ZXQ6VZoBeqanwWW","feedHash":"1f42dfb21efb24828b99fbe70e6d139cd665aafcbb1706bccd8f2a9b12562db6","results":[],"result":"118.22250000","stdev":"0","variance":"0"}]With the current implementation, this entire result is thrown away because the library does not parse the decimal in
resultand becauseresultsis empty.This is an opinionated approach:
resultexists, use that.resultdoes not exist, get the median fromresults.You could also do the inverse:
resultsexist, get the median and overwriteresult.resultsdoes not exist, use the existingresult.There is also a third option which is to do nothing when result is none and let the downstream user handle it all.
I prefer the proposed approach as it allows the caller to get both raw values and decide what they want to do.