''' Created on Aug 18, 2019 @author: Brett Paufler (c) Copyright Brett Paufler Research Graphs Statistics On one or more logfiles in input Outputs Text Research Order Each Game Graph Culminative Research Turn Normalized Research ''' from os import listdir from os.path import join as path_join from civ_parse_logfile import Game from civ_parse_tech_tree import standard_tech_tree import matplotlib.pyplot as plt ################################################# # # Pre-Process Games & Tech Tree # ################################################# dir_in = './input/' dir_out = './output/' log_list = [path_join(dir_in, log_file) for log_file in listdir(dir_in)] games = [Game(log) for log in log_list] tech_tree = standard_tech_tree() iCost = tech_tree.icost_from_name ################################################# # # Process Games for Culminative Research Data # ################################################# num_games = len(games) print num_games game_names = [game.name for game in games] print game_names #For ALL gameS games_research_culminative_total = [] games_research_order = [] for g in games: #For Each Game total_research = 0 game_research_culminative_total = [] game_research_order = [] for turn in g.turns: for tech in turn.tech_finished: #Comes First For Natural Spelling game_research_order.append(tech) tech = tech.upper() tech = tech.replace(' ', '_') beakers = iCost(tech) total_research += beakers #print total_research, beakers, tech #print game_research_order game_research_culminative_total.append(total_research) games_research_order.append(list(game_research_order)) games_research_culminative_total.append(list(game_research_culminative_total)) print games_research_order print games_research_culminative_total ################################################# # # Output Research Order as Text File # ################################################# for n, name in enumerate(game_names): print game_research_order[n] sn = log_list[n].replace(dir_in, dir_out) sn = sn.replace('.txt', ' Research Order.txt') print sn with open(sn, 'w') as f: f.write('\n'.join(games_research_order[n])) ################################################# # # The Difference Between Two Lists # A Difficult Problem # Edit Distance # Movement Distance # # Not Implemented at this juncture # # SEE # from difflib import SequenceMatcher ################################################# ################################################# # # Graph Culminative Research # # Absolute Values # ################################################# #Turn Length of Longest Game max_turns = max([len(n) for n in games_research_culminative_total]) print max_turns plt.figure(figsize=(10,5)) for n, game in enumerate(games_research_culminative_total): plt.plot( range(0, len(game)), game, label=game_names[n] ) plt.legend() plt.xlim(xmin=0, xmax=max_turns) plt.title('Absolute Research') plt.ylabel('Culminative Research') plt.xlabel('Turn Number') plt.savefig('./output/culminative_research_absolute.png') plt.close() print 'GRAPHED CULMINATIVE RESEARCH' print '\t ABSOLUTE' ################################################# # # Graph Culminative Research # # Normalized by Turn # ################################################# plt.figure(figsize=(10,5)) for n, cul_research in enumerate(games_research_culminative_total): #Find the Norm Culm/Turn norm_research = [0] for t,t_r in enumerate(cul_research[1:], 1): norm_research.append(t_r/t) plt.plot( range(0, len(norm_research)), norm_research, label=game_names[n] ) plt.legend() plt.xlim(xmin=0, xmax=max_turns) plt.title('Normalized Research') plt.ylabel('Research per Turn') plt.xlabel('Turn Number') plt.savefig('./output/culminative_research_turn_normalized.png') plt.close() print '\t TURN NORMALIZED'