https://github.com/antonmi/fire_alarm
An example problem solved with Strom
https://github.com/antonmi/fire_alarm
Last synced: 10 months ago
JSON representation
An example problem solved with Strom
- Host: GitHub
- URL: https://github.com/antonmi/fire_alarm
- Owner: antonmi
- Created: 2024-05-23T09:02:59.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-09T16:20:53.000Z (about 2 years ago)
- Last Synced: 2025-03-24T10:12:24.086Z (about 1 year ago)
- Language: Elixir
- Size: 28.3 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FireAlarm
**An example problem solved with Strom**
Strom is [here](https://github.com/antonmi/Strom)
## The problem
We are implementing a fire-alarm logic for a storage of goods.
The storage has many rooms (let's say 100). Each room has 3 sensors:
- Temperature sensor
- Humidity sensor
- Smoke detector
Each sensor produces event every 100ms (it may vary).
The program reports the status of the storage every second.
On the room level the logic is following:
1. If the temperature exceeds 50C and the same time the humidity exceeds 90% the program produces the `:warning` event for the room.
2. If smoke is detected the program produces the `:alarm` event for the room.
3. If everything is ok the program reports the `:ok` event.
On the storage level the logic is:
1. If everything ok, the `{:ok, []}` event is generated.
2. If there are warnings in rooms, the `{:warning, [:room_x, :room_y]}` is produced
3. If there are alarms in rooms, the `{:alarm, [:room_x, :room_y]}` is produced.
4. If there are more than 3 rooms with the `:alarm` event, then the `{:siren, [:room_x, :room_y]}` event is produced.
5. Extra task. Sensors may stop working. We need an additional `maintenance` stream which report malfunctions,
smth like `{:maintenance, {:roomx_x, [:smoke, :temperature]}}`.
And there is a priority in events, the `:siren` has the highest priority, `:ok` - the lowest.
It means, if there is any event with the high priority, then only this event is generated.
In terms of streams and flow one can formulate the problem in the following way:
Input: The flow of `3 * room_number` streams:
```elixir
%{
room_1_temperature: Stream.t([{:temperature, integer()}]),
room_1_humidity: Stream.t([{:humidity, integer()}),
room_1_smoke: Stream.t([{:smoke, boolean()}),
...
}
```
Output:
```elixir
%{
status: [{:ok, []} | {:warning, [room()]} | {:alarm, [room()]} | {:siren, [room()]}
}
```