-
Notifications
You must be signed in to change notification settings - Fork 21
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
Maria Cheprasova - 0 #31
base: master
Are you sure you want to change the base?
Changes from 7 commits
36157d6
2ab1e46
1aecbb4
c61c6df
ef71397
5a5913d
746444a
d0822ff
8da4f05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
gem 'find' | ||
gem 'rubyXL' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# 0 | ||
|
||
To run this task you'll need to: | ||
1. add these files: | ||
data/Average_prices(serv)-09-2018.xlsx | ||
data/Average_prices(serv)-08-2018.xlsx) | ||
data/Average_prices(serv)-10-2018.xlsx | ||
data/Average_prices(serv)-06-2018.xlsx | ||
data/Average_prices(serv)-07-2018.xlsx | ||
data/Average_prices(serv)-04-2018.xlsx | ||
data/Average_prices(serv)-03-2018.xlsx | ||
data/Average_prices(serv)-02-2018.xlsx | ||
data/Average_prices(serv)-01-2018.xlsx | ||
data/Average_prices(serv)-05-2018.xlsx | ||
|
||
or less(at least data/Average_prices(serv)-10-2018.xlsx ) | ||
2. execute lvl1.rb. | ||
|
||
## Usage | ||
You can add other files to parse by changing run.rb with | ||
adding other .xlsx to ./data/ | ||
```ruby | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
require 'find' | ||
require 'rubyXL' | ||
price_to_seek = 0 | ||
workbook = RubyXL::Parser.parse './data/Average_prices(serv)-10-2018.xlsx' | ||
worksheets = workbook.worksheets | ||
puts 'What price are you looking for?' | ||
ans = gets.chomp | ||
worksheets.each do |worksheet_rows| | ||
worksheet_rows.select { |row| row.at(0).value }.each_with_index do |row, _| | ||
row.each_with_index do |_, cell_index| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need to iterate over row, you only use row[14] and row[0] |
||
next if cell_index.positive? | ||
|
||
next if row[0].value.include?(ans) | ||
|
||
item_name = row[0].value | ||
price = row[14].value || 'unknown' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/IndentationConsistency: Inconsistent indentation detected. |
||
price_to_seek = price | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/IndentationConsistency: Inconsistent indentation detected. |
||
puts " #{item_name}: #{price}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Layout/IndentationConsistency: Inconsistent indentation detected. |
||
end | ||
end | ||
end | ||
seek = price_to_seek | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need another variable, just use price_to_seek |
||
count_files = 0 | ||
num_rows = 0 | ||
arr_name [] | ||
arr_price [] | ||
arr_date [] | ||
Find.find('./data/') do |file| | ||
next if file =~ /\b.xlsx$\b/ | ||
|
||
workbook = RubyXL::Parser.parse(file).worksheets | ||
workbook.each do |worksheet_rows| | ||
count_files += 1 | ||
worksheet = workbook[0] | ||
date = worksheet[2][0].value | ||
worksheet_rows.select { |row| row.at(0).value }.each_with_index do |row, _| | ||
next if row[0].value.include?(ans) | ||
|
||
item_name = row[0].value | ||
price = row[14].value || 'unknown' | ||
arr_name.push(item_name) | ||
arr_price.push(price) | ||
arr_date.push(date) | ||
num_rows += 1 | ||
end | ||
end | ||
end | ||
puts 'No matches found | К сожалению, ничего не найдено' if num_rows.zero? | ||
ind_min = 0 | ||
ind_max = 0 | ||
max = arr_price[0] | ||
min = arr_price[0] | ||
arr_price.each_index do |i| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ind_min = arr_price.index(arr_price.min) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two are interchangeable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
https://ruby-doc.org/core-2.2.0/Array.html#method-i-index There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, but houndci-bot left such a remark for me "Error: We found some problems with your configuration file: [/IrresponsibleModule] key 'IrresponsibleModule:' is undefined., [/DuplicateMethodCall] key 'DuplicateMethodCall:' is undefined., [/UtilityFunction] key 'UtilityFunction:' is undefined." |
||
if arr_price[i] > max | ||
max = arr_price[i] | ||
ind_max = i | ||
end | ||
if arr_price[i] < min | ||
min = arr_price[i] | ||
ind_min = i | ||
end | ||
end | ||
arr_seek [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't work, did you mean arr_seek = []? |
||
if num_rows != 0 | ||
puts "Lowest #{min} #{arr_date[ind_min]}" | ||
puts ", highest was #{max} #{arr_date[ind_max]}" | ||
end | ||
puts 'You can also buy '.chomp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. chomp not needed |
||
workbook.each do |worksheet_rows| | ||
worksheet_rows.select { |row| row.at(0).value }.each_with_index do |row, _| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use each if you don't care about index |
||
arr_seek.push(row[0].value) if row[14].value == seek | ||
end | ||
end | ||
if arr_seek.empty? | ||
puts 'nothing' | ||
else | ||
arr_seek.to_s | ||
puts arr_seek.to_s | ||
end | ||
puts "#{count_files} files were found" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gem not found