-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53bffd8
commit f43d031
Showing
12 changed files
with
93 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,2 @@ | ||
module HomeHelper | ||
def nav_link(link_text, link_path) | ||
class_name = current_page?(link_path) ? "active" : "" | ||
|
||
content_tag(:li, class: class_name) do | ||
link_to link_text, link_path | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class extends Controller { | ||
static targets = ['input'] | ||
|
||
show() { | ||
this.inputTarget.showPicker() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require "prophet-rb" | ||
require "rover" | ||
|
||
class Metric::ForecastCharter | ||
FORECAST_PERIODS = 6 | ||
FREQUENCIES = { | ||
monthly: "MS" | ||
}.freeze | ||
|
||
def initialize(chart_data:) | ||
@chart_data = chart_data | ||
end | ||
|
||
def chart_data | ||
return [] if insufficient_data? | ||
|
||
dataframe = dataframe_from_chart_data | ||
prophet = prophet_for(dataframe) | ||
future_dataframe = future_dataframe_from(prophet) | ||
|
||
generate_forecast_data(prophet, future_dataframe, @chart_data.keys.last) | ||
end | ||
|
||
private | ||
|
||
def insufficient_data? | ||
@chart_data.size < 10 | ||
end | ||
|
||
def dataframe_from_chart_data | ||
Rover::DataFrame.new({"ds" => @chart_data.keys, "y" => @chart_data.values}) | ||
end | ||
|
||
def prophet_for(dataframe) | ||
Prophet.new.fit(dataframe) | ||
end | ||
|
||
def future_dataframe_from(prophet) | ||
prophet.make_future_dataframe(periods: FORECAST_PERIODS, freq: FREQUENCIES[:monthly]) | ||
end | ||
|
||
def generate_forecast_data(prophet, future_dataframe, last_date) | ||
forecast = prophet.predict(future_dataframe) | ||
data = [] | ||
forecast["ds"].each_with_index do |date, index| | ||
data << [date, forecast["yhat"][index]] if date > last_date | ||
end | ||
data | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters