From 74e20e00dfbffdcf117778049e47acd79e320110 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sun, 2 Aug 2020 09:46:42 +0200 Subject: moving-average --- moving-average | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 moving-average (limited to 'moving-average') diff --git a/moving-average b/moving-average new file mode 100644 index 0000000..e32a777 --- /dev/null +++ b/moving-average @@ -0,0 +1,22 @@ +import numpy as np +import optparse + + +def main(): + cmdlineParser = optparse.OptionParser(usage="") + (options, args) = cmdlineParser.parse_args() + path = args[0] + window = int(args[1]) + half_window = window/2 + f = open(path, "r") + numbers = [] + for line in f.readlines(): + numbers.append(float(line)) + + for i in range(len(numbers)): + min_id = max(0, i-window) + print(np.average(numbers[min_id:i+1])) + + +if __name__ == "__main__": + main() -- cgit v1.2.3