Skip to content

Update run_tests.sh #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
280 changes: 184 additions & 96 deletions insight_testsuite/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,100 +1,188 @@
#!/bin/bash
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 27 08:45:19 2020

@author: 17815
"""
### Reading the file line by line
with open('C:/Users/17815/Downloads/Border_Crossing_Entry_Data.csv', 'r') as f:
results = []
for line in f:
words = line.split(',')
results.append(words[0:])
#print(results)

### Getting each row out
port_name = [results[i][0] for i in range(1,len(results))]
state = [results[i][1] for i in range(1,len(results))]
port_code = [results[i][2] for i in range(1,len(results))]
border = [results[i][3] for i in range(1,len(results))]
date = [results[i][4] for i in range(1,len(results))]
measure = [results[i][5] for i in range(1,len(results))]
value = [results[i][6] for i in range(1,len(results))]

### Splitting the date as day, month, and year
x = [str(date[i]).split(" ") for i in range(len(date))]
x1 = [x[i][0] for i in range(len(x))]
y = [str(i).split("/") for i in x1]
month = [y[i][0] for i in range(len(y))]
year = [y[i][2] for i in range(len(y))]
day = [y[i][1] for i in range(len(y))]

#### Creating a list of list with all the imputations
a = list(zip(port_name, state, port_code, border, date, day, month, year, measure, value))
yr = list(sorted(set(year)))
#set(measure)
#set(border)

############### Group By Year - making subsets from the data in accorddance to year
y1996 = []
y1997 = []
y1998 = []
y1999 = []
y2000 = []
y2001 = []
y2002 = []
y2003 = []
y2004 = []
y2005 = []
y2006 = []
y2007 = []
y2008 = []
y2009 = []
y2010 = []
y2011 = []
y2012 = []
y2013 = []
y2014 = []
y2015 = []
y2016 = []
y2017 = []
y2018 = []
y2019 = []
l = [y1996, y1997, y1998, y1999, y2000, y2001, y2002, y2003, y2004, y2005, y2006, y2007, y2008, y2009, y2010, y2011, y2012, y2013, y2014, y2015, y2016, y2017, y2018, y2019]
for i in range(len(l)):
for j in range(len(a)):
if(a[j][7] == yr[i]):
l[i].append(a[j])

### Soring by month in every year
for i in l:
i.sort(key = lambda x: x[6])

### Grouping by Border type in every set of year
UC_1996 = []
UM_1996 = []
UC_1997 = []
UM_1997 = []
UC_1998 = []
UM_1998 = []
UC_1999 = []
UM_1999 = []
UC_2000 = []
UM_2000 = []
UC_2001 = []
UM_2001 = []
UC_2002 = []
UM_2002 = []
UC_2003 = []
UM_2003 = []
UC_2004 = []
UM_2004 = []
UC_2005 = []
UM_2005 = []
UC_2006 = []
UM_2006 = []
UC_2007 = []
UM_2007 = []
UC_2008 = []
UM_2008 = []
UC_2009 = []
UM_2009 = []
UC_2010 = []
UM_2010 = []
UC_2011 = []
UM_2011 = []
UC_2012 = []
UM_2012 = []
UC_2013 = []
UM_2013 = []
UC_2014 = []
UM_2014 = []
UC_2015 = []
UM_2015 = []
UC_2016 = []
UM_2016 = []
UC_2017 = []
UM_2017 = []
UC_2018 = []
UM_2018 = []
UC_2019 = []
UM_2019 = []
b = [UC_1996,UM_1996,UC_1997,UM_1997,UC_1998,UM_1998,UC_1999,UM_1999,UC_2000,UM_2000,UC_2001,UM_2001,UC_2002,UM_2002,UC_2003,UM_2003,UC_2004,UM_2004,UC_2005,UM_2005,UC_2006,UM_2006,UC_2007,UM_2007,UC_2008,UM_2008,UC_2009,UM_2009,UC_2010,UM_2010,UC_2011,UM_2011,UC_2012,UM_2012,UC_2013,UM_2013,UC_2014,UM_2014,UC_2015,UM_2015,UC_2016,UM_2016,UC_2017,UM_2017,UC_2018,UM_2018,UC_2019,UM_2019]

### The subsets created are converted to list form from tuple
for x in b:
for y in range(len(x)):
x[y] = list(x[y])


### Creating a list of lists in which Group by border has been implemented
j = 0
for i in l:
for k in range(len(i)):
if(i[k][3] == "US-Canada Border"):
b[j].append(i[k])
elif(i[k][3] == "US-Mexico Border"):
b[j+1].append(i[k])
j = j + 2

### Final calculations and updating the data with the rolling average number of border crossings per measure type
table = []
c = list(sorted(set(measure)))
d = list(sorted(set(month)))
for z in range(len(b)):
### There are 12 types of measures- creating empty lists for them to subset the data further
bus_pas = []
buses = []
pedestrians = []
personal_vehicle_pas = []
personal_vehicle = []
rail_contain_empty = []
rail_contain_full = []
train_pas = []
train = []
truck_contain_empty = []
truck_contain_full = []
truck = []
mes = [bus_pas,buses,pedestrians,personal_vehicle_pas,personal_vehicle,rail_contain_empty,rail_contain_full,train_pas,train,truck_contain_empty,truck_contain_full,truck]
### The loop breaks the data per year per border to different measures
for i in range(len(UC_1996)):
for j in range(len(c)):
if(UC_1996[i][8] == c[j]):
mes[j].append(UC_1996[i])
### To Facilitate final average calculations
ind= []
for k in mes:
s = 0
e = []
for m in range(1,12):
for n in range(len(k)):
k[n] = list(k[n])
if(k[n][6] < d[m]):
e.append(k[n][9])
if(k[n][6] == d[m]):
ind.append(n)
#if(k[n][6] == d[0]):
# k[n][6].append('0')
for p in e:
s = s+ int(p)
avg = round(s/len(e))
for p in ind:
k[p].append(avg)
table.append(mes)


declare -r color_start="\033["
declare -r color_red="${color_start}0;31m"
declare -r color_green="${color_start}0;32m"
declare -r color_blue="${color_start}0;34m"
declare -r color_norm="${color_start}0m"

GRADER_ROOT=$(dirname ${BASH_SOURCE})

PROJECT_PATH=${GRADER_ROOT}/..

function print_dir_contents {
local proj_path=$1
echo "Project contents:"
echo -e "${color_blue}$(ls ${proj_path})${color_norm}"
}

function find_file_or_dir_in_project {
local proj_path=$1
local file_or_dir_name=$2
if [[ ! -e "${proj_path}/${file_or_dir_name}" ]]; then
echo -e "[${color_red}FAIL${color_norm}]: no ${file_or_dir_name} found"
print_dir_contents ${proj_path}
echo -e "${color_red}${file_or_dir_name} [MISSING]${color_norm}"
exit 1
fi
}

# check project directory structure
function check_project_struct {
find_file_or_dir_in_project ${PROJECT_PATH} run.sh
find_file_or_dir_in_project ${PROJECT_PATH} src
find_file_or_dir_in_project ${PROJECT_PATH} input
find_file_or_dir_in_project ${PROJECT_PATH} output
}

# setup testing output folder
function setup_testing_input_output {
TEST_OUTPUT_PATH=${GRADER_ROOT}/temp
if [ -d ${TEST_OUTPUT_PATH} ]; then
rm -rf ${TEST_OUTPUT_PATH}
fi

mkdir -p ${TEST_OUTPUT_PATH}

cp -r ${PROJECT_PATH}/src ${TEST_OUTPUT_PATH}
cp -r ${PROJECT_PATH}/run.sh ${TEST_OUTPUT_PATH}
cp -r ${PROJECT_PATH}/input ${TEST_OUTPUT_PATH}
cp -r ${PROJECT_PATH}/output ${TEST_OUTPUT_PATH}

rm -r ${TEST_OUTPUT_PATH}/input/*
rm -r ${TEST_OUTPUT_PATH}/output/*
cp -r ${GRADER_ROOT}/tests/${test_folder}/input/Border_Crossing_Entry_Data.csv ${TEST_OUTPUT_PATH}/input/Border_Crossing_Entry_Data.csv
}

function compare_outputs {
NUM_OUTPUT_FILES_PASSED=0
OUTPUT_FILENAME=report.csv
PROJECT_ANSWER_PATH1=${GRADER_ROOT}/temp/output/${OUTPUT_FILENAME}
TEST_ANSWER_PATH1=${GRADER_ROOT}/tests/${test_folder}/output/${OUTPUT_FILENAME}

DIFF_RESULT1=$(diff -bB ${PROJECT_ANSWER_PATH1} ${TEST_ANSWER_PATH1} | wc -l)
if [ "${DIFF_RESULT1}" -eq "0" ] && [ -f ${PROJECT_ANSWER_PATH1} ]; then
echo -e "[${color_green}PASS${color_norm}]: ${test_folder} ${OUTPUT_FILENAME}"
NUM_OUTPUT_FILES_PASSED=$(($NUM_OUTPUT_FILES_PASSED+1))
else
echo -e "[${color_red}FAIL${color_norm}]: ${test_folder}"
diff ${PROJECT_ANSWER_PATH1} ${TEST_ANSWER_PATH1}
fi

if [ "${NUM_OUTPUT_FILES_PASSED}" -eq "1" ]; then
PASS_CNT=$(($PASS_CNT+1))
fi

}

function run_all_tests {
TEST_FOLDERS=$(ls ${GRADER_ROOT}/tests)
NUM_TESTS=$(($(echo $(echo ${TEST_FOLDERS} | wc -w))))
PASS_CNT=0

# Loop through all tests
for test_folder in ${TEST_FOLDERS}; do

setup_testing_input_output

cd ${GRADER_ROOT}/temp
bash run.sh 2>&1
cd ../

compare_outputs
done

echo "[$(date)] ${PASS_CNT} of ${NUM_TESTS} tests passed"
echo "[$(date)] ${PASS_CNT} of ${NUM_TESTS} tests passed" >> ${GRADER_ROOT}/results.txt
}

check_project_struct
run_all_tests