ElvarThorS commited on
Commit
09fe854
·
1 Parent(s): be6bc50

Plot age brackets sidebar

Browse files
Files changed (2) hide show
  1. app/app.py +34 -7
  2. app/data_processing/point_scoring.py +1 -1
app/app.py CHANGED
@@ -7,6 +7,7 @@ import geopandas as gpd
7
  from datetime import datetime
8
 
9
  import seaborn as sns
 
10
 
11
  from pandas.core.frame import functools
12
  # Load data and compute static values
@@ -80,13 +81,39 @@ with ui.layout_columns(col_widths=[8, 4]):
80
  print((y, x))
81
  score = initBackend.get_station_score((y, x), radius=input.rad())
82
  return f"Score: {score}"
83
- @render.plot(alt="A Seaborn histogram on penguin body mass in grams.")
84
- def plot():
85
- ax = sns.histplot(data=[1,2,3,4,5,6,7,8,9], x="body_mass_g", bins=input.n())
86
- ax.set_title("Palmer Penguins")
87
- ax.set_xlabel("Mass (g)")
88
- ax.set_ylabel("Count")
89
- return ax
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
 
92
 
 
7
  from datetime import datetime
8
 
9
  import seaborn as sns
10
+ import matplotlib.pyplot as plt
11
 
12
  from pandas.core.frame import functools
13
  # Load data and compute static values
 
81
  print((y, x))
82
  score = initBackend.get_station_score((y, x), radius=input.rad())
83
  return f"Score: {score}"
84
+ @render.plot(alt="A bar chart of age bracket data.")
85
+ def plot():
86
+ print("Generating age bracket bar chart")
87
+
88
+ # Dummy coords
89
+ # station_coord = (-21.910388, 64.144947)
90
+
91
+ x,y = stop.get()
92
+ station_coord = (y,x)
93
+
94
+ # Fetch age bracket data from the Data_provider instance
95
+ age_data = initBackend.get_station_score(station_coord)['age_data'] # Assume this returns a dictionary or DataFrame
96
+
97
+ # Example structure: {'0-4 ára': 120, '5-9 ára': 140, ...}
98
+ age_brackets = list(age_data.keys())
99
+ populations = list(age_data.values())
100
+
101
+ # Create a Matplotlib figure
102
+ fig, ax = plt.subplots(figsize=(8, 4))
103
+
104
+ # Create the bar chart
105
+ ax.bar(age_brackets, populations, color='skyblue')
106
+
107
+ # Customize the plot
108
+ ax.set_title("Population by Age Bracket")
109
+ ax.set_xlabel("Age Bracket")
110
+ ax.set_ylabel("Population")
111
+ ax.set_xticks(range(len(age_brackets)))
112
+ ax.set_xticklabels(age_brackets, rotation=45, ha="right")
113
+
114
+ # Return the figure for rendering in Shiny
115
+ return fig
116
+
117
 
118
 
119
 
app/data_processing/point_scoring.py CHANGED
@@ -54,7 +54,7 @@ def score_current(station_coord, df_features, cov_smsv, w_density, w_income, w_a
54
 
55
  density_score = smsv_info["density"].iloc[0] * w_density
56
  total_score += (age_score + income_score + density_score) * smsv["coverage_percentage"] # TODO: Area of the cricle * percent covered / total area of the small area
57
- return {"total_score": total_score, "income_score": income_score, "age_score": age_score, "density_score": density_score}
58
 
59
  def get_age_score(age_distribution):
60
  """
 
54
 
55
  density_score = smsv_info["density"].iloc[0] * w_density
56
  total_score += (age_score + income_score + density_score) * smsv["coverage_percentage"] # TODO: Area of the cricle * percent covered / total area of the small area
57
+ return {"total_score": total_score, "income_score": income_score, "age_score": age_score, "density_score": density_score, "age_data": age_dist}
58
 
59
  def get_age_score(age_distribution):
60
  """