image path substitution takes location

This commit is contained in:
matthias@arch 2022-11-23 23:55:23 +01:00
parent 165e25dac0
commit b6e81eea74
6 changed files with 81 additions and 72 deletions

View File

@ -1,104 +1,108 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<diagram program="umlet" version="15.0.0"> <diagram program="umlet" version="15.0.0">
<zoom_level>19</zoom_level> <zoom_level>13</zoom_level>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>133</x> <x>364</x>
<y>247</y> <y>273</y>
<w>342</w> <w>299</w>
<h>266</h> <h>208</h>
</coordinates> </coordinates>
<panel_attributes>User <panel_attributes>User
-- --
&lt;&lt;PK&gt;&gt;- user_id &lt;&lt;PK&gt;&gt;
- user_id: INTEGER
-- --
- ip address - ip address: TEXT
- user agent string - user agent string: TEXT
- platform - platform: TEXT
- browser - browser: TEXT
- mobile - mobile: INTEGER
style=autoresize</panel_attributes> style=autoresize</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>1159</x> <x>1092</x>
<y>247</y> <y>273</y>
<w>247</w> <w>234</w>
<h>152</h> <h>130</h>
</coordinates> </coordinates>
<panel_attributes>FileGroup <panel_attributes>FileGroup
-- --
&lt;&lt;PK&gt;&gt;- group_id &lt;&lt;PK&gt;&gt;
- group_id: INTEGER
-- --
- group_name - group_name: TEXT
style=autoresize</panel_attributes> style=autoresize</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>969</x> <x>988</x>
<y>247</y> <y>273</y>
<w>228</w> <w>130</w>
<h>95</h> <h>65</h>
</coordinates> </coordinates>
<panel_attributes>lt=- <panel_attributes>lt=-
m1=n m1=n
m2=1 m2=1
</panel_attributes> </panel_attributes>
<additional_attributes>10.0;20.0;100.0;20.0</additional_attributes> <additional_attributes>10.0;20.0;80.0;20.0</additional_attributes>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>703</x> <x>754</x>
<y>228</y> <y>260</y>
<w>285</w> <w>247</w>
<h>285</h> <h>221</h>
</coordinates> </coordinates>
<panel_attributes>Request <panel_attributes>Request
-- --
&lt;&lt;PK&gt;&gt;- request_id &lt;&lt;PK&gt;&gt;
- request_id: INTEGER
-- --
- user_id - user_id: INTEGER
- file name - group_id: INTEGER
-- --
- date - date: TEXT
- referer - referer: TEXT
- status - status: INTEGER
style=autoresize</panel_attributes> style=autoresize</panel_attributes>
<additional_attributes/> <additional_attributes/>
</element> </element>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>456</x> <x>650</x>
<y>247</y> <y>273</y>
<w>285</w> <w>130</w>
<h>95</h> <h>65</h>
</coordinates> </coordinates>
<panel_attributes>lt=- <panel_attributes>lt=-
m1=1 m1=1
m2=n m2=n
</panel_attributes> </panel_attributes>
<additional_attributes>10.0;20.0;130.0;20.0</additional_attributes> <additional_attributes>10.0;20.0;80.0;20.0</additional_attributes>
</element> </element>
<element> <element>
<id>UMLClass</id> <id>UMLClass</id>
<coordinates> <coordinates>
<x>1159</x> <x>1092</x>
<y>646</y> <y>546</y>
<w>190</w> <w>234</w>
<h>152</h> <h>130</h>
</coordinates> </coordinates>
<panel_attributes>File <panel_attributes>File
-- --
&lt;&lt;PK&gt;&gt;- name &lt;&lt;PK&gt;&gt;
- name: TEXT
-- --
- group_id - group_id: INTEGER
-- --
style=autoresize</panel_attributes> style=autoresize</panel_attributes>
<additional_attributes/> <additional_attributes/>
@ -106,24 +110,24 @@ style=autoresize</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>1216</x> <x>1131</x>
<y>380</y> <y>390</y>
<w>76</w> <w>52</w>
<h>304</h> <h>182</h>
</coordinates> </coordinates>
<panel_attributes>lt=- <panel_attributes>lt=-
m1=n m1=n
m2=1 m2=1
</panel_attributes> </panel_attributes>
<additional_attributes>10.0;140.0;10.0;10.0</additional_attributes> <additional_attributes>10.0;120.0;10.0;10.0</additional_attributes>
</element> </element>
<element> <element>
<id>UMLNote</id> <id>UMLNote</id>
<coordinates> <coordinates>
<x>874</x> <x>897</x>
<y>19</y> <y>117</y>
<w>570</w> <w>390</w>
<h>133</h> <h>91</h>
</coordinates> </coordinates>
<panel_attributes>One group contains multiple files. <panel_attributes>One group contains multiple files.
Lets you group the images from a Lets you group the images from a
@ -134,10 +138,10 @@ style=autoresize</panel_attributes>
<element> <element>
<id>Relation</id> <id>Relation</id>
<coordinates> <coordinates>
<x>1178</x> <x>1105</x>
<y>133</y> <y>195</y>
<w>57</w> <w>39</w>
<h>152</h> <h>104</h>
</coordinates> </coordinates>
<panel_attributes>lt=&lt;-</panel_attributes> <panel_attributes>lt=&lt;-</panel_attributes>
<additional_attributes>10.0;60.0;10.0;10.0</additional_attributes> <additional_attributes>10.0;60.0;10.0;10.0</additional_attributes>

