Commit 7e743d61 authored by Schlauch, Tobias's avatar Schlauch, Tobias
Browse files

Add initial prototype

# Ignore Python-specific temporary files
# Contributors
- Tobias Schlauch
- Martin Stoffers
# Sample Calculator
Sample Calculator is a command line tool to calculate characteristic values of a sample.
It provides the following features:
- Reading sample values from command line and CSV (Colon Separated Values) files.
- Performing statistic calculations such as average, variance, and deviation.
- Configurable logging of results and interim results.
- Easy integration of new input sources and calculations.
> **Please note:**
> The current version is only an initial alpha version which is **NOT** suited for production use.
\ No newline at end of file
package = []
content-hash = "de7600acb56ad9a67b77fd08bb5acd96ae59d0bbc6d538e5682444b7d4b1cc16"
python-versions = "^3.6"
name = "sample-calculator"
version = "0.1.0"
description = "Sample Calculator is a command line tool to calculate characteristic values of a sample."
license = "Not Defined Yet"
authors = ["Tobias Schlauch <>"]
readme = ""
include = ["", "example-data/sample-values.csv"]
sample-calculator = "sample_calculator:main"
python = "^3.6"
from decimal import Decimal
import sys
""" Simple prototype of the SampleCalculator. """
def _read_sample_values():
""" Reads the sample values from console or file. """
if len(sys.argv) == 1: # read values from commandline
sample_values = input("Please, enter the sample values:\n")
sample_values = [Decimal(value.strip()) for value in sample_values.split(";")]
else: # read values from file
sample_values = list()
with open(sys.argv[1], "r", encoding="utf-8") as file_object:
lines = file_object.readlines()
for line in lines:
values = line.split(";")
for value in values:
value = value.strip()
if len(value) > 0:
return sample_values
def _calculate_average(sample_values):
""" Calculates the average. """
sum = Decimal(0)
for sample_value in sample_values:
sum += sample_value
return sum / len(sample_values)
def _calculate_variance(sample_values, average):
""" Calculates the variance. """
variance = Decimal(0)
for sample_value in sample_values:
variance += (sample_value - average) ** 2
return variance / (len(sample_values) - 1)
def _calculate_deviation(variance):
""" Calculates the standard degression. """
return variance ** Decimal("0.5")
def main():
""" Main entry point of the function. """
# Read sample values
sample_values = _read_sample_values()
# Calculate results
average = _calculate_average(sample_values)
variance = _calculate_variance(sample_values, average)
standard_degression = _calculate_deviation(variance)
# Print results on the console
print("average:", average)
print("variance:", variance)
print("deviation:", standard_degression)
if __name__ == "__main__":
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment