---
title: "episomer Dashboard"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: pdf_document
classoption: landscape
params:
  topics: ["COVID-19"]
  countries: ["1", "2"]
  period_type: "created_date"
  period: ["2020-01-01", "2020-03-31"]
  with_quotes: FALSE
  location_type: "post"
  alert_alpha: 0.025
  alert_alpha_outlier: 0.05
  alert_k_decay: 4
  alert_historic: 7
  bonferroni_correction: FALSE
  same_weekday_baseline: FALSE
  top_type1: "hastags"
  top_type2: "urls"
---

```{r include=FALSE}
regions <- get_country_items()
countries <- Reduce(function(l1, l2) {
  unique(c(l1, l2))
}, lapply(as.integer(params$countries), function(i) unlist(regions[[i]]$codes)))
region_names <- lapply(as.integer(params$countries), function(i) regions[[i]]$name)
```

# episomer dashboard
Parameters

* Topics: `r params$topics`
* Regions: `r region_names`
* Period type: `r params$period_type`
* Period: `r params$period`
* With quotes: `r params$with_quotes`
* Location Type: `r params$location_type`
* Signal detection confidence (alpha): `r as.character(params$alert_alpha)`
* Outliers detection confidence (alpha-outlier): `r as.character(params$alert_alpha_outlier)`
* Outliers downweighting strength (k-decay): `r as.character(params$alert_k_decay)`
* Days in baseline: `r params$alert_historic`
* Boferroni correction: `r params$bonferroni_correction`
* Same weekday baseline: `r params$same_weekday_baseline`

## Line chart
```{r, echo = FALSE, message=FALSE, warning=FALSE}
line_chart_from_filters(
  params$topics,
  params$countries,
  params$period_type,
  params$period,
  params$with_quotes,
  params$location_type,
  params$alert_alpha,
  params$alert_alpha_outlier,
  params$alert_k_decay,
  params$alert_historic,
  params$bonferroni_correction,
  params$same_weekday_baseline
)$chart
```

## Map
```{r, echo = FALSE, message=FALSE, warning=FALSE}
map_chart_from_filters(
  params$topics,
  params$countries,
  params$period,
  params$with_quotes,
  params$location_type
)$chart
```

## Top `r params$top_type1 ` chart
```{r, echo = FALSE, message=FALSE, warning=FALSE}
top_chart_from_filters(
  params$topics,
  params$top_type1,
  params$countries,
  params$period,
  params$with_quotes,
  params$location_type,
  20
)$chart
```

## Top `r params$top_type2 ` chart
```{r, echo = FALSE, message=FALSE, warning=FALSE}
top_chart_from_filters(
  params$topics,
  params$top_type2,
  params$countries,
  params$period,
  params$with_quotes,
  params$location_type,
  20
)$chart
```

## Top URLS 

### `r paste("Top URLS of posts mentioning", params$topic, "from", params$periond[[1]], "to", params$period[[2]])`

```{r, echo = FALSE, message=FALSE, warning=FALSE}
df <- top_chart_from_filters(
  params$topics,
  "urls",
  params$countries,
  params$period,
  params$with_quotes,
  params$location_type,
  50
)$data
if (is.data.frame(df)) {
  knitr::kable(df)
} else {
  "No data found for the selected filters"
}
```
Top urls table only considers post location, ignoring the location type parameter



`r ""`
