
#### sorting out planting dates: before duplicated plots are removed. get trial and plantingdates frrom here
## and link that to the data where duplicated plots aare ermoved and correction for nrplants is made

setwd("D:/ACAI_Wrapper/cloud_compute/LINTUL")
dsNOT_row <- read.csv("DS_NOT_Clean_2020.csv")## this data comes from NOT_DataAnalysis_July2020.R in D:\ACAI_Wrapper\cloud_compute\LINTUL
str(dsNOT_row) ## get trial and plot ids from here and link to it planting date and check that agianst teh most recent data


### link data specicfally to get planting dates
setwd("D:/ACAI_sample_processing/Version3/linkedForms")
plotconfirm_ODK_ONA <- read.csv("plotconfirm_ODK_ONA.csv")
Trial_ODK_ONA <- read.csv("Trial_ODK_ONA.csv")
Root_ONA_ODK <- read.csv("Root_Yield_Cassava_ONA_ODK.csv")
Trial_ODK_ONA$plantingDate <- as.character(Trial_ODK_ONA$plantingDate)
plotconfirm_ODK_ONA$plantingDate <- as.character(plotconfirm_ODK_ONA$plantingDate)

trialdate <- Trial_ODK_ONA[Trial_ODK_ONA$plantingDate != "notGiven",]
trialnodate <- Trial_ODK_ONA[Trial_ODK_ONA$plantingDate == "notGiven",]

## for trials with out pldate, check if plot confirm provides that info
for(k in unique(trialnodate$trialID)){
  if(k %in% unique(plotconfirm_ODK_ONA$trialID)){
    Q <-  plotconfirm_ODK_ONA[plotconfirm_ODK_ONA$trialID == k, ]
    trialnodate[trialnodate$trialID == k, ]$plantingDate <- unique(Q$plantingDate)[1]
  }
}

trialdate <- rbind(trialdate, trialnodate[trialnodate$plantingDate != "notGiven", ])
trialnodate <- trialnodate[trialnodate$plantingDate == "notGiven",]


## check for planting dates in the linked data
setwd("D:/ACAI_sample_processing/Version3/data")
ODK_ONA_ID_GPS <- read.csv("ODK_ONA_ID_GPS.csv")

trialnodate1 <- merge(subset(trialnodate, select=-c(plantingDate)), unique(ODK_ONA_ID_GPS[, c("trialID", "plantingDate")]), by="trialID")
trialnodate1 <- droplevels(trialnodate1[!is.na(trialnodate1$plantingDate), ])
unique(trialnodate1$plantingDate)
trialnodate <- trialnodate[!trialnodate$trialID %in% trialnodate1$trialID, ]

trialnodate2 <- merge(subset(trialnodate, select=-c(plantingDate)), unique(ODK_ONA_ID_GPS[, c("newTrialID", "plantingDate")]), by.x="trialID", by.y="newTrialID")
trialnodate2 <- droplevels(trialnodate2[!is.na(trialnodate2$plantingDate), ])
unique(trialnodate2$plantingDate)
trialnodate <- trialnodate[!trialnodate$trialID %in% trialnodate2$trialID, ]


trialdate <- rbind(trialdate, trialnodate1, trialnodate2)
head(trialdate)

### add planting date in dsNOT_row
ddcheck <- merge(unique(dsNOT_row[, c("trialID", "plotID")]), trialdate[, c("trialID", "plantingDate")], by="trialID")

ddcheck$Pdate <- ddcheck$plantingDate
ddcheck$Pdate <- gsub(" ", "_", ddcheck$Pdate)
ddcheck$Pdate <- gsub(", ", "_", ddcheck$Pdate)
ddcheck$Pdate <- gsub(",", "", ddcheck$Pdate)
head(ddcheck)

for(k in 1:nrow(ddcheck)){
  ddcheck$plantMonth[k] <- strsplit(ddcheck$Pdate[k], "_")[[1]][1]
  ddcheck$plantingDate[k] <- as.numeric(strsplit(ddcheck$Pdate[k], "_")[[1]][2])
  ddcheck$plantYear[k] <- as.numeric(strsplit(ddcheck$Pdate[k], "_")[[1]][3])
  ddcheck$PPdate[k] <- paste(ddcheck$plantingDate[k],"/", ddcheck$plantMonth[k], "/", ddcheck$plantYear[k], sep="")
  ddcheck$plantDOY[k] <- lubridate::yday(as.Date(ddcheck$PPdate[k], format = '%d/%b/%Y'))
  ddcheck$plantingDate[k] <- ddcheck$PPdate[k] 
}


head(ddcheck)


######################################################################################################
### link the most cleaned data now 
######################################################################################################
setwd("D:/ACAI_Wrapper/Rwanda")
# saveRDS(dsY2, "ACAI_NOT_Oct.RDS")
# dsY <- readRDS("ACAI_NOT_Oct.RDS")
# summary(readRDS("ACAI_NOT_Oct.RDS")$Rowyield)
### data get corrected for nr of plants per plot
dsY <- read.csv("NOT_Oct2020.csv")
dsY <- dsY[!is.na(dsY$rootY_tha),]
# dsY <- dsY[dsY$rootY <= 200,]
dsY <- dsY[rowSums(is.na(dsY)) <= ncol(dsY),]
summary(dsY$rootY_tha)
head(dsY)

