Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash running machine learning with no data dir #5014

Merged
merged 2 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix crash running machine learning with no data dir
The scripts crashed when the `data` folder wasn't present, which is the
common situation in development environments or production environments
not using Capistrano, since this folder isn't under version control.
  • Loading branch information
javierm committed Oct 19, 2022
commit 33f7a05d3e31f6c04a2e5ee9a1f927608836a536
7 changes: 7 additions & 0 deletions app/models/machine_learning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,24 @@ def description_from(script_filename)

private

def create_data_folder
FileUtils.mkdir_p DATA_FOLDER
end

def export_proposals_to_json
create_data_folder
filename = DATA_FOLDER.join(MachineLearning.proposals_filename)
Proposal::Exporter.new.to_json_file(filename)
end

def export_budget_investments_to_json
create_data_folder
filename = DATA_FOLDER.join(MachineLearning.investments_filename)
Budget::Investment::Exporter.new(Array.new).to_json_file(filename)
end

def export_comments_to_json
create_data_folder
filename = DATA_FOLDER.join(MachineLearning.comments_filename)
Comment::Exporter.new.to_json_file(filename)
end
Expand Down
9 changes: 0 additions & 9 deletions spec/models/machine_learning_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,6 @@ def full_sanitizer(string)

describe "#export_proposals_to_json" do
it "creates a JSON file with all proposals" do
require "fileutils"
FileUtils.mkdir_p Rails.root.join("public", "machine_learning", "data")

first_proposal = create(:proposal)
last_proposal = create(:proposal)

Expand All @@ -332,9 +329,6 @@ def full_sanitizer(string)

describe "#export_budget_investments_to_json" do
it "creates a JSON file with all budget investments" do
require "fileutils"
FileUtils.mkdir_p Rails.root.join("public", "machine_learning", "data")

first_budget_investment = create(:budget_investment)
last_budget_investment = create(:budget_investment)

Expand All @@ -359,9 +353,6 @@ def full_sanitizer(string)

describe "#export_comments_to_json" do
it "creates a JSON file with all comments" do
require "fileutils"
FileUtils.mkdir_p Rails.root.join("public", "machine_learning", "data")

first_comment = create(:comment)
last_comment = create(:comment)

Expand Down