calc.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """
  2. Calculate percentage level of index for regions
  3. inside the Verenigde Nederlanden.
  4. """
  5. REGIONS = [
  6. 'Amsterdam',
  7. 'Northern Netherlands',
  8. 'Eastern Netherlands',
  9. 'Western Netherlands',
  10. 'Southern Netherlands',
  11. ]
  12. def region_in_string(string):
  13. """Look for region in string"""
  14. for region in REGIONS:
  15. if region in string:
  16. return True
  17. return False
  18. def calculate_index():
  19. """Calculate index bases on file"""
  20. with open('regions.txt', 'r') as file:
  21. line_nr = 0
  22. last_percentage = 11
  23. for line in file:
  24. line_nr += 1
  25. if region_in_string(line):
  26. percentage = 11 - 10 / 998 * line_nr
  27. diff_percentage = last_percentage - percentage
  28. last_percentage = percentage
  29. region = line.strip().split('\t')
  30. print('%40s %2s %6.2f %% %6.2f %%' % (
  31. region[0],
  32. region[1],
  33. percentage,
  34. diff_percentage
  35. ))
  36. if __name__ == '__main__':
  37. calculate_index()