Skip to content

Commit ae0849d

Browse files
Merge pull request #1949 from OneCommunityGlobal/development
Backend Release to Main [2.75]
2 parents 0bd195d + 69a63b5 commit ae0849d

39 files changed

Lines changed: 631 additions & 358 deletions
Lines changed: 87 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
const { participants, events, attendance } = require('./AttendanceMockData');
22

33
const noShowVizController = function () {
4-
54
// Async function to get no-shows data
65
const getNoShowsData = async (req, res) => {
7-
const { period } = req.query; // Get period from request query
6+
const { period } = req.query; // Get period from request query
87

98
try {
109
const groupedData = {};
11-
const eventMap = Object.fromEntries(events.map(event => [event.eventID, event.eventType]));
12-
const allEventTypes = [...new Set(events.map(event => event.eventType))];
10+
const eventMap = Object.fromEntries(events.map((event) => [event.eventID, event.eventType]));
11+
const allEventTypes = [...new Set(events.map((event) => event.eventType))];
1312

14-
attendance.forEach(record => {
13+
attendance.forEach((record) => {
1514
const eventType = eventMap[record.eventID];
16-
const eventDate = events.find(event => event.eventID === record.eventID)?.date;
15+
const eventDate = events.find((event) => event.eventID === record.eventID)?.date;
1716
const parsedDate = new Date(eventDate);
18-
17+
1918
// Format date using JavaScript's native Date functions
2019
const formattedDate =
2120
period === 'year'
@@ -43,18 +42,17 @@ const noShowVizController = function () {
4342
const dateB = period === 'year' ? new Date(b) : new Date(Date.parse(b));
4443
return dateA - dateB;
4544
})
46-
.map(date => {
45+
.map((date) => {
4746
const entry = { date };
4847

49-
allEventTypes.forEach(event => {
48+
allEventTypes.forEach((event) => {
5049
entry[event] = groupedData[date][event] || { attended: 0, notAttended: 0 };
5150
});
5251

5352
return entry;
5453
});
5554

5655
res.status(200).json(result); // Send the result as a JSON response
57-
5856
} catch (error) {
5957
console.error('Error fetching no-shows data:', error);
6058
res.status(500).json({ message: 'Error fetching no-shows data', error });
@@ -65,11 +63,11 @@ const noShowVizController = function () {
6563
const getNoShowsByLocation = async (req, res) => {
6664
try {
6765
const groupedData = {};
68-
const eventTypes = [...new Set(events.map(event => event.eventType))];
66+
const eventTypes = [...new Set(events.map((event) => event.eventType))];
6967

70-
attendance.forEach(record => {
71-
const participant = participants.find(p => p.participantID === record.participantID);
72-
const event = events.find(e => e.eventID === record.eventID);
68+
attendance.forEach((record) => {
69+
const participant = participants.find((p) => p.participantID === record.participantID);
70+
const event = events.find((e) => e.eventID === record.eventID);
7371

7472
if (participant && event) {
7573
const { location } = event;
@@ -89,21 +87,20 @@ const noShowVizController = function () {
8987
}
9088
});
9189

92-
Object.keys(groupedData).forEach(location => {
93-
eventTypes.forEach(eventType => {
90+
Object.keys(groupedData).forEach((location) => {
91+
eventTypes.forEach((eventType) => {
9492
if (!groupedData[location][eventType]) {
9593
groupedData[location][eventType] = 0;
9694
}
9795
});
9896
});
9997

100-
const result = Object.keys(groupedData).map(location => ({
98+
const result = Object.keys(groupedData).map((location) => ({
10199
location,
102100
...groupedData[location],
103101
}));
104102

105103
res.status(200).json(result); // Send the result as a JSON response
106-
107104
} catch (error) {
108105
console.error('Error fetching no-shows by location:', error);
109106
res.status(500).json({ message: 'Error fetching no-shows by location', error });
@@ -125,10 +122,10 @@ const noShowVizController = function () {
125122
const groupedData = {};
126123
const genderTypes = new Set();
127124

128-
attendance.forEach(item => {
129-
const participant = participants.find(p => p.participantID === item.participantID);
125+
attendance.forEach((item) => {
126+
const participant = participants.find((p) => p.participantID === item.participantID);
130127
if (participant && !item.attended) {
131-
const ageGroup = Object.keys(ageGroups).find(group => {
128+
const ageGroup = Object.keys(ageGroups).find((group) => {
132129
const [min, max] = ageGroups[group];
133130
return participant.age >= min && participant.age <= max;
134131
});
@@ -147,101 +144,101 @@ const noShowVizController = function () {
147144
}
148145
});
149146

150-
const resultData = Object.keys(ageGroups).map(ageGroup => {
147+
const resultData = Object.keys(ageGroups).map((ageGroup) => {
151148
const groupData = groupedData[ageGroup] || {};
152149
const result = { ageGroup };
153150

154-
[...genderTypes].forEach(gender => {
151+
[...genderTypes].forEach((gender) => {
155152
result[gender] = groupData[gender] || 0;
156153
});
157154

158155
return result;
159156
});
160157

161158
res.status(200).json({ ageGroupData: resultData, genderTypes: Array.from(genderTypes) });
162-
163159
} catch (error) {
164160
console.error('Error fetching no-shows by age group:', error);
165161
res.status(500).json({ message: 'Error fetching no-shows by age group', error });
166162
}
167163
};
168164

169165
// Async function to get no-show proportions
170-
const getNoShowProportions = async (req, res) => {
171-
try {
172-
const genderCounts = {};
166+
const getNoShowProportions = async (req, res) => {
167+
try {
168+
const genderCounts = {};
173169

174-
attendance.forEach(item => {
175-
const participant = participants.find(p => p.participantID === item.participantID);
170+
attendance.forEach((item) => {
171+
const participant = participants.find((p) => p.participantID === item.participantID);
176172

177-
if (participant && !item.attended) {
178-
genderCounts[participant.gender] = (genderCounts[participant.gender] || 0) + 1;
179-
}
180-
});
173+
if (participant && !item.attended) {
174+
genderCounts[participant.gender] = (genderCounts[participant.gender] || 0) + 1;
175+
}
176+
});
181177

182-
const result = Object.keys(genderCounts).map(gender => ({
183-
name: gender,
184-
value: genderCounts[gender],
185-
}));
178+
const result = Object.keys(genderCounts).map((gender) => ({
179+
name: gender,
180+
value: genderCounts[gender],
181+
}));
186182

187-
res.status(200).json(result); // Send the result as a JSON response
183+
res.status(200).json(result); // Send the result as a JSON response
184+
} catch (error) {
185+
console.error('Error fetching no-show proportions:', error);
186+
res.status(500).json({ message: 'Error fetching no-show proportions', error });
187+
}
188+
};
188189

189-
} catch (error) {
190-
console.error('Error fetching no-show proportions:', error);
191-
res.status(500).json({ message: 'Error fetching no-show proportions', error });
192-
}
193-
};
190+
// Async function to get unique event types
191+
const getUniqueEventTypes = async (req, res) => {
192+
try {
193+
const eventTypes = new Set(events.map((event) => event.eventType));
194+
const result = [...Array.from(eventTypes)];
194195

195-
// Async function to get unique event types
196-
const getUniqueEventTypes = async (req, res) => {
197-
try {
198-
const eventTypes = new Set(events.map(event => event.eventType));
199-
const result = [...Array.from(eventTypes)];
196+
res.status(200).json(result); // Send the result as a JSON response
197+
} catch (error) {
198+
console.error('Error fetching unique event types:', error);
199+
res.status(500).json({ message: 'Error fetching unique event types', error });
200+
}
201+
};
200202

201-
res.status(200).json(result); // Send the result as a JSON response
203+
// Async function to get attendance by day, based on event type
204+
const getAttendanceByDay = async (req, res) => {
205+
const { selectedEventType } = req.query; // Get selected event type from request query
202206

203-
} catch (error) {
204-
console.error('Error fetching unique event types:', error);
205-
res.status(500).json({ message: 'Error fetching unique event types', error });
206-
}
207-
};
207+
try {
208+
const groupedData = {
209+
Sunday: 0,
210+
Monday: 0,
211+
Tuesday: 0,
212+
Wednesday: 0,
213+
Thursday: 0,
214+
Friday: 0,
215+
Saturday: 0,
216+
};
208217

209-
// Async function to get attendance by day, based on event type
210-
const getAttendanceByDay = async (req, res) => {
211-
const { selectedEventType } = req.query; // Get selected event type from request query
212-
213-
try {
214-
const groupedData = {
215-
Sunday: 0,
216-
Monday: 0,
217-
Tuesday: 0,
218-
Wednesday: 0,
219-
Thursday: 0,
220-
Friday: 0,
221-
Saturday: 0,
222-
};
223-
224-
attendance.forEach(item => {
225-
const event = events.find(e => e.eventID === item.eventID);
226-
227-
if (event && item.attended && (selectedEventType === 'All' || event.eventType === selectedEventType)) {
228-
const day = new Date(event.date).toLocaleString('en-US', { weekday: 'long' });
229-
groupedData[day] += 1;
230-
}
231-
});
232-
233-
const result = Object.keys(groupedData).map(day => ({
234-
day,
235-
attended: groupedData[day],
236-
}));
237-
238-
res.status(200).json(result); // Send the result as a JSON response
239-
240-
} catch (error) {
241-
console.error('Error fetching attendance by day:', error);
242-
res.status(500).json({ message: 'Error fetching attendance by day', error });
243-
}
244-
};
218+
attendance.forEach((item) => {
219+
const event = events.find((e) => e.eventID === item.eventID);
220+
221+
if (
222+
event &&
223+
item.attended &&
224+
(selectedEventType === 'All' || event.eventType === selectedEventType)
225+
) {
226+
const day = new Date(event.date).toLocaleString('en-US', { weekday: 'long' });
227+
groupedData[day] += 1;
228+
}
229+
});
230+
231+
const result = Object.keys(groupedData).map((day) => ({
232+
day,
233+
attended: groupedData[day],
234+
}));
235+
236+
res.status(200).json(result); // Send the result as a JSON response
237+
} catch (error) {
238+
console.error('Error fetching attendance by day:', error);
239+
res.status(500).json({ message: 'Error fetching attendance by day', error });
240+
}
241+
};
245242

246243
return {
247244
getNoShowsData,
@@ -253,5 +250,4 @@ const getAttendanceByDay = async (req, res) => {
253250
};
254251
};
255252

256-
257253
module.exports = noShowVizController;

src/controllers/analyticsPopularPRsController.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const NodeCache = require('node-cache');
2-
32
const PullRequest = require('../models/pullRequest');
43
const PullRequestReview = require('../models/pullRequestReview');
54
const PullRequestSyncMetadata = require('../models/pullRequestSyncMetadata');
6-
75
const {
86
parseDurationValue,
97
isStaleData,

0 commit comments

Comments
 (0)