Skip to content

Commit

Permalink
remove old date_range page
Browse files Browse the repository at this point in the history
  • Loading branch information
BradleySappington committed Nov 8, 2023
1 parent 3ee4483 commit 5be0a6c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 387 deletions.
126 changes: 0 additions & 126 deletions jwql/website/apps/jwql/data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2002,132 +2002,6 @@ def thumbnails_ajax(inst, proposal, obs_num=None):

return data_dict


def thumbnails_date_range_ajax(inst, observations, inclusive_start_time_mjd, exclusive_stop_time_mjd):
"""Generate a page that provides data necessary to render thumbnails for
``archive_date_range`` template.
Parameters
----------
inst : str
Name of JWST instrument
observations: list
observation models to use to get filenames
inclusive_start_time_mjd : float
Start time in mjd format for date range
exclusive_stop_time_mjd : float
Stop time in mjd format for date range
Returns
-------
data_dict : dict
Dictionary of data needed for the ``thumbnails`` template
"""

data_dict = {'inst': inst,
'file_data': dict()}
exp_types = set()
exp_groups = set()

# Get the available files for the instrument
for observation in observations:
obs_num = observation.obsnum
proposal = observation.proposal.prop_id
filenames, columns = get_filenames_by_instrument(inst, proposal, observation_id=obs_num, other_columns=['expstart', 'exp_type'])
# Get set of unique rootnames
rootnames = set(['_'.join(f.split('/')[-1].split('_')[:-1]) for f in filenames])
# Gather data for each rootname, and construct a list of all observations in the proposal
for rootname in rootnames:
# Parse filename
try:
filename_dict = filename_parser(rootname)

# Weed out file types that are not supported by generate_preview_images
if 'stage_3' in filename_dict['filename_type']:
continue

except ValueError:
# Temporary workaround for noncompliant files in filesystem
filename_dict = {'activity': rootname[17:19],
'detector': rootname[26:],
'exposure_id': rootname[20:25],
'observation': rootname[7:10],
'parallel_seq_id': rootname[16],
'program_id': rootname[2:7],
'visit': rootname[10:13],
'visit_group': rootname[14:16],
'group_root': rootname[:26]}

# Get list of available filenames and exposure start times. All files with a given
# rootname will have the same exposure start time, so just keep the first.
available_files = []
exp_start = None
exp_type = None
for i, item in enumerate(filenames):
if rootname in item:
available_files.append(item)
if exp_start is None:
exp_start = columns['expstart'][i]
exp_type = columns['exp_type'][i]

if exp_start >= inclusive_start_time_mjd and exp_start < exclusive_stop_time_mjd:
exp_types.add(exp_type)
# Viewed is stored by rootname in the Model db. Save it with the data_dict
# THUMBNAIL_FILTER_LOOK is boolean accessed according to a viewed flag
try:
root_file_info = RootFileInfo.objects.get(root_name=rootname)
viewed = THUMBNAIL_FILTER_LOOK[root_file_info.viewed]
except RootFileInfo.DoesNotExist:
viewed = THUMBNAIL_FILTER_LOOK[0]

# Add to list of all exposure groups
exp_groups.add(filename_dict['group_root'])

# Add data to dictionary
data_dict['file_data'][rootname] = {}
data_dict['file_data'][rootname]['filename_dict'] = filename_dict
data_dict['file_data'][rootname]['available_files'] = available_files
data_dict['file_data'][rootname]["viewed"] = viewed
data_dict['file_data'][rootname]["exp_type"] = exp_type
data_dict['file_data'][rootname]['thumbnail'] = get_thumbnail_by_rootname(rootname)

try:
data_dict['file_data'][rootname]['expstart'] = exp_start
data_dict['file_data'][rootname]['expstart_iso'] = Time(exp_start, format='mjd').iso.split('.')[0]
except (ValueError, TypeError) as e:
logging.warning("Unable to populate exp_start info for {}".format(rootname))
logging.warning(e)
except KeyError:
print("KeyError with get_expstart for {}".format(rootname))

# Extract information for sorting with dropdown menus
# (Don't include the proposal as a sorting parameter if the proposal has already been specified)
detectors, proposals = [], []
for rootname in list(data_dict['file_data'].keys()):
proposals.append(data_dict['file_data'][rootname]['filename_dict']['program_id'])
try: # Some rootnames cannot parse out detectors
detectors.append(data_dict['file_data'][rootname]['filename_dict']['detector'])
except KeyError:
pass

