I want to add 5 hours and 30 minute in a time in N1QL. How can I do it ?
I have time like 2016-04-03T18:30:00.000Z I need to add 5:30.
You can use the DATE_ADD_STR(expression, n, part) Date Function. Your query would look similar to the following:
SELECT
DATE_ADD_STR(DATE_ADD_STR(old_time, 5, "hour"), 30, "minute") AS new_time, ...
FROM some_bucket
Documentation:
Performs date arithmetic. n and part are used to define an interval or
duration, which is then added (or subtracted) to the date string in a
supported format, returning the result. Parts:
"millennium"
"century"
"decade"
"year"
"quarter"
"month"
"week"
"day"
"hour"
"minute"
"second"
"millisecond"
Source: http://developer.couchbase.com/documentation/server/4.5/n1ql/n1ql-language-reference/datefun.html
Related
I'm currently working with Yelp's dataset and my objective is to find the total hours a business is open a week. From the data, I am able to extract a time range for each day that looks like "9:0-0:0" or "17:30-21:30" for a certain day. How can I use SQL to get a single value for these hourly ranges?
This is some code I used to simply show the hours for a business in the dataset.
df_busSelected = df_business.select("business_id", "name"
, "hours.Sunday", "hours.Monday", "hours.Tuesday"
,"hours.Wednesday", "hours.Thursday", "hours.Friday"
, "hours.Saturday")
df_busSelected.show()
I hope to make a new column with the total hours a business is open a week with the given ranges.
Using pyspark, you can do something like the following:
from pyspark.sql.functions import expr
df.withColumn('h', expr('split(hours, "[-:]")').astype('array<int>')) \
.withColumn('h1', expr('''
h[2] - h[0] + IF(h[2]<h[0],24,0) + round((h[3]-h[1])/60,0)
''').astype('int')) \
.show()
+----------+-----------+----------------+---+
| bdate| hours| h| h1|
+----------+-----------+----------------+---+
|2019-10-17| 9:0-0:0| [9, 0, 0, 0]| 15|
|2019-10-18|17:30-21:30|[17, 30, 21, 30]| 4|
+----------+-----------+----------------+---+
First use the charset [-:] to split the column hours into an array of 4 items (named h) and cast it into array of int (originally array of StringType)
Then do the simple math and at the end cast the result type to int again.
Next, use date_format('bdate', 'EEEE') to get week name and then use groupby and pivot and probably agg + sum functions to get the final result
Background:
We are trying to identify if notifications are due to go out against records that have configurable schedules. So, for instance, a record could have:
NotificationStep: 'week(s)'
NotificationCount: 3
StartDate: 2018-11-17
This would signal that 3 weeks after Nov 17 -- or the last time one of these notifications went out -- we need to send out a new notification.
In SQL this would involve comparing today to subquery (and possibly a union) utilizing the MAX() method.
Question:
Is there a good way to use today's date as the value by which you're comparing your calculated values against?
Something like:
myModel.find({
where:{
new Date(): {$gt: Notifications.max('date', {where: ... }
}
});
All you need is sequelize.where and sequelize.fn
Here you go :
myModel.find({
where:
sequelize.where(sequelize.fn('now') , {$gt: Notifications.max('date', {where: ... } )
});
Note : sequelize.fn('now') // <---- Give you current time from DB
How can I use patterns in perseo rules with time windows? I have tried many different combinations, following the directions of EsperTech Tutorials, though, none of them was successful each time I post it to perseo. Any example for time window and how to get the average of any value (e.g. temperature) during that time will be highly appreciated. Trust me, before asking I have made a ton of efforts ;)
One working query for me is the following:
select *,\"temperature_range_XX-YY\" as ruleName, *, ev.temperature? as Temperature, ev.id? as Id, ev.datetime? as DateTime, ev.cid? as CID, current_timestamp as TS from pattern [every ev=iotEvent(cast(cast(temperature?,String),float)>XX or cast(cast(temperature?,String),float)<YY and type=\"sensors\")]
Of course, this query returns only any temperature outside XX and YY range. What I need is to get an alert if temperature is outside the range for specific time and what is the average of all values during that time.
To get an average you could use de avg() function within the select clause.
The following rule does work for me:
{
"name":"calculate_avg",
"text":"select *, avg(cast(cast(ev.NO2?,String),float)) as mediaNO2, ev.id? as id, \"calculate_avg\" as ruleName from pattern [every ev=iotEvent(type=\"AirQualityObserved\")].win:time(1 minute) group by ev.id?",
"action":{
"type":"update",
"parameters":{
"id":"${id}",
"type":"AirQualityAveraged",
"attributes": [
{
"name":"average",
"value":"${mediaNO2}"
}
]
}
}
}
I'd say your rule should be similar to:
"text":"select *,\"temperature_range_XX-YY\" as ruleName, *, avg(cast(cast(ev.temperature?, String), float)) as Temperature, ev.id? as Id, ev.datetime? as DateTime, ev.cid? as CID, current_timestamp as TS from pattern [every ev=iotEvent(cast(cast(temperature?,String),float)>XX or cast(cast(temperature?,String),float)<YY and type=\"sensors\")].win:time(1 minute)"
1) a) You have a list of addresses. Use Google APIs to calculate the timezones of each location object and then return output as this same array of objects, with each object comprising of following values -
[{
"id":"1",
"address":"Plot 5, CDCL Building, Chandigarh"m
"latitude":"30.123123",
"longitude":"76.123213"
"timezone":"-330", //in minutes
"UTC_time":"2016-10-18 5:30:00 AM"
}]
b) Now write an algorithm, to divide this array into least no. of sub-arrays, such that difference between the minimum UTC_time and maximum UTC_time in that array is less than or equal to 4 hrs.
2) Parse the attached html file and generate a JSON file as output, which contains all the key
FORMAT
Test Duration- 5 Hours
Test Date -27 October,2016
Format to be send in : "Student name- college name -roll number- 2016"||
Email Id - kunal#tookanapp.com ( All the students need to send their test on the mentioned email ID in the mentioned format )
Start Time - 11.00 AM
End Time - 4.00 PM
Just go through this link.You will get the answer.
https://developers.google.com/maps/documentation/timezone/intro
This is an algorithm not a program::--
initialise i, ar [100],d ;
MAX UTC_time= +14:00(150°);
Min UTC_time=-12:00 (180°);
for min UTC_time initialise to -12:00;
min UTC_time <=+14:00
If min UTC_time > +10:00
Then d=max UTC _time - min UTC_time;
And then print d;
Else
Min UTC_time++;
Link is :--
https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331766000&key=YOUR_API_KEY
{
"dstOffset" : 0,
"rawOffset" : -28800,
"status" : "OK",
"timeZoneId" : "America/Los_Angeles",
"timeZoneName" : "Pacific Standard Time"
}
In html language......
OK
-28800.0000000
0.0000000
America/Los_Angeles
Pacific Standard Time
time_zone_name>
I'm encountering an issue while develloping some report on RB.
I have a tablix that where the columns are the hours of the day, and the rows are different products. I also have a parameter with 3 values (AM, PM, NIGHT).
The point here is that if the parameter is set to AM, the tablix only display columns from 6 to 12, if it's set to PM, the tablix display from 12 to 18,...
I can display time intervals (6 to 12) by using filter where i tell him "Hour" IN "6, 7, 8, 9, 10, 11, 12". But it doesn't work when i set the filter value as following:
Expression: =Cstr(Fields!ProdHour.Value)
Operator: IN
Value:
=iif(join(Parameters!Shift.Value) = "AM",
"6, 7, 8, 9, 10, 11, 12" ,
iif(join(Parameters!Shift.Value) = "PM",
"13, 14, 15, 16, 17, 18",
iif(join(Parameters!Shift.Value) = "NIGHT",
"19, 20, 21, 22, 23, 0",
false)
)
)
Do you have any idea how I could solve this? Tried to change every number in Integer but didn't work...
I found a working solution:
I had to create 2 new fields in the same dataset as the table,I named those fields "ShiftStart" and "ShiftStop".
ShiftStart value : =iif(join(Parameters!Shift.Label)="AM","6",iif(join(Parameters!Shift.Label)="PM","12",iif(join(Parameters!Shift.Label)="NIGHT","0","0")))
Same with ShiftStop but with others values (12,18,0). So with those 2 data, when I pick "AM", ShitStart= 6 and ShiftStop=12, now i can create a filter to display columns where [Hour] is between [ShiftStart] and [ShiftStop].
Simple as that!
Thanks guys for you help! Sorry I can't Uptvote you, not enough reputation :(
I would suggest change the binding of your parameter like (ID,Value) see screen shot below
Now you can use the expression to get selected value
=Parameters!ReportParameter1.Value
You can also use below query to bind your dropdown, if don't want to hard code
Select ID,Value From
(Values('6,7,8,9,10,11,12','AM'),
('13,14,15,16,17,18','PM'),
('19,20,21,22,23,0','Night'))
tblTime(ID,Value)
I think that is what you are looking for
I would abandon using the In operator in the SSRS Filter Expression. I have only had universally bad experiences with Filters using any operator apart from "=" and also issues with datatypes.
My preference would be to filter this data out in the dataset query using SQL. However that is not the question.
In SSRS Filters, from hard experience, I now only always set datatype: "Boolean", operator: "=" and Value: "True". Then your challenge is to code an expression that only returns True for the rows you want to keep.
That could be something like:
=Iif ( ( Parameters!Shift.Value = AM and ("6,7,8,9,10,11,12").Contains(Fields!Hour.Value) )
Or ( ...
Is the Shift parameter multi-select?