-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Vertical histogram to display next reviews (#11)
- "summary" displays a vertical histogram of the daily review plan. - Add test for the histogram and the summary output - When no next reviews for the day are available display: "No more reviews for today" - Made a new demo.gif with the new summary output - Add python freezegun to help testing the histogram (mock date)
- Loading branch information
Showing
12 changed files
with
261 additions
and
16 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,8 @@ | |
|
||
url_to_ascii | ||
|
||
utc_to_local | ||
|
||
wanikani_tag_to_color | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
hebikani.hebikani.utc\_to\_local | ||
================================ | ||
|
||
.. currentmodule:: hebikani.hebikani | ||
|
||
.. autofunction:: utc_to_local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
"""All graph related functions | ||
Inspired by: https://github.com/tammoippen/plotille | ||
Usage: | ||
>>> from hebikani.graph import hist | ||
>>> hist([(datetime(2020, 1, 1, 12, 0, 0), 1), (datetime(2020, 1, 2, 15, 0, 0), 2)]) | ||
""" | ||
from datetime import datetime | ||
import os | ||
|
||
from colorama import Fore | ||
|
||
|
||
def hist( | ||
data: list[tuple[datetime, int]], | ||
width: int = 80, | ||
total: int = 0, | ||
linesep: str = os.linesep, | ||
): | ||
"""Create histogram over `data` from left to right | ||
The values on the left are the dates of this bucket. | ||
The values on the right are the number of reviews of this bucket. | ||
Args: | ||
data: list[tuple[datetime, int]] The items to count over. | ||
width: int The number of characters for the width (columns). | ||
total: int The total number of items at the start of the histogram. | ||
linesep: str The requested line seperator. default: os.linesep | ||
Returns: | ||
str: histogram over `data` from left to right. | ||
""" | ||
canvas = [] | ||
if data: | ||
# Sort the data by date | ||
data.sort(key=lambda _data: _data[0]) | ||
|
||
# Extract X and Y values | ||
x_values = [_data[0] for _data in data] | ||
y_values = [_data[1] for _data in data] | ||
|
||
y_max = max(y_values) | ||
y_total = total + sum(y_values) | ||
|
||
# Calculate the delimiter width | ||
delimiter_width = 2 * 8 + len(str(y_total)) + width | ||
|
||
header = "Today | " | ||
canvas += [ | ||
linesep + header + "{}".format("_" * (delimiter_width - len(header))) | ||
] | ||
lasts = ["", "⠂", "⠆", "⠇", "⡇", "⡗", "⡷", "⡿"] | ||
|
||
current_reviews_nb = total | ||
|
||
for i, x_value in enumerate(x_values): | ||
x_value_str = x_value.strftime("%I %p") | ||
current_reviews_nb += y_values[i] | ||
hight = int(width * 8 * y_values[i] / y_max) | ||
spaces = " " * (len(str(y_max)) - len(str(y_values[i]))) | ||
canvas += [ | ||
"{} | {}{}{}{} +{}{} | {}".format( | ||
x_value_str, | ||
Fore.GREEN, | ||
"⣿" * (hight // 8) + lasts[hight % 8], | ||
Fore.RESET, | ||
"⣿" * (width - (hight // 8) + int(hight % 8 == 0)), | ||
y_values[i], | ||
spaces, | ||
current_reviews_nb, | ||
) | ||
] | ||
canvas += ["‾" * delimiter_width] | ||
return linesep.join(canvas) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from datetime import datetime | ||
from hebikani.graph import hist | ||
|
||
|
||
def test_hist(): | ||
"""Test histogram.""" | ||
data = [(datetime(2020, 1, 1, 12, 0, 0), 1), (datetime(2020, 1, 2, 15, 0, 0), 2)] | ||
assert hist(data) == ( | ||
"\nToday | ____________________________________" | ||
"______________________________________________" | ||
"_______\n12 PM | \x1b[32m⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿" | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\x1b[39m⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿" | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿ +1 | 1\n03 PM | " | ||
"\x1b[32m⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿" | ||
"⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿" | ||
"⣿⣿\x1b[39m⣿ +2 | 3\n‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾" | ||
"‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾" | ||
"‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾" | ||
) | ||
|
||
# Test empty data | ||
assert hist([]) == "" |
Oops, something went wrong.