@@ -9,18 +9,35 @@ import profileImg from '../../../assets/images/profile.png';
99
1010ChartJS . register ( ArcElement , Tooltip , Legend ) ;
1111
12- function StatsChart ( { stats } ) {
13- const totalMembers = stats . find ( stat => stat . title === 'Total Community Members' ) ?. value || 1 ;
14- const registered = stats . find ( stat => stat . title === 'Registered' ) ?. value || 0 ;
15- const percentage = ( ( registered / totalMembers ) * 100 ) . toFixed ( 1 ) ;
12+ function deriveAttendanceMetrics ( {
13+ totalCommunityMembers,
14+ registeredMembers,
15+ registeredNoShows,
16+ communityVisitors,
17+ } ) {
18+ const attendingMembers = Math . max ( registeredMembers - registeredNoShows , 0 ) ;
1619
20+ const totalAttendees = attendingMembers + communityVisitors ;
21+
22+ const participationPercentage =
23+ totalCommunityMembers > 0
24+ ? Number ( ( ( totalAttendees / totalCommunityMembers ) * 100 ) . toFixed ( 1 ) )
25+ : 0 ;
26+
27+ return {
28+ attendingMembers,
29+ totalAttendees,
30+ participationPercentage,
31+ } ;
32+ }
33+
34+ function StatsChart ( { attendingMembers, communityVisitors, participationPercentage } ) {
1735 const data = {
18- labels : stats . map ( stat => stat . title ) ,
36+ labels : [ 'Attending Members' , 'Community Visitors' ] ,
1937 datasets : [
2038 {
21- data : stats . map ( stat => stat . value ) ,
22- backgroundColor : [ '#4CAF50' , '#2196F3' , '#F44336' , '#FF9800' ] ,
23- hoverBackgroundColor : [ '#388E3C' , '#1976D2' , '#D32F2F' , '#F57C00' ] ,
39+ data : [ attendingMembers , communityVisitors ] ,
40+ backgroundColor : [ '#2196F3' , '#FF9800' ] ,
2441 borderWidth : 1 ,
2542 } ,
2643 ] ,
@@ -30,14 +47,23 @@ function StatsChart({ stats }) {
3047 cutout : '70%' ,
3148 plugins : {
3249 legend : { display : false } ,
33- tooltip : { enabled : true } ,
50+ tooltip : {
51+ callbacks : {
52+ label : ctx => {
53+ const total = attendingMembers + communityVisitors ;
54+ const value = ctx . raw ;
55+ const percent = total > 0 ? ( ( value / total ) * 100 ) . toFixed ( 1 ) : 0 ;
56+ return `${ ctx . label } : ${ value } (${ percent } %)` ;
57+ } ,
58+ } ,
59+ } ,
3460 } ,
3561 } ;
3662
3763 return (
3864 < div className = { styles . chartContainer } >
3965 < Doughnut data = { data } options = { options } />
40- < div className = { styles . chartLabel } > { percentage } %</ div >
66+ < div className = { styles . chartLabel } > { participationPercentage } %</ div >
4167 </ div >
4268 ) ;
4369}
@@ -57,7 +83,7 @@ const exportToCSV = students => {
5783 document . body . removeChild ( link ) ;
5884} ;
5985
60- function StatsCard ( { title, value, color , definition } ) {
86+ function StatsCard ( { title, value, colorClass , definition } ) {
6187 return (
6288 < div className = { styles . statsCard } >
6389 < div className = { styles . statsCardHeader } >
@@ -71,9 +97,7 @@ function StatsCard({ title, value, color, definition }) {
7197 < FaInfoCircle className = { styles . infoIcon } />
7298 </ button >
7399 </ div >
74- < p className = { styles . statsValue } style = { { color } } >
75- { value }
76- </ p >
100+ < p className = { `${ styles . statsValue } ${ styles [ colorClass ] } ` } > { value } </ p >
77101 </ div >
78102 ) ;
79103}
@@ -168,34 +192,62 @@ function ActivityAttendance() {
168192 const [ searchTerm , setSearchTerm ] = useState ( '' ) ;
169193 const [ statusFilter , setStatusFilter ] = useState ( 'All' ) ;
170194
195+ /* -------- Raw inputs -------- */
196+ const totalCommunityMembers = 400 ;
197+ const registeredMembers = 100 ;
198+ const registeredNoShows = 15 ;
199+ const communityVisitors = 19 ;
200+
201+ const { attendingMembers, totalAttendees, participationPercentage } = deriveAttendanceMetrics ( {
202+ totalCommunityMembers,
203+ registeredMembers,
204+ registeredNoShows,
205+ communityVisitors,
206+ } ) ;
207+
171208 const statsData = [
172209 {
173210 id : uuidv4 ( ) ,
174211 title : 'Total Community Members' ,
175- value : 400 ,
176- color : '#4CAF50 ' ,
177- definition : 'All members registered in the community, including inactive users and visitors .' ,
212+ value : totalCommunityMembers ,
213+ colorClass : 'statGreen ' ,
214+ definition : 'Total number of people who live in the community .' ,
178215 } ,
179216 {
180217 id : uuidv4 ( ) ,
181- title : 'Registered' ,
182- value : 100 ,
183- color : '#2196F3 ' ,
184- definition : 'Members registered for the selected event/session only .' ,
218+ title : 'Registered Members ' ,
219+ value : registeredMembers ,
220+ colorClass : 'statBlue ' ,
221+ definition : 'Community members who registered for the event/session.' ,
185222 } ,
186223 {
187224 id : uuidv4 ( ) ,
188- title : 'No Show ' ,
189- value : 15 ,
190- color : '#F44336 ' ,
191- definition : 'Registered members who did not check in or attend the event.' ,
225+ title : 'Registered No-Shows ' ,
226+ value : registeredNoShows ,
227+ colorClass : 'statRed ' ,
228+ definition : 'Registered community members who did not attend the event.' ,
192229 } ,
193230 {
194231 id : uuidv4 ( ) ,
195- title : 'Community Visitor' ,
196- value : 19 ,
197- color : '#FF9800' ,
198- definition : 'Non-registered participants who attended the event.' ,
232+ title : 'Attending Members' ,
233+ value : attendingMembers ,
234+ colorClass : 'statBlue' ,
235+ definition : 'Community members who registered and actually attended the event.' ,
236+ } ,
237+ {
238+ id : uuidv4 ( ) ,
239+ title : 'Community Visitors' ,
240+ value : communityVisitors ,
241+ colorClass : 'statOrange' ,
242+ definition : 'Non-community members who attended the event.' ,
243+ } ,
244+ {
245+ id : uuidv4 ( ) ,
246+ title : 'Total Attendees' ,
247+ value : totalAttendees ,
248+ colorClass : 'statDarkGreen' ,
249+ definition :
250+ 'Total number of people who attended the event. Used for participation and continuation decisions.' ,
199251 } ,
200252 ] ;
201253
@@ -232,21 +284,25 @@ function ActivityAttendance() {
232284
233285 < div className = { styles . dashboardMain } >
234286 < div className = { styles . statsChartContainer } >
235- < StatsChart stats = { statsData } />
287+ < StatsChart
288+ attendingMembers = { attendingMembers }
289+ communityVisitors = { communityVisitors }
290+ participationPercentage = { participationPercentage }
291+ />
292+
236293 < div className = { styles . statsGrid } >
237294 { statsData . map ( stat => (
238295 < StatsCard
239296 key = { stat . id }
240297 title = { stat . title }
241298 value = { stat . value }
242- color = { stat . color }
299+ colorClass = { stat . colorClass }
243300 definition = { stat . definition }
244301 />
245302 ) ) }
246303 </ div >
247304 </ div >
248305
249- { /* Live Student Updates */ }
250306 < LiveUpdates
251307 students = { students }
252308 searchTerm = { searchTerm }
0 commit comments