@@ -4,6 +4,7 @@ const { faker } = require('@faker-js/faker');
44const weighted = require ( 'weighted' ) ;
55const fs = require ( 'fs' ) ;
66const path = require ( 'path' ) ;
7+ const config = require ( '../config' ) ;
78
89const { generateParticipant } = require ( './generators/participant-generator' ) ;
910const { generateClinicsForBSU } = require ( './generators/clinic-generator' ) ;
@@ -13,33 +14,17 @@ const { generateEvent } = require('./generators/event-generator');
1314const breastScreeningUnits = require ( '../data/breast-screening-units' ) ;
1415const ethnicities = require ( '../data/ethnicities' ) ;
1516
16- const CONFIG = {
17- numberOfParticipants : 1000 ,
18- outputPath : path . join ( __dirname , '../data/generated' ) ,
19- clinicDefaults : {
20- slotsPerDay : 32 ,
21- daysToGenerate : 5 ,
22- startTime : '09:00' ,
23- endTime : '17:00' ,
24- slotDurationMinutes : 8
25- } ,
26- eventOutcomes : {
27- 'clear' : 0.95 ,
28- 'needs_further_tests' : 0.04 ,
29- 'cancer_detected' : 0.01
30- }
31- } ;
32-
3317const generateData = async ( ) => {
3418 // Create output directory if it doesn't exist
35- if ( ! fs . existsSync ( CONFIG . outputPath ) ) {
36- fs . mkdirSync ( CONFIG . outputPath , { recursive : true } ) ;
19+ if ( ! fs . existsSync ( config . paths . generatedData ) ) {
20+ fs . mkdirSync ( config . paths . generatedData , { recursive : true } ) ;
3721 }
3822
3923 // Generate base data
4024 console . log ( 'Generating participants...' ) ;
41- const participants = Array . from ( { length : CONFIG . numberOfParticipants } , ( ) =>
42- generateParticipant ( { ethnicities, breastScreeningUnits } )
25+ const participants = Array . from (
26+ { length : config . generation . numberOfParticipants } ,
27+ ( ) => generateParticipant ( { ethnicities, breastScreeningUnits } )
4328 ) ;
4429
4530 console . log ( 'Generating clinics and events...' ) ;
@@ -48,31 +33,31 @@ const generateData = async () => {
4833
4934 // Calculate date range
5035 const startDate = new Date ( ) ;
51- startDate . setDate ( startDate . getDate ( ) - 3 ) ;
36+ startDate . setDate ( startDate . getDate ( ) - config . clinics . daysBeforeToday ) ;
5237
53- for ( let i = 0 ; i < CONFIG . clinicDefaults . daysToGenerate ; i ++ ) {
38+ for ( let i = 0 ; i < config . clinics . daysToGenerate ; i ++ ) {
5439 const clinicDate = new Date ( startDate ) ;
5540 clinicDate . setDate ( clinicDate . getDate ( ) + i ) ;
5641
57- // Generate clinics for each BSU (currently just Oxford)
42+ // Generate clinics for each BSU
5843 breastScreeningUnits . forEach ( unit => {
5944 const newClinics = generateClinicsForBSU ( {
6045 date : clinicDate ,
6146 breastScreeningUnit : unit ,
62- config : CONFIG . clinicDefaults
47+ config : config . clinics
6348 } ) ;
6449
6550 // Generate events for each clinic
6651 newClinics . forEach ( clinic => {
6752 const clinicEvents = clinic . slots
68- . filter ( slot => Math . random ( ) > 0.2 )
53+ . filter ( ( ) => Math . random ( ) < config . generation . bookingProbability )
6954 . map ( slot => {
7055 const participant = faker . helpers . arrayElement ( participants ) ;
7156 return generateEvent ( {
7257 slot,
7358 participant,
7459 clinic,
75- outcomeWeights : CONFIG . eventOutcomes
60+ outcomeWeights : config . screening . outcomes
7661 } ) ;
7762 } ) ;
7863
@@ -86,7 +71,7 @@ const generateData = async () => {
8671 // Write generated data to files
8772 const writeData = ( filename , data ) => {
8873 fs . writeFileSync (
89- path . join ( CONFIG . outputPath , filename ) ,
74+ path . join ( config . paths . generatedData , filename ) ,
9075 JSON . stringify ( data , null , 2 )
9176 ) ;
9277 } ;
0 commit comments