The table_monitor function processes input data and generates an Excel workbook with various monitoring statistics and conditional formatting. It is designed for analyzing and visualizing data related to house monitoring, feed intake, and other relevant metrics over a specified period.

table_monitor(data, house_width = "1", days, ref_date = Sys.Date(), save_path)

Arguments

data

data.frame, required. The input data frame containing the data to be processed.

house_width

character, optional. A character string representing the house width. Default is "1".

days

integer, optional. An integer representing the number of days for the analysis.

ref_date

Date, optional. A Date object representing the reference date. Default is the current date (Sys.Date()).

save_path

character, required. A character string representing the path where the Excel file will be saved. Must be a non-empty string ending with ".xlsx".

Value

A list containing various monitoring statistics:

  • responder_na: Data frame with responder NA statistics.

  • extreme_weight: Data frame with extreme weight outlier statistics.

  • feed_time_n: Data frame with feed time statistics.

  • low_feedintake: Data frame with low feed intake statistics.

  • all_feedintake: Data frame with all feed intake statistics.

  • mean_feedintake: Data frame with mean feed intake statistics.

  • house_weight: Data frame with house weight statistics.

  • visit_n_hour: Data frame with the number of visits per hour.

  • feed_time_hour: Data frame with feed time per hour.

  • feed_intake_hour: Data frame with feed intake per hour.

Note

The save_path parameter must be a valid path ending with ".xlsx". Ensure that the data parameter is a data frame and contains the necessary columns for processing.

Examples

