File size: 1,967 Bytes
8664fba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1783518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8664fba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import json
from pathlib import Path
import pandas as pd
import plotly.express as px


def parse_json_files(folder_path):
    # Convert folder path to Path object
    folder = Path(folder_path)
    
    # List to store data from each file
    data_list = []
    
    # Iterate through all JSON files in the folder
    for json_file in folder.glob('*.json'):
        try:
            with open(json_file, 'r') as file:
                data = json.load(file)
                
                # Extract config and results
                config = data['config']
                results = data['results']
                
                # Combine config and results into a single dictionary
                combined_data = {
                    'agent_name': config['agent_name'],
                    'benchmark_name': config['benchmark_name'],
                    'date': config['date']
                }
                
                # Add results with 'results_' prefix
                for key, value in results.items():
                    combined_data[f'results_{key}'] = value
                
                data_list.append(combined_data)
        except Exception as e:
            print(f"Error processing {json_file}: {e}. Skipping!")
    
    # Create DataFrame from the list of dictionaries
    df = pd.DataFrame(data_list)
    
    return df


def create_scatter_plot(df, x: str, y: str, x_label: str = None, y_label: str = None, hover_data: list = None):
    fig = px.scatter(df, 
                     x=x, 
                     y=y,
                     hover_data=hover_data,
                     )
    fig.update_layout(
    width = 600,
    height = 500,
    xaxis_title = x_label,
    yaxis_title = y_label,
    xaxis = dict(
    showline = True,
    linecolor = 'black',
    showgrid = False),
    yaxis = dict(
        showline = True,
        showgrid = False,
        linecolor = 'black'
    ),
    plot_bgcolor = 'white'
    )
    return fig