Skip to content

Commit 74f7ef2

Browse files
Prototype cleanup (#24)
* Add file path as comment at top of each file * Fix more linting errors * Simplify logging * Only generate smart clinics for today's clinics to improve performance
1 parent 7a38607 commit 74f7ef2

27 files changed

+740
-785
lines changed

app.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,11 @@ if (useCookieSessionStore === 'true' && !onlyDocumentation) {
120120
store: new FileStore({
121121
path: sessionPath,
122122
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')
123+
// Suppress all expected session-related messages
124+
if (message.endsWith('Deleting expired sessions') || message.includes('ENOENT')) {
129125
return
130126
}
127+
// Only log unexpected issues
131128
console.log(message)
132129
}
133130
})

app/config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// app/config.js
2+
13
// Use this file to change prototype configuration.
24
const path = require('path')
35

@@ -28,7 +30,7 @@ module.exports = {
2830
slotDurationMinutes: 8,
2931

3032
// Target percentages
31-
targetBookingPercent: 120, // 150% represents overbooking (e.g. 60 bookings for 40 slots)
33+
targetBookingPercent: 130, // 150% represents overbooking (e.g. 60 bookings for 40 slots)
3234
targetAttendancePercent: 100, // 100% of original capacity (not overbooking)
3335

3436
// Date range for generating data

app/data/ethnicities.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// app/data/ethnicities.js
2+
13
module.exports = {
24
'Asian or Asian British': [
35
'Bangladeshi',

app/data/users.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// app/data/users.js
2+
13
module.exports = [
24
{
35
firstName: 'Jane',

app/filters.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// app/filters.js
2+
13
const fs = require('fs')
24
const path = require('path')
35

app/filters/formatting.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// app/filers/formatting.js
2+
13
/**
24
* Format a yes/no/not answered response with optional additional details
35
* @param {string|boolean} value - The response value to format

app/lib/generate-seed-data.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// app/lib/generate-seed-data.js
2-
// node app/lib/generate-seed-data.js
2+
3+
// to run: node app/lib/generate-seed-data.js
4+
// can also be run from ui at localhost:3000/settings
35

46
const dayjs = require('dayjs')
57
const fs = require('fs')

app/lib/generators/address-generator.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// app/lib/utils/address-generator.js
1+
// app/lib/generators/address-generator.js
22

3-
const { faker } = require('@faker-js/faker');
3+
const { faker } = require('@faker-js/faker')
44

55
// Common UK street suffixes
66
const STREET_SUFFIXES = [
@@ -18,7 +18,7 @@ const STREET_SUFFIXES = [
1818
'Green',
1919
'Park',
2020
'Walk',
21-
'Mews'
21+
'Mews',
2222
]
2323

2424
// Common UK street name prefixes
@@ -45,7 +45,7 @@ const STREET_PREFIXES = [
4545
'North',
4646
'South',
4747
'East',
48-
'West'
48+
'West',
4949
]
5050

5151
// Common house/building names
@@ -64,7 +64,7 @@ const HOUSE_NAMES = [
6464
'Holly Cottage',
6565
'The Laurels',
6666
'The Old Farm',
67-
'Sunnyside'
67+
'Sunnyside',
6868
]
6969

7070
/**
@@ -73,41 +73,41 @@ const HOUSE_NAMES = [
7373
* @returns {string} Postcode area (e.g., 'OX' from 'OX3 7LE')
7474
*/
7575
const getPostcodeArea = (postcode) => {
76-
return postcode.match(/^[A-Z]{1,2}/)[0];
77-
};
76+
return postcode.match(/^[A-Z]{1,2}/)[0]
77+
}
7878

7979
/**
8080
* Get the postcode district (number after area) from a full postcode
8181
* @param {string} postcode - Full UK postcode
8282
* @returns {string} Postcode district number
8383
*/
8484
const getPostcodeDistrict = (postcode) => {
85-
return postcode.match(/^[A-Z]{1,2}(\d+)/)[1];
86-
};
85+
return postcode.match(/^[A-Z]{1,2}(\d+)/)[1]
86+
}
8787

8888
/**
8989
* Generate a random postcode in the same area as the reference postcode
9090
* @param {string} referencePostcode - Postcode to base the new one on
9191
* @returns {string} New postcode in same area
9292
*/
9393
const generateNearbyPostcode = (referencePostcode) => {
94-
const area = getPostcodeArea(referencePostcode);
95-
const district = getPostcodeDistrict(referencePostcode);
96-
94+
const area = getPostcodeArea(referencePostcode)
95+
const district = getPostcodeDistrict(referencePostcode)
96+
9797
// Generate nearby district number (±1 of reference, staying in valid range)
98-
const districtNum = parseInt(district);
98+
const districtNum = parseInt(district)
9999
const nearbyDistrict = faker.helpers.arrayElement([
100100
districtNum,
101101
Math.max(1, districtNum - 1),
102-
districtNum + 1
103-
]);
104-
102+
districtNum + 1,
103+
])
104+
105105
// Generate random sector (0-9) and unit (two letters)
106-
const sector = faker.number.int({ min: 0, max: 9 });
107-
const unit = faker.helpers.arrayElement('ABCDEFGHJKLMNPQRSTUWXYZ') +
108-
faker.helpers.arrayElement('ABCDEFGHJKLMNPQRSTUWXYZ');
109-
110-
return `${area}${nearbyDistrict} ${sector}${unit}`;
106+
const sector = faker.number.int({ min: 0, max: 9 })
107+
const unit = faker.helpers.arrayElement('ABCDEFGHJKLMNPQRSTUWXYZ') +
108+
faker.helpers.arrayElement('ABCDEFGHJKLMNPQRSTUWXYZ')
109+
110+
return `${area}${nearbyDistrict} ${sector}${unit}`
111111
}
112112

113113
/**
@@ -128,7 +128,7 @@ const generateAddressLine1 = () => {
128128
// 20% chance of using a house name instead of number
129129
if (Math.random() < 0.2) {
130130
return {
131-
line1: faker.helpers.arrayElement(HOUSE_NAMES)
131+
line1: faker.helpers.arrayElement(HOUSE_NAMES),
132132
}
133133
}
134134

@@ -139,12 +139,12 @@ const generateAddressLine1 = () => {
139139
if (Math.random() < 0.15) {
140140
const flatNumber = faker.number.int({ min: 1, max: 20 })
141141
return {
142-
line1: `Flat ${flatNumber}, ${houseNumber} ${streetName}`
142+
line1: `Flat ${flatNumber}, ${houseNumber} ${streetName}`,
143143
}
144144
}
145145

146146
return {
147-
line1: `${houseNumber} ${streetName}`
147+
line1: `${houseNumber} ${streetName}`,
148148
}
149149
}
150150

@@ -161,7 +161,7 @@ const generateNearbyAreas = (bsu) => {
161161
...bsu.locations
162162
.filter(l => l.type === 'hospital')
163163
.map(l => l.address.city)
164-
.filter(Boolean)
164+
.filter(Boolean),
165165
].filter(Boolean))
166166

167167
// Add some generated nearby areas
@@ -170,9 +170,9 @@ const generateNearbyAreas = (bsu) => {
170170
const suffix = faker.helpers.arrayElement([
171171
'on-Sea', 'upon-Thames', 'St Mary', 'St John',
172172
'under-Edge', 'on-the-Hill',
173-
'', '', '', '' // More weight to no suffix
173+
'', '', '', '', // More weight to no suffix
174174
])
175-
175+
176176
const name = `${faker.location.city()}${suffix ? ` ${suffix}` : ''}`
177177
areas.add(name)
178178
}
@@ -188,20 +188,20 @@ const generateNearbyAreas = (bsu) => {
188188
const generateBSUAppropriateAddress = (bsu) => {
189189
const nearbyAreas = generateNearbyAreas(bsu)
190190
const addressLine1 = generateAddressLine1()
191-
191+
192192
// 30% chance of having a line2
193-
const line2 = Math.random() < 0.3 ?
194-
`${faker.word.adjective().charAt(0).toUpperCase() + faker.word.adjective().slice(1)} House` :
195-
null
193+
const line2 = Math.random() < 0.3
194+
? `${faker.word.adjective().charAt(0).toUpperCase() + faker.word.adjective().slice(1)} House`
195+
: null
196196

197197
return {
198198
...addressLine1,
199199
line2,
200200
city: faker.helpers.arrayElement(nearbyAreas),
201-
postcode: generateNearbyPostcode(bsu.address.postcode)
201+
postcode: generateNearbyPostcode(bsu.address.postcode),
202202
}
203203
}
204204

205205
module.exports = {
206-
generateBSUAppropriateAddress
207-
};
206+
generateBSUAppropriateAddress,
207+
}

0 commit comments

Comments
 (0)