# Load CSV data
data <- data.table::fread("C:/Users/Dell/Documents/projects/pptsdm_data/ppt_monitor_test_data.csv")
# Monitor station and data
res <- table_monitor(data = data, days = 5, save_path = "C:/Users/Dell/Downloads/test")
# Monitor the number of times 'na' appears in the last n days
head(res$responder_na)
#>    location 06-03 06-04 06-05 06-06 06-07 total_nas
#>      <char> <int> <int> <int> <int> <int>     <num>
#> 1:      501     0     0     0     0     0         0
#> 2:      502     2     1     1     3     2         9
#> 3:      503     0     2     2     0     0         4
#> 4:      504     2     0     2     0     0         4
#> 5:      505     0     0     0     0     0         0
#> 6:      506     0     0     0     0     0         0
# Monitor the percentage of extreme weight records in the last n days
head(res$extreme_weight)
#> Key: <location>
#>    location 06-03 06-04 06-05 06-06 06-07
#>       <int> <num> <num> <num> <num> <num>
#> 1:      501  7.07  4.31  4.12  2.78  5.79
#> 2:      502  5.38  6.86  3.12  6.67  7.32
#> 3:      503  4.82  5.32  6.17  5.19  5.21
#> 4:      504  5.95  3.70  2.41  5.41  3.53
#> 5:      505  1.28  3.37  5.05  4.67 11.30
#> 6:      506  7.69  7.46  4.35  1.28  7.50
# Monitor the visiting time and frequency of pigs in the last n days
head(res$feed_time_n)
#> Key: <location>
#>    location n_06-03 n_06-04 n_06-05 n_06-06 n_06-07 time_06-03 time_06-04
#>       <int>   <int>   <int>   <int>   <int>   <int>      <num>      <num>
#> 1:      501      99     116      97     108     121      17.62      18.14
#> 2:      502      93     102      96      75      82      17.24      16.38
#> 3:      503      83      94      81      77      96      18.15      16.92
#> 4:      504      84      81      83      74      85      18.61      17.66
#> 5:      505      78      89      99     107     115      16.82      17.51
#> 6:      506      65      67      69      78      80      18.65      17.29
#>    time_06-05 time_06-06 time_06-07
#>         <num>      <num>      <num>
#> 1:      18.64      18.62      18.54
#> 2:      16.92      16.48      16.30
#> 3:      15.49      15.84      15.86
#> 4:      16.87      17.10      16.49
#> 5:      16.73      17.26      16.33
#> 6:      17.48      19.43      18.44
# Monitor the low feedintake over the last n days
head(res$low_feedintake)
#>    location responder 06-03 06-04 06-05 06-06 06-07 sum_feedintake
#>       <int>     <int> <num> <num> <num> <num> <num>          <num>
#> 1:      507   2315012    NA    NA    NA 0.029 0.003           0.03
#> 2:      502        NA 0.081 0.046 0.056 0.087 0.027           0.30
#> 3:      510        NA    NA 0.048 0.208 0.014    NA           0.27
#> 4:      503        NA    NA 0.212 0.022    NA    NA           0.23
#> 5:      509        NA    NA    NA 0.010    NA 0.152           0.16
#> 6:      504        NA 0.026    NA 0.023    NA    NA           0.05
# Monitor the total feed intake over the last n days
head(res$all_feedintake)
#> Key: <location>
#>    location 06-03 06-04 06-05 06-06 06-07 all_feedintake
#>      <char> <num> <num> <num> <num> <num>          <num>
#> 1:      501 41.30 43.52 46.97 45.56 46.34         223.69
#> 2:      502 46.95 46.13 49.73 46.41 50.10         239.32
#> 3:      503 51.22 49.40 47.49 48.06 48.47         244.65
#> 4:      504 48.68 49.71 48.49 48.85 47.98         243.70
#> 5:      505 43.64 46.99 47.73 47.40 44.47         230.23
#> 6:      506 47.60 46.10 45.98 50.43 47.72         237.83
# Monitor the average feed intake over the last n days
head(res$mean_feedintake)
#> Key: <date>
#>      date 5_feed all_feedintake   5_n 5_mean_feed
#>    <char>  <num>          <num> <int>       <num>
#> 1:  06-03 460.51         460.51   147        3.13
#> 2:  06-04 464.41         464.41   146        3.18
#> 3:  06-05 469.79         469.79   145        3.24
#> 4:  06-06 470.22         470.22   146        3.22
#> 5:  06-07 469.56         469.56   146        3.22
# Monitor the average weight per pen over the last n days
head(res$house_weight)
#> Key: <date>
#>      date house_5
#>    <char>   <num>
#> 1:  06-03   75.08
#> 2:  06-04   76.42
#> 3:  06-05   77.64
#> 4:  06-06   79.34
#> 5:  06-07   80.61
# Monitor visit time in each hour over the last 1 day.
head(res$visit_n_hour)
#> Key: <location>
#>    location     0     1     2     3     4     5     6     7     8     9    10
#>       <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
#> 1:      501     3     5     4     4     4     3     4     9     5     5     8
#> 2:      502     4     1     3     4     1     2     4     4     4     4     4
#> 3:      503     2     7     4     3     1     3     3     3     4     2     7
#> 4:      504     4     4     1     5     1     2     3     3     3     5     4
#> 5:      505     5     9     4     3     2     4     4     2     4     5     3
#> 6:      506     3     4     2     3     1     1     3     2     4     2     4
#>       11    12    13    14    15    16    17    18    19    20    21    22
#>    <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
#> 1:     4     4     6     4     9    10     6     6     4     5     3     2
#> 2:     3     3     4     5     5     5     4     5     5     4     1     5
#> 3:     5     4     4     4     4     5     7     5     4     4     1     6
#> 4:     5     3     5     3     9     4     5     3     4     2     1     3
#> 5:     8     7     6     6     6     7     8     6     4     5     4     1
#> 6:     6     2     4     6     3     5     4     3     3     4     5     5
#>       23
#>    <int>
#> 1:     4
#> 2:    NA
#> 3:     4
#> 4:     3
#> 5:     2
#> 6:     1
# Monitor feed intake time in each hour over the last 1 day.
head(res$feed_time_hour)
#> Key: <location>
#>    location     0     1     2     3     4     5     6     7     8     9    10
#>       <int> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#> 1:      501  9.57 33.95 48.88 59.77 34.53 36.38 50.50 41.57 52.70 55.47 48.17
#> 2:      502 36.35 12.25 37.57 53.27 11.37 18.67 36.13 62.23 42.80 49.67 48.58
#> 3:      503 18.97 39.23 40.38 21.13  6.62 29.62 50.40 41.62 71.25 23.22 50.48
#> 4:      504 33.45 56.98  7.00 68.78 12.65 25.65 34.40 28.45 36.30 60.68 56.87
#> 5:      505 30.82 34.20 17.30 25.02 18.45 46.52 52.07 21.17 45.72 74.60 44.17
#> 6:      506 66.65 50.72 16.48 31.30  8.08 18.82 58.05 47.10 57.83 46.55 54.50
#>       11    12    13    14    15    16    17    18    19    20    21    22
#>    <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#> 1: 60.68 48.07 48.53 51.03 52.95 43.55 64.73 60.97 55.23 45.68 49.97 21.82
#> 2: 45.80 25.98 51.55 58.68 61.32 56.58 64.05 47.82 65.83 41.63  6.27 43.73
#> 3: 40.33 21.33 50.57 64.28 55.67 48.55 54.83 62.55 41.50 53.48  5.27 45.27
#> 4: 60.58 41.45 68.10 47.85 44.65 60.88 56.72 51.77 46.52 19.98  4.45 23.38
#> 5: 40.10 48.08 32.12 52.98 57.20 44.18 57.08 67.37 56.15 63.82 33.68  1.47
#> 6: 73.53 50.00 50.40 76.15 42.93 58.73 62.28 56.82 58.42 50.52 42.28 27.53
#>       23
#>    <num>
#> 1: 37.85
#> 2:    NA
#> 3: 15.00
#> 4: 41.63
#> 5: 15.62
#> 6:  0.83
# Monitor feed intake in each hour over the last 1 day.
head(res$feed_intake_hour)
#> Key: <location>
#>    location     0     1     2     3     4     5     6     7     8     9    10
#>       <int> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#> 1:      501  0.40  1.10  2.05  2.18  1.90  1.41  2.23  2.26  1.85  2.29  2.13
#> 2:      502  1.73  0.81  1.80  2.45  0.53  1.00  1.76  3.04  1.86  2.58  2.39
#> 3:      503  0.84  1.90  2.20  1.07  0.31  1.37  2.44  2.53  3.84  1.01  2.41
#> 4:      504  1.32  2.61  0.35  3.07  0.72  1.52  1.75  1.34  1.66  2.63  2.85
#> 5:      505  1.29  1.16  0.56  1.21  0.89  2.02  2.39  0.97  2.24  2.87  2.32
#> 6:      506  2.60  2.15  0.72  1.43  0.47  0.66  2.44  2.02  2.72  2.09  2.13
#>       11    12    13    14    15    16    17    18    19    20    21    22
#>    <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num> <num>
#> 1:  2.28  1.94  2.48  1.78  2.20  1.51  2.42  2.71  2.80  2.26  2.27  0.80
#> 2:  2.19  1.50  2.63  2.89  2.98  2.89  3.69  2.80  3.33  2.38  0.36  2.50
#> 3:  1.92  1.13  2.52  3.35  3.10  2.25  3.01  3.18  1.96  2.48  0.21  2.52
#> 4:  2.91  2.38  3.44  2.35  2.11  3.10  2.93  2.80  2.17  0.88  0.28  1.02
#> 5:  1.47  2.22  1.67  2.65  2.06  2.15  1.64  3.80  3.38  3.34  1.44  0.08
#> 6:  3.11  1.73  2.24  3.74  1.47  1.79  3.10  2.63  3.00  2.27  1.91  1.30
#>       23
#>    <num>
#> 1:  1.07
#> 2:    NA
#> 3:  0.90
#> 4:  1.79
#> 5:  0.64
#> 6:  0.02