Skip to content

Commit b92cef4

Browse files
NikitaNikita
Nikita
authored and
Nikita
committed
[Third] add progress bars
1 parent 4cc6a1c commit b92cef4

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ gem 'ruby-prof'
77
gem 'vernier', '~> 1.0'
88
gem 'rspec'
99
gem 'byebug'
10-
gem 'oj'
10+
gem 'oj'
11+
gem 'progressbar'

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ GEM
88
bigdecimal (>= 3.0)
99
ostruct (>= 0.2)
1010
ostruct (0.6.1)
11+
progressbar (1.13.0)
1112
rspec (3.13.0)
1213
rspec-core (~> 3.13.0)
1314
rspec-expectations (~> 3.13.0)
@@ -32,6 +33,7 @@ PLATFORMS
3233
DEPENDENCIES
3334
byebug
3435
oj
36+
progressbar
3537
rspec
3638
ruby-prof
3739
stackprof

main.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
require 'progressbar'
2+
13
class Main
24
PARTIAL_VOLUME_FILE_NAME = "dataN.txt"
35

46
def initialize(options: {})
57
@source_file_name = options[:source_file_name] || 'data_large.txt'
68
@count_lines = options[:count_lines]
79
@with_gc = options[:with_gc] || true
10+
@read_progress_bar = options[:with_progress_bar] ? ProgressBar.create(title: "Read") : nil
11+
@process_file_progress_bar = options[:with_progress_bar] ? ProgressBar.create(title: "Process file") : nil
12+
@collect_report_progress_bar = options[:with_progress_bar] ? ProgressBar.create(title: "Collect report") : nil
13+
@write_to_result_file_progress_bar = options[:with_progress_bar] ? ProgressBar.create(title: "Write to result file") : nil
814
end
915

1016
def call
@@ -15,11 +21,12 @@ def call
1521

1622
private
1723

18-
attr_reader :source_file_name, :count_lines, :with_gc
24+
attr_reader :source_file_name, :count_lines, :with_gc, :read_progress_bar, :process_file_progress_bar, :collect_report_progress_bar, :write_to_result_file_progress_bar
1925

2026
def work
2127
`head -n #{count_lines} #{source_file_name} > #{PARTIAL_VOLUME_FILE_NAME}` if count_lines
2228
file_lines = File.read(count_lines ? PARTIAL_VOLUME_FILE_NAME : source_file_name).split("\n")
29+
read_progress_bar&.progress = 100
2330

2431
users = []
2532
sessions = []
@@ -34,7 +41,7 @@ def work
3441
sessions << session
3542
end
3643
end
37-
44+
process_file_progress_bar&.progress = 100
3845
# Отчёт в json
3946
# - Сколько всего юзеров +
4047
# - Сколько всего уникальных браузеров +
@@ -104,13 +111,15 @@ def work
104111
collect_stats_from_users(report, users_objects) do |user|
105112
{ 'alwaysUsedChrome' => user.sessions.map{|s| s['browser']}.all? { |b| b.upcase =~ /CHROME/ } }
106113
end
107-
114+
108115
# Даты сессий через запятую в обратном порядке в формате iso8601
109116
collect_stats_from_users(report, users_objects) do |user|
110117
{ 'dates' => user.sessions.map{|s| s['date']}.map {|d| Date.strptime(d, '%Y-%m-%d')}.sort.reverse.map { |d| d.iso8601 } }
111118
end
119+
collect_report_progress_bar&.progress = 100
112120

113121
File.write('result.json', "#{report.to_json}\n")
122+
write_to_result_file_progress_bar&.progress = 100
114123
end
115124

116125
def parse_user(fields)

0 commit comments

Comments
 (0)