library(tidyverse)
count_data_fp <-"/mmfs1/gscratch/comdata/users/mjilg/mw-repo-lifecycles/case1/event_0216_ve_gerrit_count.csv"
input_df <- read.csv(count_data_fp, header = TRUE) 


#window_num <- 19
window_num <- 26
input_df <- input_df |>
  filter(relative_week >= (- window_num) & relative_week <= (window_num)) |>
  mutate(parent_projects = project)

library(scales)
library(ggplot2)

time_plot <- input_df |>
  ggplot(aes(x=relative_week, y=task_count, color=parent_projects)) +
  labs(x="Weekly Offset", y="New Gerrit Tasks Created", color = "Project") +
  geom_smooth() +
  geom_point() +
  geom_vline(xintercept = 0)+
  theme_bw() +
  theme(legend.position = "top")
time_plot


abandoned_df <- input_df |>
  filter(status == "ABANDONED")
time_plot <- abandoned_df |>
  ggplot(aes(x=relative_week, y=task_count, color=parent_projects)) +
  labs(x="Weekly Offset", y="AbandonedGerrit Tasks Created", color = "Project") +
  geom_smooth() +
  geom_point() +
  geom_vline(xintercept = 0)+
  theme_bw() +
  theme(legend.position = "top")
time_plot


delta_df <- input_df |>
  filter(task_count != 0) |>
  filter(relative_week >= (- 12)) |> 
  filter(status != "ABANDONED")
time_plot <- delta_df |>
  ggplot(aes(x=relative_week, y=avg_resolution_time, color=parent_projects)) +
  labs(x="Weekly Offset", y="Avg. (weekly) Time from task creation to last update (days)", color = "Project") +
  geom_line() +
  geom_vline(xintercept = 0)+
  theme_bw() +
  theme(legend.position = "top")
time_plot


loc_df <- input_df |>
  filter(relative_week >= (- 19) & relative_week <= (19)) |>
  filter(task_count != 0) |>
  filter(status != "ABANDONED")
time_plot <- loc_df |>
  ggplot(aes(x=relative_week, y=avg_insertions, color=parent_projects)) +
  labs(x="Weekly Offset", y="Avg. LOC Inserted per Accepted Gerrit Task", color = "Project") +
  geom_line() +
  geom_vline(xintercept = 0)+
  theme_bw() +
  theme(legend.position = "top")
time_plot
