def display(): time_start = time.time() dict_query = request_form2dict_query(request.form) list_images = dict_query2list_images(dict_query) # TODO : run this part of code as seprate thread to reduce execution time of query # store the query in the user history if dict_query: #if dict_query is not empty if current_user.history is None: list_hist = [] else: list_hist = eval(current_user.history) if len(list_hist) ==10: list_hist.pop(0) list_hist.append(dict_query) current_user.history = str(list_hist) db.session.commit() n_matches = len(list_images) list_filepaths = list_images2list_filepaths(list_images) #typecasting the list to string eg: str([0,1,2])->'[0,1,2]' str_list_filepaths = str(list_filepaths) #replacing / with * is a just a hack used because the /s cause issues when passed in the url str_list_filepaths = (str_list_filepaths).replace('/','*') time_end = time.time() execution_time = time_end-time_start print(list_images, file=sys.stdout) # some hack works to keep values Nan by printing this line return render_template('display_result.html', title='Results', dict_query=dict_query, form_attributes=form_attributes, list_attributes = dict_attributes.keys(), dict_attributes=dict_attributes, list_images = list_images, str_list_filepaths = str_list_filepaths, execution_time=execution_time, n_matches=n_matches)
def history(str_dict_query): time_start = time.time() dict_query = eval(str_dict_query) list_images = dict_query2list_images(dict_query) list_filepaths = list_images2list_filepaths(list_images) str_list_filepaths = str(list_filepaths) str_list_filepaths = (str_list_filepaths).replace('/', '*') n_matches = len(list_images) time_end = time.time() execution_time = time_end - time_start return render_template('display_result.html', title='Results', dict_query=dict_query, form_attributes=form_attributes, list_attributes=dict_attributes.keys(), dict_attributes=dict_attributes, list_images=list_images, str_list_filepaths=str_list_filepaths, execution_time=execution_time, n_matches=n_matches)
def nightly_page(): #extracting date from form and querying database to get results date = request.form['date'] jd_min, jd_max = date_in_ist2min_max_jd(date) list_images = Image.query.filter(Image.jd >= jd_min, Image.jd <= jd_max).all() list_filepaths = list_images2list_filepaths(list_images) str_list_filepaths = str(list_filepaths) str_list_filepaths = (str_list_filepaths).replace('/', '*') #calculating observation metrics dict_times = date2dict_times(date) total_observable_time = ( dict_times['Twelve degree Morning Twilight ']['utc'] - dict_times['Twelve degree Evening Twilight ']['utc']).total_seconds() obs_start_time, obs_end_time = list_images2obs_start_end(list_images) total_observed_time = (obs_end_time['utc'] - obs_start_time['utc']).total_seconds() dict_targets, total_exposure = list_images2dict_targets_time(list_images) sc_obs_frac = total_observed_time / total_observable_time sc_duty_cycle = total_exposure / total_observable_time return render_template('nightly.html', title='Nightly Page', date=date, dict_times=dict_times, list_attributes=dict_attributes.keys(), dict_attributes=dict_attributes, list_images=list_images, str_list_filepaths=str_list_filepaths, obs_start_time=obs_start_time, obs_end_time=obs_end_time, sc_obs_frac=sc_obs_frac, sc_duty_cycle=sc_duty_cycle, dict_targets=dict_targets)
def display(): time_start = time.time() dict_query = request_form2dict_query(request.form) list_images = dict_query2list_images(dict_query) if dict_query: #if dict_query is not empty if current_user.history is None: list_hist = [] else: list_hist = eval(current_user.history) if len(list_hist) == 10: list_hist.pop(0) list_hist.append(dict_query) current_user.history = str(list_hist) db.session.commit() n_matches = len(list_images) list_filepaths = list_images2list_filepaths(list_images) str_list_filepaths = str(list_filepaths) str_list_filepaths = (str_list_filepaths).replace('/', '*') time_end = time.time() execution_time = time_end - time_start return render_template('display_result.html', title='Results', dict_query=dict_query, form_attributes=form_attributes, list_attributes=dict_attributes.keys(), dict_attributes=dict_attributes, list_images=list_images, str_list_filepaths=str_list_filepaths, execution_time=execution_time, n_matches=n_matches)