LINQ query on timestamp between 22:30 and 1:00 - entity-framework

I am trying to use LINQ to get a list of entities where the timestamp falls between either 22:30 - 24:00 or 00:00 - 1:00 on a saturday or sunday and I am looking to set both timeframes in the one LINQ query but I have been unable to do so and have had to break it up as follows:
weekdayNight = intervalInformations.Where(ii => ii.IntervalPeriodTimestamp.TimeOfDay >= new TimeSpan(22, 30, 0)
&& ii.IntervalPeriodTimestamp.TimeOfDay <= new TimeSpan(23, 30, 0)
&& ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Saturday
&& ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Sunday
&& !dates.Contains(ii.IntervalPeriodTimestamp.ToShortDateString()))
.OrderBy(ii => ii.IntervalPeriodTimestamp)
.ToList();
weekdayNight2 = intervalInformations.Where(ii => ii.IntervalPeriodTimestamp.TimeOfDay >= new TimeSpan(0, 0, 0)
&& ii.IntervalPeriodTimestamp.TimeOfDay <= new TimeSpan(0, 30, 0)
&& ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Saturday
&& ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Sunday
&& !dates.Contains(ii.IntervalPeriodTimestamp.ToShortDateString()))
.OrderBy(ii => ii.IntervalPeriodTimestamp)
.ToList();
weekdayNight.Add(weekdayNight2);
How can I write this query without needing to join two different queries

Adding an OR between the two conditions defining time intervals should do the trick:
weekdayNight = intervalInformations.Where(ii =>
((ii.IntervalPeriodTimestamp.TimeOfDay >= new TimeSpan(22, 30, 0) && ii.IntervalPeriodTimestamp.TimeOfDay <= new TimeSpan(23, 30, 0))
|| (ii.IntervalPeriodTimestamp.TimeOfDay >= new TimeSpan(0, 0, 0) && ii.IntervalPeriodTimestamp.TimeOfDay <= new TimeSpan(0, 30, 0)))
&& ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Saturday
&& ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Sunday
&& !dates.Contains(ii.IntervalPeriodTimestamp.ToShortDateString())
)
.OrderBy(ii => ii.IntervalPeriodTimestamp)
.ToList();
Note: Your query appears to exclude the last half-hour between 23:30 and midnight. If this is not intentional, you can simplify the query even further:
weekdayNight = intervalInformations.Where(ii =>
(ii.IntervalPeriodTimestamp.TimeOfDay >= new TimeSpan(22, 30, 0)
|| ii.IntervalPeriodTimestamp.TimeOfDay <= new TimeSpan(0, 30, 0))
&& ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Saturday
&& ii.IntervalPeriodTimestamp.DayOfWeek != DayOfWeek.Sunday
&& !dates.Contains(ii.IntervalPeriodTimestamp.ToShortDateString())
)
.OrderBy(ii => ii.IntervalPeriodTimestamp)
.ToList();

Related

How to query mongoDB for a given date range?

I am using mongoose to query data for my node.js application for a given month where I accept the input for a year and month from the user.
This is what I am doing
var lastDay = 31
if (month == 3 || month == 5 || month == 8 || month == 10) lastDay = 30
else if (month == 1) lastDay = 28
var cookies = await Cookies.find({
docDate: {
"$gte": new Date(parseInt(year), parseInt(month), 1),
"$lte": new Date(parseInt(year), parseInt(month), lastDay)}}).sort("docDate");
When I try to query the db for the month of february, I am getting results only uptil the 26 Feb and the result also includes data from january.
Please help me figure out what I am doing wrong.
I think the issue is with the date that is passed to the query.
new Date(2021,01,01); --> 2021-01-31T16:00:00.000Z
new Date(Date.UTC(2021,01,01)); --> 2021-02-01T00:00:00.000Z
If the date field in the database is in UTC then try using new Date(Date.UTC(year, month, day))
Use moment.js library:
docDate: {
"$gte": moment().startOf('month').toDate(),
"$lte": moment().endOf('month').toDate()
}
moment() is the current time. In order to input specific day, use moment(year + '-' + month, "YYYY-MM") for example.

