Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve LowWine alert system #293

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions ikabot/function/alertLowWine.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

import re
import time
import datetime
import traceback
from decimal import *
import json
@@ -50,8 +51,7 @@ def alertLowWine(session, event, stdin_fd, predetermined_input):
else:
auto_transfer = False
transfer_amount = 0

print("It will be alerted when the wine runs out in less than {:d} hours in any city".format(hours))
print("It will be alerted when the wine runs out in less than {:d} hours in any city, and {:,d} wine will be transferred if necessary.".format(hours, transfer_amount))
enter()
except KeyboardInterrupt:
event.set()
@@ -134,8 +134,15 @@ def do_it(session, hours, auto_transfer, transfer_amount):
was_alerted = {}
message_log = []
routes = [] # Store all routes for batch execution

last_reset_time = datetime.datetime.now()

while True:
current_time = datetime.datetime.now()
time_elapsed = (current_time - last_reset_time).total_seconds()
if time_elapsed >= 12 * 60 * 60: # 12 h to reset the alerted list
was_alerted.clear() # Reset all alerts
last_reset_time = current_time # Update the last time reseted the list

ids, cities = getIdsOfCities(session)

for cityId in cities:
@@ -176,7 +183,7 @@ def do_it(session, hours, auto_transfer, transfer_amount):
if seconds_left < hours * 60 * 60:
if was_alerted[cityId] is False:
time_left = daysHoursMinutes(seconds_left)
message_log.append(f"In {city['name']}, the wine will run out in {time_left}")
message_log.append(f"In {city['name']} you have: {city['availableResources'][1]:,.0f} wine. Consumption: {consumption_per_hour:.2f} per hour.\nThe wine will run out in {time_left}")

if auto_transfer:
transport_status = isWineTransportInProgress(session, cityId)
@@ -222,7 +229,7 @@ def do_it(session, hours, auto_transfer, transfer_amount):
0, # Sulfur
))

message_log.append(f"Will transfer {transfer_amount} from {donor_city['name']}.")
message_log.append(f"Will transfer {transfer_amount:,.0f:,.0f} from {donor_city['name']}.")
else:
message_log.append(f"No city has sufficient wine to transfer to {city['name']}.")