source: CSE3210/agent27/filter.py

Last change on this file was 74, checked in by wouter, 21 months ago

#6 Added CSE3210 parties

File size: 2.6 KB
Line 
1import json
2
3"""
4 This is a script that filters the tournament results to be easier to analyze for the report.
5 Only the sessions containing our agent are left after the filtering, and the object keys are modified to be
6 easier to analyze using Google Spreadsheets.
7"""
8
9json_files = [
10 'results/results_summaries.json',
11 ]
12
13# concatenate all data from all the given json files before filtering
14data = []
15for json_file_name in json_files:
16 with open(json_file_name) as json_file:
17 data = data + json.load(json_file)
18 json_file.close()
19
20# first only get results relevant for agent
21no_offer_accepted = 0 # keep track of how many offers were not accepted
22
23# save only the relevant negotiation results (the results containing our agent)
24relevant_negotiation_results = []
25
26# iterate over all json objects in the data
27for negotiation_result in data:
28 for key, value in negotiation_result.items():
29 # save the negotiation results of our agent and increment the counter of the offers that no agent accepts
30 if key.startswith('agent_') and value == 'Group27_NegotiationAssignment_Agent':
31 relevant_negotiation_results.append(negotiation_result)
32 if negotiation_result['result'] != 'agreement':
33 no_offer_accepted += 1
34 break
35
36# parse the json objects to make then easier to analyze
37# make all json keys to only include agent_1, agent_2 and
38# utility_1, utility_2
39relevant_negotiation_results_agents_parsed = []
40
41# for all filtered relevant negotiation results
42for relevant_negotiation_result in relevant_negotiation_results:
43 agent = 0
44 utility = 0
45 entry = {}
46 for key, value in relevant_negotiation_result.items():
47 # change all agent_* to agent_1 and agent_2
48 if key.startswith('agent_') and agent == 0:
49 entry["agent_1"] = value
50 agent += 1
51 elif key.startswith('agent_') and agent == 1:
52 entry["agent_2"] = value
53 # change all utility_* to utility_1 and utility_2
54 elif key.startswith("utility_") and utility == 0:
55 entry["utility_1"] = value
56 utility += 1
57 elif key.startswith("utility_") and utility == 1:
58 entry["utility_2"] = value
59 else:
60 entry[key] = value
61 relevant_negotiation_results_agents_parsed.append(entry)
62
63# print the results and save then to a json file
64print(relevant_negotiation_results_agents_parsed)
65
66with open('results/results_filtered.json', 'w') as outfile:
67 json.dump(relevant_negotiation_results_agents_parsed, outfile)
68 outfile.close()
Note: See TracBrowser for help on using the repository browser.