intervals

Finding minimum number of points which covers entire set of intervals?

99封情书 提交于 2019-12-01 01:31:15
问题 Given a set of intervals [x,y] where 0 <= x,y <= 2000 how to find minimum number of points which can cover(i.e. Every interval should contain at least one point in resultant set of points) all intervals? example: Given Set of intervals: [2,5] [3,7] [7,10] then answer should be 2 (minimum number of points required to cover all intervals) as points x=3,x=7 is one solution. 回答1: You can use a greedy algorithm: Sort all intervals by their end points(in increasing order). Iterate over a sorted

Getting number of certain days-of-the-week (weekend) from interval in PostgreSQL

浪尽此生 提交于 2019-12-01 00:14:42
Given 2 timestamps in postgres, how do you calculate the time difference without counting whole Saturdays and Sundays? OR How do you count the number of Saturdays and Sundays in a given time interval? The following function is returning the number of full weekend days between two dates. As you need full days, you can cast the timestamps to dates before calling the function. It returns 0 in case the first date is not strictly before the second. CREATE FUNCTION count_full_weekend_days(date, date) RETURNS int AS $BODY$ SELECT ($1 < $2)::int * ( (($2 - $1) / 7) * 2 + (EXTRACT(dow FROM $1)<6 AND

How to make calculation on time intervals?

醉酒当歌 提交于 2019-11-30 21:54:58
问题 I have a problem ,i solve it but i have written a long procedure and i can't be sure that it covers all the possible cases . The problem: If i have a main interval time ( From A to B ), and secondary interval times (Many or no) (`From X to Y AND From X` to Y` AND X`` to Y`` AND ....`) I want to SUM all parts of My Main interval time (AB) out of secondary intervals in minutes in efficient and the least number of conditions (SQL server Procedure and C# method)? For Example : If my Main interval

Multiple Enumerators for a Single C# Class

时光总嘲笑我的痴心妄想 提交于 2019-11-30 21:44:56
I have created a data structure consisting of intervals. The data structure should naturally have an enumerator that enumerates all intervals, but I would like to expose two different enumerators that enumerate the intervals in different order. One of the enumerators enumerate the intervals really fast, but in somewhat arbitrary order. The other enumerates them in lexicographical order, but a bit slower (depends on the intervals though). Depending on what you try to achieve, one enumerator might be to prefer over the other. Is there a way to allow the user to decide which enumerator should be

Partition into classes: jenks vs kmeans

一曲冷凌霜 提交于 2019-11-30 18:53:37
I want to partition a vector (length around 10^5) into five classes. With the function classIntervals from package classInt I wanted to use style = "jenks" natural breaks but this takes an inordinate amount of time even for a much smaller vector of only 500. Setting style = "kmeans" executes almost instantaneously. library(classInt) my_n <- 100 set.seed(1) x <- mapply(rnorm, n = my_n, mean = (1:5) * 5) system.time(classIntervals(x, n = 5, style = "jenks")) R> system.time(classIntervals(x, n = 5, style = "jenks")) user system elapsed 13.46 0.00 13.45 system.time(classIntervals(x, n = 5, style =

Getting number of certain days-of-the-week (weekend) from interval in PostgreSQL

随声附和 提交于 2019-11-30 18:20:27
问题 Given 2 timestamps in postgres, how do you calculate the time difference without counting whole Saturdays and Sundays? OR How do you count the number of Saturdays and Sundays in a given time interval? 回答1: The following function is returning the number of full weekend days between two dates. As you need full days, you can cast the timestamps to dates before calling the function. It returns 0 in case the first date is not strictly before the second. CREATE FUNCTION count_full_weekend_days(date

How can i loop through a daterange with different intervals?

ⅰ亾dé卋堺 提交于 2019-11-30 14:07:51
问题 I have a daterange (from, to) that i want loop through an different intervals (daily, weekly, monthly, ...) How can i loop through this dateranges? Update Thanks for your answers, i came up with the following: interval = 'week' # month, year start = from while start < to stop = start.send("end_of_#{interval}") if stop > to stop = to end logger.debug "Interval from #{start.inspect} to #{stop.inspect}" start = stop.send("beginning_of_#{interval}") start += 1.send(interval) end This will loop

How to convert an interval like “1 day 01:30:00” into “25:30:00”?

流过昼夜 提交于 2019-11-30 11:03:54
I need to add some intervals and use the result in Excel. Since sum(time.endtime-time.starttime) returns the interval as "1 day 01:30:00" and this format breaks my Excel sheet, I thought it'd be nice to have the output like "25:30:00" but found no way to do it in the PostgreSQL documentation. Can anyone here help me out? zaratustra Since there is not an exact solution for the topic: => SELECT date_part('epoch', INTERVAL '1 day 01:30:00') * INTERVAL '1 second' hours; hours ----------- 25:30:00 (1 row) Source: Documentation The only thing I can come with (beside parsing the number of days and

How to subtract 4 months from today's date?

点点圈 提交于 2019-11-30 10:57:04
I need to declare two dates in "Ymd" format: $toDate and $fromDate . $toDate represents today's date and $fromDate needs to be 4 months earlier than today. $toDate = Date('Ymd'); $fromDate = ? How do I create $fromDate ? Use the magic of strtotime : $fromDate = date("Ymd", strtotime("-4 months")); see the code below... $fourmonthsback = date("Ymd", mktime(0, 0, 0, date("m")-4, date("d"), date("Y"))); OR $fourmonthsback = mktime(0, 0, 0, date("m")-4, date("d"), date("Y")); 来源: https://stackoverflow.com/questions/4163387/how-to-subtract-4-months-from-todays-date

How can i loop through a daterange with different intervals?

穿精又带淫゛_ 提交于 2019-11-30 09:07:05
I have a daterange (from, to) that i want loop through an different intervals (daily, weekly, monthly, ...) How can i loop through this dateranges? Update Thanks for your answers, i came up with the following: interval = 'week' # month, year start = from while start < to stop = start.send("end_of_#{interval}") if stop > to stop = to end logger.debug "Interval from #{start.inspect} to #{stop.inspect}" start = stop.send("beginning_of_#{interval}") start += 1.send(interval) end This will loop through a date range with intervals week, month or year and respects the beginning and end of the given