瀏覽代碼

Initial commit

JoostSijm 6 年之前
當前提交
338a69f315
共有 4 個文件被更改,包括 108 次插入0 次删除
  1. 1 0
      .gitignore
  2. 44 0
      calc.py
  3. 35 0
      department.py
  4. 28 0
      military.py

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+*.txt

+ 44 - 0
calc.py

@@ -0,0 +1,44 @@
+
+"""
+Calculate percentage level of index for regions
+inside the Verenigde Nederlanden.
+"""
+
+REGIONS = [
+    'Amsterdam',
+    'Northern Netherlands',
+    'Eastern Netherlands',
+    'Western Netherlands',
+    'Southern Netherlands',
+]
+
+def region_in_string(string):
+    """Look for region in string"""
+    for region in REGIONS:
+        if region in string:
+            return True
+    return False
+
+
+def calculate_index():
+    """Calculate index bases on file"""
+    with open('regions.txt', 'r') as file:
+        line_nr = 0
+        last_percentage = 11
+        for line in file:
+            line_nr += 1
+            if region_in_string(line):
+                percentage = 11 - 10 / 998 * line_nr
+                diff_percentage = last_percentage - percentage
+                last_percentage = percentage
+                region = line.strip().split('\t')
+                print('%40s %2s %6.2f %% %6.2f %%' % (
+                    region[0],
+                    region[1],
+                    percentage,
+                    diff_percentage
+                ))
+
+
+if __name__ == '__main__':
+    calculate_index()

+ 35 - 0
department.py

@@ -0,0 +1,35 @@
+
+"""
+Calculate percentage level of index for regions
+inside the Verenigde Nederlanden.
+"""
+
+import re
+
+PLAYERS = {}
+
+def calculate_buildings():
+    """Count working in departments"""
+    with open('department.txt', 'r') as file:
+        for line in file:
+            line = re.sub(r'\s\d\d.*', '', line)
+            line = re.sub(r'\[.*\]', '', line)
+            line = line.strip()
+            try:
+                count = re.search(r'\+\d+', line).group(0)
+                count = count.replace('+', '')
+                player = re.sub(r'\s\(.*', '', line)
+                if player in PLAYERS:
+                    PLAYERS[player] += int(count)
+                else:
+                    PLAYERS[player] = 1
+            except Exception as exception:
+                print('%s %s' % (line, exception))
+
+
+    for player in sorted(PLAYERS, key=PLAYERS.get, reverse=True):
+        print('%3s %s' % (PLAYERS[player], player))
+
+
+if __name__ == '__main__':
+    calculate_buildings()

+ 28 - 0
military.py

@@ -0,0 +1,28 @@
+
+"""
+Calculate percentage level of index for regions
+inside the Verenigde Nederlanden.
+"""
+
+import re
+
+PLAYERS = {}
+
+def calculate_buildings():
+    """Count number of buildings"""
+    with open('military.txt', 'r') as file:
+        for line in file:
+            line = re.sub(r'\s\t\d\d.*', '', line)
+            line = re.sub(r'\[.*\]', '', line)
+            line = line.strip()
+            if line in PLAYERS:
+                PLAYERS[line] += 1
+            else:
+                PLAYERS[line] = 1
+
+    for player in sorted(PLAYERS, key=PLAYERS.get, reverse=True):
+        print('%2s %s' % (PLAYERS[player], player))
+
+
+if __name__ == '__main__':
+    calculate_buildings()