intervals

Data structure for handling intervals

爱⌒轻易说出口 提交于 2019-11-27 11:00:20
问题 I have got a series of time intervals (t_start,t_end), that cannot overlap, i.e.: t_end(i) > t_start(i+1). I want to do the following operations: 1) Add new (Union of) intervals [ {(1,4),(8,10)} U (3,7) = {(1,7),(8,10)} ] 2) Take intervals out [ (1,7) - (3,5) = {(1,3),(5,7)} 3) Checking whether a point or a interval overlaps with an interval in my series (intersection) 4) Finding the first "non-interval" of a minimum length after some point [ {(1,4),(7,8)}: there is a "non-interval" of length

How to add markers on Google Maps polylines based on distance along the line?

不问归期 提交于 2019-11-27 10:42:05
I am trying to create a Google Map where the user can plot the route he walked/ran/bicycled and see how long he ran. The GPolyline class with it’s getLength() method is very helpful in this regard (at least for Google Maps API V2), but I wanted to add markers based on distance, for example a marker for 1 km, 5 km, 10 km, etc., but it seems that there is no obvious way to find a point on a polyline based on how far along the line it is. Any suggestions? Daniel Vassallo Having answered a similar problem a couple of months ago on how to tackle this on the server-side in SQL Server 2008, I am

Why is datediff interval “weekday” returning interval based on weeks and not days minus weekends?

谁说我不能喝 提交于 2019-11-27 09:53:16
I'm using the expression builder to give me a calculated value. It looks like this: =DateDiff("w",Date(),[Latest_Call_Date]) However, this is giving me results as if it were doing a calculation based on weeks instead of days minus weekends . When I try the same function, but with the interval set to days (d) instead of weekdays (w) I get the expected results (but of course, including Saturdays and Sundays, which I do not wish to include in the calculation). So, for example, for everyday this week I'm getting 1,2,3,4,5 day differences but they all return zero with weekdays. That formula is:

Union of intervals

我们两清 提交于 2019-11-27 08:41:27
I've got a class representing an interval. This class has two properties "start" and "end" of a comparable type. Now I'm searching for an efficient algorithm to take the union of a set of such intervals. Thanks in advance. Sort them by one of the terms (start, for example), then check for overlaps with its (right-hand) neighbor as you move through the list. class tp(): def __repr__(self): return '(%d,%d)' % (self.start, self.end) def __init__(self,start,end): self.start=start self.end=end s=[tp(5,10),tp(7,8),tp(0,5)] s.sort(key=lambda self: self.start) y=[ s[0] ] for x in s[1:]: if y[-1].end <

Counting values by day/hour with timeseries in MATLAB

非 Y 不嫁゛ 提交于 2019-11-27 08:16:29
问题 So, I'm beginning to use timeseries in MATLAB and I'm kinda stuck. I have a list of timestamps of events which I imported into MATLAB. It's now a 3000x25 array which looks like 2000-01-01T00:01:01+00:00 2000-01-01T00:01:02+00:00 2000-01-01T00:01:03+00:00 2000-01-01T00:01:04+00:00 As you can see, each event was recorded by date, hour, minute, second, etc. Now, I would like to count the number of events by date, hour, etc. and then do various analyses (regression, etc.). I considered creating a

Working with INTERVAL and CURDATE in MySQL

会有一股神秘感。 提交于 2019-11-27 07:24:29
I'm building a chart and I want to receive data for each month. Here's my first request which is working: SELECT s.GSP_nom AS nom, timestamp, AVG( v.vote + v.prix ) /2 AS avg FROM votes_serveur AS v INNER JOIN serveur AS s ON v.idServ = s.idServ WHERE s.valide =1 AND v.date > CURDATE() -30 GROUP BY s.GSP_nom ORDER BY avg DESC But, in my case I've to write 12 request to receive data for the 12 previous months, is there any trick to avoid writing: // example for the previous month AND v.date > CURDATE() -60 AND v.date < CURDATE () -30 I heard about INTERVAL, I went to the MySQL doc but i didn't

Python interval interesction

混江龙づ霸主 提交于 2019-11-27 07:15:31
问题 My problem is as follows: having file with list of intervals: 1 5 2 8 9 12 20 30 And a range of 0 200 I would like to do such an intersection that will report the positions [start end] between my intervals inside the given range. For example: 8 9 12 20 30 200 Beside any ideas how to bite this, would be also nice to read some thoughts on optimization, since as always the input files are going to be huge. 回答1: this solution works as long the intervals are ordered by the start point and does not

Does an open-ended interval implementation exist for Java?

岁酱吖の 提交于 2019-11-27 07:01:05
问题 I've got a classification of certain values in different intervals. Most have the form [20-30], but some are of the form [30-infinite). Is there an interval class you know of which can represent: an interval which is not closed on both sides (e.g. (0-5) or [0-5) ) an interval which closes (or starts) on infinite 回答1: Time&Money project seems to have Interval class that you need. See these files in their svn: interval package. 回答2: The Apache-commons-lang project (http://commons.apache.org

C: How to wrap a float to the interval [-pi, pi)

你。 提交于 2019-11-27 06:25:24
I'm looking for some nice C code that will accomplish effectively: while (deltaPhase >= M_PI) deltaPhase -= M_TWOPI; while (deltaPhase < -M_PI) deltaPhase += M_TWOPI; What are my options? Edit Apr 19, 2013: Modulo function updated to handle boundary cases as noted by aka.nice and arr_sea: static const double _PI= 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348; static const double _TWO_PI= 6.2831853071795864769252867665590057683943387987502116419498891846156328125724179972560696; // Floating-point modulo // The result (the remainder) has same sign as

Algorithm to find the maximum sum in a sequence of overlapping intervals

房东的猫 提交于 2019-11-27 06:16:45
The problem I am trying to solve has a list of intervals on the number line, each with a pre-defined score. I need to return the maximum possible total score. The catch is that the intervals overlap, and of the overlapping intervals I can use only one. Here is an example. Intervals - Score 0- 5 - 15 4- 9 - 18 10-15 - 12 8-21 - 19 25-30 - 25 Here, the intervals 0-5, 4-9 and 8-21 overlap. The intervals 10-15 and 8-21 also overlap. The maximum sum would be 55 (18+12+25). It is important to note here that we select the interval 4-9 of the first batch of overlapping intervals even though it does