From c84cb2ff8c60361d2996b8a15dcc64e742ffaaf4 Mon Sep 17 00:00:00 2001 From: ashpandey2509 Date: Sun, 2 Sep 2018 04:47:15 +0000 Subject: [PATCH 1/8] Done --- q01_read_data/build.py | 11 +++-------- q02_teams/build.py | 11 +---------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/q01_read_data/build.py b/q01_read_data/build.py index e13d2f74..70a58658 100644 --- a/q01_read_data/build.py +++ b/q01_read_data/build.py @@ -1,12 +1,7 @@ import yaml def read_data(): + with open('./data/ipl_match.yaml') as f: + data = yaml.load(f) + return data - # import the csv file into `data` variable - # You can use this path to access the CSV file: '../data/ipl_match.yaml' - # Write your code here - - data = - - # return data variable - return data diff --git a/q02_teams/build.py b/q02_teams/build.py index 3cf9d3cf..2297b919 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -1,11 +1,2 @@ -# default imports -from greyatomlib.python_getting_started.q01_read_data.build import read_data -data = read_data() +l1 = {'RB1':'Akash','RB2:Virat} -# solution -def teams(data=data): - - # write your code here - #teams = - - return teams From 49e8872f44c8d21f943bd516f6d8a8df27745d85 Mon Sep 17 00:00:00 2001 From: ashpandey2509 Date: Sun, 2 Sep 2018 05:10:23 +0000 Subject: [PATCH 2/8] Done --- q02_teams/build.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/q02_teams/build.py b/q02_teams/build.py index 2297b919..d5cfc73b 100644 --- a/q02_teams/build.py +++ b/q02_teams/build.py @@ -1,2 +1,11 @@ -l1 = {'RB1':'Akash','RB2:Virat} +# default imports +from greyatomlib.python_getting_started.q01_read_data.build import read_data +data = read_data() + +# solution +def teams(data=data): + teams = data['info']['teams'] + return teams + + From d0c3ba42abb6ec0dd71a9f77900e774fb5818de3 Mon Sep 17 00:00:00 2001 From: ashpandey2509 Date: Sun, 9 Sep 2018 11:37:48 +0000 Subject: [PATCH 3/8] Done --- q03_first_batsman/build.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/q03_first_batsman/build.py b/q03_first_batsman/build.py index 84984081..3050a3bb 100644 --- a/q03_first_batsman/build.py +++ b/q03_first_batsman/build.py @@ -1,13 +1,15 @@ -# Default Imports +# default imports +from unittest import TestCase from greyatomlib.python_getting_started.q01_read_data.build import read_data + data = read_data() -# Your Solution def first_batsman(data=data): + + batsman_name = data['innings'][0]['1st innings']['deliveries'][0][0.1]['batsman'] + return batsman_name - # Write your code here - +first_batsman() - return name From 059baaa8526bebca5aef3c1047ce992efdd948fb Mon Sep 17 00:00:00 2001 From: ashpandey2509 Date: Tue, 11 Sep 2018 18:08:10 +0000 Subject: [PATCH 4/8] Done --- q04_count/build.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/q04_count/build.py b/q04_count/build.py index 6cf3dcbc..c67f1388 100644 --- a/q04_count/build.py +++ b/q04_count/build.py @@ -1,11 +1,23 @@ +# %load q04_count/build.py # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() - # Your Solution Here def deliveries_count(data=data): - # Your code here - - + count = 0 + deliveries_faced = data['innings'][0]['1st innings']['deliveries'] + for ele in deliveries_faced: + for key, value in ele.items(): + batsman_name = value['batsman'] + print (batsman_name) + if (batsman_name == 'RT Ponting'): + count = count+1 return count + +deliveries_count(data) + + + + + From 8c55fca4bccdca2695e77528379ff954fff14c98 Mon Sep 17 00:00:00 2001 From: ashpandey2509 Date: Sat, 22 Sep 2018 08:51:36 +0000 Subject: [PATCH 5/8] Done --- q05_runs/build.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/q05_runs/build.py b/q05_runs/build.py index a250631a..5d22cfa1 100644 --- a/q05_runs/build.py +++ b/q05_runs/build.py @@ -1,12 +1,25 @@ + # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() +# Your Solution Here +def BC_runs (data=data): + # Initialize the variable + runs = 0 + runs_scored = 0 + # Read list value for deliveries + deliveries_info = data['innings'][0]['1st innings']['deliveries'] + for ele in deliveries_info: + # Read jey value pair + for key, value in ele.items(): + batsman_name = value['batsman'] + runs_scored = value['runs']['batsman'] + #Check specific batsman + if (batsman_name == 'BB McCullum'): + runs += runs_scored + return runs +data = read_data() +print (data['innings'][0]['1st innings']['deliveries'][0][0.1]) +BC_runs(data) -# Your Solution -def BC_runs(data): - - # Write your code here - - - return(runs) From 41b3811868c04da75a14f527ec17618e2729bbad Mon Sep 17 00:00:00 2001 From: ashpandey2509 Date: Mon, 24 Sep 2018 05:59:39 +0000 Subject: [PATCH 6/8] Done --- q06_bowled_players/build.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/q06_bowled_players/build.py b/q06_bowled_players/build.py index 914cb6d2..76a0f51c 100644 --- a/q06_bowled_players/build.py +++ b/q06_bowled_players/build.py @@ -1,11 +1,30 @@ + # Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() +# Your Solution Here +def bowled_out (data=data): + # Initialize the variable + bowled_players =[] + runs = 0 + runs_scored = 0 + # Read list value for deliveries + deliveries_info = data['innings'][1]['2nd innings']['deliveries'] + for i in range (len(deliveries_info)): + for key, value in (data['innings'][1]['2nd innings']['deliveries'][i]).items(): + batsman_name = value['batsman'] + if ('wicket' in data['innings'][1]['2nd innings']['deliveries'][i][key].keys()): + wicket_kind = value ['wicket'] + for key, value in wicket_kind.items(): + if (value == 'bowled'): + bowled_players.append(batsman_name) + return bowled_players + + + + + -# Your Solution -def bowled_out(data=data): - # Write your code here - return bowled_players From 3a47f79ddcb0e65c1df602f2ce9161c2df2493f4 Mon Sep 17 00:00:00 2001 From: ashpandey2509 Date: Mon, 24 Sep 2018 16:34:36 +0000 Subject: [PATCH 7/8] Done --- q07_extras/build.py | 54 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/q07_extras/build.py b/q07_extras/build.py index cdeb803b..880033d4 100644 --- a/q07_extras/build.py +++ b/q07_extras/build.py @@ -1,14 +1,48 @@ -# Default Imports + +#Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() - -# Your Solution -def extras_runs(data=data): - - # Write your code here - - - difference = +# Your Solution Here +def extras_runs (data=data): + # Initialize the variable + bowled_players =[] + extras1 = 0 + extras2 = 0 + wides =0 + legbyes =0 + difference = 0 + # Read list value for deliveries + deliveries_info = data['innings'][0]['1st innings']['deliveries'] + for i in range (len(deliveries_info)): + for key, value in (data['innings'][0]['1st innings']['deliveries'][i]).items(): + if ('extras' in data['innings'][0]['1st innings']['deliveries'][i][key].keys()): + extra_key_value = value['extras'] + for key, value in extra_key_value.items(): + if (key == 'wides'): + wides += value + if (key == 'legbyes'): + legbyes += value + extras1 = wides + legbyes + wides =0 + legbyes =0 + # Read list value for deliveries + deliveries_info = data['innings'][1]['2nd innings']['deliveries'] + for i in range (len(deliveries_info)): + for key, value in (data['innings'][1]['2nd innings']['deliveries'][i]).items(): + if ('extras' in data['innings'][1]['2nd innings']['deliveries'][i][key].keys()): + extra_key_value = value['extras'] + for key, value in extra_key_value.items(): + if (key == 'wides'): + wides += value + if (key == 'legbyes'): + legbyes += value + extras2 = wides + legbyes + if (extras1>extras2): + difference = extras1 - extras2 + else: + difference = extras2 - extras1 + return difference + +extras_runs(data) - return difference From b474160b5adbf1627033d245b0403159b79edb62 Mon Sep 17 00:00:00 2001 From: ashpandey2509 Date: Mon, 24 Sep 2018 17:10:53 +0000 Subject: [PATCH 8/8] Done --- q07_extras/build.py | 62 +++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/q07_extras/build.py b/q07_extras/build.py index 880033d4..3e38bf0d 100644 --- a/q07_extras/build.py +++ b/q07_extras/build.py @@ -1,42 +1,46 @@ + #Default Imports from greyatomlib.python_getting_started.q01_read_data.build import read_data data = read_data() # Your Solution Here def extras_runs (data=data): # Initialize the variable - bowled_players =[] extras1 = 0 extras2 = 0 - wides =0 - legbyes =0 difference = 0 # Read list value for deliveries - deliveries_info = data['innings'][0]['1st innings']['deliveries'] - for i in range (len(deliveries_info)): - for key, value in (data['innings'][0]['1st innings']['deliveries'][i]).items(): - if ('extras' in data['innings'][0]['1st innings']['deliveries'][i][key].keys()): - extra_key_value = value['extras'] - for key, value in extra_key_value.items(): - if (key == 'wides'): - wides += value - if (key == 'legbyes'): - legbyes += value - extras1 = wides + legbyes - wides =0 - legbyes =0 - # Read list value for deliveries - deliveries_info = data['innings'][1]['2nd innings']['deliveries'] - for i in range (len(deliveries_info)): - for key, value in (data['innings'][1]['2nd innings']['deliveries'][i]).items(): - if ('extras' in data['innings'][1]['2nd innings']['deliveries'][i][key].keys()): - extra_key_value = value['extras'] - for key, value in extra_key_value.items(): - if (key == 'wides'): - wides += value - if (key == 'legbyes'): - legbyes += value - extras2 = wides + legbyes + for num in range (2): + wides =0 + legbyes =0 + others = 0 + if (num ==0): + inning_sequence = '1st innings' + + else: + inning_sequence = '2nd innings' + + deliveries_info = data['innings'][num][inning_sequence]['deliveries'] + + #iterate through deliveries + for i in range (len(deliveries_info)): + for key, value in (data['innings'][num][inning_sequence]['deliveries'][i]).items(): + if ('extras' in data['innings'][num][inning_sequence]['deliveries'][i][key].keys()): + extra_key_value = value['extras'] + for key, value in extra_key_value.items(): + + if (key == 'wides'): + wides += value + else: + if (key == 'legbyes'): + legbyes += value + else: + others +=others + if (num ==0): + extras1 = wides + legbyes + others + else: + extras2 = wides + legbyes + others + if (extras1>extras2): difference = extras1 - extras2 else: @@ -46,3 +50,5 @@ def extras_runs (data=data): extras_runs(data) + +