---
title: "Static Network Experiment"
output: html_notebook
---

```{r}
library(tidyverse)
```

```{r}
deluge <- read_csv(
  './10-nodes-10-reps-4-seeders-2-seeder-sets-100MB.csv', 
  col_names = c('node', 'metric', 'timestamp', 'dataset', 'piece'),
  show_col_types = FALSE
) |>
  mutate(
    temp = str_remove(dataset, "<unknown>,dataset-"),
    seed_set = as.numeric(str_extract(temp, "^\\d+")),
    run = as.numeric(str_extract(temp, "\\d+$"))
  ) |>
  select(-temp)
```


```{r}
deluge <- deluge |> 
  group_by(node, seed_set, run) |>
  arrange(timestamp) |>
  mutate(
    piece_index = seq_along(timestamp)
  ) |>
  ungroup() |>
  mutate(completed = piece_index / max(piece))
``` 

```{r}
# Adds elapsed time
deluge <- deluge |>
  group_by(dataset) |>
  mutate(
    start_time = min(timestamp),
    end_time = max(timestamp)
  ) |> 
  ungroup() |>
  mutate(elapsed = timestamp - start_time)
```

```{r}
deluge |> head()
```

```{r}
deluge |> 
  group_by(node, seed_set, run) |> 
  count() |> 
  ungroup() |> 
  filter(n != 400)
```

```{r fig.width=10}
ggplot(deluge |> ungroup()) +
  geom_line(aes(x=elapsed, y=completed, col=node), lwd=1) + 
  theme_minimal() +
  facet_wrap(. ~ dataset, nrow = 4)
```

Averages the time to the $n^{th}$ piece index, over all runs for a given seed set:

```{r}
deluge_averaged <- deluge |> 
  group_by(node, seed_set, piece_index) |>
  summarise(elapsed=mean(elapsed), .groups = 'drop')
```

```{r fig.width=10, fig.height=5}
ggplot(deluge_averaged) +
  geom_line(aes(x = elapsed, y = piece_index, col = node), lwd=1) +
  facet_wrap(. ~ seed_set) +
  theme_minimal()
```


