source("bootstrap.R")
# connect to the sqlite file
sqlite <- dbDriver("SQLite")
LTDB <- dbConnect(sqlite,"LeanTaaSTestDB.db")
LT_table<-dbListTables(LTDB)
statement<-paste0("Select * from ",LT_table)
# get data in a dataframe
exchange_transc<-dbGetQuery(conn = LTDB,statement = statement)
dbDisconnect(LTDB)
# to analyze the file outside of tableau
#write.csv(exchange_transc,"exchange_transactions.csv")
exchange_transc$created_date<-as_date(exchange_transc$created_datetime)
exchange_transc$created_time<-substr(exchange_transc$created_datetime,12,19)
exchange_transc$snapshot_date<-as_date(exchange_transc$snapshot_date)
exchange_transc$start_time<-parse_hms(exchange_transc$start_time)
exchange_transc$end_time<-parse_hms(exchange_transc$end_time)
exchange_transc$created_time<-parse_hms(exchange_transc$created_time)
Following visualization would help us in giving an idea of how the exchange system is being used.
exchange_transc %>% group_by(action) %>% summarise(count=n()) %>% ggplot(.,mapping = aes(x=action,y=count,fill=action))+geom_bar(stat = 'identity')+theme(axis.text.x = element_text(angle = 90, hjust = 1))+geom_text(aes(label=count), position=position_dodge(width=0.9), vjust=-0.25)
kable(exchange_transc %>% filter(action %in% c('REQUEST','APPROVE_REQUEST','DENY_REQUEST')) %>% count(action),caption = "Breakdown for transactions of type Request",col.names = c('action','count'))
| action | count |
|---|---|
| APPROVE_REQUEST | 1139 |
| DENY_REQUEST | 174 |
| REQUEST | 1324 |
request_transactions<-exchange_transc %>% filter(action %in% c('REQUEST'))
getChildId<-function(parentid)
{
child_ids<-exchange_transc[exchange_transc$parent_transaction_id %in% parentid,]
child_ids<-child_ids %>% filter (action %in% c('APPROVE_REQUEST','DENY_REQUEST'))
parent_transaction<-request_transactions[request_transactions$transaction_id %in% parentid,]
time_to_resolve<-difftime(child_ids[,"created_date"],parent_transaction[,"created_date"])
return (time_to_resolve)
}
ttr<-unlist(lapply(request_transactions$transaction_id, getChildId))
The mean response rate to either deny or approve a REQUEST transaction is 0.46 days
transfer_transactions<-exchange_transc %>% filter(action %in% c('TRANSFER'))
get_tr_ChildId<-function(parentid)
{
child_ids<-exchange_transc[exchange_transc$parent_transaction_id %in% parentid,]
child_ids<-child_ids %>% filter (action %in% c('APPROVE_TRANSFER','DENY_TRANSFER'))
parent_transaction<-transfer_transactions[transfer_transactions$transaction_id %in% parentid,]
time_to_resolve<-difftime(child_ids[,"created_date"],parent_transaction[,"created_date"],units = "days")
return (time_to_resolve)
}
ttt<-unlist(lapply(transfer_transactions$transaction_id, get_tr_ChildId))
The mean response rate to either deny or approve a TRANSFER transaction is 0.29 days
release_transactions<-exchange_transc %>% filter(action %in% c('RELEASE'))
get_rs_ChildId<-function(parentid)
{
child_ids<-exchange_transc[exchange_transc$parent_transaction_id %in% parentid,]
child_ids<-child_ids %>% filter (action %in% c('MARK_UPDATED','DENY_RELEASE'))
parent_transaction<-release_transactions[release_transactions$transaction_id %in% parentid,]
time_to_resolve<-difftime(child_ids[,"created_date"],parent_transaction[,"created_date"],units = "days")
return (time_to_resolve)
}
trt<-unlist(lapply(release_transactions$transaction_id, get_rs_ChildId))
mean(trt)
## [1] 0.2790698
The mean response rate to either update a RELEASE transaction is 0.28 days
Request and Transfer transactions will be broken down in later sections of the report
Assumption: 1. Each location is not the same as every other location 2. Each room within a location is same as every other room
kable(unique(exchange_transc$location),col.names = 'location')
| location |
|---|
| CENTER |
| MRAH OR |
| VISION OR |
| MRH OR |
| MASC OR |
| CENTER PEDS |
| MSC OR |
kable(exchange_transc %>% group_by(location) %>% summarise(count=n()) %>% arrange(desc(count)))
| location | count |
|---|---|
| MRAH OR | 2205 |
| CENTER | 2055 |
| MSC OR | 870 |
| MASC OR | 657 |
| MRH OR | 549 |
| VISION OR | 535 |
| CENTER PEDS | 94 |
#kable(exchange_transc %>% group_by(location,room_name) %>% summarise(count=n()) %>% arrange(desc(count)))
exchange_transc %>% group_by(location) %>% filter(action %in% c('APPROVE_REQUEST','APPROVE_TRANSFER')) %>% summarise(count=n(),occupiedtime=mean(difftime(end_time,start_time,units = "hours"))) %>% mutate(occupiedtime=as.numeric(sprintf("%0.2f",occupiedtime)))%>% ggplot(.,mapping = aes(x=reorder(location,-occupiedtime),y=occupiedtime,fill=location))+
geom_bar(stat='identity')+xlab('location')+ylab('avg. occupied time (hrs)')+ geom_text(aes(label=occupiedtime), position=position_dodge(width=0.9), vjust=-0.25)
Occupied time shows the average utilization of these resources
exchange_transc %>% group_by(location) %>% filter(action %in% c('RELEASE')) %>% summarise(count=n(),releasetime=mean(difftime(end_time,start_time,units = "hours")))%>%
mutate(releasetime=as.numeric(sprintf("%0.2f",releasetime))) %>% ggplot(.,mapping = aes(x=reorder(location,-releasetime),y=releasetime,fill=location))+geom_bar(stat='identity')+xlab('location')+ylab('avg. release time (hrs)')+geom_text(aes(label=releasetime), position=position_dodge(width=0.9), vjust=-0.25)
getApprovalUsagePattern<-function(location)
{
filtered_locations<-exchange_transc[exchange_transc['location']==location,]
filtered_locations<-filtered_locations[filtered_locations['action']=='APPROVE_TRANSFER'|filtered_locations['action']=='APPROVE_REQUEST',]
plot(density(hour(filtered_locations[,'created_time'])),main = "Usage patterns for Approvals",xlim = c(0,24),xlab = "Hour")
}
getApprovalUsagePattern('CENTER')
getRequestUsagePattern<-function(location)
{
filtered_locations<-exchange_transc[exchange_transc['location']==location,]
filtered_locations<-filtered_locations[filtered_locations['action']=='REQUEST'|filtered_locations['action']=='TRANSFER',]
plot(density(hour(filtered_locations[,'created_time'])),main = "Usage patterns for Requests and Transfers",xlim = c(0,24),xlab = "Hour")
}
getRequestUsagePattern('CENTER')