M README.md => README.md +18 -18
@@ 3,23 3,23 @@
Command line data filtering
```sh
-$ filter -m=ab data/weights -a=.4 -b=0 -i=160 -d=1 -r
-Testing on N=12
-Using alpha=0.4000, beta=0.0000
-Initial estimate of 160.0000, accelerating 1.0000 per time unit
- Actual: Est.:
- ======== ========
- 158.0000 159.8000
- 164.2000 162.1600
- 160.3000 162.0160
- 159.9000 161.7696
- 162.1000 162.5018
- 164.6000 163.9411
- 169.6000 166.8046
- 167.4000 167.6428
- 166.4000 167.7457
- 171.0000 169.6474
- 171.2000 170.8684
- 172.6000 172.1611
+$filter -m=ab data/weights -a=.4 -b=0 -i=160 -d=1 -r
+Alpha-beta filter
+ α=0.4000, β=0.0000
+ Initial estimate: 160.0000 changing 1.0000 per time unit
+Actual: Est.:
+======== ========
+158.0000 159.8000
+164.2000 162.1600
+160.3000 162.0160
+159.9000 161.7696
+162.1000 162.5018
+164.6000 163.9411
+169.6000 166.8046
+167.4000 167.6428
+166.4000 167.7457
+171.0000 169.6474
+171.2000 170.8684
+172.6000 172.1611
```
M filter/__main__.py => filter/__main__.py +10 -10
@@ 1,7 1,6 @@
#!/usr/bin/env python3
import sys
-import importlib
from . import cli
from . import internals
@@ 9,11 8,7 @@ from . import internals
def main():
_config, _positionals = cli.main(sys.argv[1:])
- _help = "help" in _config.keys()
_method = _config.get("method", "")
- _files = _config.get("file", [])
- _files.extend(_positionals)
-
_data = {
"alpha": internals._try_get_float(_config, "alpha"),
"beta": internals._try_get_float(_config, "beta"),
@@ 24,6 19,10 @@ def main():
"time": internals._try_get_float(_config, "time"),
}
+ if "version" in _config.keys():
+ internals._print_version()
+ sys.exit(0)
+
if _method == "ab":
from . import ab as implementation
elif len(_method) > 0:
@@ 32,23 31,24 @@ def main():
internals._print_usage()
sys.exit(1)
- if _help and len(_method) == 0:
+ if "help" in _config.keys() and "method" not in _config.keys():
# requesting help
internals._print_help()
sys.exit(0)
- elif _help:
+ elif "help" in _config.keys():
# requesting help with a methodology
- sys.stdout.print(implementation.__doc__)
+ sys.stdout.write(implementation.__doc__)
sys.exit(0)
- elif len(_method) == 0:
+ elif "method" not in _config.keys():
# not requesting help, but still no methodology
internals._print_usage()
sys.exit(1)
+ _files = _config.get("file", [])
+ _files.extend(_positionals)
_data["data_raw"] = internals._get_raw_data(_files)
implementation.cli_wrapper(**_data)
-
sys.exit(0)
if __name__ == "__main__":
M filter/cli.py => filter/cli.py +25 -1
@@ 5,7 5,7 @@ import re
def main(arguments):
config=dict()
positional=[]
- pattern=re.compile(r"(?:-(?:a|b|d|f|h|x|i|m|r|t)|--(?:alpha|beta|delta|file|help|initial|method|report|time))(?:=.*)?$")
+ pattern=re.compile(r"(?:-(?:a|b|d|f|h|x|i|m|r|t|v|V)|--(?:alpha|beta|delta|file|help|initial|method|report|time|version))(?:=.*)?$")
consuming,needing,wanting=None,0,0
attached_value=None
while len(arguments) and arguments[0]!="--":
@@ 94,6 94,14 @@ def main(arguments):
else:
config["time"]=None
consuming,needing,wanting="time",1,1
+ elif option=="version":
+ if attached_value is not None:
+ message=(
+ 'unexpected value while parsing "version"'
+ ' (expected 0 values)'
+ )
+ raise ValueError(message) from None
+ config["version"]=True
elif option=="a":
if attached_value is not None:
config["alpha"]=attached_value
@@ 174,6 182,22 @@ def main(arguments):
else:
config["time"]=None
consuming,needing,wanting="time",1,1
+ elif option=="v":
+ if attached_value is not None:
+ message=(
+ 'unexpected value while parsing "version"'
+ ' (expected 0 values)'
+ )
+ raise ValueError(message) from None
+ config["version"]=True
+ elif option=="V":
+ if attached_value is not None:
+ message=(
+ 'unexpected value while parsing "version"'
+ ' (expected 0 values)'
+ )
+ raise ValueError(message) from None
+ config["version"]=True
else:
positional.append(arguments.pop(0))
if needing>0:
M filter/cli.toml => filter/cli.toml +4 -0
@@ 35,3 35,7 @@ alternatives = ['r']
number = 1
alternatives = ['t']
+[version]
+number = 0
+alternatives = ['v', 'V']
+
M filter/internals.py => filter/internals.py +4 -0
@@ 70,6 70,10 @@ def _print_help() -> None:
_msg = "Usage: filter -m=METHOD DATA\n"
sys.stdout.write(_msg)
+def _print_version() -> None:
+ _msg = "gap 1.0.0\n"
+ sys.stdout.write(_msg)
+
def _print_usage() -> None:
_msg = "Usage: filter -m=METHOD DATA\n"
sys.stderr.write(_msg)