def changeset(self,c): assert_equals(34, c.id) assert_equals(1, c.uid) assert_false(c.user_is_anonymous()) assert_equals("Steve", c.user) assert_equals(mkdate(2005, 4, 9, 19, 54, 13), c.created_at) assert_equals(mkdate(2005, 4, 9, 20, 54, 39), c.closed_at) assert_false(c.open) assert_equals(2, c.num_changes) assert_equals(0, len(c.tags)) assert_equals(-1464925, c.bounds.top_right.x) assert_equals(515288620, c.bounds.top_right.y) assert_equals(-1465242, c.bounds.bottom_left.x) assert_equals(515288506, c.bounds.bottom_left.y) assert_true(check_repr(c))
def changeset(c): assert 34 == c.id assert 1 == c.uid assert not c.user_is_anonymous() assert "Steve" == c.user assert mkdate(2005, 4, 9, 19, 54, 13), c.created_at assert mkdate(2005, 4, 9, 20, 54, 39), c.closed_at assert not c.open assert 2 == c.num_changes assert 0 == len(c.tags) assert -1464925 == c.bounds.top_right.x assert 515288620 == c.bounds.top_right.y assert -1465242 == c.bounds.bottom_left.x assert 515288506 == c.bounds.bottom_left.y assert check_repr(c)
def changeset(self, c): assert_equals(34, c.id) assert_equals(1, c.uid) assert_false(c.user_is_anonymous()) assert_equals("Steve", c.user) assert_equals(mkdate(2005, 4, 9, 19, 54, 13), c.created_at) assert_equals(mkdate(2005, 4, 9, 20, 54, 39), c.closed_at) assert_false(c.open) assert_equals(2, c.num_changes) assert_equals(0, len(c.tags)) assert_equals(-1464925, c.bounds.top_right.x) assert_equals(515288620, c.bounds.top_right.y) assert_equals(-1465242, c.bounds.bottom_left.x) assert_equals(515288506, c.bounds.bottom_left.y) assert_true(check_repr(c))
def node(n): assert n.deleted == False assert n.visible == True assert n.version == 5 assert n.changeset == 58674 assert n.uid == 42 assert n.user_is_anonymous() == False assert n.timestamp == mkdate(2014, 1, 31, 6, 23, 35) assert n.user == u'änonymous' assert n.positive_id() == 1 assert check_repr(n)
def test_get_newest_change_from_file(): data = [osmobj('N', id=1, version=1, changeset=63965061, uid=8369524, timestamp='2018-10-29T03:56:07Z', user='******')] fn = create_osm_file(data) try: val = osmium.replication.newest_change_from_file(fn) assert_equals(val, mkdate(2018, 10, 29, 3, 56, 7)) finally: os.remove(fn)
def node(self, n): assert_equals(n.id, 1) assert_equals(n.deleted, False) assert_equals(n.visible, True) assert_equals(n.version, 5) assert_equals(n.changeset, 58674) assert_equals(n.uid, 42) assert_equals(n.user_is_anonymous(), False) assert_equals(n.timestamp, mkdate(2014, 1, 31, 6, 23, 35)) assert_equals(n.user, u'änonymous') assert_equals(n.positive_id(), 1) assert_true(check_repr(n))
def node(self, n): assert_equals(n.id, 1) assert_equals(n.deleted, False) assert_equals(n.visible, True) assert_equals(n.version, 5) assert_equals(n.changeset, 58674) assert_equals(n.uid, 42) assert_equals(n.user_is_anonymous(), False) assert_equals(n.timestamp, mkdate(2014, 1, 31, 6, 23, 35)) assert_equals(n.user, 'anonymous') assert_equals(n.positive_id(), 1) assert_true(check_repr(n))
def relation(o): assert o.id == 1 assert o.deleted == False assert o.visible == True assert o.version == 5 assert o.changeset == 58674 assert o.uid == 42 assert o.user_is_anonymous() == False assert o.timestamp == mkdate(2014, 1, 31, 6, 23, 35) assert o.user == ' anonymous' assert o.positive_id() == 1 assert check_repr(o) assert check_repr(o.members)
def complete_table(rel_dates, withdrawal, amount): n = 2 for rate in range(len(rel_dates) - 1): if n == len(rel_dates): # last row 3 print("case 3") print(f"n = {n}") last_change = mkdate(str(rel_dates[n - 1]['start_date'])) period = withdrawal - last_change start = last_change end = withdrawal print(n) else: # middle rows in rel_dates 4 print("case 4") print(f"n = {n}") change = mkdate(str(rel_dates[n]['start_date'])) last_change = mkdate(str(rel_dates[n - 1]['start_date'])) period = change - last_change start = last_change end = change interest = calc_interest(period, amount, rel_dates, n, end) amount = amount + interest cum_interest = db.execute("SELECT SUM(interest) FROM rel_dates") cum_interest = cum_interest[0]['SUM(interest)'] + interest print(f"cum_interest= {cum_interest}") print( f"'start_date': {start}, 'end_date': {end}, 'period': {period.days}, 'rate': {rel_dates[n-1]['rate']}, 'interest': {gbp(interest)}, 'cum_funds': {gbp(amount)}" ) db.execute( "UPDATE rel_dates SET end_date = :end, period = :period, interest = :interest, cum_interest=:cum_interest, cum_funds=:cum_funds WHERE start_date= :start", start=str(start), end=end, period=period.days, interest=interest, cum_interest=cum_interest, cum_funds=amount) n += 1
def way(self, n): assert_equals(n.id, 1) assert_equals(n.deleted, False) assert_equals(n.visible, True) assert_equals(n.version, 5) assert_equals(n.changeset, 58674) assert_equals(n.uid, 42) assert_equals(n.user_is_anonymous(), False) assert_equals(n.timestamp, mkdate(2014, 1, 31, 6, 23, 35)) assert_equals(n.user, 'anonymous') assert_equals(n.positive_id(), 1) assert_false(n.is_closed()) assert_false(n.ends_have_same_id()) assert_false(n.ends_have_same_location()) assert_true(check_repr(n)) assert_true(check_repr(n.nodes))
def way(o): assert o.id == 1 assert o.deleted == False assert o.visible == True assert o.version == 5 assert o.changeset == 58674 assert o.uid == 42 assert o.user_is_anonymous() == False assert o.timestamp == mkdate(2014, 1, 31, 6, 23, 35) assert o.user == 'anonymous' assert o.positive_id() == 1 assert not o.is_closed() assert not o.ends_have_same_id() assert not o.ends_have_same_location() assert check_repr(o) assert check_repr(o.nodes)
def test_get_state_valid(mock): mock.set_result("""\ #Sat Aug 26 11:04:04 UTC 2017 txnMaxQueried=1219304113 sequenceNumber=2594669 timestamp=2017-08-26T11\:04\:02Z txnReadyList= txnMax=1219304113 txnActiveList=1219303583,1219304054,1219304104""") res = rserv.ReplicationServer("http://test.io").get_state_info() assert_is_not_none(res) assert_equals(res.timestamp, mkdate(2017, 8, 26, 11, 4, 2)) assert_equals(res.sequence, 2594669) assert_equal(mock.call_count, 1)
def test_get_state_sequence_cut(mock): mock.set_script(("""\ #Sat Aug 26 11:04:04 UTC 2017 txnMaxQueried=1219304113 sequenceNumber=259""", """\ #Sat Aug 26 11:04:04 UTC 2017 txnMaxQueried=1219304113 sequenceNumber=2594669 timestamp=2017-08-26T11\:04\:02Z""")) res = rserv.ReplicationServer("https://test.io").get_state_info() assert_is_not_none(res) assert_equals(res.timestamp, mkdate(2017, 8, 26, 11, 4, 2)) assert_equals(res.sequence, 2594669) assert_equal(mock.call_count, 2)
def test_get_state_valid(mock): mock.set_result("""\ #Sat Aug 26 11:04:04 UTC 2017 txnMaxQueried=1219304113 sequenceNumber=2594669 timestamp=2017-08-26T11\\:04\\:02Z txnReadyList= txnMax=1219304113 txnActiveList=1219303583,1219304054,1219304104""") res = rserv.ReplicationServer("https://test.io").get_state_info() assert res is not None assert res.timestamp == mkdate(2017, 8, 26, 11, 4, 2) assert res.sequence == 2594669 assert mock.call_count == 1
def test_get_newest_change_from_file(): data = [ osmobj('N', id=1, version=1, changeset=63965061, uid=8369524, timestamp='2018-10-29T03:56:07Z', user='******') ] fn = create_osm_file(data) try: val = osmium.replication.newest_change_from_file(fn) assert_equals(val, mkdate(2018, 10, 29, 3, 56, 7)) finally: os.remove(fn)
def test_get_state_sequence_cut(mock): mock.set_script(("""\ #Sat Aug 26 11:04:04 UTC 2017 txnMaxQueried=1219304113 sequenceNumber=259""", """\ #Sat Aug 26 11:04:04 UTC 2017 txnMaxQueried=1219304113 sequenceNumber=2594669 timestamp=2017-08-26T11\\:04\\:02Z""")) res = rserv.ReplicationServer("https://test.io").get_state_info() assert res is not None assert res.timestamp == mkdate(2017, 8, 26, 11, 4, 2) assert res.sequence == 2594669 assert mock.call_count == 2
def add_dates(end_of_month, withdrawal, status, product_id): rel_changes = db.execute("SELECT * FROM rel_dates") change = 0 while end_of_month < withdrawal: # if try creates error, it is the last row of rel_changes, in which case just add a final line to rel_dates using current rates try: change_date = mkdate(rel_changes[change + 1]['start_date']) except: rate = rel_changes[change]['rate'] db.execute( "INSERT INTO rel_dates (start_date, rate, is_change) VALUES (:last_day, :rate, 'False')", last_day=end_of_month, rate=rate) break if end_of_month > change_date: # if last day of month comes after a rate change, move onto next rate change = change + 1 rate = rel_changes[change]['rate'] db.execute( "INSERT INTO rel_dates (start_date, rate, is_change) VALUES (:change_date, :rate, 'False')", change_date=end_of_month, rate=rate) end_of_month = add_months(end_of_month, 1) # if it comes before the next rate change, enter it into rel_dates with old rate # else enter it into the rel_dates with new rate and move cursor onto next one # add today into the table if product not already withdrawn if status != "withdrawn": today = datetime.today().date() current_rate = db.execute( "SELECT * FROM rates WHERE change_date < :today AND product_id = :product_id ORDER BY change_date DESC LIMIT 1", product_id=product_id, today=today) current_rate = current_rate[0]['rate'] print(f"CURRENT RATE IS {current_rate}") db.execute( "INSERT INTO rel_dates (start_date, rate, is_change) VALUES (:today, :current_rate, 'False')", today=today, current_rate=current_rate) rel_dates = db.execute("SELECT * FROM rel_dates ORDER BY start_date") return rel_dates
def area(self, n): assert_equals(n.id, 46) assert_equals(n.deleted, False) assert_equals(n.visible, True) assert_equals(n.version, 5) assert_equals(n.changeset, 58674) assert_equals(n.uid, 42) assert_equals(n.user_is_anonymous(), False) assert_equals(n.timestamp, mkdate(2014, 1, 31, 6, 23, 35)) assert_equals(n.user, 'anonymous') assert_equals(n.positive_id(), 46) assert_equals(n.orig_id(), 23) assert_equals(n.from_way(), True) assert_equals(n.is_multipolygon(), False) assert_equals(n.num_rings(), (1, 0)) assert_equals(len(list(n.outer_rings())), 1) oring = list(n.outer_rings())[0] assert_equals(len(list(oring)), 4) assert_equals(set((1, 2, 3)), set([x.ref for x in oring])) assert_true(oring.is_closed()) assert_true(oring.ends_have_same_id()) assert_true(oring.ends_have_same_location()) assert_equals(len(list(n.inner_rings(oring))), 0)
def area(o): assert o.id == 3 assert o.deleted == False assert o.visible == True assert o.version == 3 assert o.changeset == 7654 assert o.uid == 42 assert o.user_is_anonymous() == False assert o.timestamp == mkdate(2014, 1, 31, 6, 23, 35) assert o.user == 'Anon' assert o.positive_id() == 3 assert o.orig_id() == 1 assert o.from_way() == False assert o.is_multipolygon() == False assert o.num_rings() == (1, 0) assert len(list(o.outer_rings())) == 1 oring = list(o.outer_rings())[0] assert len(list(oring)) == 4 assert set((1, 2, 3)) == set([x.ref for x in oring]) assert oring.is_closed() assert oring.ends_have_same_id() assert oring.ends_have_same_location() assert len(list(o.inner_rings(oring))) == 0
def area(self, n): assert_equals(n.id, 46) assert_equals(n.deleted, False) assert_equals(n.visible, True) assert_equals(n.version, 5) assert_equals(n.changeset, 58674) assert_equals(n.uid, 42) assert_equals(n.user_is_anonymous(), False) assert_equals(n.timestamp, mkdate(2014, 1, 31, 6, 23, 35)) assert_equals(n.user, 'anonymous') assert_equals(n.positive_id(), 46) assert_equals(n.orig_id(), 23) assert_equals(n.from_way(), True) assert_equals(n.is_multipolygon(), False) assert_equals(n.num_rings(), (1, 0)) assert_equals(len(list(n.outer_rings())), 1) oring = list(n.outer_rings())[0] assert_equals(len(list(oring)), 4) assert_equals(set((1,2,3)), set([x.ref for x in oring])) assert_true(oring.is_closed()) assert_true(oring.ends_have_same_id()) assert_true(oring.ends_have_same_location()) assert_equals(len(list(n.inner_rings(oring))), 0)
def test_get_newest_change_from_file(tmp_path): fn = tmp_path / 'change.opl' fn.write_text('n6365 v1 c63965061 t2018-10-29T03:56:07Z i8369524 ux x1 y7') val = osmium.replication.newest_change_from_file(str(fn)) assert val == mkdate(2018, 10, 29, 3, 56, 7)
(O(id=None), '0 v0 dV c0 t i0 u T'), (O(visible=None), '0 v0 dV c0 t i0 u T'), (O(version=None), '0 v0 dV c0 t i0 u T'), (O(uid=None), '0 v0 dV c0 t i0 u T'), (O(user=None), '0 v0 dV c0 t i0 u T'), (O(timestamp=None), '0 v0 dV c0 t i0 u T'), (O(id=1), '1 v0 dV c0 t i0 u T'), (O(id=-99), '-99 v0 dV c0 t i0 u T'), (O(visible=True), '0 v0 dV c0 t i0 u T'), (O(visible=False), '0 v0 dD c0 t i0 u T'), (O(version=23), '0 v23 dV c0 t i0 u T'), (O(user="******"), '0 v0 dV c0 t i0 uSchmidt T'), (O(user=""), '0 v0 dV c0 t i0 u T'), (O(uid=987), '0 v0 dV c0 t i987 u T'), (O(timestamp='2012-04-14T20:58:35Z'), '0 v0 dV c0 t2012-04-14T20:58:35Z i0 u T'), (O(timestamp=mkdate(2009, 4, 14, 20, 58, 35)), '0 v0 dV c0 t2009-04-14T20:58:35Z i0 u T'), (O(timestamp='1970-01-01T00:00:01Z'), '0 v0 dV c0 t1970-01-01T00:00:01Z i0 u T') ]) def attr_sample(request): return request.param def test_node_simple_attr(test_writer, attr_sample): with test_writer('n' + attr_sample[1] + ' x y') as w: w.add_node(attr_sample[0]) def test_way_simple_attr(test_writer, attr_sample): with test_writer('w' + attr_sample[1] + ' N') as w: w.add_way(attr_sample[0]) def test_relation_simple_attr(test_writer, attr_sample): with test_writer('r' + attr_sample[1] + ' M') as w:
def make_readable_dates(rel_dates): for date in range(len(rel_dates)): new_date = mkdate(str(rel_dates[date]['start_date'])) rel_dates[date]['start_date'] = new_date return rel_dates
first_month = datetime.strptime(rel_dates[0]['change_date'], "%Y-%m-%d").date() withdrawal = date(2020,12, 20) first_rate = rel_dates[0]['rate'] last_day_of_month = date(invest_date.year, invest_date.month, calendar.monthrange(invest_date.year, invest_date.month)[1]) # add_months function adapted form David Webb and Scott Staffored's answer on Stackoverflowhttps://stackoverflow.com/questions/4130922/how-to-increment-datetime-by-custom-months-in-python-without-using-library def add_months(sourcedate, months): month = sourcedate.month - 1 + months year = sourcedate.year + month // 12 month = month % 12 + 1 day = calendar.monthrange(year,month)[1] return date(year, month, day) change = 0 change_date = mkdate(rel_dates[change + 1]['change_date']) print(f"Last day of first month = {last_day_of_month}") print("changes:") print("________________________________________________") while last_day_of_month < withdrawal: if last_day_of_month < change_date: # if last day of month comes before a rate change rate = rel_dates[change]['rate'] rel_dates.append({'change_date': last_day_of_month, 'rate': rate, 'is_change': False}) else: change = change + 1 rate = rel_dates[change]['rate'] rel_dates.append({'change_date': last_day_of_month, 'rate': rate, 'is_change': False})
def test_get_replication_header_full(test_data_dir): val = rutil.get_replication_header(str(test_data_dir / 'example-test.pbf')) assert val.url == 'http://download.geofabrik.de/europe/andorra-updates' assert val.sequence == 2167 assert val.timestamp == mkdate(2019, 2, 23, 21, 15, 2)