|
@@ -3,19 +3,24 @@
|
|
import random
|
|
import random
|
|
from datetime import datetime, timedelta
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
-from app import LOGGER, SCHEDULER, RESOURCE_IDS, DEEP_EXPLORATION_MAX, jobs, api, database
|
|
|
|
|
|
+from app import LOGGER, SCHEDULER, RESOURCE_IDS, DEEP_EXPLORATION_MAX, KOEF_FACTOR, \
|
|
|
|
+ jobs, api, database
|
|
|
|
|
|
|
|
|
|
-def sync_deep_exploration(region_id):
|
|
|
|
- """Check resources and refill if necessary"""
|
|
|
|
- deep_explorations = api.download_deep_explorations(region_id)
|
|
|
|
- database.save_deep_explorations(region_id, deep_explorations)
|
|
|
|
-
|
|
|
|
def schedule_orders():
|
|
def schedule_orders():
|
|
"""start deep exploration orders"""
|
|
"""start deep exploration orders"""
|
|
|
|
+ LOGGER.info('Start schedule orders')
|
|
orders = database.get_orders()
|
|
orders = database.get_orders()
|
|
for order in orders:
|
|
for order in orders:
|
|
schedule_order(order)
|
|
schedule_order(order)
|
|
|
|
+ LOGGER.info('Finish schedule orders')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def sync_deep_exploration(region_id):
|
|
|
|
+ """Check resources and refill if necessary"""
|
|
|
|
+ LOGGER.info('Sync deep exploration history for %s', region_id)
|
|
|
|
+ deep_explorations = api.download_deep_explorations(region_id)
|
|
|
|
+ database.save_deep_explorations(region_id, deep_explorations)
|
|
|
|
|
|
def schedule_order(order):
|
|
def schedule_order(order):
|
|
"""start deep exploration order"""
|
|
"""start deep exploration order"""
|
|
@@ -55,6 +60,13 @@ def start_deep_exploration(order_id):
|
|
if order.order_type in order_types:
|
|
if order.order_type in order_types:
|
|
points = order_types[order.order_type](order)
|
|
points = order_types[order.order_type](order)
|
|
state = database.get_state(order.region_id)
|
|
state = database.get_state(order.region_id)
|
|
|
|
+ LOGGER.info(
|
|
|
|
+ 'Deep explorate %s points for %s in %s',
|
|
|
|
+ points,
|
|
|
|
+ RESOURCE_IDS[order.resource_type],
|
|
|
|
+ order.region_id
|
|
|
|
+ )
|
|
|
|
+ return
|
|
api.deep_explorate(state.id, order.region_id, order.resource_type, points, False)
|
|
api.deep_explorate(state.id, order.region_id, order.resource_type, points, False)
|
|
schedule_order(order)
|
|
schedule_order(order)
|
|
|
|
|
|
@@ -70,8 +82,22 @@ def get_fixed_points(order):
|
|
|
|
|
|
def get_percentage_points(order):
|
|
def get_percentage_points(order):
|
|
"""Get deep exploration points for order"""
|
|
"""Get deep exploration points for order"""
|
|
- return 1
|
|
|
|
|
|
+ region = database.get_region(order.region_id)
|
|
|
|
+ return calc_deep_exploration(
|
|
|
|
+ region.get_limit(order.resource_type),
|
|
|
|
+ order.amount,
|
|
|
|
+ order.resource_type
|
|
|
|
+ )
|
|
|
|
|
|
def get_auto_points(order):
|
|
def get_auto_points(order):
|
|
"""Get deep exploration points for order"""
|
|
"""Get deep exploration points for order"""
|
|
return 1
|
|
return 1
|
|
|
|
+
|
|
|
|
+def calc_deep_exploration(resource_limit, percentage, resource_type):
|
|
|
|
+ """Calculate deep expo for resource"""
|
|
|
|
+ koef_factor = KOEF_FACTOR[resource_type]
|
|
|
|
+ max_deep_exploration = DEEP_EXPLORATION_MAX[resource_type] - resource_limit
|
|
|
|
+ initial_resource_factor = pow(resource_limit * koef_factor / 10, 0.8)
|
|
|
|
+ new_resource_factor = initial_resource_factor * (percentage / 100 + 1)
|
|
|
|
+ points = (10 * (new_resource_factor ** (1/0.8))) / koef_factor - resource_limit
|
|
|
|
+ return max_deep_exploration if points > max_deep_exploration else round(points)
|