Skip to content

Commit

Permalink
Adapting for gui_less app to work without survey.dta
Browse files Browse the repository at this point in the history
  • Loading branch information
fhalamos committed Oct 30, 2020
1 parent 2cb87bf commit c71a70d
Showing 1 changed file with 55 additions and 35 deletions.
90 changes: 55 additions & 35 deletions gui_less_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,55 +41,75 @@ def import_file(dataset_path):

return dataset

def get_case_id_from_image_name(url_database_pic_names_to_case_id, picture_second_wave):

#Read file
df_pic_names_to_case_ids = import_file(url_database_pic_names_to_case_id)

def get_case_id_from_image_name(survey_path, midline_pic_path):

#Read survey
survey_df = import_file(survey_path)

#Get row for given image url
df_image = df_pic_names_to_case_ids[df_pic_names_to_case_ids['picture_url']==picture_second_wave]
df_image = survey_df[survey_df['picture_url']==midline_pic_path]

#Return value in case_id column
case_id = df_image['case_id'].iloc[0]
return case_id

if __name__ == '__main__':
def main(baseline_pics_dir_path, midline_pics_dir_path, survey_path, pic_files_extension='.JPG'):
# survey.dta aregument is given when midline pics names is not their case id, survey.dta is use to get their caseid

#To work when running from .exe with arguments
if(len(sys.argv)==4):
url_folder_baseline_pics = abspath(sys.argv[1])
url_folder_second_wave_pics = abspath(sys.argv[2])
pic_names_to_case_id_file_url = abspath(sys.argv[3])
else:
print("Did not give arguments")
sys.exit()
#Make file_pairings df to call analyze_images
file_pairings = pd.DataFrame(columns= ['Picture baseline', 'Picture midline'])

print(url_folder_baseline_pics)
print(url_folder_second_wave_pics)
print(pic_names_to_case_id_file_url)
#Generate path to pictures in midline

midline_pics_names = [f for f in listdir(midline_pics_dir_path) if isfile(join(midline_pics_dir_path, f))]

#Make file_pairings df to call analyze_images
file_pairings = pd.DataFrame(columns= ['Picture baseline', 'Picture second-wave'])
#For every picture in midline, check if it matches with its corresponding in baseline
for index, midline_pic_name in enumerate(midline_pics_names):
midline_pic_path = join(midline_pics_dir_path, midline_pic_name)

#For every picture in second_wave, check if it matches with its corresponding in baseline

pictures_second_wave = [f for f in listdir(url_folder_second_wave_pics) if isfile(join(url_folder_second_wave_pics, f))]
for index, picture_second_wave in enumerate(pictures_second_wave):
picture_second_wave = join(url_folder_second_wave_pics, picture_second_wave)
#Get case id for this picture
case_id = get_case_id_from_image_name(pic_names_to_case_id_file_url, picture_second_wave)
#If midline_pic caseid is not present in file name, get get case id from survey
if survey_path:
baseline_pic_name = get_case_id_from_image_name(survey_path, midline_pic_path)+ pic_files_extension
else:
baseline_pic_name = midline_pic_name

#Get url of picture in baseline
picture_baseline = url_folder_baseline_pics +'\\'+case_id+'.jpg' #We sure they will all be .jpg?

#Save in df
file_pairings.loc[index] = [picture_baseline, picture_second_wave]
#Get url of picture in baseline
baseline_pic_path = baseline_pics_dir_path +'\\'+baseline_pic_name

#Save in df
file_pairings.loc[index] = [baseline_pic_path, midline_pic_path]

status, file_pairings = fvp.process_images(file_pairings)
file_pairings.to_csv('a.csv', index=False)
print(file_pairings)

status, file_pairings = fvp.process_images(file_pairings)
file_pairings.to_csv('b.csv', index=False)

print(file_pairings)
#
status, file_pairings = fvp.compare_images(file_pairings)
#
# #Save result
print('e')
file_pairings.to_csv('results.csv', index=False)

if __name__ == '__main__':

#If no arguments given, use default for testing
if(len(sys.argv)==1):
print("Using default folder locations")
baseline_pics_dir_path = "C:\\Users\\felip\\Desktop\\GYS Pictures\\GYS Pictures_baseline\\test"
midline_pics_dir_path = "C:\\Users\\felip\Desktop\\GYS Pictures\\GYS Pictures_midline\\test"
survey_path = None
#To work when running from .exe with arguments
if(len(sys.argv)>=3):
baseline_pics_dir_path = abspath(sys.argv[1])
midline_pics_dir_path = abspath(sys.argv[2])

status, file_pairings = fvp.compare_images(file_pairings)
if(len(sys.argv)==4):
survey_path = abspath(sys.argv[3])
else:
survey_path = None

#Save result
file_pairings.to_csv('results.csv', index=False)
main(baseline_pics_dir_path, midline_pics_dir_path, survey_path)

0 comments on commit c71a70d

Please sign in to comment.