aus10powell commited on
Commit
c0d813b
1 Parent(s): 6551064

Upload app_plot_utils.py

Browse files
Files changed (1) hide show
  1. app_plot_utils.py +41 -0
app_plot_utils.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import altair as alt
3
+ """
4
+ app_plot_utils.py
5
+
6
+ Description: This file contains utility functions for generating interactive plots
7
+ using the Altair library. These functions are designed for visualizing fish count data
8
+ obtained from processed videos and historical records.
9
+
10
+ Author: Austin Powell
11
+ """
12
+
13
+ def plot_count_date(dataframe):
14
+ """Plots counts vs relative time for uploaded video."""
15
+ dataframe["seconds"] = dataframe["timestamps"] / 1000
16
+ dataframe["class"] = "Herring" # TBD: Hard-coded for now
17
+ return (
18
+ alt.Chart(dataframe, title="Processed video detected fish")
19
+ .mark_line()
20
+ .encode(x="seconds", y="fish_count", color="class")
21
+ .interactive()
22
+ )
23
+
24
+ def plot_historical_data(dataframe):
25
+ """Returns altair plot of historical counts to be rendered on main dashboard."""
26
+ dataframe["Date"] = pd.to_datetime(dataframe["Date"])
27
+ s = (
28
+ dataframe.resample(rule="D", on="Date")["Count"].sum().reset_index()
29
+ ) # Resample on day
30
+ return (
31
+ alt.Chart(s, title="Historical Video Counts of Herring")
32
+ .mark_bar()
33
+ .transform_window(
34
+ # The field to average
35
+ rolling_mean="mean(Count)",
36
+ # The number of values before and after the current value to include.
37
+ frame=[-9, 0],
38
+ )
39
+ .encode(x="Date", y="Count", tooltip=["Count", "Date"])
40
+ .interactive()
41
+ )