-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD registered users in last year visual
- Loading branch information
Showing
6 changed files
with
132 additions
and
55 deletions.
There are no files selected for viewing
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,43 @@ | ||
from anubis.utils.usage.users import get_platform_users | ||
from anubis.utils.cache import cache | ||
from anubis.utils.data import is_debug, is_job | ||
from datetime import datetime, timedelta | ||
from anubis.utils.visuals.files import convert_fig_bytes | ||
from anubis.utils.visuals.watermark import add_watermark | ||
|
||
|
||
@cache.memoize(timeout=-1, forced_update=is_job, unless=is_debug) | ||
def get_platform_users_plot(days: int, step: int = 1): | ||
import matplotlib.pyplot as plt | ||
|
||
now = datetime.now().replace(hour=0, second=0, microsecond=0) | ||
start_datetime = now - timedelta(days=days - 1) | ||
|
||
xx = [] | ||
yy = [] | ||
|
||
fig, ax = plt.subplots(figsize=(12, 10)) | ||
|
||
for n in range(0, days, step): | ||
day = start_datetime + timedelta(days=n) | ||
y = get_platform_users(day) | ||
|
||
xx.append(day) | ||
yy.append(y) | ||
|
||
ax.plot(xx, yy, 'b--', label='Total users registered on platform') | ||
|
||
ax.legend(loc='upper left') | ||
ax.grid() | ||
ax.set( | ||
title='Total users registered on Anubis LMS over time', | ||
xlabel='Time', | ||
ylabel='Registered Users', | ||
) | ||
# Set y max to the nearest hundred | ||
ax.set_ylim([0, ((yy[-1] // 100) + 1) * 100]) | ||
add_watermark(ax) | ||
|
||
return convert_fig_bytes(plt, fig) | ||
|
||
|
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,9 @@ | ||
from datetime import datetime | ||
|
||
|
||
def add_watermark(ax): | ||
ax.text( | ||
0.97, 0.9, f"Generated {datetime.now()}", | ||
transform=ax.transAxes, fontsize=12, color="gray", alpha=0.5, | ||
ha="right", va="center", | ||
) |
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