-
Notifications
You must be signed in to change notification settings - Fork 2
Features #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: complaints-and-suggestions
Are you sure you want to change the base?
Features #14
Changes from all commits
f7c25af
5d43c73
d15a545
4a6e76c
fe5e52c
b35e536
e6cb757
076a690
7b05758
18c97c5
d2e7d1b
7f7a78d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import matplotlib.pyplot as plt | ||
| from matplotlib.ticker import AutoMinorLocator | ||
| import numpy as np | ||
| import pylab as pltt | ||
| import datetime | ||
| import matplotlib.dates as mdates | ||
|
|
||
|
|
||
| dict_with_data = {datetime.datetime(2020, 12, 7, 1): 53, | ||
| datetime.datetime(2020, 12, 7, 2): 14, | ||
| datetime.datetime(2020, 12, 7, 3): 15, | ||
| datetime.datetime(2020, 12, 7, 4): 12, | ||
| datetime.datetime(2020, 12, 7, 5): 35, | ||
| datetime.datetime(2020, 12, 7, 6): 31, | ||
| datetime.datetime(2020, 12, 7, 7): 2} | ||
|
|
||
| label_of_image = "zsd" | ||
|
|
||
| sample_data = {datetime.datetime(2020, 12, 7): 53, | ||
| datetime.datetime(2020, 12, 8): 14, | ||
| datetime.datetime(2020, 12, 9): 15, | ||
| datetime.datetime(2020, 12, 10): 12, | ||
| datetime.datetime(2020, 12, 11): 35, | ||
| datetime.datetime(2020, 12, 12): 31, | ||
| datetime.datetime(2020, 12, 13): 2} | ||
|
|
||
|
|
||
| def create_weekday_image(dict_with_data, label_of_image): | ||
| if len(dict_with_data) > 7: | ||
| return | ||
| day_of_week = [0, 1, 2, 3, 4, 5, 6] | ||
| online_on_this_weekday = [0, 0, 0, 0, 0, 0, 0] | ||
| for date in dict_with_data: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Не очень понимаю здесь: ты бегаешь переменной date по dict_with_data, а потом итерируешься по date...
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. date -- ключи в словаре, цикл нужен для того, чтобы узнать дельту данных. я просто не в курсе, как просто посмотреть разницу между соседними ячейками словаря |
||
| online_on_this_weekday[date.weekday()] = dict_with_data[date] | ||
| labels = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] | ||
| pltt.rcParams['figure.figsize'] = 7, 5 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Наверное был бы неплох коммент, где ты разъясняешь, что значат эти слова. Оно наверное понятно и так, но нужно ведь наверняка
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ну это просто оформление и всякие параметры картинки. так и напишу |
||
| pltt.bar(day_of_week, online_on_this_weekday, align='center') | ||
| pltt.xticks(day_of_week, labels) | ||
| pltt.savefig(label_of_image + '.png') | ||
| pltt.close() | ||
|
|
||
|
|
||
| def create_daily_image(dict_with_data, label_of_image): | ||
| day_delta = 0 | ||
| prev_key = datetime.datetime.now() | ||
| for key in dict_with_data: | ||
| day_delta = key - prev_key | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А почему нельзя сразу в конец списка рассмотреть?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. потому что из data_length - 1 -- не ключ словаря. ну промежуточные и правда не нужны, но это такой костыль, чтобы коротко написать
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ну смотри... |
||
| prev_key = key | ||
| period = day_delta.total_seconds() | ||
| period = period // 60 | ||
| number_of_dots = int(1440 // period) | ||
| y_axis = [0] * int(number_of_dots) | ||
| x_axis = [datetime.datetime(2020, 1, 1, 0, 0, 0) + day_delta * i for i in range(number_of_dots)] | ||
| for key in dict_with_data: | ||
| y_axis[int((key.minute + key.hour * 60) // period)] = dict_with_data[key] | ||
| figure, ax = plt.subplots(figsize=(number_of_dots, 10)) | ||
| ax.set_title(label_of_image) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Коротенькие комментарии напиши, наверное, что какой мини-блок делает
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. кок |
||
| ax.set_xlabel("Время", fontsize=14) | ||
| ax.set_ylabel("Процент онлайна", fontsize=14) | ||
| ax.grid(which="major", linewidth=1.2) | ||
| ax.grid(which="minor", linestyle="--", color="gray", linewidth=0.5) | ||
| ax.scatter(x_axis, y_axis, c="red") | ||
| ax.plot(x_axis, y_axis) | ||
| my_fmt = mdates.DateFormatter('%H:%M') | ||
| ax.xaxis.set_major_formatter(my_fmt) | ||
| figure.savefig("images/" + label_of_image + ".png") | ||
|
|
||
|
|
||
| def create_graph_image(period, total_time, y_axis, label_of_graph): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Аналогично - комментики. И докстринги кстати!!!
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. кок |
||
| number_of_dots = total_time//period | ||
| x = np.linspace(1, number_of_dots, number_of_dots) | ||
| figure, ax = plt.subplots(figsize=(number_of_dots, 10)) | ||
| ax.set_title(label_of_graph, fontsize=16) | ||
| ax.set_xlabel("Время", fontsize=14) | ||
| ax.set_ylabel("Процент онлайна", fontsize=14) | ||
| ax.grid(which="major", linewidth=1.2) | ||
| ax.grid(which="minor", linestyle="--", color="gray", linewidth=0.5) | ||
| ax.scatter(x, y_axis, c="red") | ||
| ax.plot(x, y_axis) | ||
| ax.xaxis.set_minor_locator(AutoMinorLocator()) | ||
| ax.yaxis.set_minor_locator(AutoMinorLocator()) | ||
| return figure | ||
|
|
||
|
|
||
| #figure1 = create_graph_image(1, 11, [1, 2, 3, 4, 5, 64, 40, 8, 7, 5, 9], "28 ноября") | ||
| #figure1.savefig("images/plot.png") | ||
| create_weekday_image(sample_data, "21") | ||
| plt.imsave | ||
| create_daily_image(dict_with_data, label_of_image) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не очень понятно, что это за циферки
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Которыми ты заполняешь dict_with_data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если это просто чиселки для тестинга, то наверно лучше коммент поставить
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
да, оно не надо ни для чего, закомменчу