Overview

Row

Introduction

To become more productive in my life and to improve my work-life balance, I started to track my time spending since July 2022 via Atracker on my phone. ATracker is a time tracking application that allows you to export your time spending history data in CSV format.

Note

  • Night sleep time was not recorded via the app.
  • Date range analyzed was from 7/15/2022 to 11/15/2022

Questions

In this dashboard, I’ll use visualizations to answer the following questions:

  1. If I divide my life into multiple modules, how much time I spent on each category overall?

  2. What is my average weekly working hours? How does that vary from day of the week?

  3. How I typically spent my weekend?

  4. How much time I spent every day on work/study/entertainment?

  5. What’s the relationship among the 3 modules?

Data Pre-processing

The exported data is in the task-level detail where it shows when a task starts and ends. To answer my questions, I need to

  1. clean up the start and end time for each of the task and convert them to date format.

  2. aggregate the data by grouping the tasks and date and then sum the time duration.

Total

Column

Overall Time Spent Distribution

Working Hours

Column

Average weekly working hours

Working hours by day of the week

Weekend Analysis

column 2

Top 10 Activities I Did on Weekend

Daily Analysis

column

Daily Time Spending on work/study/entertainment

Relationship Among Work, Study, and Entertainment

Relationship Between Study and Entertainment

---
title: "Dashboard | Time Spent Analysis"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    social: menu
    source: embed
    navbar:
      - { title: "Author: Bingqing Li" , href: "https://www.linkedin.com/in/bingqing-li/", align: right }
---


```{r setup, include=FALSE, source_code = TRUE}
library(flexdashboard)
library(dplyr)
library(ggplot2)
library(readxl)
library(tidyverse)
library(lubridate)
library(knitr)
library(dygraphs)
library(xts)
library(tidyr)
library(forcats) 
```

**Overview** {data-orientation=rows}
=====================================     

Row 
-------------------------------------
    
### **Introduction** 

To become more productive in my life and to improve my work-life balance, I started to track my time spending since July 2022 via Atracker on my phone. ATracker is a time tracking application that allows you to export your time spending history data in CSV format.    

**Note**  

* Night sleep time was not recorded via the app.
* Date range analyzed was from 7/15/2022 to 11/15/2022


### **Questions** 

In this dashboard, I'll use visualizations to answer the following questions:

1. If I divide my life into multiple modules, how much time I spent on each category overall?  

2. What is my average weekly working hours? How does that vary from day of the week?  

3. How I typically spent my weekend?   

4. How much time I spent every day on work/study/entertainment?  

5. What's the relationship among the 3 modules?


### **Data Pre-processing**

The exported data is in the task-level detail where it shows when a task starts and ends. To answer my questions, I need to  

1. clean up the start and end time for each of the task and convert them to date format.  

2. aggregate the data by grouping the tasks and date and then sum the time duration. 


**Total** {data-orientation=rows}
===================================== 
## {.sidebar data-width=400}

**Summary**  

* Work took almost half of my awake life time. The time I spent on Entertainment (mostly social media and TVs) is almost the same as that on Study.

* Eating is another big part of my life, which accounts for 14% of the total. As a foodie, I can hardly see how that could change (like reducing the time for eating, especially when I have already not cooked very often).  

* I should've spent more time on exercise. The ideal case is to increase it to 5%.


Column 
-----------------------------------------------------------------------
### **Overall Time Spent Distribution**

