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
|
FROM staking_event
|
||||||
INNER JOIN staking_source on staking_event.source_id = staking_source.id
|
INNER JOIN staking_source on staking_event.source_id = staking_source.id
|
||||||
WHERE staking_event.source_id = 4 AND staking_source.user_id = 1;
|
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
|
return items
|
||||||
|
|
||||||
def get_moons():
|
def get_moons():
|
||||||
staking_sources = {}
|
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
cursor.execute("SELECT id,created_at FROM staking_source")
|
cursor.execute("SELECT id,created_at FROM staking_source")
|
||||||
|
|
||||||
|
staking_sources = {}
|
||||||
for i,(sid,ts) in enumerate(cursor.fetchall()):
|
for i,(sid,ts) in enumerate(cursor.fetchall()):
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT name,supply,staking_event.created_at
|
SELECT name,supply,staking_event.created_at
|
||||||
@ -44,14 +44,13 @@ def get_moons():
|
|||||||
WHERE resource_well.source_id = ?;
|
WHERE resource_well.source_id = ?;
|
||||||
""", (sid,))
|
""", (sid,))
|
||||||
wells = {name: (supply,timestamp) for name,supply,timestamp in cursor.fetchall()}
|
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)
|
staking_sources[sid] = (ts,wells,stakes)
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
return staking_sources
|
return staking_sources
|
||||||
|
|
||||||
def get_inventory():
|
def get_inventory():
|
||||||
inventory = {}
|
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
@ -67,8 +66,26 @@ def get_inventory():
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
return inventory
|
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):
|
def get_stakes(source_id):
|
||||||
stakes = {}
|
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
@ -130,7 +147,6 @@ def buy_item(item_id):
|
|||||||
def mine(source_id, resource, item_id):
|
def mine(source_id, resource, item_id):
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
print(world.resource_to_id)
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
INSERT INTO staking_event (source_id, well_id, inventory_item_id, duration_in_mins)
|
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 = ?), ?, ?)
|
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()
|
world.staking_sources = get_moons()
|
||||||
cursor.close()
|
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):
|
def upgrade(a,b,user_data):
|
||||||
()
|
()
|
||||||
|
|
||||||
@ -249,13 +278,17 @@ def draw_moons():
|
|||||||
im.spacing()
|
im.spacing()
|
||||||
|
|
||||||
im.next_column()
|
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)
|
start_time = parse(start)
|
||||||
now = datetime.datetime.utcnow().replace(microsecond=0)
|
now = datetime.datetime.utcnow().replace(microsecond=0)
|
||||||
delta = now - start_time
|
delta = now - start_time
|
||||||
if im.button("Claim"):
|
im.push_id(f"Claim{stake_id}")
|
||||||
if delta > datetime.timedelta(minutes=dur):
|
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.text(f"{world.store[world.inventory[invId][0]][0]}: {delta}")
|
||||||
|
|
||||||
im.next_column()
|
im.next_column()
|
||||||
@ -323,6 +356,7 @@ def draw_panels():
|
|||||||
class World:
|
class World:
|
||||||
current_user = "Joe"
|
current_user = "Joe"
|
||||||
current_user_id = 1
|
current_user_id = 1
|
||||||
|
moon_img_tex_id = -1
|
||||||
bank = dict()
|
bank = dict()
|
||||||
resources = []
|
resources = []
|
||||||
id_to_resource = dict()
|
id_to_resource = dict()
|
||||||
@ -331,7 +365,6 @@ class World:
|
|||||||
inventory = dict()
|
inventory = dict()
|
||||||
staking_sources = dict()
|
staking_sources = dict()
|
||||||
stakes = dict()
|
stakes = dict()
|
||||||
moon_img_tex_id = -1
|
|
||||||
|
|
||||||
world = World()
|
world = World()
|
||||||
|
|
||||||
|
@ -48,11 +48,11 @@ CREATE TABLE staking_event(
|
|||||||
|
|
||||||
CREATE TABLE claim_event(
|
CREATE TABLE claim_event(
|
||||||
id integer primary key autoincrement,
|
id integer primary key autoincrement,
|
||||||
resource_id int not null,
|
|
||||||
claim_amount int not null,
|
claim_amount int not null,
|
||||||
|
staking_event_id int not null,
|
||||||
created_at timestamp DEFAULT (current_timestamp),
|
created_at timestamp DEFAULT (current_timestamp),
|
||||||
CONSTRAINT fk_rid FOREIGN KEY(resource_id)
|
CONSTRAINT fk_se_id FOREIGN KEY(staking_event_id)
|
||||||
REFERENCES resource(id)
|
REFERENCES staking_event(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE upgrade_event(
|
CREATE TABLE upgrade_event(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user