From 0f49c8e32f870a139fc16f8f4857a8aad57a6747 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 13 Jun 2022 20:33:25 +0200 Subject: [PATCH] replace spaces with tabs --- files/classes/lottery.py | 38 ++-- files/helpers/actions.py | 2 +- files/helpers/const.py | 28 +-- files/helpers/lottery.py | 152 +++++++------- files/helpers/stats.py | 4 +- files/routes/lottery.py | 34 +-- files/templates/header.html | 4 +- files/templates/lottery.html | 362 ++++++++++++++++---------------- files/templates/submission.html | 2 +- run_tests.py | 62 +++--- 10 files changed, 344 insertions(+), 344 deletions(-) diff --git a/files/classes/lottery.py b/files/classes/lottery.py index 35d163278..0142a7166 100644 --- a/files/classes/lottery.py +++ b/files/classes/lottery.py @@ -6,27 +6,27 @@ from files.helpers.const import * class Lottery(Base): - __tablename__ = "lotteries" + __tablename__ = "lotteries" - id = Column(Integer, primary_key=True) - is_active = Column(Boolean, default=False) - ends_at = Column(Integer) - prize = Column(Integer, default=0) - tickets_sold = Column(Integer, default=0) - winner_id = Column(Integer, ForeignKey("users.id")) + id = Column(Integer, primary_key=True) + is_active = Column(Boolean, default=False) + ends_at = Column(Integer) + prize = Column(Integer, default=0) + tickets_sold = Column(Integer, default=0) + winner_id = Column(Integer, ForeignKey("users.id")) - @property - @lazy - def timeleft(self): - if not self.is_active: - return 0 + @property + @lazy + def timeleft(self): + if not self.is_active: + return 0 - epoch_time = int(time.time()) - remaining_time = self.ends_at - epoch_time + epoch_time = int(time.time()) + remaining_time = self.ends_at - epoch_time - return 0 if remaining_time < 0 else remaining_time + return 0 if remaining_time < 0 else remaining_time - @property - @lazy - def stats(self): - return {"active": self.is_active, "timeLeft": self.timeleft, "prize": self.prize, "ticketsSoldThisSession": self.tickets_sold,} + @property + @lazy + def stats(self): + return {"active": self.is_active, "timeLeft": self.timeleft, "prize": self.prize, "ticketsSoldThisSession": self.tickets_sold,} diff --git a/files/helpers/actions.py b/files/helpers/actions.py index 1f4872021..d22b823ff 100644 --- a/files/helpers/actions.py +++ b/files/helpers/actions.py @@ -4,7 +4,7 @@ from files.classes.badges import Badge, BadgeDef # TODO: More sanity checks on passed parameters. # TODO: Add `replace=False` parameter which, when set true, removes any -# existing badge with identical id & user and replaces with new one. +# existing badge with identical id & user and replaces with new one. def badge_grant(user_id, badge_id, desc='', url='', commit=True): user = g.db.query(User).filter(User.id == int(user_id)).one_or_none() if not user: diff --git a/files/helpers/const.py b/files/helpers/const.py index af8c0690c..c8e6eeaf0 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -525,13 +525,13 @@ AWARDS = { "price": 500 }, "glowie": { - "kind": "glowie", - "title": "Glowie", - "description": "Indicates that the recipient can be seen when driving. Just run them over.", - "icon": "fas fa-user-secret", - "color": "text-green", - "price": 500 - }, + "kind": "glowie", + "title": "Glowie", + "description": "Indicates that the recipient can be seen when driving. Just run them over.", + "icon": "fas fa-user-secret", + "color": "text-green", + "price": 500 + }, "rehab": { "kind": "rehab", "title": "Rehab", @@ -541,13 +541,13 @@ AWARDS = { "price": 777 }, "beano": { - "kind": "beano", - "title": "Beano", - "description": "Stops you from embarrassing yourself with your flatulence", - "icon": "fas fa-gas-pump-slash", - "color": "text-green", - "price": 1000 - }, + "kind": "beano", + "title": "Beano", + "description": "Stops you from embarrassing yourself with your flatulence", + "icon": "fas fa-gas-pump-slash", + "color": "text-green", + "price": 1000 + }, "progressivestack": { "kind": "progressivestack", "title": "Progressive Stack", diff --git a/files/helpers/lottery.py b/files/helpers/lottery.py index 6a3ca0945..ab1e2a18c 100644 --- a/files/helpers/lottery.py +++ b/files/helpers/lottery.py @@ -10,120 +10,120 @@ from .const import * LOTTERY_WINNER_BADGE_ID = 137 def get_active_lottery(): - return g.db.query(Lottery).order_by(Lottery.id.desc()).filter(Lottery.is_active).one_or_none() + return g.db.query(Lottery).order_by(Lottery.id.desc()).filter(Lottery.is_active).one_or_none() def get_users_participating_in_lottery(): - return g.db.query(User) \ - .filter(User.currently_held_lottery_tickets > 0) \ - .order_by(User.currently_held_lottery_tickets.desc()).all() + return g.db.query(User) \ + .filter(User.currently_held_lottery_tickets > 0) \ + .order_by(User.currently_held_lottery_tickets.desc()).all() def get_active_lottery_stats(): - active_lottery = get_active_lottery() - participating_users = get_users_participating_in_lottery() + active_lottery = get_active_lottery() + participating_users = get_users_participating_in_lottery() - return None if active_lottery is None else active_lottery.stats, len(participating_users) + return None if active_lottery is None else active_lottery.stats, len(participating_users) def end_lottery_session(): - active_lottery = get_active_lottery() + active_lottery = get_active_lottery() - if (active_lottery is None): - return False, "There is no active lottery." + if (active_lottery is None): + return False, "There is no active lottery." - participating_users = get_users_participating_in_lottery() - raffle = [] - for user in participating_users: - for _ in range(user.currently_held_lottery_tickets): - raffle.append(user.id) + participating_users = get_users_participating_in_lottery() + raffle = [] + for user in participating_users: + for _ in range(user.currently_held_lottery_tickets): + raffle.append(user.id) - winner = choice(raffle) - active_lottery.winner_id = winner - winning_user = next(filter(lambda x: x.id == winner, participating_users)) - winning_user.coins += active_lottery.prize - winning_user.total_lottery_winnings += active_lottery.prize - badge_grant(winner, LOTTERY_WINNER_BADGE_ID) + winner = choice(raffle) + active_lottery.winner_id = winner + winning_user = next(filter(lambda x: x.id == winner, participating_users)) + winning_user.coins += active_lottery.prize + winning_user.total_lottery_winnings += active_lottery.prize + badge_grant(winner, LOTTERY_WINNER_BADGE_ID) - for user in participating_users: - chance_to_win = user.currently_held_lottery_tickets / len(raffle) * 100 - if user.id == winner: - notification_text = f'You won {active_lottery.prize} coins in the lottery! ' \ - + f'Congratulations!\nYour odds of winning were: {chance_to_win}%' - else: - notification_text = f'You did not win the lottery. Better luck next time!\n' \ - + f'Your odds of winning were: {chance_to_win}%\nWinner: @{winning_user.username} (won {active_lottery.prize} coins)' - send_repeatable_notification(user.id, notification_text) - user.currently_held_lottery_tickets = 0 + for user in participating_users: + chance_to_win = user.currently_held_lottery_tickets / len(raffle) * 100 + if user.id == winner: + notification_text = f'You won {active_lottery.prize} coins in the lottery! ' \ + + f'Congratulations!\nYour odds of winning were: {chance_to_win}%' + else: + notification_text = f'You did not win the lottery. Better luck next time!\n' \ + + f'Your odds of winning were: {chance_to_win}%\nWinner: @{winning_user.username} (won {active_lottery.prize} coins)' + send_repeatable_notification(user.id, notification_text) + user.currently_held_lottery_tickets = 0 - active_lottery.is_active = False + active_lottery.is_active = False - g.db.commit() + g.db.commit() - return True, f'{winning_user.username} won {active_lottery.prize} coins!' + return True, f'{winning_user.username} won {active_lottery.prize} coins!' def start_new_lottery_session(): - end_lottery_session() + end_lottery_session() - lottery = Lottery() - epoch_time = int(time.time()) - # Subtract 4 minutes from one week so cronjob interval doesn't cause the - # time to drift toward over multiple weeks. - one_week_from_now = epoch_time + 60 * 60 * 24 * 7 - (4 * 60) - lottery.ends_at = one_week_from_now - lottery.is_active = True + lottery = Lottery() + epoch_time = int(time.time()) + # Subtract 4 minutes from one week so cronjob interval doesn't cause the + # time to drift toward over multiple weeks. + one_week_from_now = epoch_time + 60 * 60 * 24 * 7 - (4 * 60) + lottery.ends_at = one_week_from_now + lottery.is_active = True - g.db.add(lottery) - g.db.commit() + g.db.add(lottery) + g.db.commit() def check_if_end_lottery_task(): - active_lottery = get_active_lottery() + active_lottery = get_active_lottery() - if active_lottery is None: - return False - elif active_lottery.timeleft > 0: - return False + if active_lottery is None: + return False + elif active_lottery.timeleft > 0: + return False - start_new_lottery_session() - return True + start_new_lottery_session() + return True def lottery_ticket_net_value(): - return LOTTERY_TICKET_COST - LOTTERY_SINK_RATE + return LOTTERY_TICKET_COST - LOTTERY_SINK_RATE def purchase_lottery_tickets(v, quantity=1): - if quantity < 1: - return False, "Must purchase one or more lottery tickets." - elif (v.coins < LOTTERY_TICKET_COST * quantity): - return False, f'Lottery tickets cost {LOTTERY_TICKET_COST} coins each.' + if quantity < 1: + return False, "Must purchase one or more lottery tickets." + elif (v.coins < LOTTERY_TICKET_COST * quantity): + return False, f'Lottery tickets cost {LOTTERY_TICKET_COST} coins each.' - most_recent_lottery = get_active_lottery() - if (most_recent_lottery is None): - return False, "There is no active lottery." + most_recent_lottery = get_active_lottery() + if (most_recent_lottery is None): + return False, "There is no active lottery." - v.coins -= LOTTERY_TICKET_COST * quantity - v.currently_held_lottery_tickets += quantity - v.total_held_lottery_tickets += quantity + v.coins -= LOTTERY_TICKET_COST * quantity + v.currently_held_lottery_tickets += quantity + v.total_held_lottery_tickets += quantity - net_ticket_value = lottery_ticket_net_value() * quantity - most_recent_lottery.prize += net_ticket_value - most_recent_lottery.tickets_sold += quantity + net_ticket_value = lottery_ticket_net_value() * quantity + most_recent_lottery.prize += net_ticket_value + most_recent_lottery.tickets_sold += quantity - g.db.commit() + g.db.commit() - if quantity == 1: return True, f'Successfully purchased {quantity} lottery ticket!' - return True, f'Successfully purchased {quantity} lottery tickets!' + if quantity == 1: return True, f'Successfully purchased {quantity} lottery ticket!' + return True, f'Successfully purchased {quantity} lottery tickets!' def grant_lottery_tickets_to_user(v, quantity): - active_lottery = get_active_lottery() - prize_value = lottery_ticket_net_value() * quantity + active_lottery = get_active_lottery() + prize_value = lottery_ticket_net_value() * quantity - if active_lottery: - v.currently_held_lottery_tickets += quantity - v.total_held_lottery_tickets += quantity + if active_lottery: + v.currently_held_lottery_tickets += quantity + v.total_held_lottery_tickets += quantity - active_lottery.prize += prize_value - active_lottery.tickets_sold += quantity + active_lottery.prize += prize_value + active_lottery.tickets_sold += quantity - g.db.commit() + g.db.commit() diff --git a/files/helpers/stats.py b/files/helpers/stats.py index db5e1f719..9000ce336 100644 --- a/files/helpers/stats.py +++ b/files/helpers/stats.py @@ -63,13 +63,13 @@ def chart(kind, site): plt.rcParams['figure.figsize'] = (chart_width, 20) signup_chart = plt.subplot2grid((chart_width, 20), ( 0, 0), rowspan=6, colspan=chart_width) - posts_chart = plt.subplot2grid((chart_width, 20), (10, 0), rowspan=6, colspan=chart_width) + posts_chart = plt.subplot2grid((chart_width, 20), (10, 0), rowspan=6, colspan=chart_width) comments_chart = plt.subplot2grid((chart_width, 20), (20, 0), rowspan=6, colspan=chart_width) signup_chart.grid(), posts_chart.grid(), comments_chart.grid() signup_chart.plot (daily_times, daily_signups, color='red') - posts_chart.plot (daily_times, post_stats, color='blue') + posts_chart.plot (daily_times, post_stats, color='blue') comments_chart.plot(daily_times, comment_stats, color='purple') signup_chart.set_ylim(ymin=0) diff --git a/files/routes/lottery.py b/files/routes/lottery.py index 59d9fd8b8..0d05991cd 100644 --- a/files/routes/lottery.py +++ b/files/routes/lottery.py @@ -11,16 +11,16 @@ import requests @admin_level_required(3) @lottery_required def lottery_end(v): - success, message = end_lottery_session() - return {"message": message} if success else {"error": message} + success, message = end_lottery_session() + return {"message": message} if success else {"error": message} @app.post("/lottery/start") @admin_level_required(3) @lottery_required def lottery_start(v): - start_new_lottery_session() - return {"message": "Lottery started."} + start_new_lottery_session() + return {"message": "Lottery started."} @app.post("/lottery/buy") @@ -28,15 +28,15 @@ def lottery_start(v): @auth_required @lottery_required def lottery_buy(v): - quantity = int(request.values.get("quantity")) - success, message = purchase_lottery_tickets(v, quantity) - lottery, participants = get_active_lottery_stats() + quantity = int(request.values.get("quantity")) + success, message = purchase_lottery_tickets(v, quantity) + lottery, participants = get_active_lottery_stats() - if success: - return {"message": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}} - else: - return {"error": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}} + if success: + return {"message": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}} + else: + return {"error": message, "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}} @app.get("/lottery/active") @@ -44,20 +44,20 @@ def lottery_buy(v): @auth_required @lottery_required def lottery_active(v): - lottery, participants = get_active_lottery_stats() + lottery, participants = get_active_lottery_stats() - return {"message": "", "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}} + return {"message": "", "stats": {"user": v.lottery_stats, "lottery": lottery, "participants": participants}} @app.get("/lottery") @auth_required @lottery_required def lottery(v): - lottery_stats, participant_stats = get_active_lottery_stats() - return render_template("lottery.html", v=v, lottery_stats=lottery_stats, participant_stats=participant_stats) + lottery_stats, participant_stats = get_active_lottery_stats() + return render_template("lottery.html", v=v, lottery_stats=lottery_stats, participant_stats=participant_stats) @app.get("/admin/lottery/participants") @admin_level_required(2) @lottery_required def lottery_admin(v): - participants = get_users_participating_in_lottery() - return render_template("admin/lottery.html", v=v, participants=participants) + participants = get_users_participating_in_lottery() + return render_template("admin/lottery.html", v=v, participants=participants) diff --git a/files/templates/header.html b/files/templates/header.html index 6879fac70..fca4daa0d 100644 --- a/files/templates/header.html +++ b/files/templates/header.html @@ -44,11 +44,11 @@ } {% endif %} -
+
-
+
{% endif %}
diff --git a/files/templates/lottery.html b/files/templates/lottery.html index 79be86ab4..5cc25fff1 100644 --- a/files/templates/lottery.html +++ b/files/templates/lottery.html @@ -1,191 +1,191 @@ {% extends "default.html" %} {% block content %}
-
- - -
-
- {% if v.admin_level > 2 %} -
- - - - -
- {% endif %} -
-
-
Prize
-
Time Left
-
Tickets Sold
-
Participants
-
-
-
- - - -
-
-
-
-
-
-
-
-
-
-
-
Your Held Tickets
-
Lifetime Held Tickets
-
Lifetime Winnings
-
-
-
-
-
-
-
-
-
-
+
+ + +
+
+ {% if v.admin_level > 2 %} +
+ + + + +
+ {% endif %} +
+
+
Prize
+
Time Left
+
Tickets Sold
+
Participants
+
+
+
+ + - +
+
-
+
-
+
-
+
+
+
+
+
Your Held Tickets
+
Lifetime Held Tickets
+
Lifetime Winnings
+
+
+
-
+
-
+
-
+
+
-
-
-
Purchase Quantity
-
-
-
- -
-
-
+
+
+
Purchase Quantity
+
+
+
+ +
+
+
- -
+ +
- - + + - - + +
diff --git a/files/templates/submission.html b/files/templates/submission.html index 133f01cfb..00e651aca 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -68,7 +68,7 @@ {% endif %} {% if p.award_count("firework") %} - +
diff --git a/run_tests.py b/run_tests.py index c3a976218..2b3ca6193 100755 --- a/run_tests.py +++ b/run_tests.py @@ -5,48 +5,48 @@ import sys # we want to leave the container in whatever state it currently is, so check to see if it's running docker_inspect = subprocess.run([ - "docker", - "container", - "inspect", - "-f", "{{.State.Status}}", - "rDrama", - ], - capture_output = True, - ).stdout.decode("utf-8").strip() + "docker", + "container", + "inspect", + "-f", "{{.State.Status}}", + "rDrama", + ], + capture_output = True, + ).stdout.decode("utf-8").strip() was_running = docker_inspect == "running" # update containers, just in case they're out of date if was_running: - print("Updating containers . . .", flush=True) + print("Updating containers . . .", flush=True) else: - print("Starting containers . . .", flush=True) + print("Starting containers . . .", flush=True) subprocess.run([ - "docker-compose", - "up", - "--build", - "-d", - ], - check = True, - ) + "docker-compose", + "up", + "--build", + "-d", + ], + check = True, + ) # run the test print("Running test . . .", flush=True) result = subprocess.run([ - "docker", - "exec", - "rDrama", - "bash", "-c", "cd service && python3 -m pytest -s" - ]) + "docker", + "exec", + "rDrama", + "bash", "-c", "cd service && python3 -m pytest -s" + ]) if not was_running: - # shut down, if we weren't running in the first place - print("Shutting down containers . . .", flush=True) - subprocess.run([ - "docker-compose", - "stop", - ], - check = True, - ) + # shut down, if we weren't running in the first place + print("Shutting down containers . . .", flush=True) + subprocess.run([ + "docker-compose", + "stop", + ], + check = True, + ) -sys.exit(result.returncode) \ No newline at end of file +sys.exit(result.returncode)