You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					188 lines
				
				5.1 KiB
			
		
		
			
		
	
	
					188 lines
				
				5.1 KiB
			| 
											3 years ago
										 | 
 | ||
|  | # Functions | ||
|  | 
 | ||
|  | rxl <- function(path, ...) { | ||
|  |   tryCatch( | ||
|  |     read_excel(path, ...), | ||
|  |     error = function(c) { | ||
|  |       c$message <- "No Data" | ||
|  |       print("No Data") | ||
|  |       stop(c) | ||
|  |     } | ||
|  |   ) | ||
|  | } | ||
|  | 
 | ||
|  | ltodf <- function(path, ...) { | ||
|  |   tryCatch( | ||
|  |     rbind.data.frame(path, ...), | ||
|  |     error = function(c) { | ||
|  |       c$message <- "No Data" | ||
|  |       print("No Data") | ||
|  |       stop(c) | ||
|  |     } | ||
|  |   ) | ||
|  | } | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | # Data import | ||
|  | 
 | ||
|  | contactinputpath <- | ||
|  |   list.files("./contacts/raw-data", | ||
|  |              pattern = "*.xlsx", | ||
|  |              full.names = T) | ||
|  | accountinputpath <- | ||
|  |   list.files("./accounts/raw-data", | ||
|  |              pattern = "*.xlsx", | ||
|  |              full.names = T) | ||
|  | projectinputpath <- | ||
|  |   list.files("./projects/raw-data", | ||
|  |              pattern = "*.xlsx", | ||
|  |              full.names = T) | ||
|  | 
 | ||
|  | 
 | ||
|  | # Operations on Data and creation of other data | ||
|  | 
 | ||
|  | # S4HANA Sales with integration to C4 Quote configuration and integration process. Support controlling and project team towards impletation and go live. | ||
|  | # Little bit knowledge with Finance and SAP implementation. Data migration, testing, Go live.... () | ||
|  | # BAM  of S4 HANA, support key users with data migration, testing, training (On Site) | ||
|  | 
 | ||
|  | rawformat<- function(inputpath, inputdata="Contact", pathname="./contacts/raw-data/"){ | ||
|  |   conta <- lapply(inputpath, read_excel) | ||
|  |   names(conta) <- gsub(pathname, "", inputpath) | ||
|  |   c <- lapply(conta, nrow) | ||
|  |   Input_data <- inputdata | ||
|  |   #Country<-gsub(".xlsx","",names(conta)) | ||
|  |   Observations <- c | ||
|  |    | ||
|  |   temp <- data.frame(Input_data, Observations) |> | ||
|  |     pivot_longer(cols = (-1), | ||
|  |                  names_to = "Country", | ||
|  |                  values_to = "Observations") |> | ||
|  |     mutate(Country = gsub(".xlsx", "", Country)) | ||
|  |    | ||
|  |   return(temp) | ||
|  | } | ||
|  | 
 | ||
|  | input.summary<- | ||
|  |   rbind( | ||
|  |   rawformat(inputpath=contactinputpath, inputdata="Contacts",pathname="./contacts/raw-data/"), | ||
|  |   rawformat(inputpath=accountinputpath, inputdata="Accounts", pathname="./accounts/raw-data/"), | ||
|  |   rawformat(inputpath=projectinputpath, inputdata="Projects", pathname="./projects/raw-data/") | ||
|  | ) |> arrange(desc(Observations)) | ||
|  | 
 | ||
|  | input.summary.summ <- input.summary |> | ||
|  |   group_by(Input_data) |> | ||
|  |   summarise(Observations = sum(Observations)) |> | ||
|  |   arrange(desc(Observations)) | ||
|  | 
 | ||
|  | 
 | ||
|  | # Contacts | ||
|  | 
 | ||
|  | 
 | ||
|  | error.function<- function(filepath="./contacts/summary", filename="Error_Contact", country){ | ||
|  |   errfilepath <- | ||
|  |     list.files(filepath, | ||
|  |                pattern = "*_error.csv", | ||
|  |                full.names = T) | ||
|  |   errfiles <- lapply(errfilepath, read.csv) | ||
|  |   tdf <- unique(do.call(ltodf, errfiles)) | ||
|  |    | ||
|  |   tdf <- tdf |> | ||
|  |     mutate(err.deep = word(err.type, -1)) |> | ||
|  |     mutate(err = word(err.type, 1, -2)) |> select(-err.type) |> | ||
|  |     select(c(Name, Country, err, err.deep, err.count)) |> | ||
|  |     arrange(desc(err.count)) |>  | ||
|  |     filter(Country %in% country) | ||
|  |    | ||
|  |   tdf.country <- tdf |> | ||
|  |     group_by(Country) |> | ||
|  |     summarize(err.count = sum(err.count)) |> | ||
|  |     arrange(err.count) | ||
|  |   Lvl1dfStatus <- | ||
|  |     tibble( | ||
|  |       name = tdf.country$Country, | ||
|  |       y = tdf.country$err.count, | ||
|  |       drilldown = tolower(name) | ||
|  |     ) | ||
|  |   Level_2_Drilldowns <- | ||
|  |     lapply(unique(tdf$Country), function(x_level) { | ||
|  |       tdf.err <- tdf[tdf$Country == x_level, ] | ||
|  |       tdf.err <- tdf.err |> | ||
|  |         group_by(err) |> | ||
|  |         summarize(err.count = sum(err.count)) |> arrange(err.count) | ||
|  |        | ||
|  |       Lvl2dfStatus <- | ||
|  |         tibble( | ||
|  |           name = tdf.err$err, | ||
|  |           y = tdf.err$err.count, | ||
|  |           drilldown = tolower(paste(x_level, name, sep = "_")) | ||
|  |         ) | ||
|  |       list( | ||
|  |         id = tolower(x_level), | ||
|  |         type = "column", | ||
|  |         data = list_parse(Lvl2dfStatus), | ||
|  |         name = "High Level Error" | ||
|  |       ) | ||
|  |     }) | ||
|  |   Level_3_Drilldowns <- | ||
|  |     lapply(unique(tdf.country$Country), function(x_level) { | ||
|  |       tdf.err <- tdf[tdf$Country == x_level, ] | ||
|  |       lapply(unique(tdf.err$err), function(y_level) { | ||
|  |         tdf.err.deep <- tdf.err[tdf.err$err == y_level, ] | ||
|  |         tdf.err.deep <- tdf.err.deep |> | ||
|  |           group_by(err.deep) |> | ||
|  |           summarize(err.count = sum(err.count)) |> arrange(err.count) | ||
|  |          | ||
|  |         Lvl3dfStatus <- | ||
|  |           tibble(name = tdf.err.deep$err.deep, y = tdf.err.deep$err.count) | ||
|  |         list( | ||
|  |           id = tolower(paste(x_level, y_level, sep = "_")), | ||
|  |           type = "column", | ||
|  |           data = list_parse2(Lvl3dfStatus), | ||
|  |           name = "Deep Dive" | ||
|  |         ) | ||
|  |       }) | ||
|  |     }) |> unlist(recursive = FALSE) | ||
|  |    | ||
|  |   highchart() |> | ||
|  |     hc_xAxis(type = "category") |> | ||
|  |     hc_add_series( | ||
|  |       Lvl1dfStatus, | ||
|  |       "column", | ||
|  |       hcaes(x = name, y = y), | ||
|  |       name = "Country View", | ||
|  |       showInLegend = F | ||
|  |     ) |> | ||
|  |     hc_plotOptions(column = list(stacking = "normal"), | ||
|  |                    lang = list(drillUpText = "Back")) |> | ||
|  |     hc_drilldown( | ||
|  |       allowPointDrilldown = TRUE, | ||
|  |       series = c(Level_2_Drilldowns, Level_3_Drilldowns) | ||
|  |     ) |> | ||
|  |     hc_yAxis(title = list(text = "Number of errors")) |> | ||
|  |     hc_title(text = "Error Count") |> | ||
|  |     hc_subtitle(text = "Click on bar for deep dive") |> | ||
|  |     hc_credits(enabled = TRUE, | ||
|  |                text = "LaNubia Data Science", | ||
|  |                href = "https://www.lanubia.com/") |> | ||
|  |     hc_tooltip() |> | ||
|  |     hc_exporting(enabled = TRUE, # always enabled | ||
|  |                  filename = filename) | ||
|  |    | ||
|  | } | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 | ||
|  | contdup<-read.csv("duplicatecontacts.csv") | ||
|  | accdup<-read.csv("duplicateaccounts.csv") | ||
|  | empmissing<-read.csv("empmissinginsap.csv") | ||
|  | 
 | ||
|  | 
 | ||
|  | 
 |