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

Maria Cheprasova - 0 #31

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
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
4 changes: 4 additions & 0 deletions Maria Cheprasova/0/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

gem 'find'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gem not found

% bundle install
Fetching gem metadata from https://rubygems.org/..............
Fetching gem metadata from https://rubygems.org/.
Could not find gem 'find' in any of the gem sources listed in your Gemfile.

gem 'rubyXL'
24 changes: 24 additions & 0 deletions Maria Cheprasova/0/Readme.md
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


80 changes: 80 additions & 0 deletions Maria Cheprasova/0/lvl1.rb
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|
Copy link
Collaborator

Choose a reason for hiding this comment

The 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'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationConsistency: Inconsistent indentation detected.

price_to_seek = price

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationConsistency: Inconsistent indentation detected.

puts " #{item_name}: #{price}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationConsistency: Inconsistent indentation detected.

end
end
end
seek = price_to_seek
Copy link
Collaborator

Choose a reason for hiding this comment

The 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|
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ind_min = arr_price.index(arr_price.min)
min = arr_price[ind_min]

Copy link
Author

@moooll moooll Dec 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two are interchangeable?
+What does this statement mean? (arr_price.min)

Copy link
Collaborator

@RGBD RGBD Dec 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2.5.1 (main):0 > arr_price = ["f", "c", "d", "f", "h", "b", "i"];
2.5.1 (main):0 > arr_price.index("f")
=> 0
2.5.1 (main):0 > arr_price.index("d")
=> 2
2.5.1 (main):0 > arr_price.min
=> "b"

https://ruby-doc.org/core-2.2.0/Array.html#method-i-index
https://ruby-doc.org/core-2.5.3/Enumerable.html#method-i-min

Copy link
Author

@moooll moooll Dec 14, 2018

Choose a reason for hiding this comment

The 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."
as I understood one of te errors happened due to several duplicate parts of code. but I don't know exactly where they are. mb u can help me with the reason why this error happens?

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 []
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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, _|
Copy link
Collaborator

Choose a reason for hiding this comment

The 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"