### get trial and DAP and get trials harvested within 10 to 15 months 
trialsDAP <- unique(dsY[, c("trialID", "DAP")])
trialsDAP <- trialsDAP[order(trialsDAP$trialID), ]

setwd("D:/ACAI_sample_processing/Version3/linkedForms")
plotconfirm_ODK_ONA <- read.csv("plotconfirm_ODK_ONA.csv")
Trial_ODK_ONA <- read.csv("Trial_ODK_ONA.csv")
Root_ONA_ODK <- read.csv("Root_Yield_Cassava_ONA_ODK.csv")
Trial_ODK_ONA$plantingDate <- as.character(Trial_ODK_ONA$plantingDate)
plotconfirm_ODK_ONA$plantingDate <- as.character(plotconfirm_ODK_ONA$plantingDate)

trialdate <- Trial_ODK_ONA[Trial_ODK_ONA$plantingDate != "notGiven",]
trialnodate <- Trial_ODK_ONA[Trial_ODK_ONA$plantingDate == "notGiven",]

for(k in unique(trialnodate$trialID)){
  if(k %in% unique(plotconfirm_ODK_ONA$trialID)){
    Q <-  plotconfirm_ODK_ONA[plotconfirm_ODK_ONA$trialID == k, ]
    trialnodate[trialnodate$trialID == k, ]$plantingDate <- unique(Q$plantingDate)[1]
  }
}

trialdate <- rbind(trialdate, trialnodate[trialnodate$plantingDate != "notGiven", ])
trialnodate <- trialnodate[trialnodate$plantingDate == "notGiven",]

setwd("D:/ACAI_sample_processing/Version3/data")
ODK_ONA_ID_GPS <- read.csv("ODK_ONA_ID_GPS.csv")

trialnodate1 <- merge(subset(trialnodate, select=-c(plantingDate)), unique(ODK_ONA_ID_GPS[, c("trialID", "plantingDate")]), by="trialID")
trialnodate1 <- droplevels(trialnodate1[!is.na(trialnodate1$plantingDate), ])
unique(trialnodate1$plantingDate)
trialnodate <- trialnodate[!trialnodate$trialID %in% trialnodate1$trialID, ]

trialnodate2 <- merge(subset(trialnodate, select=-c(plantingDate)), unique(ODK_ONA_ID_GPS[, c("newTrialID", "plantingDate")]), by.x="trialID", by.y="newTrialID")
trialnodate2 <- droplevels(trialnodate2[!is.na(trialnodate2$plantingDate), ])
unique(trialnodate2$plantingDate)
trialnodate <- trialnodate[!trialnodate$trialID %in% trialnodate2$trialID, ]

trialdate <- rbind(trialdate, trialnodate1, trialnodate2)
head(trialdate)


dd <- merge(unique(dsY[, c("trialID", "plantingDate")]), trialdate[, c("trialID", "plantingDate")], by="trialID")
dd <- dd[is.na(dd$plantingDate.x) & dd$plantingDate.y !="", ]

dd$Pdate <- dd$plantingDate.y
dd$Pdate <- gsub(" ", "_", dd$Pdate)
dd$Pdate <- gsub(", ", "_", dd$Pdate)
dd$Pdate <- gsub(",", "", dd$Pdate)
head(dd)

for(k in 1:nrow(dd)){
  dd$plantMonth[k] <- strsplit(dd$Pdate[k], "_")[[1]][1]
  dd$plantingDate[k] <- as.numeric(strsplit(dd$Pdate[k], "_")[[1]][2])
  dd$plantYear[k] <- as.numeric(strsplit(dd$Pdate[k], "_")[[1]][3])
  dd$PPdate[k] <- paste(dd$plantingDate[k],"/", dd$plantMonth[k], "/", dd$plantYear[k], sep="")
  dd$plantDOY[k] <- lubridate::yday(as.Date(dd$PPdate[k], format = '%d/%b/%Y'))
  dd$plantingDate[k] <- dd$PPdate[k] 
}

head(dd)
dsY[dsY$trialID == "ACTLNG000757", ]




dsY$plantingDate <- as.character(dsY$plantingDate)
dsYY1 <- droplevels(dsY[dsY$trialID %in% unique(dd$trialID), ])
dsYY2 <- droplevels(dsY[!dsY$trialID %in% unique(dd$trialID), ])

ttt <- NULL
for(tids in unique(dd$trialID)){
  tt <- dsYY1[dsYY1$trialID == tids, ]
  tt$plantingDate <- unique(dd[dd$trialID == tids, ]$plantingDate)
  tt$plantYear <- unique(dd[dd$trialID == tids, ]$plantYear)
  tt$plantMonth <- unique(dd[dd$trialID == tids, ]$plantMonth)
  tt$plantDOY <- unique(dd[dd$trialID == tids, ]$plantDOY)
  ttt <- rbind(ttt, tt)
}
ttt$DAP <- (365-ttt$plantDOY) + ttt$harvestDate_DOY

