Skip to content

Commit

Permalink
Fix #59
Browse files Browse the repository at this point in the history
  • Loading branch information
Bosse Nyström committed Nov 19, 2021
1 parent 2d57013 commit e94a8a7
Show file tree
Hide file tree
Showing 5 changed files with 447 additions and 96 deletions.
16 changes: 16 additions & 0 deletions arbetsdag.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
workingdays <- function(begins, ends, key) {
result <- c()
for (i in seq(length.out=length(begins))) {
# working days
WD_URL = "http://api.arbetsdag.se/v2/dagar.json"
WD_QUERY = paste0("?fran=", as.Date(begins[i]),
"&till=", as.Date(ends[i]),
"&key=", key,
"&id=1234")
url = paste0(WD_URL, WD_QUERY)

WD <- fromJSON(url)
result[i] <- WD$antal_vardagar
}
return(result)
}
11 changes: 7 additions & 4 deletions data-helpers.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# A set of generic functions that operate on the "aggregated" data
# to produce data formatted for the plots

# get workingdays
source("arbetsdag.R")

gen.user.data <- function(data, id) {
user.data <- subset(data, team == id) %>%
group_by(date, user, key) %>%
Expand Down Expand Up @@ -58,7 +61,7 @@ gen.team.summary <- function(summary) {
return(team.summary)
}

gen.user.delta <- function(data, id) {
gen.user.delta <- function(data, id, daily.hours, api.key) {
user.delta <- subset(data, team == id) %>%
group_by(user) %>%
summarise(
Expand All @@ -68,8 +71,8 @@ gen.user.delta <- function(data, id) {
billable = sum(billable)
)

if (! is.null(working.hours)) {
user.delta <- merge(user.delta, working.hours, by = "user")
if (! is.null(daily.hours)) {
user.delta <- merge(user.delta, daily.hours, by = "user")
} else {
if (TEMPO_DAILY == '') {
TEMPO_DAILY = 8
Expand All @@ -83,7 +86,7 @@ gen.user.delta <- function(data, id) {
user.delta <- user.delta %>%
group_by(user) %>%
mutate(
expected = daily * workingdays(start, end),
expected = daily * workingdays(start, end, api.key),
delta = hours - expected,
fraction = 100 * billable / expected
)
Expand Down
146 changes: 146 additions & 0 deletions ggplot-helpers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# ggplot-helpers

tempo.daily.plot <- function(data, id) {
# returns
# a column plot with the daily logs for each
# user in the team, colors follow the project keys
#
# data is the aggregated data for all teams
# id is the team.id for one team
#
plot <- ggplot(data = subset(data, team == id)) +
geom_col(aes(x = date, y = hours, fill = key)) +
facet_wrap(~user) + scale_fill_hue(l = 45) +
scale_y_continuous(
breaks = c(0,2,4,6,8,10),
name = "Daily",
sec.axis = dup_axis()) +
scale_x_date(name = NULL) +
theme(legend.position = "top",
axis.text.x = element_text(size = 6, angle = 45, hjust = 1)) +
ggtitle("Daily logs")

return(plot)
}

tempo.detailed.plot <- function(data, id) {
# returns
# a detailed column plot with the daily logs for each
# user in the team, colors follow the project tasks
# limited to the last 14 days
#
# data is the aggregated data for all teams
# id is the team.id for one team
#
plot <- ggplot(data = subset(data, team == id)) +
geom_col(aes(x = date, y = hours, fill = issue.key), show.legend = FALSE) +
facet_wrap(~user) + scale_fill_hue(l = 45) +
scale_y_continuous(
breaks = c(0,2,4,6,8,10),
name = "Daily",
sec.axis = dup_axis()) +
scale_x_date(name = NULL) +
theme(legend.position = "top",
axis.text.x = element_text(size = 6, angle = 45, hjust = 1)) +
coord_cartesian(xlim = c(Sys.Date() - 14, Sys.Date())) +
ggtitle("Detailed logs, last 14 days")

return(plot)
}

tempo.billable.plot <- function(data) {
# returns a scatter plot of the billable tasks
#
# data is user.detail
#
plot <- ggplot(data = subset(data, billable > 0)) +
geom_point(aes(x = reorder(issue.key, -hours),
y = hours,
color = issue.key,
fill = issue.key), show.legend = FALSE) +
facet_wrap(~user) + scale_fill_hue(l = 45) +
scale_x_discrete(name = NULL) +
scale_y_log10(
name = "Logged hours [h]",
sec.axis = dup_axis()) +
theme(legend.position = "top",
legend.title = element_blank(),
axis.text.x = element_text(size = 6, angle = 45, hjust = 1)) +
ggtitle("Billable tasks")

return(plot)
}

tempo.unbillable.plot <- function(data) {
# returns a detailed scatter plot for the unbillable tasks
#
#
plot <- ggplot(data = subset(data, billable == 0)) +
geom_point(aes(x = reorder(issue.key, -hours),
y = hours,
color = issue.key,
fill = issue.key), show.legend = FALSE) +
facet_wrap(~user) + scale_fill_hue(l = 45) +
scale_x_discrete(name = NULL) +
scale_y_log10(
name = "Logged hours [h]",
sec.axis = dup_axis()) +
theme(legend.position = "top",
axis.text.x = element_text(size = 6, angle = 45, hjust = 1)) +
ggtitle("Unbillable tasks")

return(plot)
}

team.plot <- function(data) {
plot <- ggplot(data = data) +
geom_point(aes(x = date, y = average.7.hours), color = "Gray50", shape = 1) +
geom_point(aes(x = date, y = average.30.hours), color = "Dark Blue") +
geom_smooth(aes(x = date, y = average.30.hours), color = "Dark Blue") +
geom_point(aes(x = date, y = average.7.billable), color = "Gray75", shape = 1) +
geom_point(aes(x = date, y = average.30.billable), color = "Dark Green") +
geom_smooth(aes(x = date, y = average.30.billable), color = "Dark Green") +
scale_color_hue(l = 45) + scale_fill_hue(l = 45) +
scale_y_continuous(
breaks = c(0,8,16,24,32,40, 48,56),
name = "Weekly",
sec.axis = dup_axis()) +
scale_x_date(name = NULL) +
theme(legend.position = "top",
legend.title = element_blank(),
axis.text.x = element_text(size = 6, angle = 45, hjust = 1))

return(plot)
}

rolling.plot <- function(data) {
plot <- ggplot(data = data) +
geom_point(aes(x = date, y = roll.7.hours), color = "Gray50", shape = 1) +
geom_point(aes(x = date, y = roll.7.billable), color = "Gray75", shape = 1) +
geom_point(aes(x = date, y = roll.30.hours), color = "Dark Blue") +
geom_line(aes(x = date, y = roll.30.hours), color = "Dark Blue") +
geom_point(aes(x = date, y = roll.30.billable), color = "Dark Green") +
geom_line(aes(x = date, y = roll.30.billable), color = "Dark Green") +
facet_wrap(~user) + scale_fill_hue(l = 45) + scale_color_hue(l = 45) +
scale_y_continuous(
breaks = c(0,8,16,24,32,40, 48),
name = "Rolling Weekly [h]",
sec.axis = dup_axis()) +
scale_x_date(name = NULL) +
theme(legend.position = "top", legend.title = element_blank(),
axis.text.x = element_text(size = 6, angle = 45, hjust = 1))

return(plot)
}

accumulated.plot <- function(data) {
plot <- ggplot(data = data) +
geom_col(aes(x = user, y = delta, fill = user), show.legend = FALSE) +
scale_fill_hue(l = 45) +
scale_x_discrete(name = NULL) +
scale_y_continuous(
name = "Delta hours [h]",
sec.axis = dup_axis())

return(plot)
}
Loading

0 comments on commit e94a8a7

Please sign in to comment.