loi_parser 1.0.0 → 1.1.0
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.md +11 -1
- data/Gemfile.lock +1 -1
- data/README.md +16 -8
- data/lib/loi_parser/configuration.rb +15 -0
- data/lib/loi_parser/helpers.rb +25 -0
- data/lib/loi_parser/reader.rb +25 -23
- data/lib/loi_parser/version.rb +1 -1
- data/lib/loi_parser.rb +10 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 717100c3240b162307dc6349e8bca4a99d1d9af4079c05b97663f84a298add77
|
4
|
+
data.tar.gz: 9899e509a951ba72c602f73e1bc519b1f27a553b14927d303fd79a380b3a90d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d67325b298b6c980f91d0899460f7920239d2b57bb741e0afd60a66924b1aeb149b5a1db4d2f90cb20472fc504bce48f2d83472dea0b75b778ab7bb676a0a63
|
7
|
+
data.tar.gz: e2b4acece31219290fa3b715bbb431fe6f33cd103f9304e12fb783b0a3179a5418c46f50aab778ff6b1860528edcde038f5c2c63c104d7aedaa059712de59d58
|
data/CHANGELOG.md
CHANGED
@@ -6,9 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.1.0] - 2023-03-14
|
10
|
+
### Added
|
11
|
+
- Configurable file.read length
|
12
|
+
- Thousands formater on the "founds" result
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- Reading 5 000 bytes by default in order to speed up the reading process
|
16
|
+
- Logging data
|
17
|
+
|
9
18
|
## [1.0.0] - 2023-03-13
|
10
19
|
### Added
|
11
20
|
- Initial import
|
12
21
|
|
13
|
-
[Unreleased]: https://gitlab.com/pharmony/loi-parser/compare/v1.
|
22
|
+
[Unreleased]: https://gitlab.com/pharmony/loi-parser/compare/v1.1.0...master
|
23
|
+
[1.1.0]: https://gitlab.com/pharmony/loi-parser/compare/v1.0.0...v1.1.0
|
14
24
|
[1.0.0]: https://gitlab.com/hydrana/hydrana/tags/v1.0.0
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -42,17 +42,25 @@ Or install it yourself as:
|
|
42
42
|
|
43
43
|
# Grabbing all the serial numbers being in opposition
|
44
44
|
> loi.serials_in_opposition
|
45
|
-
I, [2023-03-
|
46
|
-
I, [2023-03-
|
47
|
-
I, [2023-03-
|
45
|
+
I, [2023-03-14T14:33:12.606494 #135] INFO -- LoiParser: 0% Found: 0 (Elapsed: 0 ms)
|
46
|
+
I, [2023-03-14T14:33:12.610240 #135] INFO -- LoiParser: 1% Found: 0 (Elapsed: 3 ms)
|
47
|
+
I, [2023-03-14T14:33:12.616639 #135] INFO -- LoiParser: 2% Found: 0 (Elapsed: 10 ms)
|
48
|
+
I, [2023-03-14T14:33:12.621245 #135] INFO -- LoiParser: 3% Found: 0 (Elapsed: 14 ms)
|
49
|
+
I, [2023-03-14T14:33:12.625052 #135] INFO -- LoiParser: 4% Found: 0 (Elapsed: 18 ms)
|
48
50
|
...
|
49
|
-
I, [2023-03-
|
50
|
-
I, [2023-03-
|
51
|
-
I, [2023-03-
|
52
|
-
I, [2023-03-08T11:02:18.651881 #99340] INFO -- LoiParser: Serials in opposition: [99999999, ...]
|
53
|
-
=> [99999999, ...]
|
51
|
+
I, [2023-03-14T14:33:13.116982 #135] INFO -- LoiParser: 99% Found: 50 (Elapsed: 510 ms)
|
52
|
+
I, [2023-03-14T14:33:13.120837 #135] INFO -- LoiParser: 100% Found: 50 (Elapsed: 514 ms)
|
53
|
+
I, [2023-03-14T14:33:13.130306 #135] INFO -- LoiParser: Gathered 5113 serial number(s) in opposition in 523 ms.
|
54
54
|
```
|
55
55
|
|
56
|
+
**WARNING:** This gem doesn't have a _callback_ mechanism to pass found serial
|
57
|
+
numbers on the go. Instead it stores all the serial numbers found in an Array
|
58
|
+
which leads to a overflow failure depending on the machine's memory size.
|
59
|
+
|
60
|
+
Extracting all the serial numbers was an experiment we did in order to store
|
61
|
+
the serial numbers in a database, but we have abondonned this way since it is
|
62
|
+
very slow.
|
63
|
+
|
56
64
|
## Development
|
57
65
|
|
58
66
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LoiParser
|
4
|
+
#
|
5
|
+
# LoiParser gem configuration class
|
6
|
+
#
|
7
|
+
class Configuration
|
8
|
+
# file.read length to be used to read the LOI file
|
9
|
+
attr_accessor :read_length
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@read_length = 5000
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LoiParser
|
4
|
+
#
|
5
|
+
# This module contain various helper methods
|
6
|
+
#
|
7
|
+
module Helpers
|
8
|
+
def self.elapsed_time(elapsed)
|
9
|
+
if elapsed < 1
|
10
|
+
"#{(elapsed * 1000).to_i} ms"
|
11
|
+
elsif elapsed <= 60
|
12
|
+
"#{elapsed.to_i} seconds"
|
13
|
+
else
|
14
|
+
min, sec = elapsed.divmod(60)
|
15
|
+
|
16
|
+
"#{min} minutes #{sec.to_i} seconds"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# 1000 #=> 1,000
|
21
|
+
def self.formatted_thousands(number)
|
22
|
+
number.to_s.gsub(/\B(?=(...)*\b)/, ',')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/loi_parser/reader.rb
CHANGED
@@ -69,9 +69,8 @@ module LoiParser
|
|
69
69
|
|
70
70
|
LoiParser.logger.info(
|
71
71
|
"Gathered #{serial_numbers.size} serial number(s) " \
|
72
|
-
"in opposition in #{elapsed_time_in_minutes}
|
72
|
+
"in opposition in #{elapsed_time_in_minutes}."
|
73
73
|
)
|
74
|
-
LoiParser.logger.info "Serials in opposition: #{serial_numbers.inspect}"
|
75
74
|
|
76
75
|
serial_numbers
|
77
76
|
end
|
@@ -93,43 +92,46 @@ module LoiParser
|
|
93
92
|
header
|
94
93
|
end
|
95
94
|
|
96
|
-
def
|
95
|
+
def current_bytes_pos
|
97
96
|
@file.pos - @list_start_position - 1
|
98
97
|
end
|
99
98
|
|
100
99
|
def elapsed_time_in_minutes
|
101
|
-
|
102
|
-
|
100
|
+
Helpers.elapsed_time(
|
101
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC) - @starting
|
102
|
+
)
|
103
|
+
end
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
min, sec = elapsed.divmod(60)
|
105
|
+
def extract_serial_mumbers_from(bytes)
|
106
|
+
# Splits bytes in groups of 8 chars
|
107
|
+
splited_bytes = bytes.scan(/.{1,8}/)
|
108
108
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
109
|
+
splited_bytes.each.with_index(1).flat_map do |byte, bindex|
|
110
|
+
# Calculates the position in file for the current byte
|
111
|
+
current_byte_pos = current_bytes_pos - (splited_bytes.size - bindex)
|
113
112
|
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
# Go through the 8 bites looking for '1'
|
114
|
+
byte.each_char.with_index(1).map do |bit, index|
|
115
|
+
next if bit == '0'
|
117
116
|
|
118
|
-
|
117
|
+
# Calculates the serial number from the position in the file plus the
|
118
|
+
# offset of the bit
|
119
|
+
((current_byte_pos * 8) + (8 - index))
|
120
|
+
end
|
119
121
|
end.compact
|
120
122
|
end
|
121
123
|
|
122
124
|
def find_all_serial_numbers_in_opposition
|
123
125
|
serial_numbers = []
|
124
126
|
|
125
|
-
until (readed = @file.read(
|
126
|
-
|
127
|
+
until (readed = @file.read(LoiParser.configuration.read_length)).nil?
|
128
|
+
bytes = readed.unpack1('B*')
|
127
129
|
|
128
130
|
print_percentage(serial_numbers.size)
|
129
131
|
|
130
|
-
next
|
132
|
+
next unless bytes.include?('1')
|
131
133
|
|
132
|
-
serial_numbers |= extract_serial_mumbers_from(
|
134
|
+
serial_numbers |= extract_serial_mumbers_from(bytes)
|
133
135
|
end
|
134
136
|
|
135
137
|
serial_numbers
|
@@ -149,8 +151,8 @@ module LoiParser
|
|
149
151
|
return if percentage == @current_percentage
|
150
152
|
|
151
153
|
LoiParser.logger.info(
|
152
|
-
"
|
153
|
-
"
|
154
|
+
"#{percentage}% Found: #{Helpers.formatted_thousands(found)} (" \
|
155
|
+
"Elapsed: #{elapsed_time_in_minutes})"
|
154
156
|
)
|
155
157
|
|
156
158
|
@current_percentage = percentage
|
data/lib/loi_parser/version.rb
CHANGED
data/lib/loi_parser.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'logger'
|
4
4
|
|
5
|
+
require_relative 'loi_parser/configuration'
|
6
|
+
require_relative 'loi_parser/helpers'
|
5
7
|
require_relative 'loi_parser/reader'
|
6
8
|
require_relative 'loi_parser/version'
|
7
9
|
|
@@ -9,6 +11,14 @@ module LoiParser # rubocop:disable Style/Documentation
|
|
9
11
|
class << self
|
10
12
|
attr_writer :logger
|
11
13
|
|
14
|
+
def configuration
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure
|
19
|
+
yield(configuration)
|
20
|
+
end
|
21
|
+
|
12
22
|
def logger
|
13
23
|
@logger ||= Logger.new($stdout).tap do |log|
|
14
24
|
log.progname = name
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loi_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pharmony
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logger
|
@@ -46,6 +46,8 @@ files:
|
|
46
46
|
- bin/console
|
47
47
|
- bin/setup
|
48
48
|
- lib/loi_parser.rb
|
49
|
+
- lib/loi_parser/configuration.rb
|
50
|
+
- lib/loi_parser/helpers.rb
|
49
51
|
- lib/loi_parser/reader.rb
|
50
52
|
- lib/loi_parser/version.rb
|
51
53
|
- loi_parser.gemspec
|