---
title: "Programation Audiomoth"
author: "Simon"
date: "3/29/2022"
output:
  html_document:
    df_print: paged
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE, echo = FALSE, prompt = FALSE, cache = FALSE)
```

# Aide à la programmation des Audiomoth :

```{r}
# outil pour importer les informations sur les participants à Vigie-Chiro et programmer les audiomoth

library(kableExtra)
library(tidygeocoder)
library(tidyverse)
library(lubridate)
library(suncalc)
library(DT)


participants <- data.table::fread("~/Documents/vigie-chiro/participation_printemps_2022/vigie_chiro.csv")

# get location
address_single <- tibble(singlelineaddress = participants$`adresse geocode`)

# calculate long lat
result_long_lat <- address_single %>%
  geocode(address = singlelineaddress, method = "osm", verbose = TRUE)%>%
  rename(lon = long)

result_long_lat$date <- dmy(participants$date)


# get sunset_sunrise
df <-getSunlightTimes(
  #date = as.Date("2022-03-28"),
  keep = c("sunrise", "sunset"),
  data = result_long_lat,
  #lat = result_long_lat$lat,
  #lon = result_long_lat$long,
  tz = "CET"
)
```

```{r}

# add security time
df$debut = format(df$sunset - 30 * 60, "%H:%M")
df$fin   = format(df$sunrise + 30 * 60, "%H:%M")

df$date = format(df$date, "%d/%m/%Y")
df$nom <- participants$nom
df$`adresse envoi` <- str_replace_all(participants$`adresse envoi`, ", ", "<br/>")

df %>%
  select(nom, date, debut, fin, `adresse envoi`) %>%
  DT::datatable(escape = FALSE)
```
