Skip to content

Commit

Permalink
Add day_matcher resource
Browse files Browse the repository at this point in the history
  • Loading branch information
DougLau committed Nov 8, 2024
1 parent 3f5d4b8 commit f669560
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ update, and is caused by one of these conditions:
`comm_config` | | | |
`comm_link` | | | |
`controller` | ✔️ | | |
`day_matcher` | | | |
`detector` | | ✔️ | |
`dms` | ✔️ | ✔️ | ✔️ |
`domain` | | | |
Expand Down
1 change: 1 addition & 0 deletions honeybee/src/honey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ const fn one_sql(res: Res) -> &'static str {
CommLink => query::COMM_LINK_ONE,
Controller => query::CONTROLLER_ONE,
ControllerIo => query::CONTROLLER_IO_ONE,
DayMatcher => query::DAY_MATCHER_ONE,
Detector => query::DETECTOR_ONE,
Dms => query::DMS_ONE,
Domain => query::DOMAIN_ONE,
Expand Down
12 changes: 12 additions & 0 deletions honeybee/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ pub const CONTROLLER_IO_ONE: &str = "\
WHERE controller = $1 \
ORDER BY pin";

/// SQL query for all day matchers (primary)
pub const DAY_MATCHER_ALL: &str = "\
SELECT name, holiday, month, day, week, weekday, shift \
FROM iris.day_matcher \
ORDER BY name";

/// SQL query for one day matcher (secondary)
pub const DAY_MATCHER_ONE: &str = "\
SELECT name, holiday, month, day, week, weekday, shift \
FROM iris.day_matcher \
WHERE name = $1";

/// SQL query for all detectors (primary)
pub const DETECTOR_ALL: &str = "\
SELECT name, label, controller, notes \
Expand Down
5 changes: 5 additions & 0 deletions honeybee/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub enum Resource {
CommProtocol,
Condition,
Controller,
DayMatcher,
Detector,
DetectorPub,
Direction,
Expand Down Expand Up @@ -121,6 +122,7 @@ impl Resource {
CommProtocol,
Condition,
Controller,
DayMatcher,
Detector,
DetectorPub,
Direction,
Expand Down Expand Up @@ -203,6 +205,7 @@ impl Resource {
CommProtocol => Res::CommProtocol,
Condition => Res::Condition,
Controller => Res::Controller,
DayMatcher => Res::DayMatcher,
Detector | DetectorPub => Res::Detector,
Direction => Res::Direction,
Dms | DmsPub | DmsStat => Res::Dms,
Expand Down Expand Up @@ -278,6 +281,7 @@ impl Resource {
CommProtocol => "lut/comm_protocol",
Condition => "lut/condition",
Controller => "api/controller",
DayMatcher => "api/day_matcher",
Detector => "api/detector",
DetectorPub => "detector_pub",
Direction => "lut/direction",
Expand Down Expand Up @@ -369,6 +373,7 @@ impl Resource {
CommProtocol => query::COMM_PROTOCOL_LUT,
Condition => query::CONDITION_LUT,
Controller => query::CONTROLLER_ALL,
DayMatcher => query::DAY_MATCHER_ALL,
Detector => query::DETECTOR_ALL,
DetectorPub => query::DETECTOR_PUB,
Direction => query::DIRECTION_LUT,
Expand Down
24 changes: 15 additions & 9 deletions resources/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub enum Res {
Condition,
Controller,
ControllerIo,
DayMatcher,
Detector,
Direction,
Dms,
Expand Down Expand Up @@ -121,6 +122,7 @@ impl Res {
Condition,
Controller,
ControllerIo,
DayMatcher,
Detector,
Direction,
Dms,
Expand Down Expand Up @@ -200,6 +202,7 @@ impl Res {
Condition => "condition",
Controller => "controller",
ControllerIo => "controller_io",
DayMatcher => "day_matcher",
Detector => "detector",
Direction => "direction",
Dms => "dms",
Expand Down Expand Up @@ -273,6 +276,7 @@ impl Res {
CommConfig => "📡",
CommLink => "🔗",
Controller => "🎛️ ",
DayMatcher => "🗓️",
Detector => "🚗⬚",
Dms => "⬛",
Domain => "🖧 ",
Expand Down Expand Up @@ -327,15 +331,15 @@ impl Res {
#[allow(clippy::match_like_matches_macro)]
match self {
Alarm | Beacon | CabinetStyle | Camera | CameraPreset
| CommConfig | CommLink | Controller | Detector | Dms | Domain
| EncoderStream | EncoderType | EventConfig | FlowStream
| GateArm | GateArmArray | Gps | Incident | IncidentDetail
| IncAdvice | IncDescriptor | IncLocator | LaneMarking
| LcsArray | LcsIndication | Modem | MsgLine | MsgPattern
| ParkingArea | Permission | RampMeter | Rnode | Road
| RoadAffix | Role | SignConfig | SignDetail | SignMessage
| SystemAttribute | TagReader | User | VideoMonitor
| WeatherSensor | Word => true,
| CommConfig | CommLink | Controller | DayMatcher | Detector
| Dms | Domain | EncoderStream | EncoderType | EventConfig
| FlowStream | GateArm | GateArmArray | Gps | Incident
| IncidentDetail | IncAdvice | IncDescriptor | IncLocator
| LaneMarking | LcsArray | LcsIndication | Modem | MsgLine
| MsgPattern | ParkingArea | Permission | RampMeter | Rnode
| Road | RoadAffix | Role | SignConfig | SignDetail
| SignMessage | SystemAttribute | TagReader | User
| VideoMonitor | WeatherSensor | Word => true,
_ => false,
}
}
Expand All @@ -344,6 +348,8 @@ impl Res {
pub const fn base(self) -> Self {
use Res::*;
match self {
// Action plan resources
DayMatcher => ActionPlan,
// Camera resources
CameraPreset | EncoderStream | EncoderType => Camera,
// Controller resources
Expand Down
4 changes: 4 additions & 0 deletions sql/migrate-5.62.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ CREATE TRIGGER road_affix_notify_trig
AFTER INSERT OR UPDATE OR DELETE ON iris.road_affix
FOR EACH STATEMENT EXECUTE FUNCTION iris.table_notify();

CREATE TRIGGER day_matcher_notify_trig
AFTER INSERT OR UPDATE OR DELETE ON iris.day_matcher
FOR EACH STATEMENT EXECUTE FUNCTION iris.table_notify();

-- Rename iris_user to user_id in client_event
DROP VIEW client_event_view;

Expand Down
4 changes: 4 additions & 0 deletions sql/tms-template.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,10 @@ Christmas Day t 11 25 0 0 0
New Years Eve t 11 31 0 0 0
\.

CREATE TRIGGER day_matcher_notify_trig
AFTER INSERT OR UPDATE OR DELETE ON iris.day_matcher
FOR EACH STATEMENT EXECUTE FUNCTION iris.table_notify();

CREATE TABLE iris.day_plan (
name VARCHAR(10) PRIMARY KEY
);
Expand Down

0 comments on commit f669560

Please sign in to comment.