intervals

Allen's Interval Algebra operations in SQL

混江龙づ霸主 提交于 2019-12-09 04:19:43
问题 I've been struggling to solve a few tricky problems in SQL where I need to infer asset utilisation from event intervals, and have just learned about Allen's Interval Algebra, which seems to be the key to solving these problems. The algebra describes 13 kinds of relationships between intervals, and the image below shows the first seven, with the rest being the inverse (i.e. y before x, y meets x, etc) But I'm having trouble finding out how to implement the relevant operations. Given my sample

Calculate the perimeter and area of intersecting rectangles?

喜夏-厌秋 提交于 2019-12-09 03:34:20
问题 I searched a lot, but I didn't find a good answer that works for this case. We have some rectangles that are horizontal or vertical. They can be placed on the page randomly. They can overlap or have a common edge or be separate from each other. I want to find an algorithm with O(nlogn) that can find perimeter and area of these rectangles. These pictures may make the problem clear. I think that interval trees might help, but I'm not sure how. 回答1: It can be done by a sweep-line algorithm. We

Application.OnTime doesn't work with userform

梦想的初衷 提交于 2019-12-08 13:15:10
问题 I've got a problem with a piece of code: Private Sub cyclic() Static i As Integer i = i + 1 Cells(i, 11) = i Open source For Append As #1 Write #1, Cells(i, 11) Close #1 Application.Wait (Now + TimeValue("0:00:01")) Open source For Input As #1 Do While Not EOF(1) Input #1, x1 Loop Cells(i, 1) = x1 Close #1 Application.OnTime Now + TimeValue("00:00:03"), "cyclic" End Sub It's pretty much like this. It works perfectly from the level of worksheets alt+f8 macros, but when I want to make use of it

What is the best way (performance-wise) to flash things at a varying speed?

我与影子孤独终老i 提交于 2019-12-08 11:52:24
问题 I have an app where I flash words at a constant speed. Say it's set to 60 times a minute. Each word then shows for 1 second each. It was pretty easy to accomplish with NSTimer . However, I want to make it a little more intelligent now. Longer words show for slightly longer than shorter words. I've figured out the math on how to calculate this, but I'm not sure how in Objective-C to present a word for say, 0.15 seconds, then another word for 0.18 seconds, then a third word for 0.04 seconds,

Complex MySQL Query - Checking for overlapping DATE intervals

血红的双手。 提交于 2019-12-08 11:31:35
问题 I'm trying to write a function to move an scheduled task. The schedule can not overlap with any other event. My user inputs are as follows: schedule_id (int) new_start_time (DATETIME) My table structure is as follows: Schedules | schedule_id | start_time | end_time | task_id | 1 | 2015-12-21 02:00:00 | 2015-12-21 04:00:00 | 1 | 2 | 2015-12-21 08:30:00 | 2015-12-21 09:30:00 | 1 | 3 | 2015-12-22 01:00:00 | 2015-12-22 02:00:00 | 2 Tasks | task_id | name | max_duration | 1 | do things | 2 | 2 |

Pyspark split interval into sub intervals

我怕爱的太早我们不能终老 提交于 2019-12-08 11:06:30
问题 I have a dataframe with 3 columns "from", "to", "country" for ex: from to country 1 105 abc 500 1000 def I want to create dataframe by splitting from and to values into sizes = 10. So i should get dataframe as from to country 1 10 abc 11 20 abc 21 30 abc 31 40 abc ... 91 105 abc ( the left out values go in last bucket for that range) 500 510 def and so on... 回答1: from pyspark.sql.functions import udf, col, explode, array, struct, length from pyspark.sql.types import ArrayType, StructType,

BackgroundTask every minute Windows Store App (C#)

你。 提交于 2019-12-08 10:17:16
问题 So after much searching through the internet and trial and errors I've constructed a backgroundTask in a W8 App. But apperently the windows BackgroundTask class does only allow you to have a interval of 15 minutes. Though for the application I'm developing is this useless. I need a interval of max 1 minute. Does anyone know a working workaround for a background task to run with the app suspended in a max interval of 1 minute? 回答1: Per the documentation (see here and here), there's no way to

How to execute a Maya MEL procedure at regular intervals

时光毁灭记忆、已成空白 提交于 2019-12-08 06:43:00
问题 I would like one of my Maya MEL procedures to be executed every x seconds. Is there any way to do that ? 回答1: The mel setup would be scriptJob -e "idle" "yourScriptHere()"; However it's hard to get the time in seconds from Mel - system("time /t") will get you time to the minute but not to the second on windows. In Unix system("date +\"%H:%M:%S\"") would get you hours, minutes and seconds. The main drawback to scriptJob here is that idle events won't be processed when the user or a script is

Summing up values within an interval from another data.frame in R

爷,独闯天下 提交于 2019-12-08 03:15:21
问题 I have thousands of entries in hkdata.2 and I want to create a loop that can help me to sum up the total exposed mxtemp from another data frame data.1 for each member in each houseID in data.2 Could any expert give me a hand on this? weather.data date mpressure mxtemp 1 2008-01-01 1025.3 15.7 2 2008-01-02 1025.6 16.0 3 2008-01-03 1023.6 18.1 4 2008-01-04 1021.8 18.4 5 2008-01-05 1020.1 20.9 6 2008-01-06 1019.7 20.7 7 2008-01-07 1018.4 24.0 8 2008-01-08 1016.7 23.7 hkdata.2 row.names houseID

Counting values within levels

血红的双手。 提交于 2019-12-08 00:08:25
问题 I have a set of levels in R that I generate with cut , e.g. say fractional values between 0 and 1, broken down into 0.1 bins: > frac <- cut(c(0, 1), breaks=10) > levels(frac) [1] "(-0.001,0.1]" "(0.1,0.2]" "(0.2,0.3]" "(0.3,0.4]" "(0.4,0.5]" [6] "(0.5,0.6]" "(0.6,0.7]" "(0.7,0.8]" "(0.8,0.9]" "(0.9,1]" Given a vector v containing continuous values between [0.0, 1.0] , how do I count the frequency of elements in v that fall within each level in levels(frac) ? I could customize the number of