# Deephaven - Temporal Data Examples - Python # https:#docs.deephaven.io/ # date inside of the query language trades0825 = db.t("LearnDeephaven","StockTrades").where("Date=`2017-08-25`") CurrentDate = '2017-08-25' tradesCurrentDate = db.t("LearnDeephaven","StockTrades").where("Date=CurrentDate") # using java.lang.String methods on the Date (Date is a java String object) trades08 = db.t("LearnDeephaven","StockTrades").where("Date != null && Date.startsWith(`2017-08`)") # filters to dates in August 2017 trades08Comparator = db.t("LearnDeephaven","StockTrades").where("Date > `2017-08` && Date < `2017-09`") # equivalent to above except the ranges are inclusive trades08InRange = db.t("LearnDeephaven","StockTrades").where("inRange(Date, `2017-08-01`, `2017-09-01`)") # to construct DBDateTimes in the query language, use the single quote # all dates after 8AM 2017-08-21. Comparison operators on DBDateTimes are supported in the query language strings trades08After8 = trades08.where("Timestamp > '2017-08-21T08:00 NY'") # 8AM - 5PM 2017-08-21 trades08BusinessHours1 = trades08.where("Timestamp >= '2017-08-21T08:00 NY' && Timestamp <= '2017-08-21T17:00 NY'") #equivalent to above trades08BusinessHours2 = trades08.where("inRange(Timestamp, '2017-08-21T08:00 NY', '2017-08-21T17:00 NY')") #DBDateTimes supports simple operands as well #predefined DBDateTime variables are SECOND, MINUTE, HOUR, DAY, WEEK, and YEAR. These are included statically in the query language strings. from deephaven import * date = '2019-10-18' startOfDay = cals.calendar("USNYSE").getBusinessSchedule(date).getStartOfBusinessDay() t = db.t("MarketUs", "TradeNbboStock").where("Date = date", "Timestamp > startOfDay && Timestamp < (startOfDay + HOUR)") #transforming DBDateTimes to equivalent nanos from Epoch trades08BusinessHours3 = trades08.updateView("TimestampNanos = nanos(Timestamp)") #uses the default calendar to determine business hours, e.g., USNYSE calendar 930AM - 4PM 2017-08-21 #The default calendar is statically imported for use in query language strings trades08BusinessHours4 = trades08.where("isBusinessTime(Timestamp)") #calendar for the next three days #note that defining the nextDay(3) variable will make this significantly faster than using nextDay(3) in the where() #import the java StaticCalendarMethods class into the binding importjava('com.illumon.util.calendar.StaticCalendarMethods') current_day = StaticCalendarMethods.currentDay() current_day_plus3 = StaticCalendarMethods.nextDay(3) #Date will be >= currentDay and <= currentDay + 3 trades08BusinessHours5 = trades08.where("inRange(Date, current_day, current_day_plus3)") #all Mondays of August 2017 trades08Mondays1 = trades08.where("dayOfWeek(Date).getValue() = 1") #equivalent to above trades08Mondays2 = trades08.where("dayOfWeek(Date) = java.time.DayOfWeek.MONDAY") #time table- this is useful for table snapshots #creates a ticking table which gets a new row every second tt = db.timeTable('00:00:01')