dsY[dsY$trialID == "ACTLTZ002683", ]
ttt[ttt$trialID == "ACTLTZ002683", ]

dsY <- rbind(dsYY2, ttt)
head(dsY[!is.na(dsY$plantDOY), ])



### look in to trialiD that is closer with planting date info and check if harvest for the two trials, if yes use teh plantingdate from teh closest trial
MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
WithPlantingDate <- droplevels(dsY[!is.na(dsY$plantingDate), ])
head(WithPlantingDate)

unique(MissingPlantingDate$trialID)

pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG007607",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG007605", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plotID),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$newPlotID, "today"]## harvest date for new plot ids W planting date

dsY[dsY$trialID == "ACTLNG007607", ]$plantingDate <- "07/16/2017"
dsY[dsY$trialID == "ACTLNG007607", ]$plantYear <- 2017
dsY[dsY$trialID == "ACTLNG007607", ]$plantMonth <- 07
dsY[dsY$trialID == "ACTLNG007607", ]$plantDOY <- lubridate::yday(as.Date("16/Jul/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLNG007607", ]$DAP <- (365-197) + 365 + 204


###
MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
unique(MissingPlantingDate$trialID)
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG007606",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG007605", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plotID),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$newPlotID, "today"]## harvest date for new plot ids W planting date

dsY[dsY$trialID == "ACTLNG007606", ]$plantingDate <- "07/16/2017"## take the plantign date of the closest trial
dsY[dsY$trialID == "ACTLNG007606", ]$plantYear <- 2017
dsY[dsY$trialID == "ACTLNG007606", ]$plantMonth <- 07
dsY[dsY$trialID == "ACTLNG007606", ]$plantDOY <- lubridate::yday(as.Date("16/Jul/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLNG007606", ]$DAP <- (365-197) + 365 + 204


###
MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
unique(MissingPlantingDate$trialID)
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG007604",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG007605", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plotID),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$newPlotID, "today"]## harvest date for new plot ids W planting date

dsY[dsY$trialID == "ACTLNG007604", ]$plantingDate <- "07/16/2017"## take the plantign date of the closest trial
dsY[dsY$trialID == "ACTLNG007604", ]$plantYear <- 2017
dsY[dsY$trialID == "ACTLNG007604", ]$plantMonth <- 07
dsY[dsY$trialID == "ACTLNG007604", ]$plantDOY <- lubridate::yday(as.Date("16/Jul/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLNG007604", ]$DAP <- (365-197) + 365 + 204

###
dsY[dsY$trialID %in% c("ACTLNG007600","ACTLNG007601","ACTLNG007602","ACTLNG007603"), ]$plantingDate <- "07/16/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLNG007600","ACTLNG007601","ACTLNG007602","ACTLNG007603"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLNG007600","ACTLNG007601","ACTLNG007602","ACTLNG007603"), ]$plantMonth <- 07
dsY[dsY$trialID %in% c("ACTLNG007600","ACTLNG007601","ACTLNG007602","ACTLNG007603"), ]$plantDOY <- lubridate::yday(as.Date("16/Jul/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLNG007600","ACTLNG007601","ACTLNG007602","ACTLNG007603"), ]$DAP <- (365-197) + 365 + 204



###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% askNG, ]
unique(MissingPlantingDate$trialID)


pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ002534",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ002533", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plotID),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$newPlotID, "today"]## harvest date for new plot ids W planting date

