def get_data(): data = [{ 'id': 'joe', 'last_updated': datetime.datetime(2014, 6, 3, 0, 0, 1, tzinfo=r.make_timezone('00:00')) }, { 'id': 'sam', 'last_updated': datetime.datetime(2014, 8, 25, 0, 0, 0, tzinfo=r.make_timezone('00:00')) }] return as_db_and_table('d', 'people', data)
def test_date(self, conn): expected = set([ datetime.datetime(2014, 8, 25, tzinfo=r.make_timezone('00:00')), datetime.datetime(2014, 6, 3, tzinfo=r.make_timezone('00:00')) ]) result = r.db('d').table('people').map( lambda doc: doc['last_updated'].date()).run(conn) assertEqual(expected, set(list(result)))
def post_db_result(db: ReDB, temperature: int, humidity: int): r.db('dashboard').table('temperatures').insert({ 'timestamp': r.expr(datetime.now(r.make_timezone('+02:00'))), 'location': 'SANDBOX', 'value': temperature }).run(db.get_conn()) r.db('dashboard').table('humidity').insert({ 'timestamp': r.expr(datetime.now(r.make_timezone('+02:00'))), 'location': 'SANDBOX', 'value': humidity }).run(db.get_conn())
def test_epoch_time(self, conn): results = r.db('d').table('people').map(lambda d: d.merge( {'as_epoch': d['last_updated'].to_epoch_time()})).run(conn) results = list(results) jan1 = datetime.datetime(1970, 1, 1, tzinfo=r.make_timezone('00:00')) for doc in results: expected = int((doc['last_updated'] - jan1).total_seconds()) assertEqual(expected, doc['as_epoch'])
def _json_decoder(d): for key, val in d.items(): if val == '': continue try: obj = datetime.datetime.fromisoformat(val) d[key] = obj.astimezone(r.make_timezone("+08:00")) except (ValueError, TypeError): continue return d
def time(self): """ Rethinkdb compatible datetime """ return datetime.now(r.make_timezone('00:00'))
def time_now(): return datetime.datetime.now(r.make_timezone("+08:00"))
def post_db_result(db: ReDB, is_opened: bool): r.db('dashboard').table('doors').insert({ 'timestamp': r.expr(datetime.now(r.make_timezone('+02:00'))), 'location': 'MAIN', 'opened': is_opened }).run(db.get_conn())
def save_executions(self, executions): for exec in executions: exec["timestamp"] = r.expr(datetime.now(r.make_timezone("-03:00"))) r.db(self.db_name).table("run_exec").insert(exec).run()
def save_trade(self, trade): trade["timestamp"] = r.expr(datetime.now(r.make_timezone("-03:00"))) r.db(self.db_name).table("trades").insert(trade).run()
def save_ticker(self, ticker): ticker["timestamp"] = r.expr(datetime.now(r.make_timezone("-03:00"))) r.db(self.db_name).table("tickers").insert(ticker).run()
def save_balance(self, balance): balance["timestamp"] = r.expr(datetime.now(r.make_timezone("-03:00"))) r.db(self.db_name).table("balance").insert(balance).run()