Prepare the visits once, compute the daily tables of the monitoring window (stations, houses, pigs, hours of the last day) and list the alerts of the last day.

run_monitor(
  data,
  days = 7,
  end_date = NULL,
  house_width = 1,
  low_feed_kg = 0.5,
  max_unidentified_pct = 5,
  max_feed_drop_pct = 30,
  iqr_k = 1.5,
  station = NULL,
  verbose = 1
)

Arguments

data

Station data: a folder or files of NEDAP or FIRE exports (read with read_station()), a raw export already in R such as tidypptsda::nedap, or the result of read_station() or prep_visits().

days

Number of days in the window, ending on end_date. Default 7.

end_date

Last day of the window (a Date or "YYYY-MM-DD"). Default NULL: the last day in the data, or yesterday when the last day is today (an export taken during the day is incomplete).

house_width

Number of leading characters of the station ID that name its house, e.g. 1 for station "203" in house "2". Default 1.

low_feed_kg

A pig that ate less than this on a day (kg) is "low_feed". Default 0.5.

max_unidentified_pct

Alert when more than this percentage of the visits of a station are unidentified on the last day. Default 5.

max_feed_drop_pct

Alert when the feed intake of a station on the last day is more than this percentage below its mean of the earlier days of the window. Default 30.

iqr_k

Body weights of a pig on a day outside the Tukey fences (quartiles -/+ iqr_k times the interquartile range) are outliers. Default 1.5.

station

"nedap", "fire" or NULL (detect), passed to read_station() and prep_visits().

verbose

0 (silent), 1 (summary, default) or 2 (details).

Value

An object of class pptm_monitor, a list with:

  • stations: monitor_stations(), one row per station and day;

  • houses: monitor_houses(), one row per house and day;

  • pigs: monitor_pigs(), one row per pig and day;

  • pig_summary: one row per pig over the window (see below);

  • hours: monitor_hours() of the last day;

  • alerts: the alerts of the last day (see below);

  • visits: the visits of the window;

  • settings: the arguments, the window and the station type.

pig_summary has location, responder, days (days in the window since the pig was first seen), no_visit_days, low_feed_days, mean_feed_kg (mean daily feed intake, days without visit count as 0), last_feed_kg and last_visits (last day), last_weight_kg (last daily median weight), days_since_visit and status on the last day.

Alerts

One row per problem on the last day, with level ("danger" or "warning"), type, location, responder (pig alerts), value and message:

typelevelwhen
station_downdangerno visit at all on the station
unidentifiedwarningmore than max_unidentified_pct % of the visits unidentified (transponder or antenna)
feed_dropwarningfeed intake more than max_feed_drop_pct % below the station mean of the earlier days
pig_no_visitdangera pig seen in the window did not visit its station
pig_low_feedwarninga pig ate less than low_feed_kg

Pigs of a station without any visit get no pig alert: the station_down alert covers them.

Examples

mon <- run_monitor(tidypptsda::nedap, days = 7)
#> 
#> ── Preparing NEDAP visits ──────────────────────────────────────────────────────
#>   Visits read                                31,863
#>   └ unidentified (kept, identified = FALSE)     211    0.7%
#>   └ body weight 0 (set to NA)                   391    1.2%
#> ℹ No pig was seen at more than one station
#> ✔ 30 pigs at 2 stations, 31,863 visits over 97 days 0.1s
#> ℹ No breed column. To use breed in the feed intake model and breed-specific limits, add it with `add_breed()`.
#> 
#> ── Monitoring NEDAP stations: 2024-05-19 to 2024-05-25 (7 days) ────────────────
#> ℹ 2 stations, 28 pigs; on 2024-05-25: 366 visits, 84.8 kg feed
#> ✔ No alerts
mon$alerts
#> Empty data.table (0 rows and 6 cols): level,type,location,responder,value,message
head(mon$stations)
#>    location       date n_pigs n_visits n_unidentified pct_unidentified
#>      <char>     <Date>  <int>    <int>          <int>            <num>
#> 1:      101 2024-05-19     13      192              2              1.0
#> 2:      101 2024-05-20     13      201              4              2.0
#> 3:      101 2024-05-21     13      228              2              0.9
#> 4:      101 2024-05-22     13      214              3              1.4
#> 5:      101 2024-05-23     13      234              1              0.4
#> 6:      101 2024-05-24     13      154              1              0.6
#>    occupation_h feed_kg feed_per_pig_kg weight_kg pct_weight_outlier
#>           <num>   <num>           <num>     <num>              <num>
#> 1:        13.88  50.923           3.903    126.83                3.7
#> 2:        13.38  49.585           3.786    128.02                6.6
#> 3:        12.54  46.784           3.576    128.81                7.1
#> 4:        12.63  44.780           3.429    130.49                6.2
#> 5:        13.22  47.120           3.624    131.21                9.0
#> 6:        12.66  44.424           3.415    132.80                7.2

# Another window and stricter limits
mon2 <- run_monitor(tidypptsda::fire, days = 14, end_date = "2024-02-10",
                    low_feed_kg = 1, verbose = 0)
