I'm going to give a brief overview about the app configuration before I go into the query. I am running a Laravel 6 app using MongoDB through Jenssegers MongoDB plugin. So far I have not had to write a raw mongo query and I hope I won't have to for this one too, I mean, I have no idea how to achieve what I want through Eloquent even with SQL, so not sure if possible.
I have three models:
User - standard user details
Availability - Event type model with start_date, end_date, duration, user_id and other unrelated properties
Shift - Event type model with start_date, end_date, duration and other unrelated properties
A User can have many Availability
What I need to do now is for a given Shift, find users that are available to work in that time (from Shift's start_date to end_date). Now that is pretty simple, I do:
User::whereHas('availability', function($query) use ($shift_start, $shift_end) {
$query->where('start_date', '<=', $shift_start)->where('end_date', '>=', $shift_end);
})->get();
All of this works fine, but the users want to be able to create availability like this too:
Availability 1: 21 Sep 2020 14:00 - 21 Sep 2020 23:59
Availability 2: 22 Sep 2020 00:00 - 22 Sep 2020 06:00
What this means is that these two events are kind of "chained" together even though they are two events. This user would technically be available from 21 Sep 2020 14:00 - 22 Sep 2020 06:00 so if the Shift's dates are start: 21 Sep 2020 18:00 end: 22 Sep 2020 04:00, the user should be returned as available for the shift.
I have failed to find a way to include this edge-case into the query and it is what I need help with.
Can you try to make your query as below,
User::whereHas('availability', function($query) use ($shift_start, $shift_end) {
$query->where('start_date', '>=', $shift_start)->where('end_date', '<=', $shift_end);
$query->orwhereBetween('start_date',array($shift_start,$shift_end))
$query->orWhereBetween('end_date',array($shift_start,$shift_start))
})->get();
Related
I'm tryng to make a query on a date type field on MySql db.
I use predicate to generate more complex query.
Path<Date> path = root.get(attribute);
predicate = criteriaBuilder.equal(path, operator.getValue());
where attribute is
public static volatile SingularAttribute<Expiry, Date> dateInsert;
operator.getValue() is
binding parameter [1] as [DATE] - [Tue Feb 02 00:00:00 CET 2021]
Query return empty result set. I use repository for query.
expiryRepository.findAll(specification,getPageable(currentIndex))
I read a lot of topics about this issue but, no suggested solution works in my case.
Is there possible solution in 2021?
The problem, in my specific case, was caused by different setting of time zone between application and connection. The connection was established with UTC timezone but application works with CET time zone. When in application I did seted the date at 02 Febbruary 2021 at the 00:00 time, the connection changed it in 01 Febbruary 2021 at 11:00 pm time.
I removed this
&serverTimezone=UTC
from connection string, and all works fine.
Does anyone know of a quick algorithm to convert year over year returns to single period returns? Python code would be appreciated!
For reference, year over year refers to returns being calculated on an annual basis, for statistics that are reported on a higher frequency (to remove seasonality). So e.g. if total gas consumption is reported every month, the year over year return would be the percent difference between Dec 2018 and Dec 2017 and the single period return would be the difference between Dec 2018 and Nov 2018
So assuming you only have a series of YOY changes, is there a way to return monthly changes (in the above example)
tldr: I have a data series of year over year returns
ret(Jan 2017 to Jan 2018) = 1%
ret(Feb 2017 to Feb 2018) = -1.5%
ret(Mar 2017 to Mar 2018) = .5%
how do I convert it to a series of monthly returns?
ret(Jan 2017 to Feb 2017) = ?
ret(Feb 2017 to Mar 2017) = ?
...
Question: "So assuming you only have a series of YOY changes, is there a way to return monthly changes?"
Answer: No.
This can be demonstrated with a simple example. Here are four sample points:
Jan 2017 100
Feb 2017 90
...
Jan 2018 200
Feb 2018 180
The single period returns are -10%, and the year over year returns are +100%.
And here's another set of samples with the same year over year returns:
Jan 2017 100
Feb 2017 150
...
Jan 2018 200
Feb 2018 300
The single period returns are +50%, and the year over year returns are +100%.
Bottom line: the year-over-year returns tell you nothing about the month-to-month returns. To compute the month-to-month returns, you would need the monthly figures for at least one of the two years, in addition to the year-over-year returns.
Specifically, if the report is scheduled for the 31st of every month, at 11:59 PM, I want the report to show data from that month.
Example: Report is run on Jan 31, 2016 11:59 PM. I would like the data to show everything with Task Finish Date from Jan 1, 2016 - Jan 31, 2016.
Thanks!
the simplest way is to create variable which will return for specified dates in cross table zero or one. Then set filter on it and show only 'ones'.
the solution you've provided is also simple - fistdayofmonth might be created by creating new date as year(run_date)+monthnumber(run_date)+"01"
I'm trying to convert EST datetime to UTC in a Hive query, but can't see daylight saving taken into account. Do you know how to account for daylight saving in Hive?
For example:
TO_UTC_TIMESTAMP('2014-12-31 00:00:00', 'EST') gives 2014-12-31 05:00:00 i.e. 5 hour difference
TO_UTC_TIMESTAMP('2014-06-30 00:00:00', 'EST') gives 2014-06-30 05:00:00, also 5 hour difference
I'm expecting the June query to give a 4 hour difference.
In June the East Coast observes EDT (Eastern Daylight Savings Time), but Hive doesn't understand EDT at all:
TO_UTC_TIMESTAMP('2014-12-31 00:00:00', 'EDT') gives 2014-12-31 00:00:00 i.e. no difference
Any ideas?
Thanks,
Ilmari
(Running Hadoop 1.0.3 on AWS Elastic MapReduce)
Here is an open ticket from the Hive project that address this issue.
https://issues.apache.org/jira/browse/HIVE-12194
See 2nd comment:
Ben Breakstone added a comment - 16/Oct/15 16:54
It's worth noting the daylight saving time version of US three-letter codes like "PDT" are not included in /lib/zi/ for the Oracle JDK. New identifiers like "PST8PDT" appear to work as expected.
See http://www.oracle.com/technetwork/articles/javase/alertfurtherinfo-139131.html
Perhaps as Ben Breakstone suggests new identifiers will work?
I'm using Flash Builder 4.5 and trying to accomplish a charts dashboard task and everything works except one thing: the date when pulled from the MySQL, I can't order the columns by it. i don't care (even prefer) to make the dates like 01.06.2011 or 01/06/2011 i just need to do this somehow.
So this is what I'm doing on the service file:
$row->date = new DateTime($row->date);
When testing the operation i can see its pulling the date in this format:
Tue Jun 14 01:00:00 EEST 2011
Thanks!