mafw.examples.sum_processor

The module provides some examples for the user to develop their own processors.

Those implemented here are mainly used in the test suit.

Classes

AccumulatorProcessor(*args, **kwargs)

A processor to calculate the sum of the first n values via a looping approach.

GaussAdder(*args, **kwargs)

A processor to calculate the sum of the first n values via the so called Gauss formula.

class mafw.examples.sum_processor.AccumulatorProcessor(*args: Any, **kwargs: Any)[source]

Bases: Processor

A processor to calculate the sum of the first n values via a looping approach.

In mathematical terms, this processor solves this easy equation:

\[N = \sum_{i=0}^{n}{i}\]

by looping. It is a terribly inefficient approach, but it works as a demonstration of the looping structure.

The user can get the results by retrieving the accumulated_value parameter at the end of the processor execution.

Processor parameters

  • last_value: Last value of the series (default: 100)

Constructor parameters:

Parameters:
  • last_value (int) – The n in the equation above. Defaults to 100

  • accumulated_value (int) – The N in the equation above at the end of the process.

get_items() list[int][source]

Returns the list of the first last_value integers.

process()[source]

Increase the accumulated value by the current item.

start()[source]

Resets the accumulated value to 0 before starting.

class mafw.examples.sum_processor.GaussAdder(*args: Any, **kwargs: Any)[source]

Bases: Processor

A processor to calculate the sum of the first n values via the so called Gauss formula.

In mathematical terms, this processor solves this easy equation:

\[N = \frac{n * (n - 1)}{2}\]

without any looping

The user can get the results by retrieving the sum_value parameter at the end of the processor execution.

Processor parameters

  • last_value: Last value of the series. (default: 100)

Constructor parameters:

Parameters:
  • last_value (int) – The n in the equation above. Defaults to 100

  • sum_value (int) – The N in the equation above.

process()[source]

Compute the sum using the Gauss formula.

start()[source]

Sets the sum value to 0.