-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheart.adb
66 lines (52 loc) · 2.04 KB
/
heart.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
with Measures;
with RandomNumber;
with Ada.Text_IO; use Ada.Text_IO;
package body Heart is
-- Some boundaries for impulse shocks
NoShock : constant Measures.Joules := 0;
SmallShock : constant Measures.Joules := 5;
-- Parameters for generating random heart rate upon initialisation
HeartRateMu : constant Measures.BPM := 80;
HeartRateSigma : constant Measures.BPM := 10;
-- Used to simulate volatility of the patient's response to treatment
Volatility : constant Float := 0.02;
-- The amount to add to the heart rate to simulate rising rate
DefaultChange : Integer := 1;
-- The effect of a small shock on this heart
-- A local function to limit Dosage measures
procedure Init(Heart : out HeartType) is
begin
-- Generate a random systolic pressure
Heart.Rate := Measures.LimitBPM(RandomNumber.NormalInteger(HeartRateMu,HeartRateSigma));
Heart.Impulse := 0;
end Init;
procedure SetImpulse(Heart : in out HeartType;
Joules : in Measures.Joules) is
begin
Heart.Impulse := Joules;
end SetImpulse;
procedure GetRate(Heart : in HeartType; Rate : out Measures.BPM) is
begin
Rate := Heart.Rate;
end GetRate;
function GetImpulse(Heart : in HeartType) return Measures.Joules is
begin
return Heart.Impulse;
end GetImpulse;
procedure Tick(Heart : in out HeartType) is
begin
if (Heart.Impulse = NoShock) then
-- No impulse, and the default behaviour of this heart is to increase
-- the rate slowly.
Heart.Rate := Measures.LimitBPM(Heart.Rate + DefaultChange);
elsif (Heart.Impulse < SmallShock) then
-- A crude slowing of the heart given a shock
Heart.Rate := Measures.LimitBPM(Heart.Rate - Heart.Impulse);
else -- a large shock
Heart.Rate := 0;
DefaultChange := 0;
end if;
-- Insert some random volatility
Heart.Rate := Measures.LimitBPM(RandomNumber.UniformIntegerWithError(Heart.Rate, Volatility));
end Tick;
end Heart;