8 <& /util/import_javascript.mas, classes => [ 'd3.d3v4Min.js', 'd3pie_min.js', 'moment_min', 'd3.graphers.stackedObservationPhenotypeHistogram' ] &>
10 <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
11 <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" />
13 <& /page/page_title.mas, title => 'Database Stats' &>
15 <&| /page/info_section.mas, title => "Date Range" &>
17 Filter by date of addition to database<br /><br />
20 Start Date: <input type="text" id="dbstats_start_date" title="dbstats_start_date" />
21 <td> </td></td><td>
23 End Date: <input type="text" id="dbstats_end_date" title="dbstats_end_date" />
27 <input type="checkbox" id="include_dateless_items"> include items without a date</input>
31 <button id="update_dbstats_by_date">Update</button>
39 var dbstats_start_date_element = jQuery("#dbstats_start_date");
40 //set_daterangepicker_default(dbstats_start_date_element);
42 jQuery('input[title="dbstats_start_date"]').daterangepicker(
44 "singleDatePicker": true,
45 "showDropdowns": true,
46 "autoUpdateInput": true,
47 "startDate": "1970-01-01",
49 "minDate": "1970-01-01",
50 "maxDate": "2030-12-31",
58 var dbstats_end_date_element = jQuery("#dbstats_end_date");
60 jQuery('input[title="dbstats_end_date"]').daterangepicker(
62 "singleDatePicker": true,
63 "autoUpdateInput": true,
64 "minDate": "1970-01-01",
65 "maxDate" : "2030-12-31",
70 "showDropdowns": true,
77 <&| /page/info_section.mas, title => "Data categories" &>
81 <span id="trial_types_div"></span>
85 <span id="trials_by_breeding_programs_div"></span>
90 <span id="traits_div"></span>
94 <span id="stocks_div"></span>
101 %# <&| /page/info_section.mas, title => "Activity - past 52 weeks" &>
103 %# <svg class="bargraph" width="800" height="200"></svg>
107 %# <&| /page/info_section.mas, title => "Breeding Program Summaries", collapsible=>1 &>
109 %# <div id="program_stats">[loading program stats...]</div>
113 %# <&| /page/info_section.mas, title => "Breeding Program Summaries", collapsible=>1 &>
115 %# % foreach (@$breeding_programs){
117 %# <div class="well">
119 %# <h3>Breeding Program: <% $_->[1] %></h3>
121 %# <&| /page/info_section.mas, title => "Trials" , collapsible=>1 &>
122 %# <& /breeders_toolbox/program/trials.mas, program_id => $_->[0] &>
125 %# <&| /page/info_section.mas, title => "Traits" , collapsible=>1 &>
126 %# <& /breeders_toolbox/program/traits.mas, program_id => $_->[0], collapse_phenotypes_section => 0 &>
137 % my $breeding_program_json = encode_json($breeding_programs);
140 jQuery(document).ready( function() {
142 var start_date = jQuery('#dbstats_start_date').val();
143 var end_date = jQuery('#dbstats_end_date').val();
144 var include_dateless_items = jQuery('#include_dateless_items').val();
146 jQuery('#update_dbstats_by_date').click( function() {
147 draw_overview_charts(start_date, end_date, include_dateless_items);
148 // alert('start_date: '+ jQuery('#dbstats_start_date').val() );
151 draw_overview_charts(start_date, end_date, include_dateless_items);
153 var breeding_programs = JSON.parse('<% $breeding_program_json %>');
155 // alert(JSON.stringify(breeding_programs));
159 // for(let i=0; i<breeding_programs.length; i++) {
160 // // alert('table loop '+i + ' for '+breeding_programs[i][1]);
161 // html += "<h3>Breeding Program: "+ breeding_programs[i][1] + "</h3>";
163 // html += trial_table(html, breeding_programs[i][0]);
164 // html += trait_table(html, breeding_programs[i][0]);
167 // jQuery('#program_stats').html(html);
169 // // alert(JSON.stringify(breeding_programs));
171 // for(let n=0; n<breeding_programs.length; n++) {
172 // // alert('ajax loop '+ n + ' for '+breeding_programs[n][1]);
173 // trial_queries(breeding_programs[n][0], start_date, end_date, include_dateless_items);
174 // trait_queries(breeding_programs[n][0], start_date, end_date, include_dateless_items);
180 function draw_overview_charts(start_date, end_date, include_dateless_items) {
182 // remove old graphs if present
183 jQuery('#trial_types_div').html("");
184 jQuery('#trials_by_breeding_programs_div').html("");
185 jQuery('#traits_div').html("");
186 jQuery('#stocks_div').html("");
189 url: '/ajax/dbstats/trials_by_breeding_program_chart',
190 data: { 'start_date' : start_date, 'end_date' : end_date, 'include_dateless_items' : include_dateless_items },
191 error: function(response) { alert('An error occurred' + JSON.stringify(response)); },
192 success: function(response) {
193 //alert('success' + JSON.stringify(response));
194 var types_pie = new d3pie('trials_by_breeding_programs_div', response);
199 url: '/ajax/dbstats/traits_chart',
200 data: { 'start_date' : start_date, 'end_date' : end_date, 'include_dateless_items' : include_dateless_items },
201 error: function(response) { alert('An error occurred' + JSON.stringify(response)); },
202 success: function(response) {
203 //alert('success' + JSON.stringify(response));
204 var types_pie = new d3pie('traits_div', response);
209 url: '/ajax/dbstats/stocks_chart',
210 data: { 'start_date' : start_date, 'end_date' : end_date, 'include_dateless_items' : include_dateless_items },
211 error: function(response) { alert('An error occurred' + JSON.stringify(response)); },
212 success: function(response) {
213 var types_pie = new d3pie('stocks_div', response);
218 url: '/ajax/dbstats/trial_types_chart',
219 data: { 'start_date' : start_date, 'end_date' : end_date, 'include_dateless_items' : include_dateless_items },
220 error: function(response) { alert('An error occurred' + JSON.stringify(response)); },
221 success: function(response) {
222 //alert('success' + JSON.stringify(response));
223 var types_pie = new d3pie('trial_types_div', response);
228 url : '/ajax/dbstats/activity',
229 error: function(r) { alert('An error occurred.'); },
230 success: function(d) {
231 d.frequency = +d.frequency;
238 function bargraph(data) {
239 var svg = d3.select(".bargraph"),
240 margin = {top: 20, right: 20, bottom: 30, left: 40},
241 width = +svg.attr("width") - margin.left - margin.right,
242 height = +svg.attr("height") - margin.top - margin.bottom;
244 var x = d3.scaleBand().rangeRound([0, width]).padding(0.1),
245 y = d3.scaleLinear().rangeRound([height, 0]);
247 var g = svg.append("g")
248 .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
250 x.domain(data.map(function(d) { return d.letter; }));
252 y.domain([0, d3.max(data, function(d) { return d.frequency; })]);
255 .attr("class", "axis axis--x")
256 .attr("transform", "translate(0," + height + ")")
257 .call(d3.axisBottom(x));
260 .attr("class", "axis axis--y")
261 .call(d3.axisLeft(y).ticks(10, ""))
263 .attr("transform", "rotate(-90)")
265 .attr("dy", "0.71em")
266 .attr("text-anchor", "end")
271 .enter().append("rect")
272 .attr("class", "bar")
273 .attr("x", function(d) { return x(d.letter); })
274 .attr("y", function(d) { return y(d.frequency); })
275 .attr("width", x.bandwidth())
276 .attr("height", function(d) { return height - y(d.frequency); })
277 .attr("fill", "#AAAAEE");
282 function trial_table(html, bp_id) {
285 <table id="trial_summary_data_`+bp_id+`" class="display">
300 function trait_table(html, bp_id) {
303 <div class="well well-sm table-responsive">
304 <center><h4>Raw Data Statistics</h4></center>
308 <div id="pheno_summary_table_`+bp_id+`_div">
310 <table id="phenotype_summary_data_`+bp_id+`" class="display">
328 <div class="well well-sm" id="raw_data_histogram_well_`+bp_id+`">
329 <center><h4>Raw Data Histogram</h4></center><hr>
330 <div id="program_summary_hist_`+bp_id+`_div">
332 <div class="col-sm-8">
333 <form class="form-horizontal">
334 <div class="form-group form-group-sm">
335 <label for="program_summary_hist_dropdown_`+bp_id+`" class="col-sm-2 control-label">Select:</label>
336 <div class="col-sm-10">
337 <div id="traits_assayed_dropdown_`+bp_id+`">
342 <div class="col-sm-4" id="traits_assayed_histogram_cvterm_link_`+bp_id+`">
346 <div id="program_summary_hist_`+bp_id+`">
360 function trial_queries(bp_id, start_date, end_date, include_dateless_items) {
361 // alert('AJAX call for '+bp_id +' start_date = '+start_date);
362 jQuery('#trial_summary_data_'+bp_id).DataTable( {
364 'ajax': '/ajax/breeders/program/'+ bp_id + '/field_trials?start_date='+start_date+'&end_date='+end_date+'&include_dateless_items='+include_dateless_items,
368 function trait_queries(bp_id, start_date, end_date, include_dateless_items) {
369 // alert('getting trait data...');
370 jQuery("#phenotype_summary_data_"+bp_id).DataTable( {
371 'ajax': '/ajax/breeders/program/'+ bp_id + '/phenotypes?start_date='+start_date+'&end_date='+end_date+'&include_dateless_items='+include_dateless_items,
374 trait_summary_hist_display_change(bp_id, start_date, end_date, include_dateless_items);
376 ///clicking on the histogram glyph from the dataTable
377 /// scrolls down to the histogram div
379 jQuery('#phenotype_summary_data_'+bp_id).on('click', 'a[href^="#"]', function(event) {
380 var offset = jQuery(window).height() - jQuery('#raw_data_histogram_well_'+bp_id).height() - 40;
381 var target = jQuery(this.getAttribute('href'));
382 if( target.length ) {
383 event.preventDefault();
384 jQuery('html, body').stop().animate({
385 scrollTop: target.offset().top - offset
391 function trait_summary_hist_display_change(program_id, start_date, end_date, include_dateless_items) {
394 var draw_histogram = stackedObservationPhenotypeHistogram.draw;
396 // alert('trait_summary_hist_display_change!');
399 url : '/ajax/breeders/program/'+ program_id + '/traits_assayed?start_date='+start_date+'&end_date='+end_date+'&include_dateless_items='+include_dateless_items,
400 beforeSend: function() {
401 // jQuery("#working_modal").modal("show");
403 success: function(response){
404 //console.log(response);
405 if (response.traits_assayed[0][0]) {
406 var traits_assayed_html = "<select class='form-control' id='program_summary_hist_dropdown_"+program_id+"'>";
407 // alert('select: '+traits_assayed_html);
408 for (i=0; i<response.traits_assayed[0].length; i++) {
409 traits_assayed_html = traits_assayed_html + "<option value="+ response.traits_assayed[0][i][0] + " >" + response.traits_assayed[0][i][1] + "</option>";
411 traits_assayed_html = traits_assayed_html +"</select>";
413 // alert(traits_assayed_html);
414 jQuery("#traits_assayed_dropdown_"+program_id).html(traits_assayed_html);
415 // alert('done with dropdown!');
416 jQuery("#traits_assayed_dropdown_"+program_id).change(function(){
417 var new_trait_id = jQuery('#traits_assayed_dropdown_'+program_id).find(":selected").val();
418 // alert("NEW TRAIT ID: "+new_trait_id);
419 trait_summary_hist_change(program_id, new_trait_id);
422 jQuery('#traits_assayed_histogram_cvterm_link_'+program_id).html("<a href='/cvterm/"+response.traits_assayed[0][0][0]+"/view'>Definition</a>");
424 var trait_id = jQuery("#program_summary_hist_dropdown_"+program_id).val();
425 // alert('TRAIT_ID: '+trait_id);
427 url : '/ajax/breeders/program/'+ program_id +'/trait_phenotypes/?trait='+trait_id,
429 success: function(response){
430 jQuery("#working_modal").modal("hide");
431 var draw_histogram = stackedObservationPhenotypeHistogram.draw;
432 if (response.error) {
433 alert(response.error);
435 else if (response.status!="success"){
436 alert("Problem loading plant/plot data: "+response.status);
439 draw_histogram(response.data, d3.select("#program_summary_hist_"+program_id).node());
442 error: function(response) {
443 jQuery("#working_modal").modal("hide");
444 alert('An error occured retrieving trait histogram data.');
448 jQuery("#working_modal").modal("hide");
449 jQuery("#program_summary_hist_"+program_id).html("<center><h4>There is no data to plot.</h4></center>");
453 error: function(response){
454 alert('Error retrieving traits assayed in this breeding program');
460 function trait_summary_hist_change(program_id, value) {
462 jQuery('#traits_assayed_histogram_cvterm_link_'+program_id).html("<a href='/cvterm/"+value+"/view'>Definition</a>");
463 jQuery("#program_summary_hist_dropdown_"+program_id).val(value);
465 url : '/ajax/breeders/program/'+ program_id +'/trait_phenotypes/?trait='+value+'',
467 beforeSend: function() {
468 jQuery("#working_modal").modal("show");
470 success: function(response){
471 jQuery("#working_modal").modal("hide");
472 var draw_histogram = stackedObservationPhenotypeHistogram.draw;
473 if (response.error) {
474 alert(response.error);
476 else if (response.status!="success"){
477 alert("Problem loading plant/plot data: "+response.status);
480 draw_histogram(response.data, d3.select("#program_summary_hist_"+program_id).node());
483 error: function(response) {
484 jQuery("#working_modal").modal("hide");
485 alert('An error occured retrieving trait histogram data.');