mon2$pig_summary
#> Index: <location>
#>     location responder  days no_visit_days low_feed_days mean_feed_kg
#>       <char>    <char> <int>         <int>         <int>        <num>
#>  1:      101     25822    14             0             0        3.625
#>  2:      101     35853    14             0             0        3.844
#>  3:      101     35855    14             0             0        5.180
#>  4:      101     35862    14             0             0        3.839
#>  5:      101     35865    14             0             0        3.565
#>  6:      101     35869    14             0             0        3.534
#>  7:      101     35873    14             0             0        2.698
#>  8:      101     35875    14             0             0        3.318
#>  9:      101     35877    14             0             0        3.447
#> 10:      101     35878    14             0             0        4.179
#> 11:      101     35885    14             0             0        3.400
#> 12:      101     35887    14             0             0        3.020
#> 13:      102     35851    14             0             0        3.771
#> 14:      102     35857    14             0             0        3.205
#> 15:      102     35858    14             0             0        4.222
#> 16:      102     35860    14             0             0        3.745
#> 17:      102     35861    14             0             0        4.157
#> 18:      102     35868    14             0             0        4.804
#> 19:      102     35874    14             0             0        3.794
#> 20:      102     35876    14             0             0        3.473
#> 21:      102     35882    14             0             0        3.809
#> 22:      102     35883    14             0             0        3.735
#> 23:      102     35892    14             0             0        4.121
#> 24:      102     35894    14             0             0        3.018
#> 25:      102     35897    14             0             0        4.498
#>     location responder  days no_visit_days low_feed_days mean_feed_kg
#>       <char>    <char> <int>         <int>         <int>        <num>
#>     last_feed_kg last_visits last_weight_kg days_since_visit status
#>            <num>       <int>          <num>            <int> <char>
#>  1:        3.296           5          112.6                0     ok
#>  2:        3.930           9          117.4                0     ok
#>  3:        5.433           8          125.1                0     ok
#>  4:        3.762           7          113.0                0     ok
#>  5:        4.679           5          112.6                0     ok
#>  6:        2.770           5           88.6                0     ok
#>  7:        2.696           7           88.4                0     ok
#>  8:        3.295          12          100.6                0     ok
#>  9:        3.682           6           95.6                0     ok
#> 10:        4.111           3          117.4                0     ok
#> 11:        3.983           4           99.1                0     ok
#> 12:        2.638           2          108.0                0     ok
#> 13:        4.356           5          115.2                0     ok
#> 14:        3.397           3          105.2                0     ok
#> 15:        6.379           4          112.7                0     ok
#> 16:        5.299           6          108.4                0     ok
#> 17:        3.820           4          120.2                0     ok
#> 18:        4.927           3          129.2                0     ok
#> 19:        2.877           2          119.1                0     ok
#> 20:        3.386           3          116.4                0     ok
#> 21:        4.678           3          118.8                0     ok
#> 22:        3.552           5          113.4                0     ok
#> 23:        4.578           3          132.4                0     ok
#> 24:        2.963           3          105.4                0     ok
#> 25:        5.864           5          140.6                0     ok
#>     last_feed_kg last_visits last_weight_kg days_since_visit status
#>            <num>       <int>          <num>            <int> <char>
mon <- run_monitor(tidypptsda::nedap, days = 7)
#> 
#> ── Preparing NEDAP visits ──────────────────────────────────────────────────────
#>   Visits read                                31,863
#>   └ unidentified (kept, identified = FALSE)     211    0.7%
#>   └ body weight 0 (set to NA)                   391    1.2%
#> ℹ No pig was seen at more than one station
#> ✔ 30 pigs at 2 stations, 31,863 visits over 97 days 0.1s
#> ℹ No breed column. To use breed in the feed intake model and breed-specific limits, add it with `add_breed()`.
#> 
#> ── Monitoring NEDAP stations: 2024-05-19 to 2024-05-25 (7 days) ────────────────
#> ℹ 2 stations, 28 pigs; on 2024-05-25: 366 visits, 84.8 kg feed
#> ✔ No alerts
mon$alerts
#> Empty data.table (0 rows and 6 cols): level,type,location,responder,value,message
head(mon$stations)
#>    location       date n_pigs n_visits n_unidentified pct_unidentified
#>      <char>     <Date>  <int>    <int>          <int>            <num>
#> 1:      101 2024-05-19     13      192              2              1.0
#> 2:      101 2024-05-20     13      201              4              2.0
#> 3:      101 2024-05-21     13      228              2              0.9
#> 4:      101 2024-05-22     13      214              3              1.4
#> 5:      101 2024-05-23     13      234              1              0.4
#> 6:      101 2024-05-24     13      154              1              0.6
#>    occupation_h feed_kg feed_per_pig_kg weight_kg pct_weight_outlier
#>           <num>   <num>           <num>     <num>              <num>
#> 1:        13.88  50.923           3.903    126.83                3.7
#> 2:        13.38  49.585           3.786    128.02                6.6
#> 3:        12.54  46.784           3.576    128.81                7.1
#> 4:        12.63  44.780           3.429    130.49                6.2
#> 5:        13.22  47.120           3.624    131.21                9.0
#> 6:        12.66  44.424           3.415    132.80                7.2