time_pieces 1.0.3 → 1.0.4
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/Gemfile.lock +1 -1
- data/lib/time_pieces/duration.rb +1 -1
- data/lib/time_pieces/time_set.rb +21 -0
- data/lib/time_pieces/traffic_cop.rb +66 -0
- data/lib/time_pieces/version.rb +1 -1
- data/lib/time_pieces.rb +1 -0
- data/pkg/time_pieces-1.0.3.gem +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecb493c0cd2590abf40b2b7e98daaab1eb2510d5
|
4
|
+
data.tar.gz: b76a1db6d6e7e3d2a3d1954787e3ed9d59c45827
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ca9c9c3276a3770a858817ede3b71677f1085f7d132d4f1516ce940ba7b42495a8f64886813134c46780444071367ac80aa96771bc8afe1ee049a0e8a37e2d3
|
7
|
+
data.tar.gz: 1cf8fe07e291d98cdaebb4857405f96678ed05bae640adfded8cfff01ac5c1cef8b9cd7cc5c268e87c969ca6e999b74aaccc13431dac438ec2b55629d0b81182
|
data/Gemfile.lock
CHANGED
data/lib/time_pieces/duration.rb
CHANGED
data/lib/time_pieces/time_set.rb
CHANGED
@@ -4,6 +4,27 @@ module TimePieces
|
|
4
4
|
def initialize
|
5
5
|
@time_durations = []
|
6
6
|
end
|
7
|
+
def time_durations_in_lanes
|
8
|
+
|
9
|
+
end
|
10
|
+
def clip(start_at_seconds, end_at_seconds)
|
11
|
+
new_tds = []
|
12
|
+
time_durations.each do |td|
|
13
|
+
if td.start_at_seconds < start_at_seconds
|
14
|
+
td.start_at_seconds = start_at_seconds
|
15
|
+
end
|
16
|
+
if td.start_at_seconds + td.duration_seconds > end_at_seconds
|
17
|
+
td.duration_seconds = end_at_seconds - start_at_seconds
|
18
|
+
end
|
19
|
+
new_tds << td
|
20
|
+
end
|
21
|
+
return new_tds
|
22
|
+
|
23
|
+
end
|
24
|
+
def deep_dup
|
25
|
+
return Marshal.load(Marshal.dump(self))
|
26
|
+
end
|
27
|
+
|
7
28
|
#Adds a new time duration. Removes invalid time durations.
|
8
29
|
def <<(new_td)
|
9
30
|
if new_td.duration_seconds == 0
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module TimePieces
|
2
|
+
class TrafficCop
|
3
|
+
attr_accessor :time_durations
|
4
|
+
def initialize(time_durations)
|
5
|
+
@time_durations = time_durations
|
6
|
+
end
|
7
|
+
def add_time_durations(time_durations)
|
8
|
+
@time_durations += time_durations
|
9
|
+
end
|
10
|
+
def add_time_set(time_set)
|
11
|
+
@time_durations += time_set.time_durations
|
12
|
+
end
|
13
|
+
def calculate!
|
14
|
+
#This handles lane numbers also
|
15
|
+
assign_lane_counts!
|
16
|
+
|
17
|
+
end
|
18
|
+
def assign_lane_numbers!
|
19
|
+
lanes = [[], [], [], [], [], [], [], [], [], [], [], [], [], []]
|
20
|
+
time_durations.sort_by(&:start_at_seconds).each do |td|
|
21
|
+
lanes.each_with_index do |lane, lane_number|
|
22
|
+
if lane.count > 0
|
23
|
+
if lane.last.overlaps?(td)
|
24
|
+
next
|
25
|
+
else
|
26
|
+
lane << td
|
27
|
+
break
|
28
|
+
end
|
29
|
+
else
|
30
|
+
lane << td
|
31
|
+
break
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
lanes.each_with_index do |lane, lane_number|
|
37
|
+
lane.each do |td|
|
38
|
+
td.lane_number = lane_number + 1
|
39
|
+
puts td.inspect
|
40
|
+
puts td.lane_number
|
41
|
+
end
|
42
|
+
end
|
43
|
+
return lanes
|
44
|
+
end
|
45
|
+
def assign_lane_counts!
|
46
|
+
lanes = assign_lane_numbers!
|
47
|
+
lanes.reverse.each_with_index do |lane, lane_number_reversed|
|
48
|
+
real_lane = lanes.count - lane_number_reversed
|
49
|
+
other_lane_recs = []
|
50
|
+
lanes.each_with_index do |oth_lane, oth_lane_index|
|
51
|
+
break if oth_lane_index >= real_lane
|
52
|
+
other_lane_recs += oth_lane
|
53
|
+
end
|
54
|
+
lane.each do |rec|
|
55
|
+
rec.lane_count ||= real_lane
|
56
|
+
other_lane_recs.each do |oth_rec|
|
57
|
+
if rec.overlaps?(oth_rec)
|
58
|
+
oth_rec.lane_count = rec.lane_count if (oth_rec.lane_count.nil?) || (oth_rec.lane_count < rec.lane_count)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/time_pieces/version.rb
CHANGED
data/lib/time_pieces.rb
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_pieces
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant R.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -96,8 +96,10 @@ files:
|
|
96
96
|
- lib/time_pieces/duration.rb
|
97
97
|
- lib/time_pieces/simple_duration.rb
|
98
98
|
- lib/time_pieces/time_set.rb
|
99
|
+
- lib/time_pieces/traffic_cop.rb
|
99
100
|
- lib/time_pieces/version.rb
|
100
101
|
- pkg/time_pieces-1.0.2.gem
|
102
|
+
- pkg/time_pieces-1.0.3.gem
|
101
103
|
- time_pieces.gemspec
|
102
104
|
homepage: http://github.com/riggleg/time_pieces
|
103
105
|
licenses:
|