{"cells":[{"metadata":{"_uuid":"7300812c3fee27f0d0259c80e51d0987d2999683","_execution_state":"idle","trusted":true},"cell_type":"code","source":"# Importing packages\n\nlibrary(tidyverse) \nlibrary(data.table)\nlibrary(lubridate)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0d02f964686fe40f4061cebd3242c554d4ff21a5"},"cell_type":"code","source":" # loading  all the data\ngame_data<-fread('../input/game_data.csv')\npost_2016<-fread('../input/NGS-2016-post.csv')\npre_2016<-fread('../input/NGS-2016-pre.csv')\nreg1_2016<-fread('../input/NGS-2016-reg-wk1-6.csv')\nreg2_2016<-fread('../input/NGS-2016-reg-wk13-17.csv')\nreg3_2016<-fread('../input/NGS-2016-reg-wk7-12.csv')\npost_2017<-fread('../input/NGS-2017-post.csv')\npre_2017<-fread('../input/NGS-2017-post.csv')\nreg1_2017<-fread('../input/NGS-2017-reg-wk1-6.csv')\nreg2_2017<-fread('../input/NGS-2017-reg-wk13-17.csv')\nreg3_2017<-fread('../input/NGS-2017-reg-wk7-12.csv')\nplay_info<-fread('../input/play_information.csv')\ninjured_games<-fread('../input/video_review.csv')\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"311333b9a5ac688da1d4dc7d84536b0c7059d385"},"cell_type":"code","source":"#data Transformation\n#converting  required variables into factors\ngame_data$Home_Team<-as.factor(game_data$Home_Team)    \ngame_data$Stadium<-as.factor(game_data$Stadium)\ngame_data$Game_Day<-as.factor(game_data$Game_Day)\ngame_data$Game_Site<-as.factor(game_data$Game_Site)\ngame_data$Season_Year<-as.factor(game_data$Season_Year)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"89bba3e94af7eec6eeebc0fd1a3d64e9b86e3432"},"cell_type":"markdown","source":"**EDA** on game_data like where most matches held in which stadium,Numbers of MAtches played in a season"},{"metadata":{"trusted":true,"_uuid":"a9a32fe15d3b938a264f4f0ff6369c410ffb3ae7"},"cell_type":"code","source":"game_data%>%\nggplot(aes(x=Stadium))+\n     geom_bar(aes(fill=Stadium),show.legend = FALSE ,colour=\"BLACK\")+\n      labs(x=\"Stadium\",y=\"NO. of Matches Played\",title =\"Highly Played Stadium\")+\n        coord_flip()+\n        theme(axis.text.x = element_text(colour=\"BLACK\"))\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"18eb1bf5ed5defa7e6e0b042f12618dcd1b150df"},"cell_type":"code","source":"game_data%>%\n ggplot(aes(x=factor(Season_Type),fill=factor(Season_Year)))+geom_bar(position=\"fill\")+\n    geom_text(aes(label=..count..),stat=\"count\",position=position_fill(0.5))+\n        labs(x=\"Season Type\",title=\"Total Matches Played \")\n            ","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"b1a2a02031b03b6a4bc424a54819855922d84632"},"cell_type":"markdown","source":"**EDA** on concussed games(i.e game_data)"},{"metadata":{"trusted":true,"_uuid":"331d95190458177e512bd4ee9337531affc3ca2f"},"cell_type":"code","source":"injured_games%>%\nggplot(aes(x=Season_Year))+\n    geom_bar(aes(fill=factor(Season_Year)))+\n        scale_x_continuous(breaks = c(2016,2017))+\n          scale_fill_manual(values = c(\"slateblue1\",\"yellow2\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b8fd0fd309e05eec1913fa35c542a0e7848fd1ac"},"cell_type":"code","source":"plot_activity<-injured_games%>%group_by(Player_Activity_Derived)%>%count()%>%arrange(desc(n))\nggplot(plot_activity)+\n    geom_bar(aes(x=reorder(Player_Activity_Derived,-n),y=n,fill=Player_Activity_Derived),stat=\"identity\")+\n        labs(x=\"Player Activity\",y=\"NO. of Player Activities\",title=\"The Play Techniques that most player used\")+\n          theme(legend.position = \"NONE\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a21ddc963e09017db009f235f2bb460ecb9a68ad"},"cell_type":"code","source":"plot_impact<-injured_games %>% group_by(Primary_Impact_Type)%>%count()%>%arrange(desc(n))\nplot_impact$perc<-round(plot_impact$n/sum(plot_impact$n)*100)\nplot_impact","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c6fd0834823fb16b001ba484b27623f3021456ea"},"cell_type":"code","source":"plot_impact%>% arrange(desc(perc)) %>%\n                        mutate(label_pos = cumsum(perc) - perc / 2,\n                               perc_text = paste0(round(perc), \"%\"))%>%\n    ggplot(aes_string(x=factor(1),y=\"perc\",fill=\"Primary_Impact_Type\"))+\n      geom_bar(stat=\"identity\",colour=\"black\",width=1)+\n          geom_text(aes(x=1.3,y=perc,label=perc_text),size=4,position=position_stack(vjust=0.5))+\n            coord_polar(\"y\",start=0)+ \n             scale_y_continuous(breaks = NULL) +\n              scale_x_discrete(breaks=NULL)+\n              theme(text = element_text(size = 14),\n                    axis.ticks = element_blank(),\n                    axis.text = element_blank(),\n                    axis.title = element_blank())+\n                labs(title=\"Impact Type that led to Concussion in Percentages\")\n               \n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"43cce99c4615efd8449761a74740364301cddee4"},"cell_type":"code","source":"##Filtering out concussed games  from NGS Data\n#Only 2016 games\nprimary1_2016<-pre_2016[pre_2016$GameKey %in% injured_games$GameKey & \n                        pre_2016$PlayID %in% injured_games$PlayID &\n                        pre_2016$GSISID %in% injured_games$GSISID]\nprimary2_2016<-reg1_2016[reg1_2016$GameKey %in% injured_games$GameKey &\n                         reg1_2016$PlayID %in% injured_games$PlayID &\n                         reg1_2016$GSISID %in% injured_games$GSISID]\nprimary3_2016<-reg2_2016[reg2_2016$GameKey %in% injured_games$GameKey &\n                         reg2_2016$PlayID %in% injured_games$PlayID &\n                         reg2_2016$GSISID %in% injured_games$GSISID]\nprimary4_2016<-reg3_2016[reg3_2016$GameKey %in% injured_games$GameK &\n                        reg3_2016$PlayID %in% injured_games$PlayID &\n                        reg3_2016$GSISID %in% injured_games$GSISID]\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8efd040eb2d088a104bc87a1a0a2e12fff06dcc7"},"cell_type":"code","source":"\npartner1_2016<-pre_2016[pre_2016$GameKey %in% injured_games$GameKey & \n                        pre_2016$PlayID %in% injured_games$PlayID &\n                        pre_2016$GSISID %in% injured_games$Primary_Partner_GSISID]\npartner2_2016<-reg1_2016[reg1_2016$GameKey %in% injured_games$GameKey & \n                        reg1_2016$PlayID %in% injured_games$PlayID &\n                        reg1_2016$GSISID %in% injured_games$Primary_Partner_GSISID]\npartner3_2016<-reg2_2016[reg2_2016$GameKey %in% injured_games$GameKey & \n                        reg2_2016$PlayID %in% injured_games$PlayID &\n                        reg2_2016$GSISID %in% injured_games$Primary_Partner_GSISID]\npartner4_2016<-reg3_2016[reg3_2016$GameKey %in% injured_games$GameKey & \n                        reg3_2016$PlayID %in% injured_games$PlayID &\n                        reg3_2016$GSISID %in% injured_games$Primary_Partner_GSISID]\nNGS_concussed_2016<-rbind(primary1_2016,primary2_2016,primary3_2016,primary4_2016,partner1_2016,\n                         partner2_2016,partner3_2016,partner4_2016)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"ae36e5946a119ef44ca41a3bb9f7629b960915f5"},"cell_type":"markdown","source":"**EDA** on a single  NGS player data how is the movement of the players,impact point"},{"metadata":{"trusted":true,"_uuid":"8149b62c28c05fb0f8ff3f7a6fff9387107935e9"},"cell_type":"code","source":"#sample plot on single game\n\nGS1<-29343\nGS2<-31059\nGame<-NGS_concussed_2016%>%filter(GameKey==21 & PlayID==2587 & GSISID==c(GS1,GS2))\n        ggplot(Game)+geom_smooth(aes(x=x,y=y,colour=factor(GSISID)),se=FALSE)+\n        annotate(\"rect\",xmin = 92, xmax = 97, ymin = 26, ymax = 29,fill=\"red\",alpha = 0.4)+\n        labs(title=\"player's impact point that led to concussion\",subtitle = paste0(\"GameKey=21\",\"\\nplayers=29343 and 31059\"))+\n        scale_color_discrete(name=\"Players\")+ \n        theme_light() +\n        theme(plot.title = element_text(color=\"#993333\", size=14, face=\"bold.italic\"),\n             panel.background = element_rect(fill=\"lightgreen\"))\n        \n         \n        \n        ","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"0b03bc5c195485adf7c5ed02ecfbe3000457d343"},"cell_type":"markdown","source":""}],"metadata":{"kernelspec":{"display_name":"R","language":"R","name":"ir"},"language_info":{"mimetype":"text/x-r-source","name":"R","pygments_lexer":"r","version":"3.4.2","file_extension":".r","codemirror_mode":"r"}},"nbformat":4,"nbformat_minor":1}