Getting claim button to insert a claim_event and redoing claim_event query
This commit is contained in:
parent
0dd5f2c6b6
commit
7c128cc540
7
data.sql
7
data.sql
@ -54,3 +54,10 @@ SELECT staking_event.id,well_id,staking_event.source_id,
|
||||
FROM staking_event
|
||||
INNER JOIN staking_source on staking_event.source_id = staking_source.id
|
||||
WHERE staking_event.source_id = 4 AND staking_source.user_id = 1;
|
||||
|
||||
SELECT staking_event.id, staking_event.well_id, staking_event.source_id,
|
||||
staking_event.inventory_item_id, staking_event.duration_in_mins,
|
||||
staking_event.created_at
|
||||
FROM staking_event
|
||||
LEFT JOIN claim_event ON staking_event.id = claim_event.staking_event_id
|
||||
WHERE staking_event.source_id = 4 AND claim_event.staking_event_id IS NULL;
|
||||
|
51
mm.py
51
mm.py
@ -30,11 +30,11 @@ def get_store_items():
|
||||
return items
|
||||
|
||||
def get_moons():
|
||||
staking_sources = {}
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("SELECT id,created_at FROM staking_source")
|
||||
|
||||
staking_sources = {}
|
||||
for i,(sid,ts) in enumerate(cursor.fetchall()):
|
||||
cursor.execute("""
|
||||
SELECT name,supply,staking_event.created_at
|
||||
@ -44,14 +44,13 @@ def get_moons():
|
||||
WHERE resource_well.source_id = ?;
|
||||
""", (sid,))
|
||||
wells = {name: (supply,timestamp) for name,supply,timestamp in cursor.fetchall()}
|
||||
stakes = get_stakes(sid)
|
||||
stakes = get_active_stakes(sid)
|
||||
staking_sources[sid] = (ts,wells,stakes)
|
||||
|
||||
cursor.close()
|
||||
return staking_sources
|
||||
|
||||
def get_inventory():
|
||||
inventory = {}
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
@ -67,8 +66,26 @@ def get_inventory():
|
||||
cursor.close()
|
||||
return inventory
|
||||
|
||||
# An active stake is basically defined as one that has yet to be claimed
|
||||
def get_active_stakes(source_id):
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
SELECT staking_event.id, staking_event.source_id, staking_event.well_id,
|
||||
staking_event.inventory_item_id, staking_event.duration_in_mins,
|
||||
staking_event.created_at
|
||||
FROM staking_event
|
||||
LEFT JOIN claim_event ON staking_event.id = claim_event.staking_event_id
|
||||
WHERE staking_event.source_id = ? AND claim_event.staking_event_id IS NULL;
|
||||
""", (source_id,))
|
||||
|
||||
active_stakes = {item[0]:item[1:] for item in cursor.fetchall()}
|
||||
|
||||
cursor.close()
|
||||
return active_stakes
|
||||
|
||||
|
||||
def get_stakes(source_id):
|
||||
stakes = {}
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
@ -130,7 +147,6 @@ def buy_item(item_id):
|
||||
def mine(source_id, resource, item_id):
|
||||
cursor = conn.cursor()
|
||||
|
||||
print(world.resource_to_id)
|
||||
cursor.execute("""
|
||||
INSERT INTO staking_event (source_id, well_id, inventory_item_id, duration_in_mins)
|
||||
VALUES (?, (SELECT id FROM resource_well WHERE resource_id = ? AND source_id = ?), ?, ?)
|
||||
@ -140,6 +156,19 @@ def mine(source_id, resource, item_id):
|
||||
world.staking_sources = get_moons()
|
||||
cursor.close()
|
||||
|
||||
def claim(staking_event_id):
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
INSERT INTO claim_event (claim_amount, staking_event_id)
|
||||
VALUES (?, ?)
|
||||
""", (10, staking_event_id))
|
||||
|
||||
conn.commit()
|
||||
world.staking_sources = get_moons()
|
||||
cursor.close()
|
||||
|
||||
|
||||
def upgrade(a,b,user_data):
|
||||
()
|
||||
|
||||
@ -249,13 +278,17 @@ def draw_moons():
|
||||
im.spacing()
|
||||
|
||||
im.next_column()
|
||||
for (sid,wid,invId,dur,start) in stakes.values():
|
||||
for stake_id,(source_id,wid,invId,dur,start) in stakes.items():
|
||||
start_time = parse(start)
|
||||
now = datetime.datetime.utcnow().replace(microsecond=0)
|
||||
delta = now - start_time
|
||||
if im.button("Claim"):
|
||||
im.push_id(f"Claim{stake_id}")
|
||||
if delta > datetime.timedelta(minutes=dur):
|
||||
print("Passed")
|
||||
if im.button("Claim"):
|
||||
claim(stake_id)
|
||||
else:
|
||||
im.text_disabled("Claim")
|
||||
im.pop_id()
|
||||
im.text(f"{world.store[world.inventory[invId][0]][0]}: {delta}")
|
||||
|
||||
im.next_column()
|
||||
@ -323,6 +356,7 @@ def draw_panels():
|
||||
class World:
|
||||
current_user = "Joe"
|
||||
current_user_id = 1
|
||||
moon_img_tex_id = -1
|
||||
bank = dict()
|
||||
resources = []
|
||||
id_to_resource = dict()
|
||||
@ -331,7 +365,6 @@ class World:
|
||||
inventory = dict()
|
||||
staking_sources = dict()
|
||||
stakes = dict()
|
||||
moon_img_tex_id = -1
|
||||
|
||||
world = World()
|
||||
|
||||
|
@ -48,11 +48,11 @@ CREATE TABLE staking_event(
|
||||
|
||||
CREATE TABLE claim_event(
|
||||
id integer primary key autoincrement,
|
||||
resource_id int not null,
|
||||
claim_amount int not null,
|
||||
staking_event_id int not null,
|
||||
created_at timestamp DEFAULT (current_timestamp),
|
||||
CONSTRAINT fk_rid FOREIGN KEY(resource_id)
|
||||
REFERENCES resource(id)
|
||||
CONSTRAINT fk_se_id FOREIGN KEY(staking_event_id)
|
||||
REFERENCES staking_event(id)
|
||||
);
|
||||
|
||||
CREATE TABLE upgrade_event(
|
||||
|
Loading…
x
Reference in New Issue
Block a user