GCAT5.0 released
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
#
|
||||
# Copyright 2012 The Board of Regents of the University of Wisconsin System.
|
||||
# Contributors: Jason Shao, James McCurdy, Enhai Xie, Adam G.W. Halstead,
|
||||
# Michael H. Whitney, Nathan DiPiazza, Trey K. Sato and Yury V. Bukhman
|
||||
#
|
||||
# This file is part of GCAT.
|
||||
#
|
||||
# GCAT is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GCAT is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with GCAT. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
module ApplicationHelper
|
||||
|
||||
def relative_path(fullpath)
|
||||
fullpath.to_s.gsub(Rails.root.to_s + "/public","")
|
||||
end
|
||||
|
||||
#find all directories in generatedFiles/ and remove
|
||||
#any that are more than a day old
|
||||
def remove_old_files(path)
|
||||
cur_date = extract_date(path)
|
||||
dirs = Dir.glob(Rails.root + "public/generatedFiles/*") + Dir.glob(Rails.root + "public/uploadedFiles/*")
|
||||
dirs.compact.each do |dir|
|
||||
date = extract_date(dir)
|
||||
if(date != cur_date)
|
||||
puts "Removing: " + dir #log deletions
|
||||
%x[ rm -rf #{dir} ]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def extract_date(path)
|
||||
part = "Files/"
|
||||
segment = path.partition(part).last
|
||||
date = segment.split(/-[0-9]+/).first
|
||||
date.to_i
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,29 @@
|
||||
#
|
||||
# Copyright 2012 The Board of Regents of the University of Wisconsin System.
|
||||
# Contributors: Jason Shao, James McCurdy, Enhai Xie, Adam G.W. Halstead,
|
||||
# Michael H. Whitney, Nathan DiPiazza, Trey K. Sato and Yury V. Bukhman
|
||||
#
|
||||
# This file is part of GCAT.
|
||||
#
|
||||
# GCAT is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# GCAT is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with GCAT. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
module AssaysHelper
|
||||
|
||||
def date_time_options
|
||||
|
||||
[['Y-m-d H:M:S', '%Y-%m-%d %H:%M:%S'],['Y-m-d H:M:S p', '%Y-%m-%d %I:%M:%S %p'],['m/d/y H:M:S','%m/%d/%y %H:%M:%S'],['m/d/y H:M:S p','%m/%d/%y %I:%M:%S %p'],['d/m/y H:M:S','%d/%m/%y %H:%M:%S'],['d/m/y H:M:S p','%d/%m/%y %I:%M:%S %p'],['m/d/Y H:M', '%m/%d/%Y %H:%M']]
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,64 @@
|
||||
module TableBuilder
|
||||
|
||||
# I decided to parse the output file produced by the R library
|
||||
# and build an html table rather than using the YUI JS library
|
||||
# previously implemented.
|
||||
#
|
||||
# This method takes the result hash returned by the R bridge routine and
|
||||
# builds an array of row arrays
|
||||
def output_table result, has_layout
|
||||
# if the user submits a layout file, there will be more columns in the output file
|
||||
offsets = {:pdf => -2, :page => -1}
|
||||
if(has_layout)
|
||||
offsets[:pdf] = -7
|
||||
offsets[:page] = -6
|
||||
end
|
||||
rel_path = result[:txtFile]
|
||||
pdf_path = File.dirname @result[:txtFile] #Rails.root.join("public/"+result[:pdfFile])
|
||||
path = Rails.root.join("public/"+rel_path)
|
||||
raise "File not found" unless File.exists? path
|
||||
file = File.open path
|
||||
output = []
|
||||
file.each_line do |line|
|
||||
if(output.empty?)
|
||||
# the headers seem to be enclosed in quotations
|
||||
# will need to parse a bit differently
|
||||
l_ar = line.split "\"\t\""
|
||||
l_ar.first.delete! "\""
|
||||
l_ar.last.delete! "\"\n"
|
||||
l_ar.collect! {|l| l.gsub ".", " "}
|
||||
output << l_ar
|
||||
else
|
||||
l_ar = line.split "\t"
|
||||
l_ar.last.delete! "\"\n"
|
||||
break unless l_ar.size > 1
|
||||
output << format_row(l_ar, pdf_path, offsets)
|
||||
end
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
# this method: removes quotations from strings, truncates floats to 2 sig. digits,
|
||||
# and creates html links to PDF files
|
||||
# params:
|
||||
# l_ar--An array of the one row of data
|
||||
# path--directory path where the pdf file is located
|
||||
# offsets-- a hash containing the negative array offsets for cells needed to build pdf link
|
||||
#
|
||||
# returns: A formatted array of one row from the output.txt data
|
||||
def format_row l_ar, path, offsets
|
||||
result = l_ar.collect! do |entry|
|
||||
if(entry.to_f.zero?)
|
||||
entry.gsub "\"", ""
|
||||
elsif(view_context.number_with_precision(entry.to_f, precision: 2, significant: true).size > 15)
|
||||
"%E" % view_context.number_with_precision(entry.to_f, precision: 2, significant: true)
|
||||
else
|
||||
view_context.number_with_precision(entry.to_f, precision: 2, significant: true)
|
||||
end
|
||||
end
|
||||
result[offsets[:page]] = result[offsets[:page]].to_i # page number
|
||||
# result[-7] == pdf.name
|
||||
result[0] = "<a href=\"#{path}/#{result[offsets[:pdf]]}?#page=#{result[offsets[:page]]}\" target='_blank'>#{result[0].to_i}</a>".html_safe # add pdf link to first row
|
||||
return result
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user