log-analyser 0.1.3.pre.documentation.20201108181359 → 0.1.3.pre.documentation.20201108213409
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG +7 -1
- data/README.md +58 -20
- data/lib/pageviews.rb +15 -13
- data/lib/pageviews_log_aggregator.rb +16 -14
- data/lib/parser.rb +28 -21
- data/lib/unique_pageviews.rb +8 -6
- metadata +18 -7
- data/.ruby-version +0 -1
- data/log-analyser.gemspec +0 -29
- data/version.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b130e3448b5bce64a194ad4843b9d7712e1cee00821086c8d207b187091784ef
|
|
4
|
+
data.tar.gz: 59933e1912afc0632d6304fe59ef74370a6bf95114773bd7883b273292c693c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6631b545a1ce34e7a0c291b043c9741dbfd2099aaf4c7129dcde40edc0511905509ac0fa4b88c25d77d72672808e2e2a075e340aaa6863a126be3cbc2f973466
|
|
7
|
+
data.tar.gz: 5c96d28a31b7b40f022acd0a09ce143e76e4df0788636f4edb15dbe0c659e65ee80e691d9e7b17287299e226356e2f1ffd13d6c60a874239ae69f0d7f58a51eb
|
data/CHANGELOG
CHANGED
data/README.md
CHANGED
|
@@ -56,13 +56,26 @@ Or install it yourself as:
|
|
|
56
56
|
|
|
57
57
|
#### Gem Usage
|
|
58
58
|
|
|
59
|
+
```ruby
|
|
60
|
+
#!/usr/bin/env ruby
|
|
61
|
+
|
|
62
|
+
require 'pageviews_log_aggregator'
|
|
63
|
+
|
|
64
|
+
file_path = '/Users/dmazzei/projects/personal/ruby/sp_test/log-analyser/resources/webserver.log'
|
|
65
|
+
log_aggregator = LogAnalyser::PageviewsLogAggregator.new(file_path)
|
|
66
|
+
|
|
67
|
+
puts "\nAll pageviews"
|
|
68
|
+
log_aggregator.all.each do |key, value|
|
|
69
|
+
puts "#{key&.to_s&.ljust(28, '.')} | #{value}"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
puts "\nUnique pageviews"
|
|
73
|
+
log_aggregator.unique.each do |key, value|
|
|
74
|
+
puts "#{key&.to_s&.ljust(28, '.')} | #{value}"
|
|
75
|
+
end
|
|
59
76
|
```
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
...
|
|
63
|
-
...
|
|
64
|
-
...
|
|
65
|
-
```
|
|
77
|
+
|
|
78
|
+

|
|
66
79
|
|
|
67
80
|
### Project
|
|
68
81
|
|
|
@@ -88,12 +101,12 @@ Run the initial setup
|
|
|
88
101
|
|
|
89
102
|
#### Usage
|
|
90
103
|
|
|
91
|
-
Call `./bin/parse_pageview_file.rb` passing a logfile path as argument, will return the pageview count ordered from most to less viewed.</br>
|
|
92
|
-
Check
|
|
104
|
+
Call `./bin/parse_pageview_file.rb` passing a logfile path as argument, it will return the pageview count ordered from most to less viewed.</br>
|
|
105
|
+
Check `--help` for more options
|
|
93
106
|
|
|
94
107
|

|
|
95
108
|
|
|
96
|
-
An example log can be found in
|
|
109
|
+
An example log can be found in :file_folder:`resources` folder:
|
|
97
110
|
|
|
98
111
|
$ ./bin/parse_pageview_file.rb --file 'resources/webserver.log'
|
|
99
112
|
|--------------------------------------------------|
|
|
@@ -147,34 +160,54 @@ A space must separate the page name (first column) from the user identifier (e.g
|
|
|
147
160
|
|
|
148
161
|
#### Start with the project:
|
|
149
162
|
|
|
163
|
+
```
|
|
164
|
+
$ git clone git@github.com:DMazzei/log-analyser.git
|
|
165
|
+
$ cd log-analyser
|
|
166
|
+
$ gem install bundler
|
|
167
|
+
$ bundle install
|
|
168
|
+
```
|
|
150
169
|
|
|
170
|
+
And the world is your oyster...
|
|
151
171
|
|
|
152
|
-
You can also run
|
|
172
|
+
You can also run `$ bundle exec console` for an interactive prompt that will allow you to experiment.
|
|
153
173
|
|
|
154
|
-
To install this gem onto your local machine, run
|
|
155
|
-
To release a new version, update the version number in `version.rb`, and then run
|
|
174
|
+
To install this gem onto your local machine, run `$ bundle exec rake install`.
|
|
175
|
+
To release a new version, update the version number in `version.rb`, and then run `$ bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
156
176
|
|
|
157
177
|
#### Linter (rubocop)
|
|
158
178
|
|
|
159
179
|
_*Rubocop*_ is used as code analyser and maintain code formatting (as well as some best practices).
|
|
160
180
|
|
|
161
|
-
Use
|
|
181
|
+
Use `$ bundle exec rake rubocop` to run the checks.
|
|
162
182
|
|
|
163
183
|
#### Test coverage
|
|
164
184
|
|
|
165
|
-
|
|
185
|
+
[](https://coveralls.io/github/DMazzei/log-analyser?branch=master)
|
|
186
|
+
|
|
187
|
+
Use `$ bundle exec rspec` or `$ bundle exec rake spec:all` to run all the tests.
|
|
188
|
+
|
|
189
|
+
:white_check_mark: To run only unit-tests
|
|
190
|
+
|
|
191
|
+
$ bundle exec rake spec:unit
|
|
192
|
+
|
|
193
|
+
:white_check_mark: To run only integration tests
|
|
194
|
+
|
|
195
|
+
$ bundle exec rake spec:integration
|
|
166
196
|
|
|
167
197
|
The test coverage is handled by `rspec`, `simplecov` and `coveralls`.
|
|
168
198
|
Status and coverage history can be checked [here](https://coveralls.io/github/DMazzei/log-analyser).
|
|
169
199
|
|
|
170
200
|
#### Deployment
|
|
171
201
|
|
|
172
|
-
|
|
173
|
-
|
|
202
|
+
Following the creation of a _*Pull Request*_ a CI workflow is triggered in CircleCI, that can be checked [here](https://app.circleci.com/pipelines/github/DMazzei/log-analyser).</br>
|
|
203
|
+
This workflow consist in _building_ the library; Running _rubocop_ and _rspec_ to validate integrity and code quality; And lastly generating and pushing a _feature-gem_ that can be used for development and tests.
|
|
204
|
+
|
|
205
|
+
After passing all checks and requirements on github, a *PR* can be merged as soon as it is reviewed and approved.
|
|
206
|
+
The _*master branch*_ merge process will trigger the deployment process on CircleCI, and this workflow ends with the generation of a _*tagged-gem*_.
|
|
174
207
|
|
|
175
|
-
The deployment process will
|
|
208
|
+
The whole deployment process will finish by building and tagging a new gem version and pushing it to [rubygems.org](https://rubygems.org/gems/log-analyser).
|
|
176
209
|
|
|
177
|
-
> :warning:
|
|
210
|
+
> :warning: To merge changes into _*master*_, the version must be bumped up, otherwise the deployment will fail!</br>
|
|
178
211
|
> The version must be updated in `version.rb`.
|
|
179
212
|
|
|
180
213
|
## Contributing
|
|
@@ -182,8 +215,13 @@ The deployment process will build and tag a new gem version and push it to [ruby
|
|
|
182
215
|
Bug reports and pull requests are welcome on GitHub at https://github.com/DMazzeig/log-analyser.
|
|
183
216
|
|
|
184
217
|
## Next Steps
|
|
185
|
-
|
|
186
|
-
-
|
|
218
|
+
|
|
219
|
+
- One conundrum faced that can be reviewed, deciding between:
|
|
220
|
+
* reading the file whilst aggregation data, preserving memory - e.g. using `Set`;
|
|
221
|
+
* loading data into memory and leaving aggregation and count to be dealt later, gaining flexibility and performance;
|
|
222
|
+
- Extend the accepted logfile format;
|
|
223
|
+
- Add more options for sorting and filtering;
|
|
224
|
+
- Automate library version bump up;
|
|
187
225
|
|
|
188
226
|
## License
|
|
189
227
|
|
data/lib/pageviews.rb
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
module LogAnalyser
|
|
4
|
+
class Pageviews
|
|
5
|
+
InvalidLogEntriesError = Class.new(StandardError)
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
def self.for(entries = {})
|
|
8
|
+
new.generate_view_count(entries)
|
|
9
|
+
rescue StandardError
|
|
10
|
+
raise InvalidLogEntriesError
|
|
11
|
+
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
def generate_view_count(entries)
|
|
14
|
+
entries
|
|
15
|
+
.transform_values(&:size)
|
|
16
|
+
.sort_by(&:last)
|
|
17
|
+
.reverse
|
|
18
|
+
.to_h
|
|
19
|
+
end
|
|
18
20
|
end
|
|
19
21
|
end
|
|
@@ -4,24 +4,26 @@ require_relative 'parser'
|
|
|
4
4
|
require_relative 'pageviews'
|
|
5
5
|
require_relative 'unique_pageviews'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
module LogAnalyser
|
|
8
|
+
class PageviewsLogAggregator
|
|
9
|
+
def initialize(file_path)
|
|
10
|
+
@file_path = file_path
|
|
11
|
+
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
def all
|
|
14
|
+
Pageviews.for(entries)
|
|
15
|
+
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
def unique
|
|
18
|
+
UniquePageviews.for(entries)
|
|
19
|
+
end
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
private
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
attr_accessor :file_path
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
def entries
|
|
26
|
+
@entries ||= Parser.call(file_path)
|
|
27
|
+
end
|
|
26
28
|
end
|
|
27
29
|
end
|
data/lib/parser.rb
CHANGED
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
module LogAnalyser
|
|
4
|
+
class Parser
|
|
5
|
+
class FileNotFoundError < StandardError
|
|
6
|
+
def initialize(path)
|
|
7
|
+
super("File not found for path: [#{path}]")
|
|
8
|
+
end
|
|
7
9
|
end
|
|
8
|
-
end
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
def self.call(file_path)
|
|
12
|
+
new.call(file_path)
|
|
13
|
+
end
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
def initialize
|
|
16
|
+
@entries = Hash.new { |h, k| h[k] = [] }
|
|
17
|
+
end
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
parse(data)
|
|
20
|
-
end
|
|
19
|
+
def call(file_path)
|
|
20
|
+
raise FileNotFoundError, file_path unless File.exist?(file_path)
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
data = File.open(file_path).map(&:strip)
|
|
23
|
+
data.reject!(&:empty?)
|
|
24
|
+
parse(data)
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
entries = Hash.new { |h, k| h[k] = [] }
|
|
26
|
-
data.each do |entry|
|
|
27
|
-
key, value = *entry.split(/\s+/)
|
|
28
|
-
entries[key] << value
|
|
26
|
+
entries
|
|
29
27
|
end
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
attr_reader :entries
|
|
32
|
+
|
|
33
|
+
def parse(data)
|
|
34
|
+
data.each do |entry|
|
|
35
|
+
key, value = *entry.split(/\s+/)
|
|
36
|
+
entries[key] << value
|
|
37
|
+
end
|
|
38
|
+
end
|
|
32
39
|
end
|
|
33
40
|
end
|
data/lib/unique_pageviews.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
entries
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
module LogAnalyser
|
|
4
|
+
class UniquePageviews < Pageviews
|
|
5
|
+
def generate_view_count(entries)
|
|
6
|
+
entries.transform_values { |value| value.uniq.size }
|
|
7
|
+
.sort_by(&:last)
|
|
8
|
+
.reverse
|
|
9
|
+
.to_h
|
|
10
|
+
end
|
|
9
11
|
end
|
|
10
12
|
end
|
metadata
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: log-analyser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.3.pre.documentation.
|
|
4
|
+
version: 0.1.3.pre.documentation.20201108213409
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dan Mazzei
|
|
8
8
|
autorequire:
|
|
9
|
-
bindir:
|
|
9
|
+
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
date: 2020-11-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
@@ -15,9 +15,11 @@ email:
|
|
|
15
15
|
- danielmazzei@gmail.com
|
|
16
16
|
executables: []
|
|
17
17
|
extensions: []
|
|
18
|
-
extra_rdoc_files:
|
|
18
|
+
extra_rdoc_files:
|
|
19
|
+
- CHANGELOG
|
|
20
|
+
- LICENSE.txt
|
|
21
|
+
- README.md
|
|
19
22
|
files:
|
|
20
|
-
- ".ruby-version"
|
|
21
23
|
- CHANGELOG
|
|
22
24
|
- LICENSE.txt
|
|
23
25
|
- README.md
|
|
@@ -25,15 +27,24 @@ files:
|
|
|
25
27
|
- lib/pageviews_log_aggregator.rb
|
|
26
28
|
- lib/parser.rb
|
|
27
29
|
- lib/unique_pageviews.rb
|
|
28
|
-
- log-analyser.gemspec
|
|
29
|
-
- version.rb
|
|
30
30
|
homepage: https://github.com/DMazzei/log-analyser
|
|
31
31
|
licenses:
|
|
32
32
|
- MIT
|
|
33
33
|
metadata:
|
|
34
34
|
homepage_uri: https://github.com/DMazzei/log-analyser
|
|
35
|
+
source_code_uri: https://github.com/DMazzei/log-analyser
|
|
36
|
+
changelog_uri: https://github.com/DMazzei/log-analyser/blob/master/CHANGELOG
|
|
37
|
+
bug_tracker_uri: https://github.com/DMazzei/log-analyser/issues
|
|
38
|
+
documentation_uri: https://www.rubydoc.info/gems/log-analyser
|
|
35
39
|
post_install_message:
|
|
36
|
-
rdoc_options:
|
|
40
|
+
rdoc_options:
|
|
41
|
+
- "--title"
|
|
42
|
+
- Emoticon - emotions in terminal
|
|
43
|
+
- "--main"
|
|
44
|
+
- README.md
|
|
45
|
+
- "--line-numbers"
|
|
46
|
+
- "--inline-source"
|
|
47
|
+
- "--quiet"
|
|
37
48
|
require_paths:
|
|
38
49
|
- lib
|
|
39
50
|
required_ruby_version: !ruby/object:Gem::Requirement
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.7.1
|
data/log-analyser.gemspec
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative 'version'
|
|
4
|
-
|
|
5
|
-
Gem::Specification.new do |spec|
|
|
6
|
-
spec.name = 'log-analyser'
|
|
7
|
-
spec.version = VERSION
|
|
8
|
-
spec.authors = ['Dan Mazzei']
|
|
9
|
-
spec.email = ['danielmazzei@gmail.com']
|
|
10
|
-
|
|
11
|
-
spec.summary = 'Log reader and data aggregator for pageviews information.'
|
|
12
|
-
spec.description = 'Log reader and data aggregator for pageviews information.'
|
|
13
|
-
spec.homepage = 'https://github.com/DMazzei/log-analyser'
|
|
14
|
-
spec.license = 'MIT'
|
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.7')
|
|
16
|
-
|
|
17
|
-
# spec.metadata['allowed_push_host'] = "'TODO: Set to 'http://mygemserver.com''"
|
|
18
|
-
|
|
19
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
|
20
|
-
# spec.metadata['source_code_uri'] = "'TODO: Put your gem's public repo URL here.'"
|
|
21
|
-
# spec.metadata['changelog_uri'] = "'TODO: Put your gem's CHANGELOG.md URL here.'"
|
|
22
|
-
|
|
23
|
-
# Specify which files should be added to the gem when it is released.
|
|
24
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
25
|
-
spec.files = %w(.ruby-version CHANGELOG LICENSE.txt README.md lib/pageviews.rb lib/pageviews_log_aggregator.rb lib/parser.rb lib/unique_pageviews.rb log-analyser.gemspec version.rb)
|
|
26
|
-
spec.bindir = 'exe'
|
|
27
|
-
spec.executables = spec.files.grep(/^exe\//) { |f| File.basename(f) }
|
|
28
|
-
spec.require_paths = ['lib']
|
|
29
|
-
end
|
data/version.rb
DELETED