demo additionnal content for the future
This commit is contained in:
96
algos-demo/chu-stats-generator/main.go
Normal file
96
algos-demo/chu-stats-generator/main.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const dataFile = "/data/chu_stats.json"
|
||||
|
||||
type CHUStats struct {
|
||||
GeneratedAt time.Time `json:"generated_at"`
|
||||
HospitalName string `json:"hospital_name"`
|
||||
Date string `json:"date"`
|
||||
BedsTotal int `json:"beds_total"`
|
||||
BedsOccupied int `json:"beds_occupied"`
|
||||
OccupancyRate float64 `json:"occupancy_rate"`
|
||||
PatientsAdmitted int `json:"patients_admitted"`
|
||||
PatientsDischarge int `json:"patients_discharged"`
|
||||
EmergencyVisits int `json:"emergency_visits"`
|
||||
AvgERWaitMinutes int `json:"avg_er_wait_minutes"`
|
||||
SurgeriesPerformed int `json:"surgeries_performed"`
|
||||
ICUBeds int `json:"icu_beds"`
|
||||
ICUOccupied int `json:"icu_occupied"`
|
||||
MortalityRate float64 `json:"mortality_rate"`
|
||||
InfectionRate float64 `json:"infection_rate"`
|
||||
StaffPresent int `json:"staff_present"`
|
||||
StaffRequired int `json:"staff_required"`
|
||||
PatientSatisfaction float64 `json:"patient_satisfaction"`
|
||||
}
|
||||
|
||||
func round2(v float64) float64 {
|
||||
return math.Round(v*100) / 100
|
||||
}
|
||||
|
||||
func generateStats() CHUStats {
|
||||
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
bedsTotal := 800 + rng.Intn(400)
|
||||
occupancyPct := 0.65 + rng.Float64()*0.32
|
||||
bedsOccupied := int(float64(bedsTotal) * occupancyPct)
|
||||
|
||||
icuBeds := 40 + rng.Intn(30)
|
||||
icuOccupancyPct := 0.60 + rng.Float64()*0.38
|
||||
icuOccupied := int(float64(icuBeds) * icuOccupancyPct)
|
||||
|
||||
staffRequired := 600 + rng.Intn(300)
|
||||
staffCoverage := 0.65 + rng.Float64()*0.40
|
||||
staffPresent := int(float64(staffRequired) * staffCoverage)
|
||||
|
||||
return CHUStats{
|
||||
GeneratedAt: time.Now().UTC(),
|
||||
HospitalName: "CHU Demo",
|
||||
Date: time.Now().Format("2006-01-02"),
|
||||
BedsTotal: bedsTotal,
|
||||
BedsOccupied: bedsOccupied,
|
||||
OccupancyRate: round2(occupancyPct * 100),
|
||||
PatientsAdmitted: 50 + rng.Intn(120),
|
||||
PatientsDischarge: 40 + rng.Intn(120),
|
||||
EmergencyVisits: 80 + rng.Intn(150),
|
||||
AvgERWaitMinutes: 15 + rng.Intn(130),
|
||||
SurgeriesPerformed: 10 + rng.Intn(50),
|
||||
ICUBeds: icuBeds,
|
||||
ICUOccupied: icuOccupied,
|
||||
MortalityRate: round2(0.3 + rng.Float64()*4.5),
|
||||
InfectionRate: round2(0.5 + rng.Float64()*9.0),
|
||||
StaffPresent: staffPresent,
|
||||
StaffRequired: staffRequired,
|
||||
PatientSatisfaction: round2(2.0 + rng.Float64()*3.0),
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
for i, stats := range []CHUStats{generateStats(), generateStats()} {
|
||||
data, err := json.MarshalIndent(stats, "", " ")
|
||||
if err != nil {
|
||||
log.Fatalf("failed to marshal stats: %v", err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll("/data", 0755); err != nil {
|
||||
log.Fatalf("failed to create data dir: %v", err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(strings.ReplaceAll(dataFile, "stats", "stats"+fmt.Sprintf("%v", i)), data, 0644); err != nil {
|
||||
log.Fatalf("failed to write stats file: %v", err)
|
||||
}
|
||||
|
||||
log.Printf("Stats saved to %s", dataFile)
|
||||
fmt.Println(string(data))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user