View File

@ -18,6 +18,7 @@ file_ranking_plot_max_files = 15
# "plot_figsize" = (60 40), # "plot_figsize" = (60 40),
plot_dpi = 300 plot_dpi = 300
img_dir = /www/analytics/images img_dir = /www/analytics/images
img_dir = /analytics/images
template_html = /home/my-user/analytics/template.html template_html = /home/my-user/analytics/template.html
html_out_path = /www/analytics/statistics.html html_out_path = /www/analytics/statistics.html
# filegroups = start:/index.html,/about.html,/img_on_index.png;music:/music.html,song.mp3 # filegroups = start:/index.html,/about.html,/img_on_index.png;music:/music.html,song.mp3

View File

@ -32,6 +32,7 @@ settings = {
# "plot_figsize": (60, 40), # "plot_figsize": (60, 40),
"plot_dpi": 300, "plot_dpi": 300,
"img_dir": "", "img_dir": "",
"img_location": "",
"img_filetype": "svg", "img_filetype": "svg",
"template_html": "", "template_html": "",
"html_out_path": "", "html_out_path": "",

View File

@ -374,17 +374,17 @@ def visualize(loaded_settings: dict):
img_filetype = settings["img_filetype"] img_filetype = settings["img_filetype"]
names = { names = {
# paths # paths
"img_file_ranking_last_x_days": f"{img_dir}/ranking_all_time_files_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"{img_dir}/ranking_all_time_referers_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"{img_dir}/ranking_all_time_browsers_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"{img_dir}/ranking_all_time_operating_systems_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"{img_dir}/user_request_count_daily_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_file_ranking_total": f"ranking_all_time_files_total.{img_filetype}",
"img_referer_ranking_total": f"{img_dir}/ranking_all_time_referers_total.{img_filetype}", "img_referer_ranking_total": f"ranking_all_time_referers_total.{img_filetype}",
"img_browser_ranking_total": f"{img_dir}/ranking_all_time_browsers_total.{img_filetype}", "img_browser_ranking_total": f"ranking_all_time_browsers_total.{img_filetype}",
"img_operating_system_ranking_total": f"{img_dir}/ranking_all_time_operating_systems_total.{img_filetype}", "img_operating_system_ranking_total": f"ranking_all_time_operating_systems_total.{img_filetype}",
"img_users_and_requests_total": f"{img_dir}/user_request_count_daily_total.{img_filetype}", "img_users_and_requests_total": f"user_request_count_daily_total.{img_filetype}",
# values # values
"mobile_user_percentage_total": 0.0, "mobile_user_percentage_total": 0.0,
"mobile_user_percentage_last_x_days": 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) file_ranking = get_file_ranking(cur, date_str)
if gen_img: 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 = 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
referer_ranking = get_ranking("referer", t_request, settings["referer_ranking_regex_whitelist"], cur, date_str) referer_ranking = get_ranking("referer", t_request, settings["referer_ranking_regex_whitelist"], cur, date_str)
if gen_img: 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 = 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
# user_agent_ranking = get_user_agent_ranking(cur, date_str) # 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"]) 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: 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, 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 & browser
os_ranking, browser_ranking, names[f"mobile_user_percentage{suffix}"] = get_os_browser_mobile_rankings(cur, unique_user_ids_human) os_ranking, browser_ranking, names[f"mobile_user_percentage{suffix}"] = get_os_browser_mobile_rankings(cur, unique_user_ids_human)
if gen_img: if gen_img:
fig_os_rating = plot_ranking(os_ranking, xlabel="Platform", ylabel="Share [%]", color_settings=color_settings_operating_systems) 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 = 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("File Ranking", file_ranking)
# print("referer Ranking", referer_ranking) # print("referer Ranking", referer_ranking)
@ -516,6 +516,8 @@ def visualize(loaded_settings: dict):
with open(settings["template_html"], "r") as file: with open(settings["template_html"], "r") as file:
html = file.read() html = file.read()
for name, value in names.items(): for name, value in names.items():
if "img" in name:
value = f"{img_location}/{value}"
html = html.replace(f"%{name}", str(value)) html = html.replace(f"%{name}", str(value))
with open(settings["html_out_path"], "w") as file: with open(settings["html_out_path"], "w") as file:
file.write(html) file.write(html)

View File

@ -14,6 +14,7 @@ setup(
packages=["regina"], packages=["regina"],
install_requires=[], install_requires=[],
python_requires='>=3.10',
classifiers=[ classifiers=[
"Operating System :: POSIX :: Linux", "Operating System :: POSIX :: Linux",

View File

@ -5,7 +5,7 @@
<meta name="description" content="Regina - Nginx Analytics"> <meta name="description" content="Regina - Nginx Analytics">
<meta name="keywords" content=""> <meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analytics for %server_name</title> <title>Analytics for %server-name</title>
<link rel="stylesheet" href="style.css"> <link rel="stylesheet" href="style.css">
</head> </head>
<body> <body>