[javascript] Covid

Viewer

  1. import java.io.FileWriter;
  2. import java.io.IOException;
  3. import java.util.Arrays;
  4. import java.util.Collections;
  5. import java.util.List;
  6. import java.util.Random;
  7.  
  8. public class Covid {
  9.  
  10.     // Sample data arrays
  11.     private static final String[] GENDERS = {"Male", "Female"};
  12.     private static final String[] LOCATIONS = {"Toronto", "Mississauga", "Brampton", "Hamilton", "London", "Ottawa", "Windsor", "Kingston", "Markham", "Vaughan"};
  13.     private static final String[] SYMPTOMS = {"Fever", "Cough", "Shortness of Breath", "Fatigue", "Muscle or Body Aches", "Headache", "New Loss of Taste or Smell", "Sore Throat", "Congestion or Runny Nose", "Nausea or Vomiting", "Diarrhea"};
  14.     private static final String[] TEST_RESULTS = {"Positive", "Negative", "Pending"};
  15.     private static final String[] VACCINATION_STATUSES = {"Fully Vaccinated", "Partially Vaccinated", "Not Vaccinated"};
  16.     private static final String[] PRE_EXISTING_CONDITIONS = {"Diabetes", "Hypertension", "Asthma", "Obesity", "Heart Disease", "Cancer"};
  17.     private static final String[] OUTCOMES = {"Recovered", "Deceased"};
  18.     private static final String[] CONTACT_TRACING_STATUSES = {"Involved", "Not Involved"};
  19.     private static final String[] TRAVEL_HISTORY_STATUSES = {"Domestic", "International", "None"};
  20.     private static final String[] QUARANTINE_STATUSES = {"Required", "Not Required"};
  21.     private static final String[] HEALTHCARE_WORKER_STATUSES = {"Yes", "No"};
  22.  
  23.     // Random generator
  24.     private static final Random random = new Random();
  25.  
  26.     // Number of records to generate
  27.     private static final int NUM_RECORDS = 1000;
  28.  
  29.     public static void main(String[] args) {
  30.         generateAndExportData();
  31.     }
  32.  
  33.     private static void generateAndExportData() {
  34.         try (FileWriter writer = new FileWriter("covid_data.csv")) {
  35.             // Write CSV header
  36.             writer.append("PatientID,Age,Gender,Location,Symptom1,Symptom2,Symptom3,Symptom4,Symptom5,TestResult,VaccinationStatus,TestDate,VaccineType,VaccineDose,PreExistingCondition1,PreExistingCondition2,HospitalizationStatus,ICUAdmission,VentilatorUse,Outcome,ContactTracing,TravelHistory,QuarantineStatus,HealthcareWorker\n");
  37.  
  38.             // Generate and write each record
  39.             for (int i = 0; i < NUM_RECORDS; i++) {
  40.                 int patientID = i + 1;
  41.                 int age = getRandomAge();
  42.                 String gender = getRandomGender();
  43.                 String location = getRandomLocation();
  44.                 String symptoms = getRandomSymptoms();
  45.                 String testResult = getRandomTestResult();
  46.                 String vaccinationStatus = getRandomVaccinationStatus();
  47.                 String testDate = getRandomTestDate();
  48.                 String vaccineType = getRandomVaccineType();
  49.                 String vaccineDose = getRandomVaccineDose();
  50.                 String preExistingConditions = getRandomPreExistingConditions();
  51.                 String hospitalizationStatus = getRandomHospitalizationStatus();
  52.                 String icuAdmission = getRandomICUAdmission();
  53.                 String ventilatorUse = getRandomVentilatorUse();
  54.                 String outcome = getRandomOutcome();
  55.                 String contactTracing = getRandomContactTracingStatus();
  56.                 String travelHistory = getRandomTravelHistoryStatus();
  57.                 String quarantineStatus = getRandomQuarantineStatus();
  58.                 String healthcareWorker = getRandomHealthcareWorkerStatus();
  59.  
  60.                 // Write record to CSV
  61.                 writer.append(String.format("%d,%d,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n", patientID, age, gender, location, symptoms, testResult, vaccinationStatus, testDate, vaccineType, vaccineDose, preExistingConditions, hospitalizationStatus, icuAdmission, ventilatorUse, outcome, contactTracing, travelHistory, quarantineStatus, healthcareWorker));
  62.             }
  63.  
  64.             System.out.println("COVID-19 data generated successfully!");
  65.         } catch (IOException e) {
  66.             System.err.println("Error writing to CSV file: " + e.getMessage());
  67.         }
  68.     }
  69.  
  70.     private static int getRandomAge() {
  71.         return random.nextInt(90) + 10; // Age between 10 and 99
  72.     }
  73.  
  74.     private static String getRandomGender() {
  75.         return GENDERS[random.nextInt(GENDERS.length)];
  76.     }
  77.  
  78.     private static String getRandomLocation() {
  79.         return LOCATIONS[random.nextInt(LOCATIONS.length)];
  80.     }
  81.  
  82. private static String getRandomSymptoms() {
  83.     // Shuffle the array of symptoms
  84.     List<String> shuffledSymptoms = Arrays.asList(SYMPTOMS);
  85.     Collections.shuffle(shuffledSymptoms, random);
  86.  
  87.     // Determine the number of symptoms for this record
  88.     int numSymptoms = 5;
  89.     numSymptoms = Math.min(numSymptoms, shuffledSymptoms.size()); // Ensure it doesn't exceed available symptoms
  90.  
  91.     // Select a random subset of symptoms
  92.     List<String> selectedSymptoms = shuffledSymptoms.subList(0, numSymptoms);
  93.  
  94.     // Concatenate the selected symptoms into a string
  95.     return String.join(", ", selectedSymptoms);
  96. }
  97.  
  98. private static String getRandomTestResult() {
  99.         return TEST_RESULTS[random.nextInt(TEST_RESULTS.length)];
  100.     }
  101.  
  102.     private static String getRandomVaccinationStatus() {
  103.         return VACCINATION_STATUSES[random.nextInt(VACCINATION_STATUSES.length)];
  104.     }
  105.  
  106.         private static String getRandomTestDate() {
  107.                 // Random test date within the past 30 days
  108.                 long millis = System.currentTimeMillis() - random.nextInt(30) * 24 * 60 * 60 * 1000L;
  109.                 return new java.sql.Date(millis).toString();
  110.         }
  111.        
  112.         private static String getRandomVaccineType() {
  113.                 String[] vaccineTypes = {"Pfizer", "Moderna", "Johnson & Johnson", "AstraZeneca", "Sinovac", "Sputnik V", "Sinopharm"};
  114.                 return vaccineTypes[random.nextInt(vaccineTypes.length)];
  115.         }
  116.        
  117.         private static String getRandomVaccineDose() {
  118.                 int numDoses = random.nextInt(2) + 1; // Random number of doses between 1 and 2
  119.                 return numDoses + "/2"; // Assuming two-dose vaccines
  120.         }
  121.        
  122.         private static String getRandomPreExistingConditions() {
  123.                 // Shuffle the array of pre-existing conditions
  124.                 List<String> shuffledConditions = Arrays.asList(PRE_EXISTING_CONDITIONS);
  125.                 Collections.shuffle(shuffledConditions, random);
  126.        
  127.                 // Determine the number of conditions for this record
  128.                 int numConditions = 2;
  129.                 numConditions = Math.min(numConditions, shuffledConditions.size()); // Ensure it doesn't exceed available conditions
  130.        
  131.                 // Select a random subset of conditions
  132.                 List<String> selectedConditions = shuffledConditions.subList(0, numConditions);
  133.        
  134.                 // Concatenate the selected conditions into a string
  135.                 return String.join(", ", selectedConditions);
  136.         }
  137.  
  138.         private static String getRandomHospitalizationStatus() {
  139.                 return random.nextBoolean() ? "Required" : "Not Required";
  140.         }
  141.        
  142.         private static String getRandomICUAdmission() {
  143.                 return random.nextBoolean() ? "Yes" : "No";
  144.         }
  145.        
  146.         private static String getRandomVentilatorUse() {
  147.                 return random.nextBoolean() ? "Yes" : "No";
  148.         }
  149.        
  150.         private static String getRandomOutcome() {
  151.                 return OUTCOMES[random.nextInt(OUTCOMES.length)];
  152.         }
  153.        
  154.         private static String getRandomContactTracingStatus() {
  155.                 return CONTACT_TRACING_STATUSES[random.nextInt(CONTACT_TRACING_STATUSES.length)];
  156.         }
  157.        
  158.         private static String getRandomTravelHistoryStatus() {
  159.                 return TRAVEL_HISTORY_STATUSES[random.nextInt(TRAVEL_HISTORY_STATUSES.length)];
  160.         }
  161.        
  162.         private static String getRandomQuarantineStatus() {
  163.                 return QUARANTINE_STATUSES[random.nextInt(QUARANTINE_STATUSES.length)];
  164.         }
  165.        
  166.         private static String getRandomHealthcareWorkerStatus() {
  167.                 return HEALTHCARE_WORKER_STATUSES[random.nextInt(HEALTHCARE_WORKER_STATUSES.length)];
  168.         }
  169. }
  170.  

Editor

You can edit this paste and save as new: