89 // World Heath Organization blood pressure classification |
89 // World Heath Organization blood pressure classification |
90 const ( |
90 const ( |
91 BPOptimal = iota // < 120,80: Optimal |
91 BPOptimal = iota // < 120,80: Optimal |
92 BPNormal // < 130,85: Normal |
92 BPNormal // < 130,85: Normal |
93 BPHighNormal // < 140,90: High-Normal |
93 BPHighNormal // < 140,90: High-Normal |
94 BPMildHypertension // < 160,100: Mild Hypertension |
94 BPMildHypertension // < 160,100: Grade 1 Mild Hypertension |
95 BPModerateHypertension // < 180,110: Moderate Hypertension |
95 BPModerateHypertension // < 180,110: Grade 2 Moderate Hypertension |
96 BPSevereHypertension // >=180,110: Severe Hypertension |
96 BPSevereHypertension // >=180,110: Grade 3 Severe Hypertension |
|
97 ) |
|
98 |
|
99 // Special cases that do not fit in the previous classification |
|
100 const ( |
|
101 // >=140, <90: Isolated Systolic Hypertension |
|
102 IsolatedSystolicHypertension = 1 |
97 ) |
103 ) |
98 |
104 |
99 // WHOPressureClassification contains the World Health Organization blood |
105 // WHOPressureClassification contains the World Health Organization blood |
100 // pressure categories |
106 // pressure categories |
101 var WHOPressureClassification = []string{ |
107 var WHOPressureClassification = []string{ |
103 "Normal", |
109 "Normal", |
104 "High-Normal", |
110 "High-Normal", |
105 "Mild Hypertension", |
111 "Mild Hypertension", |
106 "Moderate Hypertension", |
112 "Moderate Hypertension", |
107 "Severe Hypertension", |
113 "Severe Hypertension", |
|
114 } |
|
115 |
|
116 // WHOPressureFlag is an array of special cases |
|
117 var WHOPressureFlag = []string{ |
|
118 "", |
|
119 "Isolated Systolic Hypertension", |
108 } |
120 } |
109 |
121 |
110 func getData(s io.ReadWriteCloser, buf []byte, size int) (int, error) { |
122 func getData(s io.ReadWriteCloser, buf []byte, size int) (int, error) { |
111 t := 0 |
123 t := 0 |
112 b := buf |
124 b := buf |
445 dev.Pulse = int(sumPul / float64(len(items))) |
457 dev.Pulse = int(sumPul / float64(len(items))) |
446 |
458 |
447 return dev, nil |
459 return dev, nil |
448 } |
460 } |
449 |
461 |
450 func (m measurement) WHOClass() int { |
462 func (m measurement) WHOClass() (int, int) { |
|
463 flag := 0 |
|
464 |
|
465 if m.Systolic >= 140 && m.Diastolic < 90 { |
|
466 flag = IsolatedSystolicHypertension |
|
467 } |
|
468 |
451 switch { |
469 switch { |
452 case m.Systolic < 120 && m.Diastolic < 80: |
470 case m.Systolic < 120 && m.Diastolic < 80: |
453 return BPOptimal |
471 return BPOptimal, flag |
454 case m.Systolic < 130 && m.Diastolic < 85: |
472 case m.Systolic < 130 && m.Diastolic < 85: |
455 return BPNormal |
473 return BPNormal, flag |
456 case m.Systolic < 140 && m.Diastolic < 90: |
474 case m.Systolic < 140 && m.Diastolic < 90: |
457 return BPHighNormal |
475 return BPHighNormal, flag |
458 case m.Systolic < 160 && m.Diastolic < 100: |
476 case m.Systolic < 160 && m.Diastolic < 100: |
459 return BPMildHypertension |
477 return BPMildHypertension, flag |
460 case m.Systolic < 180 && m.Diastolic < 110: |
478 case m.Systolic < 180 && m.Diastolic < 110: |
461 return BPModerateHypertension |
479 return BPModerateHypertension, flag |
462 } |
480 } |
463 return BPSevereHypertension |
481 return BPSevereHypertension, flag |
464 } |
482 } |
465 |
483 |
466 func (m measurement) WHOClassString() string { |
484 func (m measurement) WHOClassString() string { |
467 return WHOPressureClassification[m.WHOClass()] |
485 flagStr := "" |
|
486 class, flag := m.WHOClass() |
|
487 if flag == IsolatedSystolicHypertension { |
|
488 flagStr = " (" + WHOPressureFlag[flag] + ")" |
|
489 } |
|
490 return WHOPressureClassification[class] + flagStr |
468 } |
491 } |
469 |
492 |
470 func displayWHOClassStats(items []measurement) { |
493 func displayWHOClassStats(items []measurement) { |
471 sum := 0 |
494 sum := 0.0 |
472 classes := make(map[int]int) |
495 classes := make(map[int]int) |
473 for _, m := range items { |
496 for _, m := range items { |
474 s := m.WHOClass() |
497 s, flag := m.WHOClass() |
475 classes[s]++ |
498 classes[s]++ |
476 sum += s |
499 sum += float64(s) |
477 } |
500 if flag == IsolatedSystolicHypertension { |
478 |
501 sum += 0.5 |
479 avg := float64(sum) / float64(len(items)) |
502 } |
|
503 } |
|
504 |
|
505 avg := sum / float64(len(items)) |
480 fmt.Fprintf(os.Stderr, "Average WHO classification: %s (%.2f)\n", |
506 fmt.Fprintf(os.Stderr, "Average WHO classification: %s (%.2f)\n", |
481 WHOPressureClassification[int(0.5+avg)], avg) |
507 WHOPressureClassification[int(0.5+avg)], avg) |
482 |
508 |
483 for c := range WHOPressureClassification { |
509 for c := range WHOPressureClassification { |
484 fmt.Fprintf(os.Stderr, " . %21s: %3d (%d%%)\n", |
510 fmt.Fprintf(os.Stderr, " . %21s: %3d (%d%%)\n", |