dropdown_menus = {'detector': sorted(detectors),
'proposal': sorted(proposals),
'look': THUMBNAIL_FILTER_LOOK,
'exp_type': sorted(set(exp_types))}

data_dict['tools'] = MONITORS
data_dict['dropdown_menus'] = dropdown_menus

# Order dictionary by descending expstart time.
sorted_file_data = OrderedDict(sorted(data_dict['file_data'].items(),
key=lambda x: getitem(x[1], 'expstart'), reverse=True))

data_dict['file_data'] = sorted_file_data
data_dict['exp_groups'] = sorted(exp_groups)

return data_dict


def thumbnails_query_ajax(rootnames):
"""Generate a page that provides data necessary to render the
``thumbnails`` template.
Expand Down
96 changes: 13 additions & 83 deletions jwql/website/apps/jwql/static/js/jwql.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ function determine_page_title_obs(instrument, proposal, observation) {

/**
* adds/removes disabled_section class and clears value
* @param {string} element_id
* @param {boolean} set_disable
* @param {string} element_id
* @param {boolean} set_disable
*/
function set_disabled_section (element_id, set_disable) {

Expand All @@ -331,7 +331,7 @@ function determine_page_title_obs(instrument, proposal, observation) {
* values are the number of groups for that suffix
*/
function explore_image_update_enable_options(integrations, groups) {

// Check nr of integrations and groups of currently selected extension
var ext_name = get_radio_button_value("extension");

Expand All @@ -343,7 +343,7 @@ function explore_image_update_enable_options(integrations, groups) {
groups = groups.replace(/&#39;/g, '"');
groups = groups.replace(/'/g, '"');
groups = JSON.parse(groups)[ext_name];

// Zero base our calculations
integrations -= 1
groups -=1
Expand All @@ -353,15 +353,15 @@ function explore_image_update_enable_options(integrations, groups) {
document.getElementById("integration2").max = integrations;
document.getElementById("group1").max = groups;
document.getElementById("group2").max = groups;


// If multiple integrations or groups. Allow difference calculations
// enable calculate_difference box
// enable subtrahend boxes
if (integrations > 0 || groups > 0) {
set_disabled_section("calcDifferenceForm", false);
calc_difference = document.getElementById("calcDifference").checked;

} else {
document.getElementById("calcDifference").checked.value = false;
set_disabled_section("calcDifferenceForm", true);
Expand All @@ -384,7 +384,7 @@ function explore_image_update_enable_options(integrations, groups) {
set_disabled_section("groupInput1", (groups < 1));
set_disabled_section("integrationInput2", (!calc_difference || integrations < 1));
set_disabled_section("groupInput2", (!calc_difference || groups < 1));

}


Expand Down Expand Up @@ -811,7 +811,7 @@ function sort_by_thumbnails(sort_type, base_url) {
// Update dropdown menu text
document.getElementById('sort_dropdownMenuButton').innerHTML = sort_type;

// Sort the thumbnails accordingly.
// Sort the thumbnails accordingly.
// Note: Because thumbnails will sort relating to their current order (when the exp_start is the same between thumbnails), we need to do multiple sorts to guarantee consistency.

var thumbs = $('div#thumbnail-array>div')
Expand All @@ -838,9 +838,9 @@ function sort_by_thumbnails(sort_type, base_url) {


/**
* Toggle a viewed button when pressed.
* Toggle a viewed button when pressed.
* Ajax call to update RootFileInfo model with toggled value
*
*
* @param {String} file_root - The rootname of the file corresponding to the thumbnail
* @param {String} base_url - The base URL for gathering data from the AJAX view.
*/
Expand All @@ -850,7 +850,7 @@ function toggle_viewed(file_root, base_url) {
var elem = document.getElementById("viewed");
update_viewed_button(elem.value == "New" ? true : false);
elem.disabled=true;

// Ajax Call to update RootFileInfo model with "viewed" info
$.ajax({
url: base_url + '/ajax/viewed/' + file_root,
Expand Down Expand Up @@ -1309,7 +1309,7 @@ function update_thumbnail_array(data) {
var thumbnail_content = "";
var image_updates = [];
for (var i = 0; i < Object.keys(data.file_data).length; i++) {

// Parse out useful variables
var rootname = Object.keys(data.file_data)[i];
var file = data.file_data[rootname];
Expand Down Expand Up @@ -1361,76 +1361,6 @@ function update_thumbnail_array(data) {
insert_thumbnail_images(image_updates);
}

/**
* Read and submit the form for archive date ranges.
* @param {String} inst - The instrument of interest (e.g. "FGS")
* @param {String} base_url - The base URL for gathering data from the AJAX view.
*/
function submit_date_range_form(inst, base_url, group) {

var start_date = document.getElementById("start_date_range").value;
var stop_date = document.getElementById("stop_date_range").value;

if (!start_date) {
alert("You must enter a Start Date/Time");
} else if (!stop_date) {
alert("You must enter a Stop Date/Time");
} else if (start_date >= stop_date) {
alert("Start Time must be earlier than Stop Time");
} else {
document.getElementById("loading").style.display = "block";
document.getElementById("thumbnail-array").style.display = "none";
document.getElementById("no_thumbnails_msg").style.display = "none";
$.ajax({
url: base_url + '/ajax/' + inst + '/archive_date_range/start_date_' + start_date + '/stop_date_' + stop_date,
success: function(data){
var show_thumbs = true;
var num_thumbnails = Object.keys(data.file_data).length;
// verify we want to continue with results
if (num_thumbnails > 1000) {
show_thumbs = false;
alert("Returning " + num_thumbnails + " images reduce your date/time range for page to load correctly");
}
if (show_thumbs) {
// Handle DIV updates
// Clear our existing array
$("#thumbnail-array")[0].innerHTML = "";
if (num_thumbnails > 0) {
update_show_count(num_thumbnails, 'activities');
update_thumbnail_array(data);
update_filter_options(data, base_url, 'thumbnail');
update_group_options(data, base_url);
update_sort_options(data, base_url);

// Do initial sort and group to match sort button display
group_by_thumbnails(group, base_url);
sort_by_thumbnails(data.thumbnail_sort, base_url);

// Replace loading screen with the proposal array div
document.getElementById("loading").style.display = "none";
document.getElementById("thumbnail-array").style.display = "block";
document.getElementById("no_thumbnails_msg").style.display = "none";
} else {
show_thumbs = false;
}
}
if (!show_thumbs) {
document.getElementById("loading").style.display = "none";
document.getElementById("no_thumbnails_msg").style.display = "inline-block";
}

},
error : function(response) {
document.getElementById("loading").style.display = "none";
document.getElementById("thumbnail-array").style.display = "none";
document.getElementById("no_thumbnails_msg").style.display = "inline-block";

}
});
}
}


/**
* Updates various components on the thumbnails page
* @param {String} inst - The instrument of interest (e.g. "FGS")
Expand Down
59 changes: 0 additions & 59 deletions jwql/website/apps/jwql/templates/archive_date_range.html

This file was deleted.

1 change: 0 additions & 1 deletion jwql/website/apps/jwql/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@
<!-- <a class="dropdown-item disabled-dropdown" href='#'>Unlooked Images</a> -->
<!-- <a class="dropdown-item disabled-dropdown" href="#">Image Anomalies</a> -->
<a class="dropdown-item" href={{ url('jwql:archive', args=[inst_key]) }}>Archived Images</a>
<a class="dropdown-item" href={{ url('jwql:archive_date_range', args=[inst_key]) }}>Date Range Images</a>
<div class="dropdown-divider"></div>
<a class='dropdown-heading mx-3'>Monitors</a>
{% for monitor_name, monitor_url in inst_tools %}
Expand Down
5 changes: 2 additions & 3 deletions jwql/website/apps/jwql/templates/instrument.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ <h2>Archive</h2>
<!-- <a class="dropdown-item" href={{ url('jwql:unlooked', args=[inst]) }}>Unlooked Images (Currently Unavailable)</a> -->
<!-- <a class="dropdown-item" href="#">Image Anomalies (Currently Unavailable)</a> -->
<a class="dropdown-item" href={{ url('jwql:archive', args=[inst]) }}>Archived Images</a>
<a class="dropdown-item" href={{ url('jwql:archive_date_range', args=[inst]) }}>Date Range Images</a>
</div>
</div>
</div>
Expand Down Expand Up @@ -76,7 +75,7 @@ <h2>Monitors</h2>
</div>
</div>
</div>

<div class="container">
<div class="col-md-20 text-center">
<!-- Documentation -->
Expand All @@ -94,7 +93,7 @@ <h2>Documentation</h2>
</br>
</div>
</div>

</div>

</main>
Expand Down
Loading

0 comments on commit 5be0a6c

Please sign in to comment.