Skip to content

Commit

Permalink
Rubocop autocorrect.
Browse files Browse the repository at this point in the history
  • Loading branch information
studiospring committed Sep 23, 2015
1 parent 78f91b8 commit ef19d42
Show file tree
Hide file tree
Showing 40 changed files with 751 additions and 714 deletions.
28 changes: 14 additions & 14 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
protect_from_forgery :with => :exception

before_filter :configure_permitted_parameters, if: :devise_controller?
before_filter :configure_permitted_parameters, :if => :devise_controller?

protected
#permit additional devise user parameters
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username) }
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username) }
devise_parameter_sanitizer.for(:edit_user) { |u| u.permit(:username, :email) }
end
# permit additional devise user parameters
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username) }
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username) }
devise_parameter_sanitizer.for(:edit_user) { |u| u.permit(:username, :email) }
end

#for use with Devise
def require_admin
unless current_user && current_user.admin
flash[:alert] = "You must sign in to view this page"
redirect_to new_user_session_path
end
# for use with Devise
def require_admin
unless current_user && current_user.admin
flash[:alert] = "You must sign in to view this page"
redirect_to new_user_session_path
end
end
end
15 changes: 10 additions & 5 deletions app/controllers/irradiances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ class IrradiancesController < ApplicationController
def index
@irradiances = Irradiance.all
end

def new
@irradiance = Irradiance.new
end

def create
@irradiance = Irradiance.new(irradiance_params)
if @irradiance.save
Expand All @@ -15,12 +17,15 @@ def create
render "new"
end
end

def show
@irradiance = Irradiance.find(params[:id])
end

def edit
@irradiance = Irradiance.find(params[:id])
end

def update
@irradiance = Irradiance.find(params[:id])
if @irradiance.update(irradiance_params)
Expand All @@ -30,15 +35,15 @@ def update
render "edit"
end
end

def destroy
@irradiance = Irradiance.find(params[:id])
@irradiance.destroy
redirect_to irradiances_url
end
private
def irradiance_params
#enter mass assignable fields here
params.require(:irradiance).permit(:direct, :diffuse, :postcode_id)
end
def irradiance_params
# enter mass assignable fields here
params.require(:irradiance).permit(:direct, :diffuse, :postcode_id)
end
end

12 changes: 8 additions & 4 deletions app/controllers/panels_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ class PanelsController < ApplicationController
def index
@panels = Panel.all
end

def show
@panel = Panel.find(params[:id])
end

def edit
@panel = Panel.find(params[:id])
end

def update
@panel = Panel.find(params[:id])
if @panel.update(panel_params)
Expand All @@ -18,14 +21,15 @@ def update
render "edit"
end
end

def destroy
@panel = Panel.find(params[:id])
@panel.destroy
redirect_to panels_url
end
private
def panel_params
#enter mass assignable fields here
params.require(:panel).permit(:tilt, :bearing, :panel_size)
end
def panel_params
# enter mass assignable fields here
params.require(:panel).permit(:tilt, :bearing, :panel_size)
end
end
15 changes: 10 additions & 5 deletions app/controllers/postcodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ class PostcodesController < ApplicationController
def index
@postcodes = Postcode.all.limit(10)
end

def show
@postcode = Postcode.find(params[:id])
end

def new
@postcode = Postcode.new
end

def edit
@postcode = Postcode.find(params[:id])
end

def create
@postcode = Postcode.new(postcode_params)

Expand All @@ -22,6 +26,7 @@ def create
render "new"
end
end

def update
@postcode = Postcode.find(params[:id])
if @postcode.update(postcode_params)
Expand All @@ -31,15 +36,15 @@ def update
render "edit"
end
end

def destroy
@postcode = Postcode.find(params[:id])
@postcode.destroy
redirect_to postcodes_url
end
private
def postcode_params
#enter mass assignable fields here
params.require(:postcode).permit(:pcode, :suburb, :state, :latitude, :longitude, :urban)
end
def postcode_params
# enter mass assignable fields here
params.require(:postcode).permit(:pcode, :suburb, :state, :latitude, :longitude, :urban)
end
end

31 changes: 18 additions & 13 deletions app/controllers/pv_queries_controller.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,52 @@
class PvQueriesController < ApplicationController
#before_filter :authenticate_user!, except: [:new, :results]
before_filter :require_admin, except: [:new, :create]
# before_filter :authenticate_user!, except: [:new, :results]
before_filter :require_admin, :except => [:new, :create]

respond_to :html, :js
def index
@pv_queries = PvQuery.all
end

def new
@pv_query = PvQuery.new
@pv_query.panels.build
end
#renders in new page, via create.js.coffee
# renders in new page, via create.js.coffee
def create
@pv_query = PvQuery.new(pv_query_params)

