Forráskód Böngészése

Add percentage type, first beta

JoostSijm 5 éve
szülő
commit
b1de77b629
4 módosított fájl, 53 hozzáadás és 9 törlés
  1. 8 0
      app/__init__.py
  2. 11 2
      app/__main__.py
  3. 1 0
      app/api.py
  4. 33 7
      app/app.py

+ 8 - 0
app/__init__.py

@@ -89,3 +89,11 @@ RESOURCE_MAX = {
     11: 60,
     15: 75,
 }
+
+KOEF_FACTOR = {
+    0: 0.4,
+    3: 0.65,
+    4: 0.65,
+    11: 0.75,
+    15: 0.75,
+}

+ 11 - 2
app/__main__.py

@@ -7,10 +7,19 @@ from app import SCHEDULER, LOGGER, RESOURCE_NAMES, jobs
 
 
 if __name__ == '__main__':
-    jobs.schedule_orders()
+    LOGGER.info('Starting application')
     # jobs.sync_deep_exploration(4002)
     # jobs.start_deep_exploration_order(2)
-    sys.exit()
+    # sys.exit()
+
+    jobs.schedule_orders()
+    # backup job to reschedule orders
+    SCHEDULER.add_job(
+        jobs.schedule_orders,
+        'cron',
+        id='schedule_orders',
+        hour='3'
+    )
 
     try:
         while True:

+ 1 - 0
app/api.py

@@ -40,6 +40,7 @@ def parse_deep_explorations(html):
 
 def deep_explorate(state_id, region_id, resource_type, amount, alt):
     """Main function"""
+    return
     response = requests.get(
         '{}main/content'.format(BASE_URL),
         headers=HEADERS

+ 33 - 7
app/app.py

@@ -3,19 +3,24 @@
 import random
 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():
     """start deep exploration orders"""
+    LOGGER.info('Start schedule orders')
     orders = database.get_orders()
     for order in orders:
         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):
     """start deep exploration order"""
@@ -55,6 +60,13 @@ def start_deep_exploration(order_id):
     if order.order_type in order_types:
         points = order_types[order.order_type](order)
         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)
     schedule_order(order)
 
@@ -70,8 +82,22 @@ def get_fixed_points(order):
     
 def get_percentage_points(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):
     """Get  deep exploration points for order"""
     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)