dsY[dsY$trialID == "ACTLTZ002534", ]$plantingDate <- "02/21/2018"## take the plantign date of the closest trial
dsY[dsY$trialID == "ACTLTZ002534", ]$plantYear <- 2018
dsY[dsY$trialID == "ACTLTZ002534", ]$plantMonth <- 02
dsY[dsY$trialID == "ACTLTZ002534", ]$plantDOY <- lubridate::yday(as.Date("21/Feb/2018", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLTZ002534", ]$DAP <- (365-52) + 75

###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% askNG, ]
unique(MissingPlantingDate$trialID)


pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003057",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003054", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plotID),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID == "ACTLTZ003057", ]$plantingDate <- "11/23/2017"## take the plantign date of the closest trial
dsY[dsY$trialID == "ACTLTZ003057", ]$plantYear <- 2017
dsY[dsY$trialID == "ACTLTZ003057", ]$plantMonth <- 11
dsY[dsY$trialID == "ACTLTZ003057", ]$plantDOY <- lubridate::yday(as.Date("23/Nov/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLTZ003057", ]$DAP <- (365-327) + 299

####
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003063",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003054", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plotID),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID == "ACTLTZ003063", ]$plantingDate <- "11/23/2017"## take the plantign date of the closest trial
dsY[dsY$trialID == "ACTLTZ003063", ]$plantYear <- 2017
dsY[dsY$trialID == "ACTLTZ003063", ]$plantMonth <- 11
dsY[dsY$trialID == "ACTLTZ003063", ]$plantDOY <- lubridate::yday(as.Date("23/Nov/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLTZ003063", ]$DAP <- (365-327) + 299


####
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003065",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003054", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plotID),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID == "ACTLTZ003065", ]$plantingDate <- "11/23/2017"## take the plantign date of the closest trial
dsY[dsY$trialID == "ACTLTZ003065", ]$plantYear <- 2017
dsY[dsY$trialID == "ACTLTZ003065", ]$plantMonth <- 11
dsY[dsY$trialID == "ACTLTZ003065", ]$plantDOY <- lubridate::yday(as.Date("23/Nov/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLTZ003065", ]$DAP <- (365-327) + 299


####
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID %in% c("ACTLTZ003085", "ACTLTZ003086", "ACTLTZ003100", "ACTLTZ003092", "ACTLTZ003094", "ACTLTZ003097", "ACTLTZ003100"),])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID %in% c("ACTLTZ003085", "ACTLTZ003086", "ACTLTZ003100", "ACTLTZ003092", "ACTLTZ003094", "ACTLTZ003097", "ACTLTZ003100"), c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plotID),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLTZ003085", "ACTLTZ003086", "ACTLTZ003100", "ACTLTZ003092", "ACTLTZ003094", "ACTLTZ003097", "ACTLTZ003100"), ]$plantingDate <- "11/23/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLTZ003085", "ACTLTZ003086", "ACTLTZ003100", "ACTLTZ003092", "ACTLTZ003094", "ACTLTZ003097", "ACTLTZ003100"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLTZ003085", "ACTLTZ003086", "ACTLTZ003100", "ACTLTZ003092", "ACTLTZ003094", "ACTLTZ003097", "ACTLTZ003100"), ]$plantMonth <- 11
dsY[dsY$trialID %in% c("ACTLTZ003085", "ACTLTZ003086", "ACTLTZ003100", "ACTLTZ003092", "ACTLTZ003094", "ACTLTZ003097", "ACTLTZ003100"), ]$plantDOY <- lubridate::yday(as.Date("23/Nov/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLTZ003085", "ACTLTZ003086", "ACTLTZ003100", "ACTLTZ003092", "ACTLTZ003094", "ACTLTZ003097", "ACTLTZ003100"), ]$DAP <- (365-327) + 299


#####
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)

pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ000516",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ000513", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLTZ000516", "ACTLTZ000517"), ]$plantingDate <- "01/06/2018"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLTZ000516", "ACTLTZ000517"), ]$plantYear <- 2018
dsY[dsY$trialID %in% c("ACTLTZ000516", "ACTLTZ000517"), ]$plantMonth <- 1
dsY[dsY$trialID %in% c("ACTLTZ000516", "ACTLTZ000517"), ]$plantDOY <- lubridate::yday(as.Date("06/Jan/2018", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLTZ000516", "ACTLTZ000517"), ]$DAP <- dsY[dsY$trialID %in% c("ACTLTZ000516", "ACTLTZ000517"), ]$harvestDate_DOY-6

###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ000542",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ000529", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLTZ000542", "ACTLTZ000551"), ]$plantingDate <- "01/09/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLTZ000542", "ACTLTZ000551"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLTZ000542", "ACTLTZ000551"), ]$plantMonth <- 1
dsY[dsY$trialID %in% c("ACTLTZ000542", "ACTLTZ000551"), ]$plantDOY <- lubridate::yday(as.Date("09/Jan/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLTZ000542", "ACTLTZ000551"), ]$DAP <- (365-9)+303


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)
ff <- c("ACTLTZ000576", "ACTLTZ000578")

pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ000578",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ000574", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% ff, ]$plantingDate <- "01/22/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% ff, ]$plantYear <- 2017
dsY[dsY$trialID %in% ff, ]$plantMonth <- 1
dsY[dsY$trialID %in% ff, ]$plantDOY <- lubridate::yday(as.Date("22/Jan/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% ff, ]$DAP <- (365-22)+288


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)
ff <- paste("ACTLTZ000", c(642,643,645,646,647,648,649,653,660,663,664,669,670,672,673,676,680,681,682,684,685,687,689,690,691,692,693,694,695,697,699,700,702,704,705,706,709,710,712,715,718,720,723,724,727,728,741,747,749,750,785), sep="")

pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ000785",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ000737", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% ff, ]$plantingDate <- "10/31/2016"## take the plantign date of the closest trial
dsY[dsY$trialID %in% ff, ]$plantYear <- 2016
dsY[dsY$trialID %in% ff, ]$plantMonth <- 10
dsY[dsY$trialID %in% ff, ]$plantDOY <- lubridate::yday(as.Date("31/Oct/2016", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% ff, ]$DAP <- (365-305)+dsY[dsY$trialID %in% ff, ]$harvestDate_DOY


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)
ff <- "ACTLTZ000868"

pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ000868",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ000873", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% ff, ]$plantingDate <- "1/31/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% ff, ]$plantYear <- 2017
dsY[dsY$trialID %in% ff, ]$plantMonth <- 1
dsY[dsY$trialID %in% ff, ]$plantDOY <- lubridate::yday(as.Date("31/Jan/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% ff, ]$DAP <- 325-31

###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)
ff <- c("ACTLTZ001955")

pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ001955",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ001953", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% ff, ]$plantingDate <- "06/16/2018"## take the plantign date of the closest trial
dsY[dsY$trialID %in% ff, ]$plantYear <- 2018
dsY[dsY$trialID %in% ff, ]$plantMonth <- 06
dsY[dsY$trialID %in% ff, ]$plantDOY <- lubridate::yday(as.Date("16/Jun/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% ff, ]$DAP <- 300-167

###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)
ff <- c("ACTLTZ001982")

pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ001982",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ001981", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% ff, ]$plantingDate <- "11/25/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% ff, ]$plantYear <- 2017
dsY[dsY$trialID %in% ff, ]$plantMonth <- 11
dsY[dsY$trialID %in% ff, ]$plantDOY <- lubridate::yday(as.Date("25/Nov/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% ff, ]$DAP <- (365-329)+302


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)
ff <- c("ACTLTZ001987", "ACTLTZ001988", "ACTLTZ001989", "ACTLTZ001990", "ACTLTZ001991", "ACTLTZ001992", "ACTLTZ001993",
        "ACTLTZ001994", "ACTLTZ001995", "ACTLTZ001996", "ACTLTZ001997", "ACTLTZ001998", "ACTLTZ001999", "ACTLTZ002000")

pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ002000",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ001986", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% ff, ]$plantingDate <- "10/12/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% ff, ]$plantYear <- 2017
dsY[dsY$trialID %in% ff, ]$plantMonth <- 10
dsY[dsY$trialID %in% ff, ]$plantDOY <- lubridate::yday(as.Date("12/Oct/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% ff, ]$DAP <- (365-285)+292

###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)
ff <- c("ACTLTZ002001", "ACTLTZ002002", "ACTLTZ002003", "ACTLTZ002004", "ACTLTZ002005", "ACTLTZ002006", "ACTLTZ002007",
        "ACTLTZ002008", "ACTLTZ002009", "ACTLTZ002010", "ACTLTZ002011", "ACTLTZ002012", "ACTLTZ002013", "ACTLTZ002014",
        "ACTLTZ002024", "ACTLTZ002052", "ACTLTZ002053", "ACTLTZ002082", "ACTLTZ002085", "ACTLTZ002086", "ACTLTZ002087",
        "ACTLTZ002141", "ACTLTZ002142", "ACTLTZ002143", "ACTLTZ002147", "ACTLTZ002166", "ACTLTZ002167", "ACTLTZ002168",
        "ACTLTZ002169", "ACTLTZ002170")


pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ002170",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ001986", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% ff, ]$plantingDate <- "10/12/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% ff, ]$plantYear <- 2017
dsY[dsY$trialID %in% ff, ]$plantMonth <- 10
dsY[dsY$trialID %in% ff, ]$plantDOY <- lubridate::yday(as.Date("12/Oct/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% ff, ]$DAP <- (365-285)+291


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)
ff <- c("ACTLTZ002656")

ff <- c("ACTLTZ002656", "ACTLTZ003021", "ACTLTZ003055", "ACTLTZ003060", "ACTLTZ003064", "ACTLTZ003084", "ACTLTZ003091",
        "ACTLTZ003098", "ACTLTZ003105", "ACTLTZ003106")

pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ002656",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ002655", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% ff, ]$plantingDate <- "09/02/2018"## take the plantign date of the closest trial
dsY[dsY$trialID %in% ff, ]$plantYear <- 2018
dsY[dsY$trialID %in% ff, ]$plantMonth <- 02
dsY[dsY$trialID %in% ff, ]$plantDOY <- lubridate::yday(as.Date("09/Feb/2018", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% ff, ]$DAP <- (365-40)+33



pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003021",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003022", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID == "ACTLTZ003021", ]$plantingDate <- "11/30/2017"## take the plantign date of the closest trial
dsY[dsY$trialID == "ACTLTZ003021", ]$plantYear <- 2017
dsY[dsY$trialID == "ACTLTZ003021", ]$plantMonth <- 11
dsY[dsY$trialID == "ACTLTZ003021", ]$plantDOY <- lubridate::yday(as.Date("11/Nov/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLTZ003021", ]$DAP <- (365-315)+300


pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003055",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003054", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID == "ACTLTZ003055", ]$plantingDate <- "11/23/2017"## take the plantign date of the closest trial
dsY[dsY$trialID == "ACTLTZ003055", ]$plantYear <- 2017
dsY[dsY$trialID == "ACTLTZ003055", ]$plantMonth <- 11
dsY[dsY$trialID == "ACTLTZ003055", ]$plantDOY <- lubridate::yday(as.Date("23/Nov/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLTZ003055", ]$DAP <- (365-327)+299


ff <- c("ACTLTZ003060", "ACTLTZ003064", "ACTLTZ003084", "ACTLTZ003091",
        "ACTLTZ003098", "ACTLTZ003105", "ACTLTZ003106")

pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003106",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLTZ003054", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% ff, ]$plantingDate <- "11/23/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% ff, ]$plantYear <- 2017
dsY[dsY$trialID %in% ff, ]$plantMonth <- 11
dsY[dsY$trialID %in% ff, ]$plantDOY <- lubridate::yday(as.Date("23/Nov/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% ff, ]$DAP <- (365-327)+dsY[dsY$trialID %in% ff, ]$harvestDate_DOY



###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594", "ACTLNG000599", "ACTLNG000600")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)

ff <- c("ACTLNG000772", "ACTLNG000774")
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG000774",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG000771", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% ff, ]$plantingDate <- "06/19/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% ff, ]$plantYear <- 2017
dsY[dsY$trialID %in% ff, ]$plantMonth <- 06
dsY[dsY$trialID %in% ff, ]$plantDOY <- lubridate::yday(as.Date("19/Jun/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% ff, ]$DAP <- (365-170)+241



pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG000643",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG000603", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID == "ACTLNG000643", ]$plantingDate <- "08/22/2017"## take the plantign date of the closest trial
dsY[dsY$trialID == "ACTLNG000643", ]$plantYear <- 2017
dsY[dsY$trialID == "ACTLNG000643", ]$plantMonth <- 08
dsY[dsY$trialID == "ACTLNG000643", ]$plantDOY <- lubridate::yday(as.Date("22/Aug/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLNG000643", ]$DAP <- (365-234)+264



pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG000050",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG000049", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID == "ACTLNG000050", ]$plantingDate <- "06/19/2017"## take the plantign date of the closest trial
dsY[dsY$trialID == "ACTLNG000050", ]$plantYear <- 2017
dsY[dsY$trialID == "ACTLNG000050", ]$plantMonth <- 06
dsY[dsY$trialID == "ACTLNG000050", ]$plantDOY <- lubridate::yday(as.Date("19/Jun/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLNG000050", ]$DAP <- (365-170)+242


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)

ff <- c("ACTLNG000930", "ACTLNG000935", "ACTLNG000941")
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG000941",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG000927", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% ff, ]$plantingDate <- "07/18/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% ff, ]$plantYear <- 2017
dsY[dsY$trialID %in% ff, ]$plantMonth <- 07
dsY[dsY$trialID %in% ff, ]$plantDOY <- lubridate::yday(as.Date("18/Jul/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% ff, ]$DAP <- (365-199)+240


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)

ff <- c("ACTLNG001116", "ACTLNG001117", "ACTLNG001119")
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001119",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001113", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]
pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 
## manually go to teh root yield data where today will be very close to the harvest day for plots with out planting dates, search for plot ids that are close and use that date
closerplots <- c("ACPONG010251","ACPONG010252","ACPONG010254","ACPONG010253","ACPONG010269","ACPONG010270","ACPONG010271","ACPONG010272",
                 "ACPONG010273","ACPONG010274","ACPONG010275","ACPONG010276","ACPONG010277","ACPONG010278","ACPONG010279","ACPONG010280",
                 "ACPONG010281","ACPONG010282","ACPONG010283","ACPONG010284","ACPONG010285","ACPONG010286","ACPONG010287","ACPONG010288",
                 "ACPONG010289","ACPONG010290","ACPONG010291","ACPONG010292", "ACPONG010243","ACPONG010244","ACPONG010245","ACPONG010246",
                 "ACPONG010247","ACPONG010248","ACPONG010249","ACPONG010250")

dsY[dsY$plotID %in% closerplots, ]$plantingDate
ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$plotID %in% closerplots, ]$plantingDate
ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$newPlotID %in% closerplots, ]$plantingDate


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810","ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")

MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


ff <- c("ACTLNG001260", "ACTLNG001265")
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001265",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001261", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]

pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID == "ACTLNG001265", ]$plantingDate <- "06/06/2018"## take the plantign date of the closest trial
dsY[dsY$trialID == "ACTLNG001265", ]$plantYear <- 2018
dsY[dsY$trialID == "ACTLNG001265", ]$plantMonth <- 06
dsY[dsY$trialID == "ACTLNG001265", ]$plantDOY <- lubridate::yday(as.Date("06/Jun/2018", format = '%d/%b/%Y'))
dsY[dsY$trialID == "ACTLNG001265", ]$DAP <- (365-157)+170

