Dark daily chart (#152)
* Updated daily chart to use the theme selector * Added sleep after changing theme so the chart can update * Added code for pink theme, made it easier to add more themes in the future * Added blue chart for future blue theme * Set chart background to none so it's transparent * Added back background for dark mode. * Change daily chart based on file based settings. Only support light/dark mode. * Cleanup * Added borders around the bars on the bar chart * Updated background color for dark theme * Merge from main * Fixed some spacing * Updating Python version for linting * Cleanup * Back leveled to Python 3.9 * Update scripts/daily_plot.py Co-authored-by: Nachtzuster <Nachtzuster@users.noreply.github.com> * Coding suggestions --------- Co-authored-by: Nachtzuster <Nachtzuster@users.noreply.github.com>
This commit is contained in:
+5
-1
@@ -147,7 +147,6 @@ if(isset($_GET["latitude"])){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$contents = file_get_contents("/etc/birdnet/birdnet.conf");
|
||||
$contents = preg_replace("/SITE_NAME=.*/", "SITE_NAME=\"$site_name\"", $contents);
|
||||
$contents = preg_replace("/LATITUDE=.*/", "LATITUDE=$latitude", $contents);
|
||||
@@ -176,6 +175,10 @@ if(isset($_GET["latitude"])){
|
||||
function() {
|
||||
window.parent.document.location.reload();
|
||||
}, 1000);</script>";
|
||||
|
||||
shell_exec("sudo systemctl restart chart_viewer.service");
|
||||
// the sleep allows for the service to restart and image to be generated
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
$fh = fopen("/etc/birdnet/birdnet.conf", "w");
|
||||
@@ -649,6 +652,7 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}
|
||||
|
||||
<table class="settingstable"><tr><td>
|
||||
<h2>Color scheme </h2>
|
||||
Note: when changing themes the daily chart may need a page refresh before updating.<br><br>
|
||||
<label for="color_scheme">Color scheme for the site : </label>
|
||||
<select name="color_scheme" class="testbtn">
|
||||
<?php
|
||||
|
||||
+27
-6
@@ -35,6 +35,8 @@ def get_data(now=None):
|
||||
|
||||
# Function to show value on bars - from https://stackoverflow.com/questions/43214978/seaborn-barplot-displaying-values
|
||||
def show_values_on_bars(ax, label):
|
||||
conf = get_settings()
|
||||
|
||||
for i, p in enumerate(ax.patches):
|
||||
x = p.get_x() + p.get_width() * 0.9
|
||||
y = p.get_y() + p.get_height() / 2
|
||||
@@ -43,7 +45,12 @@ def show_values_on_bars(ax, label):
|
||||
# Species Count Total
|
||||
value = '{:n}'.format(p.get_width())
|
||||
bbox = {'facecolor': 'lightgrey', 'edgecolor': 'none', 'pad': 1.0}
|
||||
ax.text(x, y, value, bbox=bbox, ha='center', va='center', size=9, color='darkgreen')
|
||||
if conf['COLOR_SCHEME'] == "dark":
|
||||
color = 'black'
|
||||
else:
|
||||
color = 'darkgreen'
|
||||
|
||||
ax.text(x, y, value, bbox=bbox, ha='center', va='center', size=9, color=color)
|
||||
|
||||
|
||||
def wrap_width(txt):
|
||||
@@ -70,9 +77,16 @@ def create_plot(df_plt_today, now, is_top=None):
|
||||
|
||||
df_plt_selection_today = df_plt_today[df_plt_today.Com_Name.isin(plt_selection_today.index)]
|
||||
|
||||
conf = get_settings()
|
||||
|
||||
# Set up plot axes and titles
|
||||
height = max(readings / 3, 0) + 1.06
|
||||
f, axs = plt.subplots(1, 2, figsize=(10, height), gridspec_kw=dict(width_ratios=[3, 6]), facecolor='#77C487')
|
||||
if conf['COLOR_SCHEME'] == "dark":
|
||||
facecolor = 'darkgrey'
|
||||
else:
|
||||
facecolor = 'none'
|
||||
|
||||
f, axs = plt.subplots(1, 2, figsize=(10, height), gridspec_kw=dict(width_ratios=[3, 6]), facecolor=facecolor)
|
||||
|
||||
# generate y-axis order for all figures based on frequency
|
||||
freq_order = df_plt_selection_today['Com_Name'].value_counts().index
|
||||
@@ -86,8 +100,12 @@ def create_plot(df_plt_today, now, is_top=None):
|
||||
norm = plt.Normalize(confmax.values.min(), confmax.values.max())
|
||||
if is_top or is_top is None:
|
||||
# Set Palette for graphics
|
||||
pal = "Greens"
|
||||
colors = plt.cm.Greens(norm(confmax)).tolist()
|
||||
if conf['COLOR_SCHEME'] == "dark":
|
||||
pal = "Greys"
|
||||
colors = plt.cm.Greys(norm(confmax)).tolist()
|
||||
else:
|
||||
pal = "Greens"
|
||||
colors = plt.cm.Greens(norm(confmax)).tolist()
|
||||
if is_top:
|
||||
plot_type = "Top"
|
||||
else:
|
||||
@@ -102,7 +120,7 @@ def create_plot(df_plt_today, now, is_top=None):
|
||||
|
||||
# Generate frequency plot
|
||||
plot = sns.countplot(y='Com_Name', hue='Com_Name', legend=False, data=df_plt_selection_today,
|
||||
palette=colors, order=freq_order, ax=axs[0])
|
||||
palette=colors, order=freq_order, ax=axs[0], edgecolor='lightgrey')
|
||||
|
||||
# Prints Max Confidence on bars
|
||||
show_values_on_bars(axs[0], confmax)
|
||||
@@ -136,7 +154,10 @@ def create_plot(df_plt_today, now, is_top=None):
|
||||
# Set color and weight of tick label for current hour
|
||||
for label in plot.get_xticklabels():
|
||||
if int(label.get_text()) == now.hour:
|
||||
label.set_color('yellow')
|
||||
if conf['COLOR_SCHEME'] == "dark":
|
||||
label.set_color('white')
|
||||
else:
|
||||
label.set_color('yellow')
|
||||
|
||||
plot.set_xticklabels(plot.get_xticklabels(), rotation=0, size=8)
|
||||
|
||||
|
||||
@@ -180,6 +180,7 @@ fi
|
||||
if [ -L /usr/local/bin/analyze.py ];then
|
||||
rm -f /usr/local/bin/analyze.py
|
||||
fi
|
||||
|
||||
if [ -L /usr/local/bin/birdnet_analysis.sh ];then
|
||||
rm -f /usr/local/bin/birdnet_analysis.sh
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user