jQuery Datepicker - how to set: datepicker1 + 1 day becomes minDate datepicker2 with the option to switch off Saturday and Sunday

I want to set the service selection for my clients like this:
possibility of disabling services on Saturdays and / or Sundays (checbox - Saturday formid-1 fielid-4_1, Sunday formid-1 fieldi-4_2; by default enabled)
minDate datapicker1 - 2 days after today (formid 1, fieldid 1)
minDate datepicker2 - 1 day after minDate datapaicker1 (formid 1, fieldid 2)
Unfortunately, I don't have the skills. I can tell dateMin, dateMax but more complicated functions don't work.
Will someone help me? :)
gform.addFilter( 'gform_datepicker_options_pre_init', function( optionsObj, formId, fieldId ) {
if ( formId == 1 && fieldId == 1 ) {
optionsObj.minDate = +2;
optionsObj.maxDate = +33;
}
return optionsObj;
} );

How to check whether day satisfies the recurrence condition using google sheet formula

I have a Google sheet where it has startdate, frequency, count. I need to check whether the todays date is satisfying the recurrence and display TRUE if today() is satisfied and false if not satisfied.
This will help me determine each time, the sheet is opened I can find out from TODAY() date is satisifed or not?
https://docs.google.com/spreadsheets/d/142od5eUib5nHmdi4mnENuPbh-Yn485NzUSt90p84QE0/edit?usp=sharing
Like #Scott Craner said, just compare the result of the formula from the previous question with TODAY():
={
"Today is the day?";
ARRAYFORMULA(
IF(
A2:A = "",
,
IFS(
A2:A >= TODAY(),
A2:A,
B2:B = "Daily",
TODAY() + MOD(TODAY() - A2:A, C2:C),
B2:B = "Weekly",
TODAY() + MOD(TODAY() - A2:A, 7 * C2:C),
B2:B = "Monthly",
EDATE(A2:A, ROUNDUP((12 * (YEAR(TODAY()) - YEAR(A2:A)) + (MONTH(TODAY()) - MONTH(A2:A)) - IF(DAY(TODAY()) < DAY(A2:A), 1, 0)) / C2:C, 0) * C2:C),
True,
""
) = TODAY()
)
)
}

Searching for entries between two dates in MongoDB

I have a collection "received" in which documents contain a embedded filed which consists of year and week details. For example:
"YearANDWeek" : {
"Year" : 1908,
"Week" : 6
}
If I want to get data between year 1956 and week 23 to year 2000 and week 40 what query I need to use? I can use $gte and $lt but there is conflict between weeks.
I would use the following query.
db.received.find({$where:"((this.YearANDWeek.Year > 1956 && this.YearANDWeek.Year < 2000) || (this.YearANDWeek.Year == 1956 && this.YearANDWeek.Week >= 23) || (this.YearANDWeek.Year == 2000 && this.YearANDWeek.Week <= 40))"});
I this you can try this
db.recieved.find({$where:"((this.YearANDWeek.Year >= 1956 && this.YearANDWeek.Week >= 6) || (this.YearANDWeek.Year < 2000 && this.YearANDWeek.Year > 2000 && this.YearANDWeek.Week < 40)) && (this.YearANDWeek.Year >= 1956 && this.YearANDWeek.Year < 2000)"})

Google chart shows dots not line chart

