From 98b324a7262c530f90a42fb6433bd2a98a745156 Mon Sep 17 00:00:00 2001 From: Maps Date: Wed, 27 May 2015 20:27:17 +0200 Subject: [PATCH] improvements to the spectrum viewer --- user_interface/coral_scanner.js | 57 +++++++++++++++++++++++++++++++-- user_interface/coral_scanner.pm | 2 ++ user_interface/pmt_ro.pl | 2 ++ user_interface/pmt_ro.pm | 40 +++++++++++++++++++++++ 4 files changed, 99 insertions(+), 2 deletions(-) diff --git a/user_interface/coral_scanner.js b/user_interface/coral_scanner.js index 5c4e239..d3145a0 100644 --- a/user_interface/coral_scanner.js +++ b/user_interface/coral_scanner.js @@ -88,6 +88,9 @@ $(document).ready(function(){ $("#button_clear_spectrum").click(function(){ clear_spectrum(); }); + $("#button_delete_selected").click(function(){ + spectrum_delete(); + }); $("#button_record_spectrum").click(function(){ record_spectrum(); }); @@ -125,6 +128,10 @@ $(document).ready(function(){ // alert($(this).prop('checked')); plot_spectrum(); }); + $('#checkbox_diff_spectrum').change(function(){ +// alert($(this).prop('checked')); + plot_spectrum(); + }); $( "#progressbar" ).progressbar({ value: 1000 @@ -210,8 +217,19 @@ function plot_choices() { ""); }); - choiceContainer.find("input").click(function(){plot_spectrum();}); + + + // select all or none with one master checkbox + choiceContainer.append("

" + + ""); + $('#checkbox_allnone').click(function(){ + var master = $(this); + choiceContainer.find("input").each(function(){ + $(this).prop( "checked", master.prop("checked") ); + }); + plot_spectrum(); + }); } @@ -231,11 +249,25 @@ function plot_spectrum() { $('#choices').find("input:checked").each(function () { var key = $(this).attr("name"); + + if (key && spectrum[key]) { // data.push(datasets[key]); + var dataset = spectrum[key].data; + + if($('#checkbox_diff_spectrum').prop('checked') == true){ + var diff = []; + + for (var i = 0; i < dataset.length; i++) { + if(i > 0) { + diff.push([(dataset[i][0]+dataset[i-1][0])/2, dataset[i][1]-dataset[i-1][1] ]); + } + } + dataset = diff; + } data.push( { - data: spectrum[key].data, + data: dataset, bars: { show: true , barWidth: 0.8*parseFloat(spectrum[key].meta.bin_width), align: "center" }, label: key } @@ -565,4 +597,25 @@ function record_spectrum(){ plot_spectrum(); } }); +} + +function spectrum_delete(){ + var runs = $('#choices input[type=checkbox]:checked').map(function() { + return $(this).attr("name"); + }).get().join(','); + $.ajax({ + url: "pmt_ro.pl", + cache: false, + async: true, + dataType: "text", + data: { + sub : "spectrum_delete", + runs : runs + }, + success: function(answer) { + spectrum = get_spectrum_JSON(); + plot_choices(); + plot_spectrum(); + } + }); } \ No newline at end of file diff --git a/user_interface/coral_scanner.pm b/user_interface/coral_scanner.pm index aec62a6..64d5682 100644 --- a/user_interface/coral_scanner.pm +++ b/user_interface/coral_scanner.pm @@ -189,7 +189,9 @@ sub main_html { print ""; print ""; print ""; + print ""; print ""; + print ""; print br; print "record name: "; print ""; diff --git a/user_interface/pmt_ro.pl b/user_interface/pmt_ro.pl index 88adc61..f8dd8ac 100755 --- a/user_interface/pmt_ro.pl +++ b/user_interface/pmt_ro.pl @@ -33,6 +33,8 @@ my $dispatch_table = { dead_time => 1, apply_device_settings => 1, spectrum_JSON => 1, + spectrum_csv => 1, + spectrum_delete => 1, clear_spectrum => 1, acquisition_time => 1 }; diff --git a/user_interface/pmt_ro.pm b/user_interface/pmt_ro.pm index b0d6fcc..a06689c 100644 --- a/user_interface/pmt_ro.pm +++ b/user_interface/pmt_ro.pm @@ -229,6 +229,46 @@ sub spectrum_JSON { } +sub spectrum_delete { + my $self = shift; + my %options = @_; + + my @runs = split(",",$options{runs}); + + my $spectrum = $self->{spectrum_shm}->readShm(); + for my $run (@runs){ + delete $spectrum->{$run}; + } + $self->{spectrum_shm}->writeShm($spectrum); + return " "; + +} + +sub spectrum_csv { + my $self = shift; + + my $spectrum = $self->{spectrum_shm}->readShm(); + + for my $key (keys %$spectrum){ + my $run = $spectrum->{$key}; + print "run name:\t".$key."\n"; + for my $info (sort keys %{$run->{meta}}){ + print $info.":\t".$run->{meta}->{$info}."\n"; + } + print "\n"; + print "threshold\tcounts\n"; + for my $data_pair (@{$run->{data}}){ + print $data_pair->[0]."\t".$data_pair->[1]."\n"; + } + + print "\n"; + print "\n"; + + } + return " "; + +} + sub clear_spectrum { my $self = shift; -- 2.43.0