Useful module to be written by a newbie
Cecil at decebal.nl
Wed Apr 29 22:47:43 CEST 2015
Op Wednesday 29 Apr 2015 21:03 CEST schreef Peter Otten:
>>> Realistically a Python coder with a little experience will have a
>>> glance at your code and run away.
>> Oops, that is not nice to hear. :'-(
> Sorry, I did not mean to discourage you or insult you, I just wanted
> to make it clear that your code is not there yet.
You did not. Of-course it is not nice to hear, but if it is true, it
is very useful. If there is a lot to be desired, then it is good when
someone point this out.
>> But can you enlighten me? Then I can learn from it.
> I was judging from the look of your MovingAverage.
> I don't like the interface, it really should take an iterable so
> that you can write
>>>> list(moving_average([1,2,3], 2))
> [1.5, 2.5]
I should probably document it better. The idea is that you do not have
the data yet. At certain intervals data is acquired and at that moment
you want the moving average with the new data. But it would not hurt
to have the possibility to feed it a list of values, beside single
value. Something to better the function. Thanks.
> I don't see how you cope with error accumulation.
That is a good one. I have the values themselves (I use them in the
test). I could every so much new values check if there is an error. If
that is the case log it and use the correct value.
> Given how generic your code is I don't see why you limit it to just
> int and float, and I don't expect that limitation to find errors
> caused by my code using your moving average.
Because it gives back a float I thought it better to use only int and
float, but I was contemplating expansion.
> And then there's the testing...
> Compare that to the beast I found in a web search for moving average
That is certainly something I can learn from.
I have to implement the following improvements:
Create a next_values
Create a internal checking function
Option to force no_rolling_sum when no_rolling_sum? is True
- for the current call
- for the current call and length -1 following
And I should move it to mathDecebal.
Senior Software Engineer
More information about the Python-list