Working on my line chart and very confused why it shows dots and not lines between the dots. So hope someone can help me with my problem. Thanks!
Google chart code, I can paste the whole code with sql query and so if needed:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
Temperatur = document.getElementById('Temperatur'),
Badende_Per_Time = document.getElementById('Badende_Per_Time'),
Luft_Temperatur = document.getElementById('Luft_Temperatur');
FrittKlor = document.getElementById('FrittKlor');
BundetKlor = document.getElementById('BundetKlor');
TotalKlor = document.getElementById('TotalKlor');
PH = document.getElementById('PH');
AutoKlor = document.getElementById('AutoKlor');
AutoPh = document.getElementById('AutoPh');
AutoTemperatur = document.getElementById('AutoTemperatur');
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
Temperatur.onchange = drawChart;
Badende_Per_Time.onchange = drawChart;
Luft_Temperatur.onchange = drawChart;
FrittKlor.onchange = drawChart;
BundetKlor.onchange = drawChart;
TotalKlor.onchange = drawChart;
PH.onchange = drawChart;
AutoKlor.onchange = drawChart;
AutoPh.onchange = drawChart;
AutoTemperatur.onchange = drawChart;
function drawChart() {
var data = new google.visualization.DataTable(<?=$jsonTable?>);
var options = {
width: 1100, height: 520,
title: 'Diagram',
curveType: 'function',
legend: { position: 'bottom' },
pointSize: 5,
vAxis: {title: "Verdi", titleTextStyle: {italic: false}},
hAxis: {title: "Tid", titleTextStyle: {italic: false}},
explorer: { actions: ['dragToZoom', 'rightClickToReset'],
axis: 'both' },
focusTarget: 'category',
};
if (!AutoTemperatur.checked) data.removeColumn(10);
if (!AutoPh.checked) data.removeColumn(9);
if (!AutoKlor.checked) data.removeColumn(8);
if (!PH.checked) data.removeColumn(7);
if (!TotalKlor.checked) data.removeColumn(6);
if (!BundetKlor.checked) data.removeColumn(5);
if (!FrittKlor.checked) data.removeColumn(4);
if (!Luft_Temperatur.checked) data.removeColumn(3);
if (!Badende_Per_Time.checked) data.removeColumn(2);
if (!Temperatur.checked) data.removeColumn(1);
var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
Code:
$sth = sqlsrv_query($conn,"
SELECT routines.date, routines.time,
SUM( CASE WHEN measurements.title = 'T_Temperatur' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS Temperatur,
SUM( CASE WHEN measurements.title = 'T_Badende_per_Time' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS Badende_Per_Time,
SUM( CASE WHEN measurements.title = 'T_Luft_Temperatur' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS Luft_Temperatur,
SUM( CASE WHEN measurements.title = 'M_Fritt_Klor' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS FrittKlor,
SUM( CASE WHEN measurements.title = 'M_Bundet_Klor' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS BundetKlor,
SUM( CASE WHEN measurements.title = 'M_Total_Klor' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS TotalKlor,
SUM( CASE WHEN measurements.title = 'M_PH' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS PH,
SUM( CASE WHEN measurements.title = 'M_Auto_Klor' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS AutoKlor,
SUM( CASE WHEN measurements.title = 'M_Auto_PH' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS AutoPh,
SUM( CASE WHEN measurements.title = 'A_Auto_Temperatur' THEN CAST( REPLACE( routines.value, ',', '.' ) AS DECIMAL( 18, 2 ) ) ELSE NULL END) AS AutoTemperatur
FROM routines
INNER JOIN measure_routine ON routines.id = measure_routine.routine_id
INNER JOIN measurements ON measure_routine.measure_id = measurements.id
INNER JOIN pools ON measure_routine.pool_id = pools.id
WHERE routines.date between '".$fraDato."' AND '".$tilDato."'
AND (pools.name = '".$basseng."' OR pools.name = 'Svommehall')
AND routines.time between '".$fraTid."' AND '".$tilTid."'
GROUP BY routines.date, routines.time
ORDER BY routines.date, routines.time;
;");
if( $sth === false ) {
die( print_r( sqlsrv_errors(), true));
}
$rows = array();
$flag = true;
$table = array();
$table['cols'] = array(
array('label' => 'routines.date' & 'routines.time', 'type' => 'datetime'),
array('label' => 'Temperatur', 'type' => 'number'),
array('label' => 'Badende_Per_Time', 'type' => 'number'),
array('label' => 'Luft_Temperatur', 'type' => 'number'),
array('label' => 'FrittKlor', 'type' => 'number'),
array('label' => 'BundetKlor', 'type' => 'number'),
array('label' => 'TotalKlor', 'type' => 'number'),
array('label' => 'PH', 'type' => 'number'),
array('label' => 'AutoKlor', 'type' => 'number'),
array('label' => 'AutoPh', 'type' => 'number'),
array('label' => 'AutoTemperatur', 'type' => 'number'),
);
$rows = array();
while($r = sqlsrv_fetch_array ($sth))
{
//$temp = array();
// assumes dates are in the format "yyyy-MM-dd"
$dateString = $r['date'];
$year = $dateString->format('Y');
$month = $dateString->format('m') -1;
$day = $dateString->format('d');
// assumes time is in the format "hh:mm:ss"
$timeString = $r['time'];
$hours = $timeString->format('G');
$minutes = $timeString->format('i');
$seconds = $timeString->format('s');
$temp = array();
$temp[] = array('v' => "Date($year, $month, $day, $hours, $minutes, $seconds)");
$temp[] = array('v' => $r['Temperatur']);
$temp[] = array('v' => $r['Badende_Per_Time']);
$temp[] = array('v' => $r['Luft_Temperatur']);
$temp[] = array('v' => $r['FrittKlor']);
$temp[] = array('v' => $r['BundetKlor']);
$temp[] = array('v' => $r['TotalKlor']);
$temp[] = array('v' => $r['PH']);
$temp[] = array('v' => $r['AutoKlor']);
$temp[] = array('v' => $r['AutoPh']);
$temp[] = array('v' => $r['AutoTemperatur']);
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsonTable = json_encode($table, JSON_NUMERIC_CHECK);
//echo $jsonTable;
$jsonTable:
00)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":28.5}]},{"c":[{"v":"Date(2014, 4, 08, 6, 00, 00)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":28.5}]},{"c":[{"v":"Date(2014, 4, 08, 7, 58, 33)"},{"v":null},{"v":null},{"v":null},{"v":1.94},{"v":0.39},{"v":2.33},{"v":7.19},{"v":2.13},{"v":7.05},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 7, 59, 39)"},{"v":28.1},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 7, 59, 59)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":28.5}]},{"c":[{"v":"Date(2014, 4, 08, 8, 01, 04)"},{"v":null},{"v":null},{"v":27.8},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 8, 02, 20)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 8, 40, 20)"},{"v":null},{"v":0},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 9, 30, 18)"},{"v":null},{"v":33},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 9, 59, 59)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":28.44}]},{"c":[{"v":"Date(2014, 4, 08, 10, 38, 34)"},{"v":null},{"v":36},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 11, 23, 02)"},{"v":null},{"v":null},{"v":null},{"v":1.94},{"v":0.39},{"v":2.33},{"v":7.21},{"v":2.15},{"v":7.08},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 11, 36, 40)"},{"v":null},{"v":0},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 12, 00, 00)"},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":28.44}]},{"c":[{"v":"Date(2014, 4, 08, 12, 30, 40)"},{"v":null},{"v":6},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 13, 33, 47)"},{"v":null},{"v":0},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 14, 22, 46)"},{"v":null},{"v":null},{"v":null},{"v":1.99},{"v":0.29},{"v":2.28},{"v":7.22},{"v":2.1},{"v":7.01},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 14, 26, 30)"},{"v":null},{"v":3},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 14, 39, 00)"},{"v":28.2},{"v":0},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 14, 41, 53)"},{"v":null},{"v":null},{"v":26.7},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 15, 45, 49)"},{"v":null},{"v":17},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 16, 34, 38)"},{"v":null},{"v":38},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 17, 16, 13)"},{"v":null},{"v":null},{"v":null},{"v":1.89},{"v":0.44},{"v":2.33},{"v":7.17},{"v":2.08},{"v":7.08},{"v":null}]},{"c":[{"v":"Date(2014, 4, 08, 17, 24, 04)"},{"v":null},{"v":62},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null},{"v":null}]}]}
From asgallant's comment:
From what I've been able to tease out of your data, your data points have null values in between them, which breaks the line in the charts by default. You can override this by setting the chart's interpolateNulls option to true.
1.You can use data.sort([{column: 0}]); for sorting it based on x-axis, Here column:0 indicatesx-axis.
google chart doc for sorting
2.If the value you are trying to pass is through some xml or json and it has null values inside, It will not plot properly and will be scattered or as dotted lines in line graph so to plot them, have a condition to remove all null values and then it will plot correctly.