Skip to content

Commit

Permalink
Reduce amount of generated seed data (#20)
Browse files Browse the repository at this point in the history
* Reduce amount of generated seed data
* Move to file based session store
* Reset sessions on restart
* Stop logging all of data to view
  • Loading branch information
edwardhorsford authored Dec 10, 2024
1 parent b9433fc commit 26b37a9
Show file tree
Hide file tree
Showing 9 changed files with 317 additions and 73 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# compiled output
/dist
/tmp
.tmp
/public
app/data/generated/
reference
Expand Down
36 changes: 35 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,45 @@ if (useCookieSessionStore === 'true' && !onlyDocumentation) {
requestKey: 'session',
})));
} else {
// app.use(sessionInMemory(Object.assign(sessionOptions, {
// name: sessionName,
// resave: false,
// saveUninitialized: false,
// })));

// Somewhat similar file store to GOV.UK
const FileStore = require('session-file-store')(sessionInMemory)
const sessionPath = path.join(__dirname, '.tmp/sessions')

// Make sure the sessions directory exists
if (!fs.existsSync(sessionPath)) {
fs.mkdirSync(sessionPath, { recursive: true })
} else {
// Clear existing session files on restart
fs.readdirSync(sessionPath).forEach(file => {
fs.unlinkSync(path.join(sessionPath, file))
})
}

app.use(sessionInMemory(Object.assign(sessionOptions, {
name: sessionName,
resave: false,
saveUninitialized: false,
})));
store: new FileStore({
path: sessionPath,
logFn: (message) => {
// Suppress noisy session cleanup logs
if (message.endsWith('Deleting expired sessions')) {
return
}
if (message.includes('ENOENT')) {
console.error('Warning: Please use different working directories for your prototypes to avoid session clashes')
return
}
console.log(message)
}
})
})))
}

// Support for parsing data in POSTs
Expand Down
8 changes: 4 additions & 4 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ module.exports = {
slotDurationMinutes: 8,

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

// Date range for generating data
daysToGenerate: 7,
daysBeforeToday: 3,
daysToGenerate: 5,
daysBeforeToday: 2,

simulatedTime: '11:30', // 24h format
},
Expand All @@ -57,6 +57,6 @@ module.exports = {
// Data generation settings
generation: {
numberOfParticipants: 1000,
bookingProbability: 0.8 // 80% of slots are booked
bookingProbability: 0.8, // 80% of slots are booked
}
};
6 changes: 3 additions & 3 deletions app/lib/generate-seed-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const generateSnapshot = (date, allParticipants, unit) => {
return age >= 50 && age <= 70;
});

// Generate a week of clinics
for (let i = 0; i < 7; i++) {
// Generate a 5 days of clinics
for (let i = 0; i < config.clinics.daysToGenerate; i++) {
const clinicDate = dayjs(date).add(i, 'day');
const newClinics = generateClinicsForBSU({
date: clinicDate.toDate(),
Expand Down Expand Up @@ -112,7 +112,7 @@ const generateData = async () => {
today.subtract(9, 'year').add(3, 'month'),
today.subtract(6, 'year').add(2, 'month'),
today.subtract(3, 'year').add(1, 'month'),
today.subtract(3, 'days')
today.subtract(config.clinics.daysBeforeToday, 'days')
];


Expand Down
8 changes: 6 additions & 2 deletions app/lib/generators/clinic-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ const generateTimeSlots = (date, sessionTimes, clinicType) => {
endDateTime: slotEndTime.toISOString(),
duration: slotDurationMinutes,
type: clinicType,
capacity: clinicType === 'assessment' ? 1 : 2, // Assessment clinics don't double book
capacity: 1,
// Don't support smart clinics yet
// capacity: clinicType === 'assessment' ? 1 : 2, // Assessment clinics don't double book
bookedCount: 0,
period: `${sessionTimes.startTime}-${sessionTimes.endTime}`
});
Expand Down Expand Up @@ -124,7 +126,9 @@ const generateClinic = (date, location, breastScreeningUnit, sessionTimes) => {
targetCapacity: {
bookingPercent: clinicType === 'assessment' ? 100 : config.clinics.targetBookingPercent,
attendancePercent: clinicType === 'assessment' ? 95 : config.clinics.targetAttendancePercent,
totalSlots: slots.length * (clinicType === 'assessment' ? 1 : 2)
totalSlots: slots.length,
// not supporting Smart clinics yet
// totalSlots: slots.length * (clinicType === 'assessment' ? 1 : 2)
},
notes: null,
sessionTimes,
Expand Down
2 changes: 1 addition & 1 deletion app/views/_templates/layout-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@


{% block content %}
{{ data | log }}

<div class="nhsuk-grid-row">
<div class="{{ gridColumn or 'nhsuk-grid-column-two-thirds' }}">

Expand Down
2 changes: 1 addition & 1 deletion app/views/participants/questionnaire/medical-history.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% set hideBackLink = true %}

{% block content %}
{{ data | log }}

<div class="nhsuk-grid-row">
<div class="{{ gridColumn or 'nhsuk-grid-column-two-thirds' }}">

Expand Down
Loading

0 comments on commit 26b37a9

Please sign in to comment.