date-range

Python postgreSQL sqlalchemy query a DATERANGE column

百般思念 提交于 2021-02-19 09:42:49
问题 I have a booking system and I save the booked daterange in a DATERANGE column: booked_date = Column(DATERANGE(), nullable=False) I already know that I can access the actual dates with booked_date.lower or booked_date.upper For example I do this here: for bdate in room.RoomObject_addresses_UserBooksRoom: unaviable_ranges['ranges'].append([str(bdate.booked_date.lower),\ str(bdate.booked_date.upper)]) Now I need to filter my bookings by a given daterange. For example I want to see all bookings

SQL merging records based on date range

亡梦爱人 提交于 2021-02-08 10:54:41
问题 I have a data set representing deliveries made by several vehicles, which can each load and discharge at different locations. I am trying to find out how many vehicles it took to do all deliveries, while grouping/merging all trips that loaded within +- x days. For example: vehicle V1 could load in Zone A (date X) and B (date X+2), and discharge in Zone C and D, that would count as 1 vehicle/trip because it loaded within 2 days. V1 could also simply do Zone A (date Y) to Zone C, that would

SQL merging records based on date range

好久不见. 提交于 2021-02-08 10:52:26
问题 I have a data set representing deliveries made by several vehicles, which can each load and discharge at different locations. I am trying to find out how many vehicles it took to do all deliveries, while grouping/merging all trips that loaded within +- x days. For example: vehicle V1 could load in Zone A (date X) and B (date X+2), and discharge in Zone C and D, that would count as 1 vehicle/trip because it loaded within 2 days. V1 could also simply do Zone A (date Y) to Zone C, that would

Expand df with range of dates to one row per day

荒凉一梦 提交于 2021-02-02 10:00:23
问题 I have a df that contains one line per item with a range of dates, and I need to expand it to contain one row per day per item. It looks like this: from to id 1 25/02/2019 27/02/2019 A 2 15/07/2019 16/07/2019 B And I want this: date id 1 25/02/2019 A 2 26/07/2019 A 3 27/07/2019 A 4 15/07/2019 B 5 16/07/2019 B I managed to write a code that works but it takes over one hour to run, so I am wondering if there is a more efficient way to do it. My code: df_dates = pd.DataFrame() for i in range(len

Expand df with range of dates to one row per day

≯℡__Kan透↙ 提交于 2021-02-02 10:00:20
问题 I have a df that contains one line per item with a range of dates, and I need to expand it to contain one row per day per item. It looks like this: from to id 1 25/02/2019 27/02/2019 A 2 15/07/2019 16/07/2019 B And I want this: date id 1 25/02/2019 A 2 26/07/2019 A 3 27/07/2019 A 4 15/07/2019 B 5 16/07/2019 B I managed to write a code that works but it takes over one hour to run, so I am wondering if there is a more efficient way to do it. My code: df_dates = pd.DataFrame() for i in range(len

Strideable Date

非 Y 不嫁゛ 提交于 2021-01-29 08:41:38
问题 I'm looking for cool ways to stride through Date ranges with different increments (either seconds aka TimeInterval or with DateComponents aka .hour , .minute ) import Foundation extension Date: Strideable { // typealias Stride = SignedInteger // doesn't work (probably because declared in extension public func advanced(by n: Int) -> Date { self.addingTimeInterval(TimeInterval(n)) } public func distance(to other: Date) -> Int { return Int(self.distance(to: other)) } } let now = Date() let

Is there a better alternative to array_filter and mapping in php?

99封情书 提交于 2021-01-29 08:36:40
问题 is there a better alternative to this code $datfrm = '01/01/2000' $datto = '01/01/2002' $place_map = ['best' => 1, 'better' => 0.8, 'good' => 0.6]; e1 ='good,better,best' e2 = 'best,better,good' d1='01/01/2000,01/01/2001,01/01/2002' d2='01/01/2001,01/01/2002,01/01/2003' $dresult = array_filter($dview, function($data_item) use($datfrm,$datto) { return $data_item >= $datfrm && $data_item <= $datto; }); $eresult = array_intersect_key($efind, $dresult); I'm trying a date range and it's not

Get dates of a day of week in a date range

我与影子孤独终老i 提交于 2021-01-28 22:05:36
问题 I need a function in PostgreSQL that accepts a date range and returns the dates inside the date range that are Mondays. Anybody have an idea how this could be done? 回答1: The most efficient way should be to find the first Monday and generate a series in steps of 7 days: CREATE OR REPLACE FUNCTION f_mondays(dr daterange) RETURNS TABLE (day date) AS $func$ SELECT generate_series(a + (8 - EXTRACT(ISODOW FROM a)::int) % 7 , z , interval '7 days')::date FROM ( SELECT CASE WHEN lower_inc(dr) THEN

Get dates of a day of week in a date range

百般思念 提交于 2021-01-28 22:02:11
问题 I need a function in PostgreSQL that accepts a date range and returns the dates inside the date range that are Mondays. Anybody have an idea how this could be done? 回答1: The most efficient way should be to find the first Monday and generate a series in steps of 7 days: CREATE OR REPLACE FUNCTION f_mondays(dr daterange) RETURNS TABLE (day date) AS $func$ SELECT generate_series(a + (8 - EXTRACT(ISODOW FROM a)::int) % 7 , z , interval '7 days')::date FROM ( SELECT CASE WHEN lower_inc(dr) THEN

R - find overlapping dates per group based on another data frame

醉酒当歌 提交于 2021-01-28 04:57:50
问题 I have a data frame with rainfall measurements from several rain gauges, like the sample below: > rnfl ID date value 1 250 2000-03-01 5.37 2 250 2000-03-02 0.00 3 250 2000-03-03 2.94 4 250 2000-03-04 0.00 5 250 2000-03-05 0.00 6 250 2000-03-06 0.00 7 250 2000-03-07 2.76 8 250 2000-03-08 3.06 9 250 2000-03-09 31.05 10 250 2000-03-10 9.48 11 250 2000-03-11 0.00 12 250 2000-03-12 0.00 13 250 2000-03-13 0.00 14 732 2011-05-01 2.40 15 732 2011-05-02 15.60 16 732 2011-05-03 8.80 17 732 2011-05-04