Method: OpenC3::ActivityModel#validate_time
- Defined in:
- lib/openc3/models/activity_model.rb
#validate_time(start, stop, ignore_score: nil) ⇒ Object
validate_time searches from the current activity @stop (exclusive because we allow overlap of stop with start) back through @start - MAX_DURATION. The method is trying to validate that this new activity does not overlap with anything else. The reason we search back past @start through MAX_DURATION is because we need to return all the activities that may start before us and verify that we don’t overlap them. Activities are only inserted by @start time so we need to go back to verify we don’t overlap existing @stop. Note: Score is the Seconds since the Unix Epoch: (%s) Number of seconds since 1970-01-01 00:00:00 UTC. zrange rev byscore finds activities from in reverse order so the first task is the closest task to the current score. In this case a parameter ignore_score allows the request to ignore that time and skip to the next time but if nothing is found in the time range we can return nil.
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/openc3/models/activity_model.rb', line 203 def validate_time(start, stop, ignore_score: nil) # Adding a '(' makes the max value exclusive array = Store.zrevrangebyscore(@primary_key, "(#{stop}", start - MAX_DURATION) array.each do |value| activity = JSON.parse(value, :allow_nan => true, :create_additions => true) if ignore_score == activity['start'] next elsif activity['stop'] > start return activity['start'] else return nil end end return nil end |