diff options
author | mr <mr@mrautenberg.de> | 2011-10-04 14:11:43 +0200 |
---|---|---|
committer | mr <mr@mrautenberg.de> | 2011-10-04 14:11:43 +0200 |
commit | ded1c581a4cf113448ca128b89fc4e1b6fb3e5b0 (patch) | |
tree | 3ebf0163d32a608fff63563e76205988844549d3 | |
parent | 3279b362947446cb35ef2ddb2406c6eee3a9b58f (diff) | |
parent | d1a61ff236cf95a7f3cba4a60e85c14e877c730d (diff) |
update to v3.0.0 and add permission to create models
-rw-r--r-- | application.rb | 32 | ||||
-rw-r--r-- | helper.rb | 30 | ||||
-rw-r--r-- | public/arrow_down.png | bin | 0 -> 411 bytes | |||
-rw-r--r-- | public/arrow_left.png | bin | 0 -> 374 bytes | |||
-rw-r--r-- | public/arrow_left_inactive.png | bin | 0 -> 364 bytes | |||
-rw-r--r-- | public/arrow_right.png | bin | 0 -> 386 bytes | |||
-rw-r--r-- | public/arrow_right_inactive.png | bin | 0 -> 400 bytes | |||
-rw-r--r-- | public/arrow_up.png | bin | 0 -> 394 bytes | |||
-rwxr-xr-x | public/javascripts/toxcreate.js | 14 | ||||
-rw-r--r-- | views/classification_validation.haml | 17 | ||||
-rw-r--r-- | views/create.haml | 21 | ||||
-rw-r--r-- | views/endpoint.haml | 2 | ||||
-rw-r--r-- | views/model.haml | 30 | ||||
-rw-r--r-- | views/model_echa.haml | 2 | ||||
-rw-r--r-- | views/model_name.haml | 6 | ||||
-rw-r--r-- | views/models.haml | 13 | ||||
-rw-r--r-- | views/models_navigation.haml | 70 | ||||
-rw-r--r-- | views/style.sass | 30 | ||||
-rw-r--r-- | views/validation.haml | 2 |
19 files changed, 222 insertions, 47 deletions
diff --git a/application.rb b/application.rb index 5137fcc..10507c3 100644 --- a/application.rb +++ b/application.rb @@ -90,10 +90,25 @@ get '/login' do end get '/models/?' do - @models = ToxCreateModel.all.sort(:order => "DESC") + @page = params[:page] ? params[:page].to_i : 0 + order = params["order"] == "ASC" ? "ASC" : "DESC" + params["order"] = order + sort_by = params["sort_by"] + if sort_by + case sort_by + when "name", "created_at", "type" + @models = ToxCreateModel.all.sort_by(sort_by.to_sym, :order => "#{order} ALPHA") + when "id" + @models = ToxCreateModel.all.sort(:order => "#{order}") + end + else + params["sort_by"] = "created_at" + end + + @models = ToxCreateModel.all.sort(:order => "DESC") unless @models @models.each{|m| raise "internal redis error: model is nil" unless m} - subjectstring = @subjectid ? "?subjectid=#{CGI.escape(@subjectid)}" : "" - haml :models, :locals=>{:models=>@models, :subjectstring => subjectstring} + @models.delete_if{|m| !is_authorized(m.web_uri, "GET")} + haml :models, :locals=>{:models=>@models} end get '/model/:id/status/?' do @@ -156,13 +171,12 @@ end get '/model/:id/:view/?' do response['Content-Type'] = 'text/plain' model = ToxCreateModel.get(params[:id]) - subjectstring = @subjectid ? "?subjectid=#{CGI.escape(@subjectid)}" : "" begin case params[:view] when "model" - haml :model, :locals=>{:model=>model,:subjectstring => subjectstring}, :layout => false + haml :model, :locals=>{:model=>model}, :layout => false when /validation/ - haml :validation, :locals=>{:model=>model,:subjectstring => subjectstring}, :layout => false + haml :validation, :locals=>{:model=>model}, :layout => false else return "unable to render model: id #{params[:id]}, view #{params[:view]}" end @@ -173,6 +187,7 @@ end get '/predict/?' do @models = ToxCreateModel.all.sort(:order => "DESC") + @models.delete_if{|m| !is_authorized(m.web_uri, "GET")} @models = @models.collect{|m| m if m.status == 'Completed'}.compact haml :predict end @@ -217,7 +232,10 @@ post '/feature' do end post '/models' do # create a new model - + unless is_aluist + flash[:notice] = "You do not have the permission to create a new model." + redirect url_for('/models') + end unless (params[:dataset] and params[:prediction_feature]) or (params[:file] and params[:file][:tempfile]) #params[:endpoint] and flash[:notice] = "Please upload a Excel or CSV file or select an AMBIT dataset." redirect url_for('/create') @@ -9,6 +9,10 @@ helpers do return false end + def is_aluist + OpenTox::Authorization.list_user_groups(session[:username], session[:subjectid]).include?("aluist") + end + def hide_link(destination) @link_id = 0 unless @link_id @link_id += 1 @@ -91,5 +95,29 @@ helpers do haml :neighbors_navigation, :layout => false end -end + def models_navigation + @page = 0 unless @page + haml :models_navigation, :layout => false + end + def endpoint_option_list(max_time=3600) + out = "" + tmpfile = File.join(TMP_DIR, "endpoint_option_list") + if File.exists? tmpfile + if Time.now-File.mtime(tmpfile) <= max_time + f = File.open(tmpfile, 'r+') + f.each{|line| out << line} + return out + else + File.unlink(tmpfile) + end + end + result = OpenTox::Ontology::Echa.endpoint_option_list() + if result.lines.count > 3 + f = File.new(tmpfile,"w") + f.print result + f.close + end + return result + end +end diff --git a/public/arrow_down.png b/public/arrow_down.png Binary files differnew file mode 100644 index 0000000..d298656 --- /dev/null +++ b/public/arrow_down.png diff --git a/public/arrow_left.png b/public/arrow_left.png Binary files differnew file mode 100644 index 0000000..8d18c67 --- /dev/null +++ b/public/arrow_left.png diff --git a/public/arrow_left_inactive.png b/public/arrow_left_inactive.png Binary files differnew file mode 100644 index 0000000..52c11bf --- /dev/null +++ b/public/arrow_left_inactive.png diff --git a/public/arrow_right.png b/public/arrow_right.png Binary files differnew file mode 100644 index 0000000..7fe64a8 --- /dev/null +++ b/public/arrow_right.png diff --git a/public/arrow_right_inactive.png b/public/arrow_right_inactive.png Binary files differnew file mode 100644 index 0000000..496f79e --- /dev/null +++ b/public/arrow_right_inactive.png diff --git a/public/arrow_up.png b/public/arrow_up.png Binary files differnew file mode 100644 index 0000000..70417dc --- /dev/null +++ b/public/arrow_up.png diff --git a/public/javascripts/toxcreate.js b/public/javascripts/toxcreate.js index ee783ce..0e82040 100755 --- a/public/javascripts/toxcreate.js +++ b/public/javascripts/toxcreate.js @@ -18,20 +18,20 @@ $(function() { return this.replace(/^\s+|\s+$/g, ''); } - checkStati = function(stati, subjectstr) { + checkStati = function(stati) { stati = stati.split(", "); $("body") var newstati = new Array; $.each(stati, function(){ - checkProgress(this, subjectstr); - if(checkStatus(this, subjectstr) > 0) newstati.push(this); + checkProgress(this); + if(checkStatus(this) > 0) newstati.push(this); }); - if (newstati.length > 0) var statusCheck = setTimeout('checkStati("' + newstati.join(", ") + '", "' + subjectstr + '")',10000); + if (newstati.length > 0) var statusCheck = setTimeout('checkStati("' + newstati.join(", ") + '")',10000); }; - checkStatus = function(id, subjectstr) { + checkStatus = function(id) { if(id == "") return -1; - var opts = {method: 'get', action: 'model/' + id + '/status' + subjectstr, id: id}; + var opts = {method: 'get', action: 'model/' + id + '/status', id: id}; var status_changed = $.ajax({ type: opts.method, url: opts.action, @@ -62,7 +62,7 @@ $(function() { }; - checkProgress = function(id, subjectstr) { + checkProgress = function(id) { var task = $("input#model_" + id + "_task").attr('value'); var opts = {action: task + "/percentageCompleted" , id: id}; var progress_changed = $.ajax({ diff --git a/views/classification_validation.haml b/views/classification_validation.haml index 47e1f75..e06cb65 100644 --- a/views/classification_validation.haml +++ b/views/classification_validation.haml @@ -5,13 +5,24 @@ %dt %a{:href => "http://en.wikipedia.org/wiki/Receiver_operating_characteristic", :rel => "external"} Average area under ROC: %dd - = sprintf("%.3f", model.average_area_under_roc.to_f) if model.average_area_under_roc + - if model.average_area_under_roc + = sprintf("%.3f", model.average_area_under_roc.to_f) + - else + = 'NA' %dt %a{:href => "http://en.wikipedia.org/wiki/Sensitivity_and_specificity", :rel => "external"} Specificity: -%dd= sprintf("%.3f", model.specificity.to_f) if model.specificity +%dd + - if model.specificity + = sprintf("%.3f", model.specificity.to_f) + - else + = 'NA' %dt %a{:href => "http://en.wikipedia.org/wiki/Sensitivity_and_specificity", :rel => "external"} Sensitivity: -%dd= sprintf("%.3f", model.sensitivity.to_f) if model.sensitivity +%dd + - if model.sensitivity + = sprintf("%.3f", model.sensitivity.to_f) + - else + = 'NA' %dt %a{:href => "http://en.wikipedia.org/wiki/Confusion_matrix", :rel => "external"} Confusion Matrix: - if model.confusion_matrix diff --git a/views/create.haml b/views/create.haml index b706484..da85382 100644 --- a/views/create.haml +++ b/views/create.haml @@ -24,6 +24,8 @@ = link_to "SDF", '/help' format: %input{:type => 'file', :name => 'file', :id => 'file', :size => '41'} + %br + -# = haml :model_echa, :layout => false %input{ :type => "submit", :value => "Create model"} =# link_to "Cancel", '/create' @@ -47,15 +49,16 @@ structure-activity models from your experimental data. The models can be used to predict toxicity of new chemicals (e.g. for %a{:href => "http://ec.europa.eu/environment/chemicals/reach/reach_intro.htm", :rel => "external"} REACH purposes) and to reduce the need for animal testing. The following methods are currently available: - %ul - %li - = toggle_link("#lazar_description","lazar") - %em= toggle_link("#classification","classification") - models and - %li - = toggle_link("#lazar_description","lazar") - %em= toggle_link("#regression","regression") - models (experimental) + %ul + %li + = toggle_link("#lazar_description","lazar") + %em= toggle_link("#classification","classification") + models and + %li + = toggle_link("#lazar_description","lazar") + %em= toggle_link("#regression","regression") + models (experimental) + %p Further modelling algorithms may be added in future versions. .login_notice diff --git a/views/endpoint.haml b/views/endpoint.haml index af06b80..9c250ca 100644 --- a/views/endpoint.haml +++ b/views/endpoint.haml @@ -9,4 +9,4 @@ %em in-vitro, or %em in-vivo - expriment, clinical trial or epidemiological study + experiment, clinical trial or epidemiological study diff --git a/views/model.haml b/views/model.haml index 266fe19..51a7498 100644 --- a/views/model.haml +++ b/views/model.haml @@ -25,8 +25,14 @@ }); %div{:id => "model_#{model.id}_progress", :class => "model_progress", :title => "#{percentage_completed}%"} - //= haml :model_progress, :locals=>{:percentage_completed=>percentage_completed}, :layout => false - + //= haml :model_progress, :locals=>{:percentage_completed=>percentage_completed}, :layout => false + + - if is_authorized(model.web_uri, "DELETE") + %a{:href => url_for("/model/#{model.id}"), :id => "delete_#{model.id}", :class => 'delete_link'} + - if model.status =~ /Completed|Error|Cancelled/ + (delete) + - else + (stop) %span %br @@ -38,7 +44,7 @@ - if model.error_messages %dt Errors: %dd= model.error_messages - - if CONFIG[:logger]=="debug" + - if CONFIG[:logger]=="debug" && is_aluist %dt Task: %dd %a{:href => "#{model.task_uri}", :id => "model_#{model.id}_task_link", :rel => "external"} @@ -60,26 +66,26 @@ %dt Training dataset: %dd - if model.training_dataset.match(/ambit/i) - %a{:href => "#{model.training_dataset}#{subjectstring}", :rel => "external"} Ambit database + %a{:href => "#{model.training_dataset}", :rel => "external"} Ambit database - else - %a{:href => "#{model.training_dataset}.xls#{subjectstring}"} Excel sheet + %a{:href => "#{model.training_dataset}.xls"} Excel sheet , -#%a{:href => "#{model.training_dataset}.rdf"} RDF/XML -#%em (experts) , - %a{:href => "#{model.training_dataset}.sdf#{subjectstring}" } SDF + %a{:href => "#{model.training_dataset}.sdf" } SDF , - %a{:href => "#{model.training_dataset}.yaml#{subjectstring}" } YAML + %a{:href => "#{model.training_dataset}.yaml" } YAML %em (experts) - if model.feature_dataset %dt Feature dataset: %dd -#%a{:href => "#{model.feature_dataset}.rdf"} RDF/XML -#, - %a{:href => "#{model.feature_dataset}.xls#{subjectstring}"} Excel sheet + %a{:href => "#{model.feature_dataset}.xls"} Excel sheet , - %a{:href => "#{model.feature_dataset}.sdf#{subjectstring}"} SDF + %a{:href => "#{model.feature_dataset}.sdf"} SDF , - %a{:href => "#{model.feature_dataset}.yaml#{subjectstring}"} YAML + %a{:href => "#{model.feature_dataset}.yaml"} YAML %em (experts) - if model.uri %dt Model: @@ -89,7 +95,7 @@ -#, - if model.validation_qmrf_uri %a{:href => File.join(model.validation_qmrf_uri,"editor")} QMRF Editor, - %a{:href => "#{model.uri}.yaml#{subjectstring}"} YAML + %a{:href => "#{model.uri}.yaml"} YAML %em (experts, models cannot be represented in Excel) - = haml :validation, :locals=>{:model=>model,:subjectstring => subjectstring}, :layout => false + = haml :validation, :locals=>{:model=>model}, :layout => false diff --git a/views/model_echa.haml b/views/model_echa.haml new file mode 100644 index 0000000..257a28a --- /dev/null +++ b/views/model_echa.haml @@ -0,0 +1,2 @@ +Select an endpoint: += endpoint_option_list
\ No newline at end of file diff --git a/views/model_name.haml b/views/model_name.haml index 874ddaa..19819f4 100644 --- a/views/model_name.haml +++ b/views/model_name.haml @@ -5,4 +5,8 @@ }); %h2 = model.name - + - if is_authorized(model.web_uri, "PUT") + %span{:class => "edit_button"} + ( + %a{:href => url_for("/model/#{model.id}/name?mode=edit"), :id => "edit_#{model.id}"} edit + ) diff --git a/views/models.haml b/views/models.haml index 9b70ae7..947e403 100644 --- a/views/models.haml +++ b/views/models.haml @@ -3,7 +3,7 @@ :javascript $(function() { if(#{stati != 0}) { - setTimeout('checkStati("#{stati_to_check}", "#{subjectstring}")',5000); + setTimeout('checkStati("#{stati_to_check}", "")',5000); } var reload_validation = true; }); @@ -18,8 +18,11 @@ = haml :similarity, :layout => false = haml :significant_fragments, :layout => false -- if @models - - @models.each do |model| - = haml :model, :locals=>{:model=>model,:subjectstring=>subjectstring}, :layout => false --if @models.size == 0 +- first = 5*@page +- last = first+4 += models_navigation if @models.size > 1 +- if @models[first..last] + - @models[first..last].each do |model| + = haml :model, :locals=>{:model=>model}, :layout => false +-if @models.size == 0 .notice There are currently no models. You have to create a model first. diff --git a/views/models_navigation.haml b/views/models_navigation.haml new file mode 100644 index 0000000..0dc1f63 --- /dev/null +++ b/views/models_navigation.haml @@ -0,0 +1,70 @@ +.models_navigation + + %form{:name => "nav", :action => url_for('/models'), :method => "get", :id => "nav"} + %input{:type => :hidden, :name => :sort_by, :id => "sort_by", :value => params[:sort_by]} + %input{:type => :hidden, :name => :order, :id => "order", :value => params[:order]} + %input{:type => :hidden, :name => :page, :id => "page", :value => params[:page]} + + Sort by: + - ["created_at","name","type"].each do |s| + - idname = s == "created_at" ? "date" : s + - if params[:sort_by] == s + %div{:id => idname, :class => "active"} + %span="#{idname.capitalize}" + - if params[:order] == "ASC" + #up{:class => "link"} + %img{:src => "arrow_down.png", :alt => 'in ascending order', :title => 'in ascending order'}/ + - else + #down{:class => "link"} + %img{:src => "arrow_up.png", :alt => 'in descending order', :title => 'in descending order'}/ + - else + %div{:id => idname, :class => "link"}="#{idname.capitalize} " + - if @models.size > 5 + | + Models: + = "#{@models.size}" + - unless @page.to_i == 0 + #prev + %img{:src => "arrow_left.png", :alt => 'previous', :title => 'previous'}/ + -else + %img{:src => "arrow_left_inactive.png", :alt => '', :title => ''}/ + + - if @models.size < 5*@page+5 + - last = @models.size + - else + - last = 5*@page+5 + + = "(#{5*@page+1}-#{last}/#{@models.size})" + - unless 5*@page.to_i+5 >= @models.size + #next + %img{:src => "arrow_right.png", :alt => 'next', :title => 'next'}/ + -else + %img{:src => "arrow_right_inactive.png", :alt => '', :title => ''}/ + + - js = "" + - ["created_at","name","type"].each do |s| + - idname = s == "created_at" ? "date" : s + - js += "$('##{idname}').click(function() \{ \n " + - js += " $('#sort_by').val('#{s}');\n " + - js += " $('#nav').submit();\n " + - js += "});\n " + + :javascript + $("#prev").click(function() { + $("#page").val(#{@page-1}); + $("#nav").submit(); + }); + $("#next").click(function() { + $("#page").val(#{@page+1}); + $("#nav").submit(); + }); + #{js} + $("#down").click(function() { + $("#order").val("ASC"); + $("#nav").submit(); + }); + $("#up").click(function() { + $("#order").val("DESC"); + $("#nav").submit(); + }); +
\ No newline at end of file diff --git a/views/style.sass b/views/style.sass index 9f1bf5b..ab05d93 100644 --- a/views/style.sass +++ b/views/style.sass @@ -281,3 +281,33 @@ dl margin-left: 16px margin-right: 16px float: left + +.models_navigation + #prev + @extend a + display: inline + cursor: pointer + #next + @extend a + display: inline + cursor: pointer + .link + @extend a + display: inline + cursor: pointer + .active + display: inline + color: #000 + font-weight: bold + .thin + font-weight: 100 + +.level_1 + padding-left: 10px + font-weight: bold +.level_2 + padding-left: 20px +.level_3 + padding-left: 30px +.level_4 + padding-left: 40px diff --git a/views/validation.haml b/views/validation.haml index b8a6eaa..0a094d6 100644 --- a/views/validation.haml +++ b/views/validation.haml @@ -7,7 +7,7 @@ - if model.validation_report_uri %dt Detailed report: %dd - %a{:href => model.validation_report_uri + subjectstring, :target => "_blank"} show + %a{:href => model.validation_report_uri, :target => "_blank"} show %dt Number of predictions: %dd= model.nr_predictions.to_s - case model.type |