queue_system 0.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 +7 -0
- data/lib/queue_system/customer.rb +19 -0
- data/lib/queue_system/service_queue.rb +60 -0
- data/lib/queue_system.rb +7 -0
- metadata +60 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1de39cc2ce439234049dd896fafcb7a0f9f85d6b9a413092dc27a173f2e0e78c
|
|
4
|
+
data.tar.gz: cd789c19ad0b6944c83949b3c77102251efb53ec73c5ff390be7d19a6552cb25
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3f89799561d54daf3742fc0ef58afe07d4cad3c5c6fc1f9c5562ae334c3cf05526948f2abb697d5d80371d8c205f2fbb253f20de19d31afd82c3287d9be18a80
|
|
7
|
+
data.tar.gz: e1f54a01ca35782832cccfacb4976c4cde19835513983225c342b904d84f3a6bbe3169a1b477575d42e9b41ae70d4bf16ade2f4fcf2a9634843df309b32ead14
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module QueueSystem
|
|
2
|
+
class Customer
|
|
3
|
+
attr_reader :id, :arrival_time, :service_time, :wait_time, :departure_time
|
|
4
|
+
|
|
5
|
+
def initialize(arrival_time)
|
|
6
|
+
@id = SecureRandom.uuid[0..7]
|
|
7
|
+
@arrival_time = arrival_time
|
|
8
|
+
@service_time = generate_service_time
|
|
9
|
+
@wait_time = 0
|
|
10
|
+
@departure_time = nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
private
|
|
14
|
+
|
|
15
|
+
def generate_service_time
|
|
16
|
+
rand(1..10)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module QueueSystem
|
|
2
|
+
class ServiceQueue
|
|
3
|
+
attr_reader :customers, :stats
|
|
4
|
+
|
|
5
|
+
def initialize
|
|
6
|
+
@customers = []
|
|
7
|
+
@current_time = 0
|
|
8
|
+
@stats = {
|
|
9
|
+
total_customers: 0,
|
|
10
|
+
avg_wait_time: 0,
|
|
11
|
+
avg_system_time: 0,
|
|
12
|
+
server_utilization: 0
|
|
13
|
+
}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def simulate(duration:, arrival_rate:)
|
|
17
|
+
server_busy_until = 0
|
|
18
|
+
|
|
19
|
+
while @current_time < duration
|
|
20
|
+
if rand < arrival_rate
|
|
21
|
+
customer = Customer.new(@current_time)
|
|
22
|
+
process_customer(customer, server_busy_until)
|
|
23
|
+
server_busy_until = calculate_server_busy_time(customer, server_busy_until)
|
|
24
|
+
@customers << customer
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
@current_time += 1
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
calculate_statistics(duration)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def process_customer(customer, server_busy_until)
|
|
36
|
+
customer.instance_variable_set(:@wait_time, [0, server_busy_until - customer.arrival_time].max)
|
|
37
|
+
service_start = [server_busy_until, customer.arrival_time].max
|
|
38
|
+
customer.instance_variable_set(:@departure_time, service_start + customer.service_time)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def calculate_server_busy_time(customer, current_busy_until)
|
|
42
|
+
[current_busy_until, customer.departure_time].max
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def calculate_statistics(duration)
|
|
46
|
+
return if @customers.empty?
|
|
47
|
+
|
|
48
|
+
total_wait_time = @customers.sum(&:wait_time)
|
|
49
|
+
total_system_time = @customers.sum { |c| c.departure_time - c.arrival_time }
|
|
50
|
+
total_service_time = @customers.sum(&:service_time)
|
|
51
|
+
|
|
52
|
+
@stats = {
|
|
53
|
+
total_customers: @customers.size,
|
|
54
|
+
avg_wait_time: total_wait_time.to_f / @customers.size,
|
|
55
|
+
avg_system_time: total_system_time.to_f / @customers.size,
|
|
56
|
+
server_utilization: (total_service_time.to_f / duration) * 100
|
|
57
|
+
}
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
data/lib/queue_system.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: queue_system
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Your Name
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-01-23 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: Simulador de fila com estatísticas de atendimento
|
|
28
|
+
email:
|
|
29
|
+
- your.email@example.com
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- lib/queue_system.rb
|
|
35
|
+
- lib/queue_system/customer.rb
|
|
36
|
+
- lib/queue_system/service_queue.rb
|
|
37
|
+
homepage: ''
|
|
38
|
+
licenses:
|
|
39
|
+
- MIT
|
|
40
|
+
metadata: {}
|
|
41
|
+
post_install_message:
|
|
42
|
+
rdoc_options: []
|
|
43
|
+
require_paths:
|
|
44
|
+
- lib
|
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
requirements:
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '0'
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubygems_version: 3.4.10
|
|
57
|
+
signing_key:
|
|
58
|
+
specification_version: 4
|
|
59
|
+
summary: Sistema de simulação de fila de atendimento
|
|
60
|
+
test_files: []
|