```{r}
data <- read.csv('TaskDetails_Atracker_H22022.csv')

data$StartDate <- as.Date(data$Start.time, format='%b %d, %Y at %I:%M:%S %p') 
data$DayofWeek <- wday(data$StartDate, label = TRUE, abbr = TRUE)
data <- data %>%
  mutate(day_type = ifelse(DayofWeek %in% c("Sat", "Sun"), "Weekend","Weekday"))

# let me filter the date from 7/15 to 11/15
data <- data[data$StartDate > "2022-07-14" &    # Extract data frame subset
                   data$StartDate < "2022-11-16", ]


# Overall Time Spent Distribution
data_with_tag <- data %>%
  filter(Tag != "") %>%
  select(c('Tag','StartDate','Duration.in.hours')) 
tag_agg_overall <- data_with_tag %>%
  group_by(Tag) %>%
  summarise(TotalDuration = sum(Duration.in.hours))

# Compute the position of labels
pie_data <- tag_agg_overall %>% 
  arrange(desc(TotalDuration)) %>%
  mutate(prop = TotalDuration / sum(tag_agg_overall$TotalDuration) *100) %>%
  mutate(ypos = cumsum(prop)- 0.5*prop )

# pie chart
ggplot(pie_data, aes(x="", y=prop, fill=reorder(Tag,TotalDuration))) +
  geom_col(width = 1, color = "white") +
  geom_text(aes(y = ypos, label = paste0(round(prop), "%")), colour = "black",size = 4) +
  coord_polar("y", start=0) +
  theme_void() + 
  guides(fill = guide_legend(title = "Life Module", reverse = TRUE)) +
  ggtitle('') + 
  scale_fill_brewer(palette="Set3") 

```


**Working Hours** {data-orientation=rows}
===================================== 
## {.sidebar data-width=400}

**Summary**  

* The week of 8/14 went a bit crazy that I worked ~65 hours in that week. Looking back at my work notes, it turned out to be a week when I dived deep in some of our data issues. I spent extra time understanding the data pipeline, why misalignment happened, and trying to figure out how to fix them or who to reach for help.

* The valley in the week of 8/28 is due to PTO.

* But in most of the weeks, I worked longer than I expected. To have a better work-life balance, I should remind myself to work smart and better manage leaders' expectations. We can already see some progress from the chart where it shows a trend of decreasing working hours starting from late September. A new hire onboarding that time also helped.

* I constraint myself from working overtime on Tuesday because I have 2 classes that night. Friday usually was lighter than other weekdays.

Column {.tabset}
-------------------------------------
### **Average weekly working hours**
```{r}
# group by week
# order.by requires an appropriate time-based object
# rounds the date down to the “start” of the week
weekly_wh <- data %>%
  filter(Tag == "Work") %>%
  # focus on full weeks
  filter(StartDate > "2022-07-16" & StartDate < "2022-11-13") %>% 
 mutate(week_start = floor_date(   # make new column, week of StartDate
    StartDate,
    unit = "week")) %>% 
  group_by(week_start) %>%
  summarize(working_hours = sum(Duration.in.hours))

dygraph(xts(weekly_wh[, -1], order.by=weekly_wh$week_start), main = '') %>% 
dyAxis("y", label="Weekly Working Hours") %>%
dyLegend(show = "always", hideOnMouseOut = FALSE) %>%
dyOptions(axisLineWidth = 2.0) %>%
dyHighlight(highlightSeriesBackgroundAlpha = 1.0,
            highlightSeriesOpts = list(strokeWidth = 3)) %>%
dyAxis("x", drawGrid = FALSE) 
```


### **Working hours by day of the week**
```{r} 

work_dow <- data %>%
  filter(Tag == "Work") %>%
  filter(StartDate > "2022-07-16" & StartDate < "2022-11-13") %>% 
  group_by(StartDate,DayofWeek) %>%
  summarize(daily_working_hours = sum(Duration.in.hours)) %>%
  group_by(DayofWeek) %>%
  summarize(avg_working_hours = mean(daily_working_hours))
  
# bar chart
ggplot(work_dow,aes(x=reorder(DayofWeek,DayofWeek),y=avg_working_hours)) +
  geom_bar(stat = "identity") +
  geom_text(aes(label = round(avg_working_hours,2)), vjust = 1.5, colour = "white") +
  labs(title="", x = '', y="Average Working Hours") +
  theme_bw() + 
  theme(legend.position = 'none')
```



