Report (version 0.0.2) | index Report.html |
This package implements tools to build python package and tools.
>>> from Report import *
>>> data = [
... {"name": "test0", "level": 5, "id": 0},
... {"name": "test1", "level": 10, "id": 1},
... {"name": "test2", "level": 2, "id": 2},
... ]
>>> r = Report(data, "level", "id")
>>> print(r.report_text())
|name |level |id |
|-------------|-------------|-------------|
|test2 |2 |2 |
|test1 |10 |1 |
>>> print(r.report_JSON())
[
{
"name": "test2",
"level": 2,
"id": 2
},
{
"name": "test1",
"level": 10,
"id": 1
}
]
>>> r.report_CSV()
'name,level,id\r\ntest2,2,2\r\ntest1,10,1\r\n'
>>> print(r.report_HTML())
<table><thead><tr><th>name</th><th>level</th><th>id</th></tr></thead><tbody><tr><td>test2</td><td>2</td><td>2</td></tr><tr><td>test1</td><td>10</td><td>1</td></tr></tbody><tfoot></tfoot></table>
>>> r.statistic()
[{'Name': 'level', 'Sum': 12, 'Max': 10, 'Min': 2, 'Count': 2, 'MaxCount': 1, 'MinCount': 1, 'Average': 6.0, 'Variance': 32, 'Median': 6.0, 'Deviation': 4.0, 'CountGreaterThanAverage': 1, 'CountLessThanAverage': 1, 'CountGreaterThanVariance': 0, 'CountLessThanVariance': 2, 'CountGreaterThanMedian': 1, 'CountLessThanMedian': 1, 'CountGreaterThanDeviation': 1, 'CountLessThanDeviation': 1}, {'Name': 'id', 'Sum': 3, 'Max': 2, 'Min': 1, 'Count': 2, 'MaxCount': 1, 'MinCount': 1, 'Average': 1.5, 'Variance': 0.5, 'Median': 1.5, 'Deviation': 0.5, 'CountGreaterThanAverage': 1, 'CountLessThanAverage': 1, 'CountGreaterThanVariance': 2, 'CountLessThanVariance': 0, 'CountGreaterThanMedian': 1, 'CountLessThanMedian': 1, 'CountGreaterThanDeviation': 2, 'CountLessThanDeviation': 0}]
>>> r2 = Report(r.statistic())
>>> print(r2.report_text(length=26))
|Name |Sum |Max |Min |Count |MaxCount |MinCount |Average |Variance |Median |Deviation |CountGreaterThanAverage |CountLessThanAverage |CountGreaterThanVariance |CountLessThanVariance |CountGreaterThanMedian |CountLessThanMedian |CountGreaterThanDeviation |CountLessThanDeviation |
|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|--------------------------|
|level |12 |10 |2 |2 |1 |1 |6.0 |32 |6.0 |4.0 |1 |1 |0 |2 |1 |1 |1 |1 |
|id |3 |2 |1 |2 |1 |1 |1.5 |0.5 |1.5 |0.5 |1 |1 |2 |0 |1 |1 |2 |0 |
>>> from dataclasses import dataclass
>>> @dataclass
... class Test:
... one: int = 1
... two: int = 2
...
>>> data = [Test(), Test(one=2, two=2)]
>>> r = Report(data)
>>> r.frequence()
>>> r = Report(data, filter_value=lambda x: x["one"] == 1)
>>> r.frequence()
50.0
>>> r = Report(data, filter_value=lambda x: x["two"] == 1)
>>> r.report_text()
>>> r.report_HTML()
>>> r.report_JSON()
>>> r.report_CSV()
>>> r.statistic()
>>>
Run tests:
~# python -m doctest Report.py
~# python Report.py # Verbose mode
1 items passed all tests:
23 tests in __main__
23 tests in 12 items.
23 passed and 0 failed.
Test passed.
~# coverage run Report.py
~# coverage report
Name Stmts Miss Cover
--------------------------------
Report.py 160 1 99%
--------------------------------
TOTAL 160 1 99%
~#
Classes | ||||||||||
|
Data | ||
__all__ = ['Report'] __author_email__ = 'mauricelambert434@gmail.com' __copyright__ = '\nPythonToolsKit Copyright (C) 2022 Maurice Lam...ome to redistribute it\nunder certain conditions.\n' __description__ = '\nThis package implements tools to build python package and tools.\n' __license__ = 'GPL-3.0 License' __maintainer__ = 'Maurice Lambert' __maintainer_email__ = 'mauricelambert434@gmail.com' __url__ = 'https://github.com/mauricelambert/PythonToolsKit' |
Author | ||
Maurice Lambert |