if @pv_query.save
@output_pa_array = @pv_query.output_pa_array.join(' ') #convert from array to string
#@column_heights = @pv_query.column_heights
@output_pa_array = @pv_query.output_pa_array.join(' ') # convert from array to string
# @column_heights = @pv_query.column_heights
@output_pa = @pv_query.output_pa
@query_params = @pv_query.panels
@search_params = @pv_query.pvo_search_params
@candidate_systems = PvOutput.search(@search_params)
#@get_system = PvOutput.get_system(453)
##call search, candidate_systems...
# @get_system = PvOutput.get_system(453)
# #call search, candidate_systems...
@similar_system = PvOutput.find_similar_system(@search_params)
if @similar_system
@pvo_system = PvOutput.new(@similar_system)
#define other attributes by calling get_statistic
# define other attributes by calling get_statistic
@pvo_system.get_stats
@empirical_output_pa = @pv_query.empirical_output_pa(@pvo_system.output_per_system_watt)
end

respond_with({output_pa_array: @output_pa_array}, location: new_pv_query_url)
respond_with({:output_pa_array => @output_pa_array}, :location => new_pv_query_url)
else
render 'new'
end
end

def show
@pv_query = PvQuery.find(params[:id])
end

def edit
@pv_query = PvQuery.find(params[:id])
@pv_query.postcode_id = @pv_query.postcode.pcode
end

def update
@pv_query = PvQuery.find(params[:id])
if @pv_query.update(pv_query_params)
Expand All @@ -52,14 +56,15 @@ def update
render "edit"
end
end

def destroy
@pv_query = PvQuery.find(params[:id])
@pv_query.destroy
redirect_to pv_queries_url
end
private
def pv_query_params
#enter mass assignable fields here
params.require(:pv_query).permit(:postcode_id, panels_attributes: [:tilt, :bearing, :panel_size])
end
def pv_query_params
# enter mass assignable fields here
params.require(:pv_query).permit(:postcode_id, :panels_attributes => [:tilt, :bearing, :panel_size])
end
end
4 changes: 2 additions & 2 deletions app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ def home

def about
end

def terms

end
end
9 changes: 5 additions & 4 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def create
render "new"
end
end

def update
@user = current_user
@user.admin = params[:user][:admin]
Expand All @@ -20,8 +21,8 @@ def update
end
end
private
def user_params
#enter mass assignable fields here
params.require(:user).permit(:username, :email)
end
def user_params
# enter mass assignable fields here
params.require(:user).permit(:username, :email)
end
end
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ApplicationHelper

#return full title on a per-page basis
# return full title on a per-page basis
def full_title(page_title)
base_title = "Solario"
if page_title.empty?
Expand Down
34 changes: 17 additions & 17 deletions app/models/concerns/solar_time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ module SolarTime
def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
end

#refactor 'B' variable used in EoT and declination methods
#return radians
# refactor 'B' variable used in EoT and declination methods
# return radians
def b
b = (360 / 365.0)*(self.day - 81).to_rad
b = (360 / 365.0) * (self.day - 81).to_rad
end
#return Equation of Time in minutes
# return Equation of Time in minutes
def eot
b = self.b
eot = 9.87 * Math.sin(2 * b) - 7.53 * Math.cos(b) - 1.5 * Math.sin(b)
end
#return lstm (local standard time meridian) in degrees (derived from timezone)
#AEST is (GMT/UTC + 10) therefore lstm (local standard time meridian) is 15 * 10
#Broken Hill is actually 142.5, Xmas Is, Lord Howe have diff timezones
#Does not account for DST
# return lstm (local standard time meridian) in degrees (derived from timezone)
# AEST is (GMT/UTC + 10) therefore lstm (local standard time meridian) is 15 * 10
# Broken Hill is actually 142.5, Xmas Is, Lord Howe have diff timezones
# Does not account for DST
def lstm
case self.state
when 'SA', 'NT'
Expand All @@ -30,22 +30,22 @@ def lstm
else
lstm = 150
end
return lstm
lstm
end
#return minutes by which local time should be corrected, to account for
#position and day of year
# return minutes by which local time should be corrected, to account for
# position and day of year
def time_correction
time_correction = 4 * (self.longitude - self.lstm) + self.eot
end
#convert local time to local solar time in decimal notation
#insert 24hr hourly time: 9, 12, 13 ...
#and 13.5 is returned for 13:30pm
# convert local time to local solar time in decimal notation
# insert 24hr hourly time: 9, 12, 13 ...
# and 13.5 is returned for 13:30pm
def to_lst
lst = self.local_time + (self.time_correction / 60)
end
#return hour angle in degrees
# return hour angle in degrees
def hra
hra = 15 * (self.to_lst - 12)
end

end
Loading

0 comments on commit ef19d42

Please sign in to comment.