[javascript] Covid
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.List;
- import java.util.Random;
- public class Covid {
- // Sample data arrays
- private static final String[] GENDERS = {"Male", "Female"};
- private static final String[] LOCATIONS = {"Toronto", "Mississauga", "Brampton", "Hamilton", "London", "Ottawa", "Windsor", "Kingston", "Markham", "Vaughan"};
- 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"};
- private static final String[] TEST_RESULTS = {"Positive", "Negative", "Pending"};
- private static final String[] VACCINATION_STATUSES = {"Fully Vaccinated", "Partially Vaccinated", "Not Vaccinated"};
- private static final String[] PRE_EXISTING_CONDITIONS = {"Diabetes", "Hypertension", "Asthma", "Obesity", "Heart Disease", "Cancer"};
- private static final String[] OUTCOMES = {"Recovered", "Deceased"};
- private static final String[] CONTACT_TRACING_STATUSES = {"Involved", "Not Involved"};
- private static final String[] TRAVEL_HISTORY_STATUSES = {"Domestic", "International", "None"};
- private static final String[] QUARANTINE_STATUSES = {"Required", "Not Required"};
- private static final String[] HEALTHCARE_WORKER_STATUSES = {"Yes", "No"};
- // Random generator
- private static final Random random = new Random();
- // Number of records to generate
- private static final int NUM_RECORDS = 1000;
- public static void main(String[] args) {
- generateAndExportData();
- }
- private static void generateAndExportData() {
- try (FileWriter writer = new FileWriter("covid_data.csv")) {
- // Write CSV header
- 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");
- // Generate and write each record
- for (int i = 0; i < NUM_RECORDS; i++) {
- int patientID = i + 1;
- int age = getRandomAge();
- String gender = getRandomGender();
- String location = getRandomLocation();
- String symptoms = getRandomSymptoms();
- String testResult = getRandomTestResult();
- String vaccinationStatus = getRandomVaccinationStatus();
- String testDate = getRandomTestDate();
- String vaccineType = getRandomVaccineType();
- String vaccineDose = getRandomVaccineDose();
- String preExistingConditions = getRandomPreExistingConditions();
- String hospitalizationStatus = getRandomHospitalizationStatus();
- String icuAdmission = getRandomICUAdmission();
- String ventilatorUse = getRandomVentilatorUse();
- String outcome = getRandomOutcome();
- String contactTracing = getRandomContactTracingStatus();
- String travelHistory = getRandomTravelHistoryStatus();
- String quarantineStatus = getRandomQuarantineStatus();
- String healthcareWorker = getRandomHealthcareWorkerStatus();
- // Write record to CSV
- 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));
- }
- System.out.println("COVID-19 data generated successfully!");
- } catch (IOException e) {
- System.err.println("Error writing to CSV file: " + e.getMessage());
- }
- }
- private static int getRandomAge() {
- return random.nextInt(90) + 10; // Age between 10 and 99
- }
- private static String getRandomGender() {
- return GENDERS[random.nextInt(GENDERS.length)];
- }
- private static String getRandomLocation() {
- return LOCATIONS[random.nextInt(LOCATIONS.length)];
- }
- private static String getRandomSymptoms() {
- // Shuffle the array of symptoms
- List<String> shuffledSymptoms = Arrays.asList(SYMPTOMS);
- Collections.shuffle(shuffledSymptoms, random);
- // Determine the number of symptoms for this record
- int numSymptoms = 5;
- numSymptoms = Math.min(numSymptoms, shuffledSymptoms.size()); // Ensure it doesn't exceed available symptoms
- // Select a random subset of symptoms
- List<String> selectedSymptoms = shuffledSymptoms.subList(0, numSymptoms);
- // Concatenate the selected symptoms into a string
- return String.join(", ", selectedSymptoms);
- }
- private static String getRandomTestResult() {
- return TEST_RESULTS[random.nextInt(TEST_RESULTS.length)];
- }
- private static String getRandomVaccinationStatus() {
- return VACCINATION_STATUSES[random.nextInt(VACCINATION_STATUSES.length)];
- }
- private static String getRandomTestDate() {
- // Random test date within the past 30 days
- long millis = System.currentTimeMillis() - random.nextInt(30) * 24 * 60 * 60 * 1000L;
- return new java.sql.Date(millis).toString();
- }
- private static String getRandomVaccineType() {
- String[] vaccineTypes = {"Pfizer", "Moderna", "Johnson & Johnson", "AstraZeneca", "Sinovac", "Sputnik V", "Sinopharm"};
- return vaccineTypes[random.nextInt(vaccineTypes.length)];
- }
- private static String getRandomVaccineDose() {
- int numDoses = random.nextInt(2) + 1; // Random number of doses between 1 and 2
- return numDoses + "/2"; // Assuming two-dose vaccines
- }
- private static String getRandomPreExistingConditions() {
- // Shuffle the array of pre-existing conditions
- List<String> shuffledConditions = Arrays.asList(PRE_EXISTING_CONDITIONS);
- Collections.shuffle(shuffledConditions, random);
- // Determine the number of conditions for this record
- int numConditions = 2;
- numConditions = Math.min(numConditions, shuffledConditions.size()); // Ensure it doesn't exceed available conditions
- // Select a random subset of conditions
- List<String> selectedConditions = shuffledConditions.subList(0, numConditions);
- // Concatenate the selected conditions into a string
- return String.join(", ", selectedConditions);
- }
- private static String getRandomHospitalizationStatus() {
- return random.nextBoolean() ? "Required" : "Not Required";
- }
- private static String getRandomICUAdmission() {
- return random.nextBoolean() ? "Yes" : "No";
- }
- private static String getRandomVentilatorUse() {
- return random.nextBoolean() ? "Yes" : "No";
- }
- private static String getRandomOutcome() {
- return OUTCOMES[random.nextInt(OUTCOMES.length)];
- }
- private static String getRandomContactTracingStatus() {
- return CONTACT_TRACING_STATUSES[random.nextInt(CONTACT_TRACING_STATUSES.length)];
- }
- private static String getRandomTravelHistoryStatus() {
- return TRAVEL_HISTORY_STATUSES[random.nextInt(TRAVEL_HISTORY_STATUSES.length)];
- }
- private static String getRandomQuarantineStatus() {
- return QUARANTINE_STATUSES[random.nextInt(QUARANTINE_STATUSES.length)];
- }
- private static String getRandomHealthcareWorkerStatus() {
- return HEALTHCARE_WORKER_STATUSES[random.nextInt(HEALTHCARE_WORKER_STATUSES.length)];
- }
- }
Editor
You can edit this paste and save as new: