def test_get_days_delimiting_dates(self): tss = self._setup_timestamps(D(2020, 5, 10, 23, 55, 0, 123500), 30000, 11) start_date = D(2020, 5, 11).timestamp() actual = dth.get_days(tss, start_date=start_date) expected = self._get_expected(tss, start_date=start_date) self.assertListEqual(expected.tolist(), actual[0].tolist())
def test_periods_day_negative_delta(self): scenarios = [ S(D(2020, 5, 10), D(2020, 5, 9), [D(2020, 5, 10), D(2020, 5, 9)]), S(D(2020, 5, 10), D(2020, 5, 10), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 11), ValueError) ] self._do_scenario_test(scenarios, 'day', -1) self._do_scenario_test(scenarios, 'days', -1)
def test_dataframe_create_with_dataframe(self): iscontents1 = ['a', 'bb', 'ccc', 'dddd'] iscontents2 = ['eeee', 'fff', 'gg', 'h'] fscontents1 = [s.encode() for s in iscontents1] fscontents2 = [s.encode() for s in iscontents2] ccontents1 = np.array([1, 2, 2, 1], dtype=np.int8) ccontents2 = np.array([2, 1, 1, 2], dtype=np.int8) ncontents1 = np.array([1, 2, 3, 4], dtype=np.int32) ncontents2 = np.array([5, 6, 7, 8], dtype=np.int32) from datetime import datetime as D tcontents1 = [D(2020, 1, 1), D(2020, 1, 2), D(2020, 1, 3), D(2020, 1, 4)] tcontents1 = np.array([d.timestamp() for d in tcontents1]) tcontents2 = [D(2021, 1, 1), D(2021, 1, 2), D(2021, 1, 3), D(2021, 1, 4)] tcontents2 = np.array([d.timestamp() for d in tcontents2]) bio = BytesIO() with session.Session() as s: ds = s.open_dataset(bio, 'w', 'ds') df1 = ds.create_dataframe('df1') df1.create_indexed_string('is_foo').data.write(iscontents1) df1.create_fixed_string('fs_foo', 4).data.write(fscontents1) df1.create_categorical('c_foo', 'int8', {b'a': 1, b'b': 2}).data.write(ccontents1) df1.create_numeric('n_foo', 'uint32').data.write(ncontents1) df1.create_timestamp('t_foo').data.write(tcontents1) df2 = ds.create_dataframe('df2', dataframe=df1) self.assertListEqual(iscontents1, df1['is_foo'].data[:]) self.assertListEqual(iscontents1, df2['is_foo'].data[:]) df2['is_foo'].data.clear() df2['is_foo'].data.write(iscontents2) self.assertListEqual(iscontents1, df1['is_foo'].data[:]) self.assertListEqual(iscontents2, df2['is_foo'].data[:]) self.assertListEqual(fscontents1, df1['fs_foo'].data[:].tolist()) self.assertListEqual(fscontents1, df2['fs_foo'].data[:].tolist()) df2['fs_foo'].data[:] = fscontents2 self.assertListEqual(fscontents1, df1['fs_foo'].data[:].tolist()) self.assertListEqual(fscontents2, df2['fs_foo'].data[:].tolist()) self.assertListEqual(ccontents1.tolist(), df1['c_foo'].data[:].tolist()) self.assertListEqual(ccontents1.tolist(), df2['c_foo'].data[:].tolist()) df2['c_foo'].data[:] = ccontents2 self.assertListEqual(ccontents1.tolist(), df1['c_foo'].data[:].tolist()) self.assertListEqual(ccontents2.tolist(), df2['c_foo'].data[:].tolist()) self.assertDictEqual({1: b'a', 2: b'b'}, df1['c_foo'].keys) self.assertDictEqual({1: b'a', 2: b'b'}, df2['c_foo'].keys) self.assertListEqual(ncontents1.tolist(), df1['n_foo'].data[:].tolist()) self.assertListEqual(ncontents1.tolist(), df2['n_foo'].data[:].tolist()) df2['n_foo'].data[:] = np.array(ncontents2, dtype=np.uint32) self.assertListEqual(ncontents1.tolist(), df1['n_foo'].data[:].tolist()) self.assertListEqual(ncontents2.tolist(), df2['n_foo'].data[:].tolist()) self.assertListEqual(tcontents1.tolist(), df1['t_foo'].data[:].tolist()) self.assertListEqual(tcontents1.tolist(), df2['t_foo'].data[:].tolist()) df2['t_foo'].data[:] = np.array(tcontents2, dtype=np.float64) self.assertListEqual(tcontents1.tolist(), df1['t_foo'].data[:].tolist()) self.assertListEqual(tcontents2.tolist(), df2['t_foo'].data[:].tolist())
def valid(n): F = False d = I(n[:2]) m = I(n[2:4]) y = n[4:6] r = I(n[6:8]) c = I(n[9]) if r < 20 or not (c == 0 or c == 9): return F try: if c == 0: y = I(S(20) + y) else: y = I(S(19) + y) D(y, m, d) except: return F s = 0 x = [3, 2, 7, 6, 5, 4, 3, 2] for i, t in E(n[:8]): s += (x[i] * I(t)) s = 11 - s % 11 if s == 11: s = 0 return s == I(n[8:9])
def test_get_days_filtered(self): tss = self._setup_timestamps(D(2020, 5, 10, 23, 55, 0, 123500), 30000, 11) filter_field = np.asarray([0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0], dtype=bool) actual = dth.get_days(tss, filter_field) expected = self._get_expected(tss, filter_field).tolist() self.assertListEqual(expected, actual[0].tolist())
def test_bug34(): "Bug 34: datetime.date ticks not handled by datarray_to_string" from datarray.print_grid import datarray_to_string from datetime import date as D A = DataArray([[1, 2], [3, 4]], [('row', ('a', D(2010, 1, 1))), ('col', 'cd')]) nt.assert_equal( datarray_to_string(A), """row col --------- ------------------- c d a 1 2 2010-01-0 3 4""")
def test_bug34(): "Bug 34: datetime.date ticks not handled by datarray_to_string" from datarray.print_grid import datarray_to_string from datetime import date as D A = DataArray([[1,2],[3,4]], [('row', ('a', D(2010,1,1))),('col', 'cd')]) exp_out = """row col --------- ------------------- c d a 1 2 2010-01-0 3 4""" nt.assert_equal(datarray_to_string(A), exp_out) # Output for unsigned integers B = A.astype(np.uint32) nt.assert_equal(datarray_to_string(B), exp_out)
def main(): signal.signal(signal.SIGINT, signal_handler) status = None percent, charging = charge_status() if charging: status = State.CHARGING else: status = State.DISCHARGING os.system('clear') status = status.next(percent, charging) status.action() while True: percent, charging = charge_status() count = int( os.popen("system_profiler SPPowerDataType | grep " + "'Cycle Count' | awk '{print $3}'").read()) cycles_remaining = 1000 - count care_days = (D(2021, 6, 30) - D.today()).days stats = None if len(sys.argv) > 2 and sys.argv[2] == "stats": stats = os.popen('istats').read() os.system('clear') print("Battery: %d%% - %s\nCharge count: %d" % (percent, status, count)) print("Remaining: %d days, %d cycles\nRate needed: %.5f cycles a day" % (care_days, cycles_remaining, cycles_remaining / care_days)) if stats is not None: print('\n' + stats[:stats.rfind('\n\n')]) status = status.next(percent, charging) time.sleep(10 if len(sys.argv) <= 1 or sys.argv[1] is None else int( sys.argv[1]))
def test_get_days(self): tss = self._setup_timestamps(D(2020, 5, 10, 23, 55, 0, 123500), 30000, 11) actual = dth.get_days(tss) expected = self._get_expected(tss).tolist() self.assertListEqual(expected, actual[0].tolist())
#!/usr/bin/env python2 # tab_cleanup.py by Amory Meltzer # Encourage me to cleanup my beowser tabs, one a day ### Hall of Shame ### # 14 Jan 2015 - 181 tabs # 18 Nov 2015 - 292 tabs # 18 Nov 2015 - 292 tabs from datetime import date as D start_date = D(2015, 11, 18) start_tabs = int(292) import sys sys.stdout.write('Today (') print D.today(), sys.stdout.write('): ') print start_tabs-(D.today() - start_date).days, print 'tabs required'
def test_periods_week_positive_delta(self): scenarios = [ S(D(2020, 5, 10), D(2020, 5, 3), ValueError), S(D(2020, 5, 10), D(2020, 5, 9), ValueError), S(D(2020, 5, 10), D(2020, 5, 10), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 11), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 16), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 17), [D(2020, 5, 10), D(2020, 5, 17)]), S(D(2020, 5, 10), D(2020, 5, 18), [D(2020, 5, 10), D(2020, 5, 17)]) ] self._do_scenario_test(scenarios, 'day', 7) self._do_scenario_test(scenarios, 'days', 7) self._do_scenario_test(scenarios, 'week', 1) self._do_scenario_test(scenarios, 'weeks', 1)
def test_periods_multi_day_negative_delta(self): scenarios = [ S(D(2020, 5, 5), D(2020, 4, 25), [D(2020, 5, 5), D(2020, 5, 2), D(2020, 4, 29), D(2020, 4, 26)]), S(D(2020, 5, 10), D(2020, 5, 7), [D(2020, 5, 10), D(2020, 5, 7)]), S(D(2020, 5, 10), D(2020, 5, 8), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 9), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 10), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 11), ValueError), ] self._do_scenario_test(scenarios, 'day', -3)
def test_periods_multi_day_positive_delta(self): scenarios = [ S(D(2020, 5, 10), D(2020, 5, 9), ValueError), S(D(2020, 5, 10), D(2020, 5, 10), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 11), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 12), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 13), [D(2020, 5, 10), D(2020, 5, 13)]), S(D(2020, 5, 25), D(2020, 6, 3), [D(2020, 5, 25), D(2020, 5, 28), D(2020, 5, 31), D(2020, 6, 3)]) ] self._do_scenario_test(scenarios, 'day', 3)
def test_periods_zero_count(self): scenarios = [ S(D(2020, 5, 10), D(2020, 5, 11), ValueError, "'delta' cannot be 0") ] self._do_scenario_test(scenarios, 'day', 0)
def test_generate_period_offset_map(self): start_dt = D(2020, 3, 1) end_dt = D(2021, 3, 1) periods = dth.get_periods(end_dt, start_dt, 'week', -1) periods.reverse()
#!/usr/local/bin/python3.4 import sys from datetime import date as D if len(sys.argv) < 2: print("usage: diffdate <dd:mm:yyyy> [<dd:mm:yyyy>]") exit() date = sys.argv[1].split(":") yr = int(date[2]) mo = int(date[1]) dy = int(date[0]) date1 = D(yr, mo, dy) date2 = D.today() if len(sys.argv) == 3: date = sys.argv[2].split(":") yr = int(date[2]) mo = int(date[1]) dy = int(date[0]) date2 = D(yr, mo, dy) datediff = (date2 - date1) days = datediff.days print(days)
def total(year, month, day): return (D.today() - D(year, month, day)).days
def test_periods_multi_week_negative_delta(self): scenarios = [ S(D(2020, 5, 10), D(2020, 4, 11), [D(2020, 5, 10), D(2020, 4, 12)]), S(D(2020, 5, 10), D(2020, 4, 12), [D(2020, 5, 10), D(2020, 4, 12)]), S(D(2020, 5, 10), D(2020, 4, 13), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 9), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 10), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 11), ValueError), S(D(2020, 5, 10), D(2020, 6, 7), ValueError) ] self._do_scenario_test(scenarios, 'day', -28) self._do_scenario_test(scenarios, 'days', -28) self._do_scenario_test(scenarios, 'week', -4) self._do_scenario_test(scenarios, 'weeks', -4)
def test_periods_week_negative_delta(self): scenarios = [ S(D(2020, 5, 10), D(2020, 5, 2), [D(2020, 5, 10), D(2020, 5, 3)]), S(D(2020, 5, 10), D(2020, 5, 3), [D(2020, 5, 10), D(2020, 5, 3)]), S(D(2020, 5, 10), D(2020, 5, 4), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 9), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 10), [D(2020, 5, 10)]), S(D(2020, 5, 10), D(2020, 5, 11), ValueError), S(D(2020, 5, 10), D(2020, 5, 17), ValueError) ] self._do_scenario_test(scenarios, 'day', -7) self._do_scenario_test(scenarios, 'days', -7) self._do_scenario_test(scenarios, 'week', -1) self._do_scenario_test(scenarios, 'weeks', -1)