From b6e81eea7446d53db838b3eb36495a22b7cdd7aa Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Wed, 23 Nov 2022 23:55:23 +0100 Subject: [PATCH] image path substitution takes location --- database.uxf | 116 +++++++++++++++++++++++--------------------- default.conf | 1 + regina/regina.py | 1 + regina/visualize.py | 32 ++++++------ setup.py | 1 + template.html | 2 +- 6 files changed, 81 insertions(+), 72 deletions(-) diff --git a/database.uxf b/database.uxf index 20b6024..d30cf51 100644 --- a/database.uxf +++ b/database.uxf @@ -1,104 +1,108 @@ - 19 + 13 UMLClass - 133 - 247 - 342 - 266 + 364 + 273 + 299 + 208 User -- -<<PK>>- user_id +<<PK>> +- user_id: INTEGER -- -- ip address -- user agent string -- platform -- browser -- mobile +- ip address: TEXT +- user agent string: TEXT +- platform: TEXT +- browser: TEXT +- mobile: INTEGER style=autoresize UMLClass - 1159 - 247 - 247 - 152 + 1092 + 273 + 234 + 130 FileGroup -- -<<PK>>- group_id +<<PK>> +- group_id: INTEGER -- -- group_name +- group_name: TEXT style=autoresize Relation - 969 - 247 - 228 - 95 + 988 + 273 + 130 + 65 lt=- m1=n m2=1 - 10.0;20.0;100.0;20.0 + 10.0;20.0;80.0;20.0 UMLClass - 703 - 228 - 285 - 285 + 754 + 260 + 247 + 221 Request -- -<<PK>>- request_id +<<PK>> +- request_id: INTEGER -- -- user_id -- file name +- user_id: INTEGER +- group_id: INTEGER -- -- date -- referer -- status +- date: TEXT +- referer: TEXT +- status: INTEGER style=autoresize Relation - 456 - 247 - 285 - 95 + 650 + 273 + 130 + 65 lt=- m1=1 m2=n - 10.0;20.0;130.0;20.0 + 10.0;20.0;80.0;20.0 UMLClass - 1159 - 646 - 190 - 152 + 1092 + 546 + 234 + 130 File -- -<<PK>>- name +<<PK>> +- name: TEXT -- -- group_id +- group_id: INTEGER -- style=autoresize @@ -106,24 +110,24 @@ style=autoresize Relation - 1216 - 380 - 76 - 304 + 1131 + 390 + 52 + 182 lt=- m1=n m2=1 - 10.0;140.0;10.0;10.0 + 10.0;120.0;10.0;10.0 UMLNote - 874 - 19 - 570 - 133 + 897 + 117 + 390 + 91 One group contains multiple files. Lets you group the images from a @@ -134,10 +138,10 @@ style=autoresize Relation - 1178 - 133 - 57 - 152 + 1105 + 195 + 39 + 104 lt=<- 10.0;60.0;10.0;10.0 diff --git a/default.conf b/default.conf index e118eb7..e2002f1 100644 --- a/default.conf +++ b/default.conf @@ -18,6 +18,7 @@ file_ranking_plot_max_files = 15 # "plot_figsize" = (60 40), plot_dpi = 300 img_dir = /www/analytics/images +img_dir = /analytics/images template_html = /home/my-user/analytics/template.html html_out_path = /www/analytics/statistics.html # filegroups = start:/index.html,/about.html,/img_on_index.png;music:/music.html,song.mp3 diff --git a/regina/regina.py b/regina/regina.py index fdbd26e..e49530a 100644 --- a/regina/regina.py +++ b/regina/regina.py @@ -32,6 +32,7 @@ settings = { # "plot_figsize": (60, 40), "plot_dpi": 300, "img_dir": "", + "img_location": "", "img_filetype": "svg", "template_html": "", "html_out_path": "", diff --git a/regina/visualize.py b/regina/visualize.py index db012b4..4818f38 100644 --- a/regina/visualize.py +++ b/regina/visualize.py @@ -374,17 +374,17 @@ def visualize(loaded_settings: dict): img_filetype = settings["img_filetype"] names = { # paths - "img_file_ranking_last_x_days": f"{img_dir}/ranking_all_time_files_last_x_days.{img_filetype}", - "img_referer_ranking_last_x_days": f"{img_dir}/ranking_all_time_referers_last_x_days.{img_filetype}", - "img_browser_ranking_last_x_days": f"{img_dir}/ranking_all_time_browsers_last_x_days.{img_filetype}", - "img_operating_system_ranking_last_x_days": f"{img_dir}/ranking_all_time_operating_systems_last_x_days.{img_filetype}", - "img_users_and_requests_last_x_days": f"{img_dir}/user_request_count_daily_last_x_days.{img_filetype}", + "img_file_ranking_last_x_days": f"ranking_all_time_files_last_x_days.{img_filetype}", + "img_referer_ranking_last_x_days": f"ranking_all_time_referers_last_x_days.{img_filetype}", + "img_browser_ranking_last_x_days": f"ranking_all_time_browsers_last_x_days.{img_filetype}", + "img_operating_system_ranking_last_x_days": f"ranking_all_time_operating_systems_last_x_days.{img_filetype}", + "img_users_and_requests_last_x_days": f"user_request_count_daily_last_x_days.{img_filetype}", - "img_file_ranking_total": f"{img_dir}/ranking_all_time_files_total.{img_filetype}", - "img_referer_ranking_total": f"{img_dir}/ranking_all_time_referers_total.{img_filetype}", - "img_browser_ranking_total": f"{img_dir}/ranking_all_time_browsers_total.{img_filetype}", - "img_operating_system_ranking_total": f"{img_dir}/ranking_all_time_operating_systems_total.{img_filetype}", - "img_users_and_requests_total": f"{img_dir}/user_request_count_daily_total.{img_filetype}", + "img_file_ranking_total": f"ranking_all_time_files_total.{img_filetype}", + "img_referer_ranking_total": f"ranking_all_time_referers_total.{img_filetype}", + "img_browser_ranking_total": f"ranking_all_time_browsers_total.{img_filetype}", + "img_operating_system_ranking_total": f"ranking_all_time_operating_systems_total.{img_filetype}", + "img_users_and_requests_total": f"user_request_count_daily_total.{img_filetype}", # values "mobile_user_percentage_total": 0.0, "mobile_user_percentage_last_x_days": 0.0, @@ -453,13 +453,13 @@ def visualize(loaded_settings: dict): file_ranking = get_file_ranking(cur, date_str) if gen_img: fig_file_ranking = plot_ranking(file_ranking, xlabel="Filename/Filegroup", ylabel="Number of requests", color_settings=color_settings_filetypes) - fig_file_ranking.savefig(names[f'img_file_ranking{suffix}']) + fig_file_ranking.savefig(f"{img_dir}/{names[f'img_file_ranking{suffix}']}") # REFERER referer_ranking = get_ranking("referer", t_request, settings["referer_ranking_regex_whitelist"], cur, date_str) if gen_img: fig_referer_ranking = plot_ranking(referer_ranking, xlabel="HTTP Referer", ylabel="Number of requests", color_settings=color_settings_alternate) - fig_referer_ranking.savefig(names[f'img_referer_ranking{suffix}']) + fig_referer_ranking.savefig(f"{img_dir}/{names[f'img_referer_ranking{suffix}']}") # USER # user_agent_ranking = get_user_agent_ranking(cur, date_str) @@ -492,15 +492,15 @@ def visualize(loaded_settings: dict): fig_daily, ax1, ax2, plots = plot2y(date_names, [len(user_ids) for user_ids in unique_user_ids_dates], [len(request_ids) for request_ids in unique_request_ids_dates], xlabel="Date", ylabel1="User count", label1="Unique users", ylabel2="Request count", label2="Unique requests", color1=palette["red"], color2=palette["blue"]) if get_humans: fig_daily, ax1, ax2, plots = plot2y(date_names, [len(user_ids) for user_ids in unique_user_ids_human_dates], [len(request_ids) for request_ids in unique_request_ids_human_dates], label1="Unique users (human)", ylabel2="Einzigartige Anfragen", label2="Unique requests (human)", color1=palette["orange"], color2=palette["green"], fig=fig_daily, ax1=ax1, ax2=ax2, plots=plots) - fig_daily.savefig(names[f"img_users_and_requests{suffix}"]) + fig_daily.savefig(f"{img_dir}{names[f'img_users_and_requests{suffix}']}") # os & browser os_ranking, browser_ranking, names[f"mobile_user_percentage{suffix}"] = get_os_browser_mobile_rankings(cur, unique_user_ids_human) if gen_img: fig_os_rating = plot_ranking(os_ranking, xlabel="Platform", ylabel="Share [%]", color_settings=color_settings_operating_systems) - fig_os_rating.savefig(names[f"img_operating_system_ranking{suffix}"]) + fig_os_rating.savefig(f"{img_dir}{names[f'img_operating_system_ranking{suffix}']}") fig_browser_rating = plot_ranking(browser_ranking, xlabel="Browsers", ylabel="Share [%]", color_settings=color_settings_browsers) - fig_browser_rating.savefig(names[f"img_browser_ranking{suffix}"]) + fig_browser_rating.savefig(f"{img_dir}/{names[f'img_browser_ranking{suffix}']}") # print("File Ranking", file_ranking) # print("referer Ranking", referer_ranking) @@ -516,6 +516,8 @@ def visualize(loaded_settings: dict): with open(settings["template_html"], "r") as file: html = file.read() for name, value in names.items(): + if "img" in name: + value = f"{img_location}/{value}" html = html.replace(f"%{name}", str(value)) with open(settings["html_out_path"], "w") as file: file.write(html) diff --git a/setup.py b/setup.py index f818d5e..3c075a7 100755 --- a/setup.py +++ b/setup.py @@ -14,6 +14,7 @@ setup( packages=["regina"], install_requires=[], + python_requires='>=3.10', classifiers=[ "Operating System :: POSIX :: Linux", diff --git a/template.html b/template.html index d7f0e55..0b0e232 100644 --- a/template.html +++ b/template.html @@ -5,7 +5,7 @@ - Analytics for %server_name + Analytics for %server-name