This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCareem-case-study.Rmd
218 lines (175 loc) · 5.74 KB
/
Careem-case-study.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
---
title: "Careem Case Study"
author: "Anish Joni"
date: "December 12, 2018"
output:
flexdashboard::flex_dashboard:
vertical_layout: scroll
orientation: rows
runtime: shiny
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r Requred packages, include=FALSE}
library(tidyverse)
library(lubridate)
library(ggthemes)
library(viridis)
library(plotly)
library(digest)
library(htmlwidgets)
library(flexdashboard)
library(shiny)
library(DT)
library(devtools)
library(leaflet)
library(leaflet)
library(rgeos)
library(htmltools)
require(rgdal)
```
### Careem Food KPIs Overview
```{r Generate dataset, include=FALSE}
###################
# Data Generation #
###################
# Delivery Table
set.seed(2);
order_daterange <- seq(as.POSIXlt("2018-08-01"),as.POSIXlt("2018-12-01"), by = "days")
order_range_high <- seq(as.POSIXlt("2018-08-01"),as.POSIXlt("2018-08-17"), by = "days")
order_range_normal <- seq(as.POSIXlt("2018-08-17"),as.POSIXlt("2018-11-03"), by = "days")
order_range_low <- seq(as.POSIXlt("2018-11-04"),as.POSIXlt("2018-12-01"), by = "days")
order_datetime_high <- sample(order_range_high, size = 250, replace = TRUE)
order_datetime_normal <- sample(order_range_normal, size = 650, replace = TRUE)
order_datetime_low <- sample(order_range_low, size = 100, replace = TRUE)
order_datetime <- c(order_datetime_high, order_datetime_normal, order_datetime_low)
#order_datetime <- sample(order_daterange, size = 1000, replace = TRUE)
order_id <- sample(230:1500, size = length(order_datetime), replace = TRUE)
store_name = sample(c("McDonald's", "KFC", "Didi Burger", "Broccoli Pizza", "Dipndip", "Doce"), size = length(order_datetime), replace = TRUE)
store_id = sample(23:150, size = length(order_datetime), replace = TRUE)
destination = paste0("Neighbourhood ",sample( LETTERS[seq( from = 1, to = 12 )],length(order_datetime),rep=T))
delivery_time <- order_datetime + sample(1200:3600, size = length(order_datetime), rep = T)
travel_time = round(difftime(delivery_time, order_datetime), 2)
delivery_df <- tibble(store_id, store_name, order_datetime, order_id, destination, delivery_time, travel_time) %>%
mutate(order_day = wday(order_datetime, label = T))
# Orders Table
```
```{r EDA & Plots, echo=FALSE}
orders_by_day <- delivery_df %>%
group_by(order_day) %>%
count() %>%
ggplot(aes(order_day, n)) +
geom_bar(stat = "identity") +
scale_fill_viridis(option = "viridis") +
theme_fivethirtyeight() +
labs(title = "Orders by day of the week ", subtitle = 'Between Aug 1st and Dec 1st, 2018', caption = "Careem case study", y = 'Orders') +
theme(legend.position = "none", axis.title = element_text(), axis.title.x = element_blank())
#ggplotly(orders_by_day)
order_trends<- delivery_df %>%
group_by(order_datetime) %>%
select(order_datetime) %>%
count() %>%
ggplot(aes(order_datetime, n)) +
geom_line() +
geom_smooth() +
scale_fill_viridis(option = "viridis") +
theme_fivethirtyeight() +
labs(title = "Trends in orders over time ", subtitle = 'Between Aug 1st and Dec 1st, 2018', caption = "Careem case study", y = '# Orders') +
theme(legend.position = "none", axis.title = element_text(), axis.title.x = element_blank())
#ggplotly(order_trends)
```
Dashboard
=======================================================================
<!-- Column {.sidebar} -->
<!-- ----------------------------------------------------------------------- -->
<!-- ```{r} -->
<!-- ``` -->
Row
-------------------------------------
### Total Orders served {.value-box}
```{r}
orderCount <- 24 #Dummy
renderValueBox({
valueBox(orderCount)
})
```
### Growth rate from last month {.value-box}
```{r}
rate <- "4%" #Dummy
renderValueBox({
valueBox(rate)
})
```
### Average delivery time {.value-box}
```{r}
deliverTime <- 32 #Dummy
renderValueBox({
valueBox(deliverTime)
})
```
### Change of Avg.Delivery time from last month {.value-box}
```{r}
Deliveryrate <- "+12 Mins" #Dummy
renderValueBox({
valueBox(Deliveryrate,color="red")
})
```
Row
-------------------------------------
### Order trend over time
```{r Trends plot, echo=FALSE}
ggplotly(order_trends)
```
Row
-------------------------------------
### Top performing locations
```{r Top performing locations, echo=FALSE}
delivery_df %>%
select(destination) %>%
group_by(destination) %>%
count() %>%
arrange(desc(n)) %>%
datatable(options = list(lengthMenu = c(5, 10, 15, 20)))
```
### Least performing locations
```{r Least performing, echo=FALSE}
delivery_df %>%
select(destination) %>%
group_by(destination) %>%
count() %>%
arrange(n) %>%
datatable(options = list(lengthMenu = c(5, 10, 15, 20)))
```
Row
-------------------------------------
```{r Geo plots, eval=FALSE, include=FALSE}
m <- leaflet() %>% addTiles()
m <- m %>%
setView(46.62, 24.59, 5) %>% # map location
addMarkers(46.52, 24.6) %>% # add a marker
#addPopups(46.72, 24.58, popup = "Hello Careem!") %>% # popup
# add som circles:
addCircles(color = "black", runif(90, -2, -1), runif(90, 53, 54), runif(90, 10, 500))
setwd("~/GitHub/Careem-case-study/SAU_adm")
SAU_adm <- read_csv("SAU_adm1.csv")
shape <- readOGR(dsn = ".", layer = "SAU_adm1")
pizza <- read_csv("~/GitHub/Careem-case-study/pizza.csv")
leaflet() %>%
# base map
addProviderTiles("Hydda.Base") %>%
addPolygons(data=shape,
stroke=TRUE, color="white", weight=1, opacity=1,
fill=TRUE, fillColor="#cccccc", smoothFactor=0.5)
m %>%
# add pizza layer
addCircles(data=pizza,
lng=~Longitude, lat=~Latitude,
radius=10, # size is in m for addCircles O_o
color="white", weight=1, opacity=1,
fillColor="steelblue", fillOpacity=1)
pizza <- pizza %>%
mutate(size = sample(25:45, nrow(pizza)))
```