###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810","ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203", "ACTLNG001260", "ACTLNG001284", "ACTLNG001285","ACTLNG001301")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


ff <- c("ACTLNG001310", "ACTLNG001311", "ACTLNG001314")
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001314",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001305", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]

pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLNG001310", "ACTLNG001311", "ACTLNG001314"), ]$plantingDate <- "06/20/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLNG001310", "ACTLNG001311", "ACTLNG001314"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLNG001310", "ACTLNG001311", "ACTLNG001314"), ]$plantMonth <- 06
dsY[dsY$trialID %in% c("ACTLNG001310", "ACTLNG001311", "ACTLNG001314"), ]$plantDOY <- lubridate::yday(as.Date("20/Jun/2018", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLNG001310"), ]$DAP <- (365-171)+241
dsY[dsY$trialID %in% c("ACTLNG001311"), ]$DAP <- (365-171)+231
dsY[dsY$trialID %in% c("ACTLNG001314"), ]$DAP <- (365-171)+230


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810","ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203", "ACTLNG001260", "ACTLNG001284", "ACTLNG001285","ACTLNG001301", "ACTLNG001338", "ACTLNG001339")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


ff <- c()
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001419",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001394", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]

pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLNG001419"), ]$plantingDate <- "05/31/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLNG001419"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLNG001419"), ]$plantMonth <- 05
dsY[dsY$trialID %in% c("ACTLNG001419"), ]$plantDOY <- lubridate::yday(as.Date("31/May/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLNG001419"), ]$DAP <- (365-151)+267



