Last active
February 22, 2022 12:48
-
-
Save MJacobs1985/8e7443ebb43ba121be0065f54877381f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rm(list = ls()) | |
| options("scipen"=100, "digits"=10) | |
| #### LIBRARIES #### | |
| library(readr) | |
| library(readxl) | |
| library(DataExplorer) | |
| library(tidyverse) | |
| library(ggExtra) | |
| library(gridExtra) | |
| library(grid) | |
| library(AzureStor) | |
| library(caret) | |
| library(car) | |
| library(skimr) | |
| library(forecast) | |
| library(lubridate) | |
| library(xgboost) | |
| library(tidymodels) | |
| library(modeltime) | |
| library(tidyverse) | |
| library(timetk) | |
| library(modelr) | |
| library(data.table) | |
| library(sweep) | |
| library(zoo) | |
| library(dynlm) | |
| library(ggfortify) | |
| library(tsDyn) | |
| library(vars) | |
| library(doParallel) | |
| library(lattice) | |
| library(pdp) | |
| library(ggfortify) | |
| library(xgboost) | |
| library(DT) | |
| library(forecastML) | |
| pacman::p_load(tidyverse, magrittr) # data wrangling packages | |
| pacman::p_load(lubridate, tsintermittent, fpp3, modeltime, timetk, modeltime.gluonts, tidymodels, modeltime.ensemble, modeltime.resample) # time series model packages | |
| pacman::p_load(foreach, future) # parallel functions | |
| pacman::p_load(viridis, plotly) # visualizations packages | |
| theme_set(hrbrthemes::theme_ipsum()) # set default themes | |
| #### IMPORT DATA #### | |
| day <- read_csv("Location860_day.csv") | |
| View(day) | |
| names(day) | |
| str(day) | |
| dim(day) | |
| hour <- read_csv("Location860_hour.csv") | |
| View(hour) | |
| names(hour) | |
| str(hour) | |
| dim(hour) | |
| Norm <- read_excel("Norm.xlsx") | |
| names(Norm) | |
| str(Norm) | |
| dim(Norm) | |
| folder<-setwd(getwd()) | |
| name="/DATA.csv" | |
| download_from_url("https://xxxxx.blob.core.windows.net/xxx/xxxx.csv", | |
| dest = paste0(folder,name), | |
| overwrite = TRUE, | |
| key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") | |
| day <- read_csv("DATA.csv") | |
| day$average_weight_eggs <- if_else(day$average_weight_eggs < 1, | |
| day$average_weight_eggs * 100, | |
| day$average_weight_eggs) | |
| options("scipen"=100, "digits"=4) | |
| day %>% | |
| group_by(location_identification, date_interval) %>% | |
| filter(location_identification == "2" & | |
| date_interval > "2021-12-05" & date_interval < "2021-12-12") %>% | |
| summarise_by_time(date_interval, | |
| .by = "week", | |
| Leg_perc_dag = egg_count/animals_actual, | |
| Leg_perc_week = (cumsum(egg_count) / 7) / (animals_start - (2 / 2)), | |
| Totaal_ei_week_tel = sum(egg_count, na.rm = TRUE), | |
| Totaal_twee_ei_week_tel = sum(eggs_second_quality, na.rm = TRUE), | |
| Totaal_twee_ei_week_perc = (sum(eggs_second_quality, na.rm = TRUE) / Totaal_ei_week_tel) * 100, | |
| Leg_Perc = (cumsum(egg_count) / 7) / (animals_start - (2 / 2)), | |
| Leg_Perc_Incre = sum(egg_count / animals_actual, na.rm = TRUE) / 7, | |
| Leg_Perc_Totaal = (sum(egg_count, na.rm = TRUE) / sum(animals_actual, na.rm = TRUE)), | |
| Eiggewicht_dag = average_weight_eggs, | |
| Eiggewicht_week_abs = abs(average_weight_eggs), | |
| Eiggewicht_week_gem_incr = mean(average_weight_eggs, na.rm=TRUE), | |
| Eiggewicht_week_gem_totaal = sum(average_weight_eggs, na.rm = TRUE) / 7, | |
| Eimassa_dag = (Eiggewicht_dag * Leg_perc_dag), | |
| Eimassa_week = (Eiggewicht_week_gem_totaal * Leg_perc_week), | |
| Totaal_ei_kg = (Totaal_ei_week_tel * Eiggewicht_week_gem_totaal) / 1000000, | |
| Begin_hennen = sum(animals_start, na.rm = TRUE), | |
| Uitval_hennen = sum(animals_out, na.rm = TRUE), | |
| Uitval_hennen_Perc = sum(Uitval_hennen / Begin_hennen) * 100) %>% | |
| mutate( | |
| Week_Eimassa = cumsum(Eiggewicht_dag * Leg_perc_dag), | |
| Totaal_ei_cum = cumsum(Totaal_ei_week_tel), | |
| Totaal_ei_kg_cum = cumsum(Totaal_ei_kg), | |
| Uitval_hennen_cum = cumsum(Uitval_hennen_Perc), | |
| Eimassa_cum = cumsum(Eimassa_dag) | |
| ) %>% # Eimassa POH cum | |
| reshape2::melt(., id.vars=1:2)%>% | |
| print.data.frame() | |
| newdf<-day %>% | |
| group_by(location_identification, date_interval) %>% | |
| summarise_by_time(date_interval, | |
| .by = "week", | |
| Eieren = egg_count, | |
| Hennen = animals_actual, | |
| Leg_perc_dag = egg_count/animals_actual, | |
| Leg_perc_week = (cumsum(egg_count) / 7) / (animals_start - (2 / 2)), | |
| Totaal_ei_week_tel = sum(egg_count, na.rm = TRUE), | |
| Totaal_twee_ei_week_tel = sum(eggs_second_quality, na.rm = TRUE), | |
| Totaal_twee_ei_week_perc = (sum(eggs_second_quality, na.rm = TRUE) / Totaal_ei_week_tel) * 100, | |
| Leg_Perc_Incre = sum(egg_count / animals_actual, na.rm = TRUE) / 7, | |
| Leg_Perc_Totaal = (sum(egg_count, na.rm = TRUE) / sum(animals_actual, na.rm = TRUE)), | |
| Eiggewicht_dag = average_weight_eggs, | |
| Eiggewicht_week_abs = abs(sum(average_weight_eggs)), | |
| Eiggewicht_week_gem_incr = mean(average_weight_eggs, na.rm=TRUE), | |
| Eiggewicht_week_gem_totaal = sum(average_weight_eggs, na.rm = TRUE) / 7, | |
| Eimassa_dag = (Eiggewicht_dag * Leg_perc_dag), | |
| Eimassa_week = (Eiggewicht_week_gem_totaal * Leg_perc_week), | |
| Totaal_ei_kg = (Totaal_ei_week_tel * Eiggewicht_week_gem_incr) / 1000000, | |
| Begin_hennen = sum(animals_start, na.rm = TRUE), | |
| Uitval_hennen = sum(animals_out, na.rm = TRUE), | |
| Uitval_hennen_Perc = sum(Uitval_hennen / Begin_hennen) * 100) %>% | |
| mutate( | |
| Week_Eimassa = cumsum(Eiggewicht_dag * Leg_perc_dag), | |
| Totaal_ei_cum = cumsum(Totaal_ei_week_tel), | |
| Totaal_ei_kg_cum = cumsum(Totaal_ei_kg), | |
| Uitval_hennen_cum = cumsum(Uitval_hennen_Perc), | |
| Eimassa_cum = cumsum(Eimassa_dag)) | |
| day$date_interval_day<-day$date_interval | |
| newdf$date_interval_week<-newdf$date_interval | |
| newdf$date_interval_day<-day$date_interval_day | |
| newdf$week=week(newdf$date_interval_day) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment