Skip to content

Commit 5fc46fe

Browse files
authored
Merge pull request #22 from jagruti8/fix-check-detectors
Added data, validated them and modified iqr_detector function
2 parents d124ae6 + 7354539 commit 5fc46fe

File tree

4 files changed

+23
-36
lines changed

4 files changed

+23
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.pyc
22
__pycache__/
3+
.DS_Store

findoutlie/detectors.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,22 +52,13 @@ def iqr_detector(measures, iqr_proportion=1.5):
5252
# * You'll likely need np.logical_or
5353
# https://textbook.nipraxis.org/numpy_logical.html
5454
# +++your code here+++
55-
55+
# Calculate the quartiles of the data
5656
Q1 = np.percentile(measures, 25, interpolation="midpoint")
5757
Q2 = np.percentile(measures, 50, interpolation="midpoint")
5858
Q3 = np.percentile(measures, 75, interpolation="midpoint")
59+
# Calculate the interquartile range
5960
IQR = Q3 - Q1
60-
61-
outlier = []
62-
63-
for i in range(len(measures)):
64-
if (measures[i] > (Q3 + IQR * iqr_proportion)) | (
65-
measures[i] < (Q1 - IQR * iqr_proportion)
66-
):
61+
# Calculate the outliers
62+
outliers = np.logical_or(measures > (Q3 + IQR * iqr_proportion), measures < (Q1 - IQR * iqr_proportion))
63+
return outliers
6764

68-
outlier.append(True)
69-
else:
70-
outlier.append(False)
71-
72-
#print(outlier)
73-
return np.array(outlier)

findoutlie/tests/test_detectors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
# Hint: sys.path
2020
# Hint: see the solutions if you are stuck.
2121
# +++your code here+++
22+
findoutlie_dir = MY_DIR.parent
23+
print("The directory containing detectors is {}".format(str(findoutlie_dir)))
24+
sys.path.append(str(findoutlie_dir))
2225

23-
#import sys
24-
#export PYTHONPATH=$PYTHONPATH:C:/Users/nauma/Documents/nipraxis-work/diagnostics-NME/findoutlie
25-
#sys.path.append('C:/Users/nauma/Documents/nipraxis-work/diagnostics-NME/findoutlie')
2626
import numpy as np
2727

2828
# This import needs the directory containing the findoutlie directory
2929
# on the Python path.
30-
from findoutlie.detectors import iqr_detector
30+
from detectors import iqr_detector
3131

3232

3333
def test_iqr_detector():

scripts/validate_data.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,13 @@ def validate_data(data_directory):
6161
# If hash for filename is not the same as the one in the file, raise
6262
# ValueError
6363
# This is a placeholder, replace it to write your solution.
64-
data_pth = Path() / data_directory
64+
data_pth = Path(data_directory)
6565
# print(data_pth)
6666
hash_pth = list(data_pth.glob("**/*.txt"))
6767
hash_pth = str(hash_pth[0])
6868
# hash_pth= "data_pth/**/hash_list.txt"
6969
# print(hash_pth[0])
7070

71-
# hash_pth = Path(data_directory)
72-
# hash_pth = data_pth/group-0/'data_hashes.txt'
73-
# data_dir = hash_pth.parent
7471
with open(hash_pth) as f:
7572
lines = f.readlines()
7673
# print(lines)
@@ -89,28 +86,26 @@ def validate_data(data_directory):
8986

9087
#print(d_pth)
9188

92-
cal_hash = file_hash(data_pth / spl[1])
89+
cal_hash = file_hash(data_pth.parent / spl[1])
9390
# Check actual hash against expected hash
9491
act_hash = spl[0]
9592
# Return False if any of the hashes do not match.
9693
if cal_hash != act_hash:
97-
return False
98-
99-
# raise NotImplementedError(
100-
# "This is just a template -- you are expected to code this."
101-
# )
102-
return True
103-
94+
raise ValueError(f'{spl[1]} changed, hashes do not match')
95+
print(f'{data_directory} is not corrupted, all the hashes match')
96+
return
10497

10598
def main():
10699
# This function (main) called when this file run as a script.
107-
#
108-
# Get the data directory from the command line arguments
109-
if len(sys.argv) < 2:
110-
raise RuntimeError("Please give data directory on " "command line")
111-
data_directory = sys.argv[1]
100+
group_directory = (Path(__file__).parent.parent / 'data')
101+
groups = list(group_directory.glob('group-??'))
102+
if len(groups) == 0:
103+
raise RuntimeError('No group directory in data directory: '
104+
'have you downloaded and unpacked the data?')
105+
if len(groups) > 1:
106+
raise RuntimeError('Too many group directories in data directory')
112107
# Call function to validate data in data directory
113-
validate_data(data_directory)
108+
validate_data(groups[0])
114109

115110

116111
if __name__ == "__main__":

0 commit comments

Comments
 (0)