**Weekend Analysis**
===================================== 
## {.sidebar data-width=400}

**Summary**  

* I spent on average more than 12 hours on weekends studying, trying to finish school assignments. I also write articles in Data Analysis and published them on social media. That's why I have to spend more time studying.  

* I wish though I could finish my homework more efficiently and have more outdoor time and read more books. They'll be the New Year Resolutions.


column 2
-------------------------------------------------------
### **Top 10 Activities I Did on Weekend**

```{r}
data$week_num <- strftime(data$StartDate, format = "%V")
wkn <- data %>%
  filter(DayofWeek %in% c("Sat", "Sun")) %>%
  # focus on full weeks
  filter(StartDate > "2022-07-16" & StartDate < "2022-11-13") %>% 
  group_by(Task.name,week_num) %>%
  summarize(wkn_hours = sum(Duration.in.hours)) %>%
  group_by(Task.name) %>%
  summarize(avg_wkn_hours = mean(wkn_hours)) %>%
  slice_max(avg_wkn_hours, n=10)

# bar chart
ggplot(wkn,aes(x=reorder(stringr::str_wrap(Task.name, 15),-avg_wkn_hours),y=avg_wkn_hours)) +
  geom_bar(stat = "identity") +
  geom_text(aes(label = round(avg_wkn_hours,2)), vjust = 1.5, colour = "white") +
  labs(title="", x = '', y="Average Weekend Hours") +
  theme_bw() + 
  theme(legend.position = 'none')

```

**Daily Analysis**
===================================== 
## {.sidebar data-width=400}

**Summary**  

* From the step plot, I find that my learning habit changed from few days with long hours to shorter hours but in multiple days, which seems to be a healthier study schedule.  

* I gave myself a lot of time on entertainment in September, because of the hard work before when I felt stressed.  

* From the scatter plot, I find that the longer the working hours are, the less time for study and entertainment. Excluding days I don't study or entertain, time spent on Entertainment follows a positive relationship with that on Study.


column {.tabset}
-------------------------------------------------------

### Daily Time Spending on work/study/entertainment

```{r}
# want to see if I spent more time on study overtime
data_with_tag <- data %>%
  filter(Tag == c("Entertainment ",'Work','Study ')) %>%
  select(c('Tag','StartDate','Duration.in.hours')) %>%
  group_by(Tag,StartDate) %>%
  summarise(DailyDuration = round(sum(Duration.in.hours),2)) %>%
# Tag has to be in columns for dygraph
  pivot_wider(names_from = Tag, values_from = DailyDuration) 
# Need to fill NA with 0
data_with_tag[is.na(data_with_tag)] <- 0

dygraph(xts(data_with_tag[, -c(1)], order.by=data_with_tag$StartDate), main = '') %>% 
dyAxis("y", label = "Hours") %>%
dyLegend(show = "always", hideOnMouseOut = FALSE, width = 600) %>%
dyOptions( stepPlot = TRUE, axisLineWidth = 2.0,  colors = c("#d8a203", "#ff6775",'#005b96','#556a0c ') ) %>% 
dyHighlight(highlightSeriesBackgroundAlpha = 1.0,
            highlightSeriesOpts = list(strokeWidth = 3)) %>%
dyAxis("x", drawGrid = FALSE) %>%
dyAxis("y", drawGrid = FALSE) 

```

### Relationship Among Work, Study, and Entertainment
```{r}
# interactive scatter plot
library(plotly)
library(gapminder)

p1 <- data_with_tag %>%
  ggplot( aes(Work, `Study `, size = `Entertainment `)) + #, color=continent
  geom_point() +
  theme_bw()

ggplotly(p1)
```

### Relationship Between Study and Entertainment
```{r}
p2 <- data_with_tag %>%
  ggplot( aes(`Study `, `Entertainment `, size = Work)) +
  geom_point() +
  theme_bw()

ggplotly(p2)
```