JoostSijm 5 gadi atpakaļ
vecāks
revīzija
f25908a172
6 mainītis faili ar 114 papildinājumiem un 10 dzēšanām
  1. 2 0
      .gitignore
  2. 29 0
      deep_expo.py
  3. 38 8
      department.py
  4. 25 0
      difference/check.py
  5. 18 0
      level.py
  6. 2 2
      rr.py

+ 2 - 0
.gitignore

@@ -1 +1,3 @@
 *.txt
+*.html
+*__pycache__/

+ 29 - 0
deep_expo.py

@@ -0,0 +1,29 @@
+"""Calculate resources koef"""
+
+def calc_koef(resource_limit, koef_value):
+    """Calculate koef based on limit"""
+    return pow(resource_limit * koef_value / 10, 0.8)
+
+
+def calc_resource(resource_limit, deep_expo, koef_value):
+    """Calculate deep expo for resource"""
+    initial_koef = calc_koef(resource_limit, koef_value)
+    new_koef = calc_koef(resource_limit + deep_expo, koef_value)
+    percentage = 100 / initial_koef * new_koef
+    print("%8.2f%8.2f%8.2f" % (initial_koef, new_koef, percentage))
+
+
+if __name__ == "__main__":
+    print("old new percentage")
+    # gold
+    calc_resource(379, 258, 0.4)
+    # oil
+    calc_resource(223, 148, 0.65)
+    # ore
+    calc_resource(247, 109, 0.65)
+    # uranium
+    calc_resource(2, 23, 0.75)
+    # diamonds
+    calc_resource(2, 25, 0.75)
+    print("lux")
+    calc_resource(267, 89, 0.65)

+ 38 - 8
department.py

@@ -4,12 +4,13 @@ Calculate percentage level of index for regions
 inside the Verenigde Nederlanden.
 """
 
+import math
 import re
 from datetime import timedelta
 import dateutil.parser
 
 # Config
-PLAYER = False
+PLAYER = True
 DATE = True
 
 PLAYERS = {}
@@ -17,13 +18,15 @@ DAYS = {}
 
 def calculate_buildings():
     """Count working in departments"""
+    total = 0
+    total_reward = 0
     with open('department.txt', 'r') as file:
         for line in file:
             try:
                 date_str = re.search(r'\s\d\d.*', line).group(0)
                 date_str = re.sub(r'\s\d\d\s', '', date_str)
                 date = dateutil.parser.parse(date_str)
-                if date.hour >= 20: 
+                if date.hour >= 20:
                     date += timedelta(days=1)
 
                 line = re.sub(r'\s\d\d.*', '', line)
@@ -32,30 +35,57 @@ def calculate_buildings():
 
                 count = re.search(r'\+\d+', line).group(0)
                 count = count.replace('+', '')
+                count = int(count)
+                total += count
 
                 if PLAYER:
                     player = re.sub(r'\s\(.*', '', line)
                     if player in PLAYERS:
-                        PLAYERS[player] += int(count)
+                        PLAYERS[player] += count
                     else:
-                        PLAYERS[player] = int(count)
+                        PLAYERS[player] = count
 
                 if DATE:
                     date_format = date.strftime("%Y-%m-%d")
                     if date_format in DAYS:
-                        DAYS[date_format] += int(count)
-                    else: 
-                        DAYS[date_format] = int(count)
+                        DAYS[date_format] += count
+                    else:
+                        DAYS[date_format] = count
             except Exception as exception:
                 print('%s %s' % (line, exception))
 
     if PLAYER:
+        print('punten,beloning,naam')
         for player in sorted(PLAYERS, key=PLAYERS.get, reverse=True):
-            print('%3s %s' % (PLAYERS[player], player))
+            worked_times = math.floor(PLAYERS[player] / 10)
+            reward = worked_times * 2000000000
+            if worked_times >= 6:
+                reward += 10000000000
+            total_reward += reward
+            print('%3s,$ %5s,%s' % (PLAYERS[player], bucks(reward), player))
     if DATE:
         for date in sorted(DAYS, reverse=True):
             print('%s,%3s' % (date, DAYS[date]))
 
+    print(total)
+    print(total_reward)
+
+
+def bucks(money):
+    """Format money"""
+    str_format = '{:,}'.format(money)
+    new_str = ''
+    for i in range(len(str_format), 0, -4):
+        if str_format[i-4:i] == ',000':
+            new_str = 'k' + new_str
+        else:
+            new_str = str_format[:i] + new_str
+            break
+
+    new_str = new_str.replace('kkkk', 't')
+    new_str = new_str.replace(',', '.')
+    return new_str
+
 
 if __name__ == '__main__':
     calculate_buildings()

+ 25 - 0
difference/check.py

@@ -0,0 +1,25 @@
+"""Check difference between lists"""
+
+inside = []
+not_inside = []
+not_outside = []
+
+with open('inside.txt', 'r') as file:
+    for line in file:
+        inside.append(line.replace('\n', ''))
+
+with open('outside.txt', 'r') as file:
+    for line in file:
+        line = line.replace('\n', '')
+        if line in inside:
+            not_outside.append(line)
+        else:
+            not_inside.append(line)
+
+print("Not inside:")
+for player in not_inside:
+    print(player)
+
+print("\nNot outside:")
+for player in not_outside:
+    print(player)

+ 18 - 0
level.py

@@ -0,0 +1,18 @@
+"""Calculate resources koef"""
+
+def calc_koef(level):
+    """Calculate koef based on level"""
+    return pow(level, 0.8)
+
+
+def calc_level_koef(old_level, new_level):
+    """Calculate resource koef for level"""
+    old_koef = calc_koef(old_level)
+    new_koef = calc_koef(new_level)
+    percentage = 100 / old_koef * new_koef
+    print("%8.2f%8.2f%8.2f" % (old_koef, new_koef, percentage))
+
+
+if __name__ == "__main__":
+    print("old new percentage")
+    calc_level_koef(86, 92)

+ 2 - 2
rr.py

@@ -21,6 +21,6 @@ class Value(int):
                 new_str = str_format[:i] + new_str
                 break
 
-        new_str = new_str.replace('kkkk', 't') 
-        new_str = new_str.replace(',', '.') 
+        new_str = new_str.replace('kkkk', 't')
+        new_str = new_str.replace(',', '.')
         return new_str