Преглед на файлове

Add department efficiency calculator

JoostSijm преди 5 години
родител
ревизия
f08e78cae8

+ 69 - 0
department_efficiency/efficiency.py

@@ -0,0 +1,69 @@
+"""Calculate efficiency in different departments"""
+
+import json
+
+from rival_regions_calc import Item, WorkProduction
+
+
+DEPARTMENTS = None
+with open('departments.json') as file:
+    DEPARTMENTS = json.load(file)
+
+PRICE = None
+with open('prices.json') as file:
+    PRICE = json.load(file)
+
+REGIONS = None
+with open('regions.json') as file:
+    REGIONS = json.load(file)
+
+WP = WorkProduction()
+WP.user_level = 80
+WP.work_exp = 80000 + 200 * 250
+
+def calculate_wage(resource_name, department_bonus):
+    """Calculate production"""
+    resource = Item(resource_name)
+    WP.resource = resource
+    WP.factory_level = 150
+    WP.department_bonus = department_bonus
+    WP.resource_max = REGIONS['1']['resources'][resource_name]
+    WP.wage_percentage = 100
+    WP.tax_rate = 0
+    WP.calculate()
+    return WP.wage() * PRICE[resource_name]
+
+
+def main():
+    """Main function"""
+    resources = {
+        'oil': {},
+        'ore': {},
+        'uranium': {},
+        'diamond': {},
+    }
+
+    for resource in resources:
+        for points in range(0, 6001, 200):
+            if points >= DEPARTMENTS[resource]:
+                department_bonus = 10
+            else:
+                department_bonus = 10 / DEPARTMENTS[resource] * points
+            resources[resource][points] = calculate_wage(resource, department_bonus)
+
+    print('points,oil,ore,uranium,diamond')
+    for points in range(0, 6001, 200):
+        print('{},{},{},{},{}'.format(
+            int(points),
+            round(resources['oil'][points]),
+            round(resources['ore'][points]),
+            round(resources['uranium'][points]),
+            round(resources['diamond'][points]),
+        ))
+
+def print_json(json_text):
+    """Print data to console"""
+    print(json.dumps(json_text, sort_keys=True, indent=4))
+
+if __name__ == '__main__':
+    main()

+ 6 - 0
department_efficiency/example_departments.json

@@ -0,0 +1,6 @@
+{
+    "oil": 5250,
+    "ore": 3630,
+    "diamond": 2575,
+    "uranium": 2760
+}

+ 7 - 0
department_efficiency/example_prices.json

@@ -0,0 +1,7 @@
+{
+    "oil": 255,
+    "gold": 0,
+    "diamond": 1650000,
+    "uranium": 2300,
+    "ore": 235
+}

+ 18 - 0
department_efficiency/example_regions.json

@@ -0,0 +1,18 @@
+{
+    "1": {
+        "name": "Ideal region",
+        "resources": {
+            "oil": 371,
+            "ore": 356,
+            "uranium": 25,
+            "diamond": 27
+        },
+        "tax": {
+            "gold": 5,
+            "oil": 5,
+            "ore": 5,
+            "uranium": 5,
+            "diamond": 5
+        }
+    }
+}