From 1fbc7f06b289239792691a0870ec7344793e640e Mon Sep 17 00:00:00 2001 From: Dave Doolin Date: Tue, 2 Feb 2016 13:44:21 -0800 Subject: [PATCH 1/3] lock gems, ruby version and gemset --- .ruby-gemset | 1 + .ruby-version | 1 + Gemfile | 2 +- Gemfile.lock | 27 +++++++++++++++++++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 .ruby-gemset create mode 100644 .ruby-version create mode 100644 Gemfile.lock diff --git a/.ruby-gemset b/.ruby-gemset new file mode 100644 index 0000000..5f9a5b4 --- /dev/null +++ b/.ruby-gemset @@ -0,0 +1 @@ +holtwinters diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..276cbf9 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.3.0 diff --git a/Gemfile b/Gemfile index 8ef761c..ea2c13b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ # -*- mode: ruby; -*- -source :rubygems +source 'https://rubygems.org' gemspec diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..aa6362c --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,27 @@ +PATH + remote: . + specs: + holt_winters (0.0.0) + +GEM + remote: https://rubygems.org/ + specs: + diff-lcs (1.1.3) + rspec (2.6.0) + rspec-core (~> 2.6.0) + rspec-expectations (~> 2.6.0) + rspec-mocks (~> 2.6.0) + rspec-core (2.6.4) + rspec-expectations (2.6.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.6.0) + +PLATFORMS + ruby + +DEPENDENCIES + holt_winters! + rspec (~> 2.6.0) + +BUNDLED WITH + 1.11.2 From 4ceb035a486ae4e4ed89a6ab571b2c89d33f7ac6 Mon Sep 17 00:00:00 2001 From: Dave Doolin Date: Tue, 2 Feb 2016 13:57:39 -0800 Subject: [PATCH 2/3] start of updates for rubocop --- .rubocop.yml | 1 + .rubocop_todo.yml | 94 +++++++++++++++++++++++++++++++++++++ Gemfile.lock | 12 +++++ holt_winters.gemspec | 21 +++++---- lib/holt_winters.rb | 2 + lib/holt_winters/version.rb | 2 +- 6 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..49f9a94 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1 @@ +inherit_from: ./.rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..d77a960 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,94 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2016-02-02 13:47:03 -0800 using RuboCop version 0.36.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. +Lint/UnusedMethodArgument: + Exclude: + - 'lib/holt_winters.rb' + +# Offense count: 2 +Metrics/AbcSize: + Max: 87 + +# Offense count: 8 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes. +# URISchemes: http, https +Metrics/LineLength: + Max: 109 + +# Offense count: 2 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 26 + +# Offense count: 2 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 9 + +# Offense count: 2 +# Cop supports --auto-correct. +Style/EmptyLines: + Exclude: + - 'lib/holt_winters.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: Width. +Style/IndentationWidth: + Exclude: + - 'lib/holt_winters.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/MutableConstant: + Exclude: + - 'lib/holt_winters/version.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'holt_winters.gemspec' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowAsExpressionSeparator. +Style/Semicolon: + Exclude: + - 'lib/holt_winters.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles. +# SupportedStyles: space, no_space +# Style/SpaceBeforeBlockBraces: +# EnforcedStyle: no_space + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles. +# SupportedStyles: use_perl_names, use_english_names +Style/SpecialGlobalVars: + EnforcedStyle: use_perl_names + +# Offense count: 12 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +#Style/StringLiterals: +# Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Style/UnneededPercentQ: + Exclude: + - 'holt_winters.gemspec' diff --git a/Gemfile.lock b/Gemfile.lock index aa6362c..caa3152 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,7 +6,12 @@ PATH GEM remote: https://rubygems.org/ specs: + ast (2.2.0) diff-lcs (1.1.3) + parser (2.3.0.2) + ast (~> 2.2) + powerpack (0.1.1) + rainbow (2.1.0) rspec (2.6.0) rspec-core (~> 2.6.0) rspec-expectations (~> 2.6.0) @@ -15,6 +20,12 @@ GEM rspec-expectations (2.6.0) diff-lcs (~> 1.1.2) rspec-mocks (2.6.0) + rubocop (0.36.0) + parser (>= 2.3.0.0, < 3.0) + powerpack (~> 0.1) + rainbow (>= 1.99.1, < 3.0) + ruby-progressbar (~> 1.7) + ruby-progressbar (1.7.5) PLATFORMS ruby @@ -22,6 +33,7 @@ PLATFORMS DEPENDENCIES holt_winters! rspec (~> 2.6.0) + rubocop BUNDLED WITH 1.11.2 diff --git a/holt_winters.gemspec b/holt_winters.gemspec index 3723ff9..46e7734 100644 --- a/holt_winters.gemspec +++ b/holt_winters.gemspec @@ -1,22 +1,23 @@ # -*- mode: ruby; encoding: utf-8 -*- -$:.push File.expand_path("../lib", __FILE__) -require "holt_winters/version" +$:.push File.expand_path('../lib', __FILE__) +require 'holt_winters/version' Gem::Specification.new do |s| - s.name = "holt_winters" + s.name = 'holt_winters' s.version = HoltWinters::VERSION s.platform = Gem::Platform::RUBY - s.authors = ["Brandon Keene"] - s.email = ["bkeene@gmail.com"] - s.homepage = "" + s.authors = ['Brandon Keene'] + s.email = ['bkeene@gmail.com'] + s.homepage = '' s.summary = %q{Holt-Winters Triple Exponential Smoothing} - s.rubyforge_project = "holt_winters" + s.rubyforge_project = 'holt_winters' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") - s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } - s.require_paths = ["lib"] + s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } + s.require_paths = ['lib'] - s.add_development_dependency "rspec", "~> 2.6.0" + s.add_development_dependency 'rspec', '~> 2.6.0' + s.add_development_dependency 'rubocop' end diff --git a/lib/holt_winters.rb b/lib/holt_winters.rb index 6f469fe..b9359bd 100644 --- a/lib/holt_winters.rb +++ b/lib/holt_winters.rb @@ -61,7 +61,9 @@ def holt_winters(y, a0, b0, alpha, beta, gamma, seasonal, period, m) (2..(y.size - 1)).each do |i| # Calculate overall smoothing + # rubocop:disable all if (i - period) >= 0 + # rubocop:enable all st[i] = alpha * y[i] / it[i - period] + (1.0 - alpha) * (st[i - 1] + bt[i - 1]) else st[i] = alpha * y[i] + (1.0 - alpha) * (st[i - 1] + bt[i - 1]) diff --git a/lib/holt_winters/version.rb b/lib/holt_winters/version.rb index 8455843..ae67f34 100644 --- a/lib/holt_winters/version.rb +++ b/lib/holt_winters/version.rb @@ -1,3 +1,3 @@ module HoltWinters - VERSION = "0.0.0" + VERSION = '0.0.0' end From 26889c6fce3f700b70e4c5b624e80cc8e4fa32a3 Mon Sep 17 00:00:00 2001 From: Dave Doolin Date: Tue, 2 Feb 2016 14:15:10 -0800 Subject: [PATCH 3/3] rubocop auto correct done --- .rubocop_todo.yml | 67 ------------------------------------- holt_winters.gemspec | 4 +-- lib/holt_winters.rb | 8 ++--- lib/holt_winters/version.rb | 3 +- 4 files changed, 7 insertions(+), 75 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d77a960..c91c7ae 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,13 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. -Lint/UnusedMethodArgument: - Exclude: - - 'lib/holt_winters.rb' - # Offense count: 2 Metrics/AbcSize: Max: 87 @@ -32,63 +25,3 @@ Metrics/MethodLength: # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: Max: 9 - -# Offense count: 2 -# Cop supports --auto-correct. -Style/EmptyLines: - Exclude: - - 'lib/holt_winters.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: Width. -Style/IndentationWidth: - Exclude: - - 'lib/holt_winters.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/MutableConstant: - Exclude: - - 'lib/holt_winters/version.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Exclude: - - 'holt_winters.gemspec' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Exclude: - - 'lib/holt_winters.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles. -# SupportedStyles: space, no_space -# Style/SpaceBeforeBlockBraces: -# EnforcedStyle: no_space - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: SupportedStyles. -# SupportedStyles: use_perl_names, use_english_names -Style/SpecialGlobalVars: - EnforcedStyle: use_perl_names - -# Offense count: 12 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -#Style/StringLiterals: -# Enabled: false - -# Offense count: 1 -# Cop supports --auto-correct. -Style/UnneededPercentQ: - Exclude: - - 'holt_winters.gemspec' diff --git a/holt_winters.gemspec b/holt_winters.gemspec index 46e7734..8db5f09 100644 --- a/holt_winters.gemspec +++ b/holt_winters.gemspec @@ -1,5 +1,5 @@ # -*- mode: ruby; encoding: utf-8 -*- -$:.push File.expand_path('../lib', __FILE__) +$LOAD_PATH.push File.expand_path('../lib', __FILE__) require 'holt_winters/version' Gem::Specification.new do |s| @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.authors = ['Brandon Keene'] s.email = ['bkeene@gmail.com'] s.homepage = '' - s.summary = %q{Holt-Winters Triple Exponential Smoothing} + s.summary = 'Holt-Winters Triple Exponential Smoothing' s.rubyforge_project = 'holt_winters' diff --git a/lib/holt_winters.rb b/lib/holt_winters.rb index b9359bd..6275295 100644 --- a/lib/holt_winters.rb +++ b/lib/holt_winters.rb @@ -40,7 +40,7 @@ def forecast(y, alpha, beta, gamma, period, m) seasonal = seasonal_indicies(y, period, seasons) - holt_winters(y, a0, b0, alpha, beta, gamma, seasonal, period, m); + holt_winters(y, a0, b0, alpha, beta, gamma, seasonal, period, m) end def holt_winters(y, a0, b0, alpha, beta, gamma, seasonal, period, m) @@ -64,7 +64,7 @@ def holt_winters(y, a0, b0, alpha, beta, gamma, seasonal, period, m) # rubocop:disable all if (i - period) >= 0 # rubocop:enable all - st[i] = alpha * y[i] / it[i - period] + (1.0 - alpha) * (st[i - 1] + bt[i - 1]) + st[i] = alpha * y[i] / it[i - period] + (1.0 - alpha) * (st[i - 1] + bt[i - 1]) else st[i] = alpha * y[i] + (1.0 - alpha) * (st[i - 1] + bt[i - 1]) end @@ -88,11 +88,10 @@ def holt_winters(y, a0, b0, alpha, beta, gamma, seasonal, period, m) # See: http://robjhyndman.com/researchtips/hw-initialization/ # 1st period's average can be taken. But y[0] works better. - def initial_level(y, period) + def initial_level(y, _period) y.first end - # See: http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc435.htm def initial_trend(y, period) sum = 0 @@ -104,7 +103,6 @@ def initial_trend(y, period) sum / (period * period) end - # See: http://www.itl.nist.gov/div898/handbook/pmc/section4/pmc435.htm def seasonal_indicies(y, period, seasons) seasonal_average = Array.new(seasons, 0.0) diff --git a/lib/holt_winters/version.rb b/lib/holt_winters/version.rb index ae67f34..b86e756 100644 --- a/lib/holt_winters/version.rb +++ b/lib/holt_winters/version.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module HoltWinters - VERSION = '0.0.0' + VERSION = '0.0.0'.freeze end