Commit b4364f2f by John Doe

working on stream download

parent 7c967683
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
# Controller for DbStreams # Controller for DbStreams
class DbStreamsController < ApplicationController class DbStreamsController < ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
before_action :set_stream, only: [:update] before_action :set_stream, only: [:update, :data]
before_action :authorize_viewer, only: [:data]
before_action :authorize_owner, only: [:update] before_action :authorize_owner, only: [:update]
def update def update
...@@ -13,6 +14,11 @@ class DbStreamsController < ApplicationController ...@@ -13,6 +14,11 @@ class DbStreamsController < ApplicationController
render status: @service.success? ? :ok : :unprocessable_entity render status: @service.success? ? :ok : :unprocessable_entity
end end
def data
headers["Content-Disposition"] = "attachment; filename='#{@db_stream.name}.txt'"
render :layout=>false, :content_type => "text/plain"
end
private private
def stream_params def stream_params
......
###############################################
# Stream: <%=@db_stream.name%>
# Path: <%=@db_stream.path%>
# Source: <%=@nilm.name%> <%unless @nilm.description.blank?%>(<%=@nilm.description%>)<%end%>
#
#
# start: --
# end: --
# total time: --
# total rows: --
#
#The raw data file can be retrieved at the following URL:
# <%=@db.url%>/stream/extract?path=<%=@db_stream.path%>&start=?&end=?
#
# to import in matlab run:
# nilm = importdata('thisfilename.txt')
#
# nilm.textdata: this help text
# nilm.data: the data
#
# The data has <%= @db_stream.db_elements.count+1 %> columns with the following format:
#
# Column 1: Timestamp (microseconds)
<% col = 2%>
<%@db_stream.db_elements.each do |element|%>
# Column <%=col%>: <%=element.name%> (<%=element.units%>)
<%col+=1%>
<%end%>
#
...@@ -8,7 +8,11 @@ Rails.application.routes.draw do ...@@ -8,7 +8,11 @@ Rails.application.routes.draw do
resources :data_views resources :data_views
resources :dbs, only: [:show, :update] resources :dbs, only: [:show, :update]
resources :db_folders, only: [:show, :update] resources :db_folders, only: [:show, :update]
resources :db_streams, only: [:update] resources :db_streams, only: [:update] do
member do
post 'data'
end
end
resources :db_elements, only: [:index] do resources :db_elements, only: [:index] do
collection do collection do
get 'data' get 'data'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment