From efcd862cf8ec503b3e34a1fa8afbfab8e552f461 Mon Sep 17 00:00:00 2001 From: 24_PolujanovVE <24_PolujanovVE@iux.local> Date: Tue, 8 Sep 2026 09:02:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BD=D0=B5=D0=B7=D0=BD=D0=B0=D1=87=D0=B8=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data.txt | 7 +++++++ src/numstats/cli.py | 7 ++++--- src/numstats/core.py | 11 +++++------ 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 data.txt diff --git a/data.txt b/data.txt new file mode 100644 index 0000000..4e127ce --- /dev/null +++ b/data.txt @@ -0,0 +1,7 @@ +1 +93 +0 +0.12 +-111 +123 +4 diff --git a/src/numstats/cli.py b/src/numstats/cli.py index 90ffd6c..4eb9ad4 100644 --- a/src/numstats/cli.py +++ b/src/numstats/cli.py @@ -17,8 +17,10 @@ def main() -> None: "--top", type=int, default=5, help="Number of largest values to display" ) parser.add_argument( - "--min-len", type=float, default=0.0, - help="Minimum value to include (numbers below are ignored)" + "--min-len", + type=float, + default=None, + help="Minimum value to include (numbers below are ignored). If not set, all numbers are included.", ) parser.add_argument( "--format", choices=["text", "json"], default="text", @@ -45,7 +47,6 @@ def main() -> None: sys.exit(1) if args.format == "json": - # convert numbers to strings or keep as is; JSON serializable output = { "count": stats["count"], "sum": stats["sum"], diff --git a/src/numstats/core.py b/src/numstats/core.py index b57655d..e5084f2 100644 --- a/src/numstats/core.py +++ b/src/numstats/core.py @@ -1,7 +1,7 @@ """Core functions for numeric analysis.""" from pathlib import Path -from typing import List, Tuple, Optional +from typing import List, Optional def read_numbers( @@ -25,7 +25,7 @@ def read_numbers( if min_value is None or val >= min_value: numbers.append(val) except ValueError: - # skip non‑numeric lines (per requirement, we can ignore them) + # skip non‑numeric lines continue return numbers @@ -33,7 +33,7 @@ def read_numbers( def analyze_numbers( file_path: Path, top_n: int = 5, - min_len: int = 0, # used as minimum numeric value + min_len: Optional[float] = None, # теперь None по умолчанию encoding: str = "utf-8", ) -> dict: """ @@ -45,9 +45,9 @@ def analyze_numbers( - mean: arithmetic mean - min: minimum value - max: maximum value - - top: list of (value, count?) or just values? We'll return top N largest numbers. + - top: list of N largest numbers """ - numbers = read_numbers(file_path, encoding=encoding, min_value=float(min_len)) + numbers = read_numbers(file_path, encoding=encoding, min_value=min_len) if not numbers: return { "count": 0, @@ -63,7 +63,6 @@ def analyze_numbers( mean = total / count min_val = min(numbers) max_val = max(numbers) - # top N largest numbers (if top_n > 0) top_values = sorted(numbers, reverse=True)[:top_n] return {