###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810","ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203", "ACTLNG001260", "ACTLNG001284", "ACTLNG001285","ACTLNG001301", "ACTLNG001338", "ACTLNG001339")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


ff <- c()
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001433",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001431", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]

pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLNG001432", "ACTLNG001433", "ACTLNG001438"), ]$plantingDate <- "06/05/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLNG001432", "ACTLNG001433", "ACTLNG001438"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLNG001432", "ACTLNG001433", "ACTLNG001438"), ]$plantMonth <- 06
dsY[dsY$trialID %in% c("ACTLNG001432", "ACTLNG001433", "ACTLNG001438"), ]$plantDOY <- lubridate::yday(as.Date("05/Jun/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLNG001432"), ]$DAP <- (365-156)+150
dsY[dsY$trialID %in% c("ACTLNG001433"), ]$DAP <- (365-156)+150
dsY[dsY$trialID %in% c("ACTLNG001438"), ]$DAP <- (365-156)+194


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810","ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203", "ACTLNG001260", "ACTLNG001284", "ACTLNG001285","ACTLNG001301", "ACTLNG001338", "ACTLNG001339")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


ff <- c()
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001449",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001437", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]

pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLNG001449"), ]$plantingDate <- "06/04/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLNG001449"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLNG001449"), ]$plantMonth <- 06
dsY[dsY$trialID %in% c("ACTLNG001449"), ]$plantDOY <- lubridate::yday(as.Date("04/Jun/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLNG001449"), ]$DAP <- (365-155)+155


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810","ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203", "ACTLNG001260", "ACTLNG001284", "ACTLNG001285","ACTLNG001301", "ACTLNG001338", "ACTLNG001339")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


ff <- c()
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001494",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001496", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]

pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLNG001494"), ]$plantingDate <- "07/16/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLNG001494"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLNG001494"), ]$plantMonth <- 07
dsY[dsY$trialID %in% c("ACTLNG001494"), ]$plantDOY <- lubridate::yday(as.Date("16/Jul/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLNG001494"), ]$DAP <- (365-197)+209


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810","ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203", "ACTLNG001260", "ACTLNG001284", "ACTLNG001285","ACTLNG001301", "ACTLNG001338", "ACTLNG001339")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


ff <- c()
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001503",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001505", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]

pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLNG001503", "ACTLNG001504"), ]$plantingDate <- "07/08/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLNG001503","ACTLNG001504"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLNG001503","ACTLNG001504"), ]$plantMonth <- 07
dsY[dsY$trialID %in% c("ACTLNG001503","ACTLNG001504"), ]$plantDOY <- lubridate::yday(as.Date("08/Jul/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLNG001503","ACTLNG001504"), ]$DAP <- (365-189)+172



###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810","ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203", "ACTLNG001260", "ACTLNG001284", "ACTLNG001285","ACTLNG001301", "ACTLNG001338", "ACTLNG001339")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


ff <- c()
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001572",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001571", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]

pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLNG001572"), ]$plantingDate <- "07/19/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLNG001572"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLNG001572"), ]$plantMonth <- 07
dsY[dsY$trialID %in% c("ACTLNG001572"), ]$plantDOY <- lubridate::yday(as.Date("19/Jul/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLNG001572"), ]$DAP <- (365-200)+224


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810","ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203", "ACTLNG001260", "ACTLNG001284", "ACTLNG001285","ACTLNG001301", "ACTLNG001338", "ACTLNG001339")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406","ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


ff <- c()
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001588",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG001596", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]

pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLNG001588"), ]$plantingDate <- "07/20/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLNG001588"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLNG001588"), ]$plantMonth <- 07
dsY[dsY$trialID %in% c("ACTLNG001588"), ]$plantDOY <- lubridate::yday(as.Date("20/Jul/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLNG001588"), ]$DAP <- (365-201)+312


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810","ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203", "ACTLNG001260", "ACTLNG001284", "ACTLNG001285","ACTLNG001301", "ACTLNG001338", "ACTLNG001339")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406", "ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


ff <- c()
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG002077",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG002076", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]

pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLNG002077"), ]$plantingDate <- "07/23/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLNG002077"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLNG002077"), ]$plantMonth <- 07
dsY[dsY$trialID %in% c("ACTLNG002077"), ]$plantDOY <- lubridate::yday(as.Date("23/Jul/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLNG002077"), ]$DAP <- (365-204)+254



###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093","ACTLNG000131", "ACTLNG000143", "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231",
           "ACTLNG000239", "ACTLNG000243", "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319",
           "ACTLNG000342", "ACTLNG000359", "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810","ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203", "ACTLNG001260", "ACTLNG001284", "ACTLNG001285","ACTLNG001301", "ACTLNG001338", "ACTLNG001339")
askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406", "ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


ff <- c()
pids_missing <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG002116",])$plotID)
pids_lookup <- unique((ODK_ONA_ID_GPS[ODK_ONA_ID_GPS$trialID == "ACTLNG002173", c("plotID", "newPlotID","plantingDate")]))
pids_missing <- pids_missing[!is.na(pids_missing)]

pids_lookup <- pids_lookup[!is.na(pids_lookup$plantingDate),]

Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_missing, "today"]## harvest date for plots W/O planting date
Root_ONA_ODK[Root_ONA_ODK$plotID %in% pids_lookup$plotID, "today"] ## harvest date for plots W planting date. 

dsY[dsY$trialID %in% c("ACTLNG002116"), ]$plantingDate <- "07/21/2017"## take the plantign date of the closest trial
dsY[dsY$trialID %in% c("ACTLNG002116"), ]$plantYear <- 2017
dsY[dsY$trialID %in% c("ACTLNG002116"), ]$plantMonth <- 07
dsY[dsY$trialID %in% c("ACTLNG002116"), ]$plantDOY <- lubridate::yday(as.Date("21/Jul/2017", format = '%d/%b/%Y'))
dsY[dsY$trialID %in% c("ACTLNG002116"), ]$DAP <- (365-202)+136


###
askNG <- c("ACTLNG007582", "ACTLNG007583", "ACTLNG007584","ACTLNG007585", "ACTLNG000093", "ACTLNG000131", "ACTLNG000143", 
           "ACTLNG000187", "ACTLNG000195", "ACTLNG000199", "ACTLNG000219", "ACTLNG000231", "ACTLNG000239", "ACTLNG000243",
           "ACTLNG000249", "ACTLNG000285", "ACTLNG000299", "ACTLNG000310", "ACTLNG000319", "ACTLNG000342", "ACTLNG000359",
           "ACTLNG000364", "ACTLNG000374", "ACTLNG000384", "ACTLNG000394", "ACTLNG000404",
           "ACTLNG000414", "ACTLNG000438", "ACTLNG000590", "ACTLNG000591", "ACTLNG000592", "ACTLNG000593", "ACTLNG000594",
           "ACTLNG000599", "ACTLNG000600", "ACTLNG000779", "ACTLNG000807", "ACTLNG000808", "ACTLNG000810", "ACTLNG001116",
           "ACTLNG001117", "ACTLNG001119", "ACTLNG001214", "ACTLNG001221", "ACTLNG001222", "ACTLNG001223", "ACTLNG001224",
           "ACTLNG001203", "ACTLNG001260", "ACTLNG001284", "ACTLNG001285","ACTLNG001301", "ACTLNG001338", "ACTLNG001339")


askTZ <- c("ACTLTZ000389", "ACTLTZ000394", "ACTLTZ000395", "ACTLTZ000397", "ACTLTZ000398", "ACTLTZ000403", "ACTLTZ000404",
           "ACTLTZ000405", "ACTLTZ000406", "ACTLTZ000407", "ACTLTZ000408", "ACTLTZ000409", "ACTLTZ000411", "ACTLTZ000412",
           "ACTLTZ000413", "ACTLTZ000414", "ACTLTZ000415", "ACTLTZ000416", "ACTLTZ000453", "ACTLTZ000456",
           "ACTLTZ000509", "ACTLTZ000510", "ACTLTZ000512", "ACTLTZ000520", "ACTLTZ000522", "ACTLTZ000532", "ACTLTZ000535",
           "ACTLTZ000851", "ACTLTZ000852", "ACTLTZ000853", "ACTLTZ000854", "ACTLTZ000855", "ACTLTZ000856", "ACTLTZ000858",
           "ACTLTZ000859", "ACTLTZ000861", "ACTLTZ001091", "ACTLTZ001093", "ACTLTZ001094", "ACTLTZ001095", "ACTLTZ001096",
           "ACTLTZ001097", "ACTLTZ001098", "ACTLTZ001099", "ACTLTZ001107", "ACTLTZ001110")


MissingPlantingDate <- droplevels(dsY[is.na(dsY$plantingDate), ])
MissingPlantingDate <- MissingPlantingDate[!MissingPlantingDate$trialID %in% c(askNG, askTZ), ]
MissingPlantingDate <- MissingPlantingDate[order(MissingPlantingDate$trialID), ]
unique(MissingPlantingDate$trialID)


### chking for pldate in files before removing the duplicates
ddcheck_pldate <- unique(subset(ddcheck, select=-c(plotID)))
ddcheck_pldate <- droplevels(ddcheck_pldate[!is.na(ddcheck_pldate$plantingDate), ])


pldate_missing<- dsY[dsY$trialID %in% unique(ddcheck_pldate$trialID) & is.na(dsY$plantingDate), ]
pldate_missing ## did not help anything

setwd("D:/ACAI_Wrapper/Rwanda")
write.csv(dsY, "NOT_Nov2020.csv")


str(dsY)
