Skip to content

Commit 26b37a9

Browse files
Reduce amount of generated seed data (#20)
* Reduce amount of generated seed data * Move to file based session store * Reset sessions on restart * Stop logging all of data to view
1 parent b9433fc commit 26b37a9

File tree

9 files changed

+317
-73
lines changed

9 files changed

+317
-73
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# compiled output
44
/dist
55
/tmp
6+
.tmp
67
/public
78
app/data/generated/
89
reference

app.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,45 @@ if (useCookieSessionStore === 'true' && !onlyDocumentation) {
9393
requestKey: 'session',
9494
})));
9595
} else {
96+
// app.use(sessionInMemory(Object.assign(sessionOptions, {
97+
// name: sessionName,
98+
// resave: false,
99+
// saveUninitialized: false,
100+
// })));
101+
102+
// Somewhat similar file store to GOV.UK
103+
const FileStore = require('session-file-store')(sessionInMemory)
104+
const sessionPath = path.join(__dirname, '.tmp/sessions')
105+
106+
// Make sure the sessions directory exists
107+
if (!fs.existsSync(sessionPath)) {
108+
fs.mkdirSync(sessionPath, { recursive: true })
109+
} else {
110+
// Clear existing session files on restart
111+
fs.readdirSync(sessionPath).forEach(file => {
112+
fs.unlinkSync(path.join(sessionPath, file))
113+
})
114+
}
115+
96116
app.use(sessionInMemory(Object.assign(sessionOptions, {
97117
name: sessionName,
98118
resave: false,
99119
saveUninitialized: false,
100-
})));
120+
store: new FileStore({
121+
path: sessionPath,
122+
logFn: (message) => {
123+
// Suppress noisy session cleanup logs
124+
if (message.endsWith('Deleting expired sessions')) {
125+
return
126+
}
127+
if (message.includes('ENOENT')) {
128+
console.error('Warning: Please use different working directories for your prototypes to avoid session clashes')
129+
return
130+
}
131+
console.log(message)
132+
}
133+
})
134+
})))
101135
}
102136

103137
// Support for parsing data in POSTs

app/config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ module.exports = {
2929
slotDurationMinutes: 8,
3030

3131
// Target percentages
32-
targetBookingPercent: 150, // 150% represents overbooking (e.g. 60 bookings for 40 slots)
32+
targetBookingPercent: 120, // 150% represents overbooking (e.g. 60 bookings for 40 slots)
3333
targetAttendancePercent: 100, // 100% of original capacity (not overbooking)
3434

3535
// Date range for generating data
36-
daysToGenerate: 7,
37-
daysBeforeToday: 3,
36+
daysToGenerate: 5,
37+
daysBeforeToday: 2,
3838

3939
simulatedTime: '11:30', // 24h format
4040
},
@@ -57,6 +57,6 @@ module.exports = {
5757
// Data generation settings
5858
generation: {
5959
numberOfParticipants: 1000,
60-
bookingProbability: 0.8 // 80% of slots are booked
60+
bookingProbability: 0.8, // 80% of slots are booked
6161
}
6262
};

app/lib/generate-seed-data.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ const generateSnapshot = (date, allParticipants, unit) => {
3838
return age >= 50 && age <= 70;
3939
});
4040

41-
// Generate a week of clinics
42-
for (let i = 0; i < 7; i++) {
41+
// Generate a 5 days of clinics
42+
for (let i = 0; i < config.clinics.daysToGenerate; i++) {
4343
const clinicDate = dayjs(date).add(i, 'day');
4444
const newClinics = generateClinicsForBSU({
4545
date: clinicDate.toDate(),
@@ -112,7 +112,7 @@ const generateData = async () => {
112112
today.subtract(9, 'year').add(3, 'month'),
113113
today.subtract(6, 'year').add(2, 'month'),
114114
today.subtract(3, 'year').add(1, 'month'),
115-
today.subtract(3, 'days')
115+
today.subtract(config.clinics.daysBeforeToday, 'days')
116116
];
117117

118118

app/lib/generators/clinic-generator.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ const generateTimeSlots = (date, sessionTimes, clinicType) => {
4747
endDateTime: slotEndTime.toISOString(),
4848
duration: slotDurationMinutes,
4949
type: clinicType,
50-
capacity: clinicType === 'assessment' ? 1 : 2, // Assessment clinics don't double book
50+
capacity: 1,
51+
// Don't support smart clinics yet
52+
// capacity: clinicType === 'assessment' ? 1 : 2, // Assessment clinics don't double book
5153
bookedCount: 0,
5254
period: `${sessionTimes.startTime}-${sessionTimes.endTime}`
5355
});
@@ -124,7 +126,9 @@ const generateClinic = (date, location, breastScreeningUnit, sessionTimes) => {
124126
targetCapacity: {
125127
bookingPercent: clinicType === 'assessment' ? 100 : config.clinics.targetBookingPercent,
126128
attendancePercent: clinicType === 'assessment' ? 95 : config.clinics.targetAttendancePercent,
127-
totalSlots: slots.length * (clinicType === 'assessment' ? 1 : 2)
129+
totalSlots: slots.length,
130+
// not supporting Smart clinics yet
131+
// totalSlots: slots.length * (clinicType === 'assessment' ? 1 : 2)
128132
},
129133
notes: null,
130134
sessionTimes,

app/views/_templates/layout-app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575

7676
{% block content %}
77-
{{ data | log }}
77+
7878
<div class="nhsuk-grid-row">
7979
<div class="{{ gridColumn or 'nhsuk-grid-column-two-thirds' }}">
8080

app/views/participants/questionnaire/medical-history.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{% set hideBackLink = true %}
1010

1111
{% block content %}
12-
{{ data | log }}
12+
1313
<div class="nhsuk-grid-row">
1414
<div class="{{ gridColumn or 'nhsuk-grid-column-two-thirds' }}">
1515

0 commit comments

Comments
 (0)