|
25 | 25 | "import json\n", |
26 | 26 | "import csv\n", |
27 | 27 | "from pathlib import Path\n", |
| 28 | + "import pandas as pd\n", |
28 | 29 | "\n", |
29 | 30 | "%matplotlib notebook\n", |
30 | 31 | "import matplotlib.pyplot as plt" |
|
42 | 43 | }, |
43 | 44 | "cell_type": "code", |
44 | 45 | "source": [ |
45 | | - "a = ips_analysis_api.get_data()\n", |
46 | | - "b = ips_analysis_api.get_child_data()\n", |
47 | | - "c = ips_analysis_api.get_child_data_not_ensembles()\n", |
48 | | - "d = ips_analysis_api.get_child_data_by_ensemble_names()" |
| 46 | + "# Gather ensemble instance data\n", |
| 47 | + "ensemble_data = ips_analysis_api.get_child_data()" |
49 | 48 | ], |
50 | 49 | "id": "3d8fa1127a2ab4ef", |
51 | 50 | "outputs": [], |
52 | 51 | "execution_count": 1 |
53 | 52 | }, |
| 53 | + { |
| 54 | + "metadata": {}, |
| 55 | + "cell_type": "markdown", |
| 56 | + "source": "`ensemble_data` will be a python dict within a dict that has a list. The outermost dict is keyed by the run number, the next dict level by the timestamp, and the list within that dict will be of all the data that was registered for the instance run.", |
| 57 | + "id": "a47d457006cb62c0" |
| 58 | + }, |
| 59 | + { |
| 60 | + "metadata": {}, |
| 61 | + "cell_type": "code", |
| 62 | + "outputs": [], |
| 63 | + "execution_count": null, |
| 64 | + "source": "ensemble_data", |
| 65 | + "id": "baab25e709153aec" |
| 66 | + }, |
| 67 | + { |
| 68 | + "metadata": {}, |
| 69 | + "cell_type": "markdown", |
| 70 | + "source": "For this example, we're interested in aggregating the instance data found in all the CSV files. (The JSON files contain the solutions for each instance for which there are separate jupyter notebooks, and so are outside the scope of this notebook.) So, let's create a pandas dataframe from all the CSV files.", |
| 71 | + "id": "be9c1c201521542c" |
| 72 | + }, |
| 73 | + { |
| 74 | + "metadata": {}, |
| 75 | + "cell_type": "code", |
| 76 | + "outputs": [], |
| 77 | + "execution_count": null, |
| 78 | + "source": [ |
| 79 | + "rows = []\n", |
| 80 | + "for k in ensemble_data.keys():\n", |
| 81 | + " csv_path = Path(ensemble_data[k][0.0][1])\n", |
| 82 | + " print(f'Reading {csv_path}')\n", |
| 83 | + " with csv_path.open('r') as csv_file:\n", |
| 84 | + " csv_reader = csv.DictReader(csv_file)\n", |
| 85 | + " for row in csv_reader:\n", |
| 86 | + " rows.append(row)" |
| 87 | + ], |
| 88 | + "id": "94a8c3dce6c33ae6" |
| 89 | + }, |
| 90 | + { |
| 91 | + "metadata": {}, |
| 92 | + "cell_type": "code", |
| 93 | + "outputs": [], |
| 94 | + "execution_count": null, |
| 95 | + "source": "df = pd.DataFrame(rows)", |
| 96 | + "id": "3954d70afe1b1794" |
| 97 | + }, |
| 98 | + { |
| 99 | + "metadata": {}, |
| 100 | + "cell_type": "code", |
| 101 | + "outputs": [], |
| 102 | + "execution_count": null, |
| 103 | + "source": "df", |
| 104 | + "id": "4ddbb45fc4de7" |
| 105 | + }, |
| 106 | + { |
| 107 | + "metadata": {}, |
| 108 | + "cell_type": "code", |
| 109 | + "outputs": [], |
| 110 | + "execution_count": null, |
| 111 | + "source": [ |
| 112 | + "# convert start and end times to floats to make new duration column\n", |
| 113 | + "df['start'] = df['start'].astype(float)\n", |
| 114 | + "df['end'] = df['end'].astype(float)" |
| 115 | + ], |
| 116 | + "id": "1bf3f724abe263db" |
| 117 | + }, |
| 118 | + { |
| 119 | + "metadata": {}, |
| 120 | + "cell_type": "code", |
| 121 | + "outputs": [], |
| 122 | + "execution_count": null, |
| 123 | + "source": "df['duration'] = df['end'] - df['start']", |
| 124 | + "id": "e1a339aacb56d29f" |
| 125 | + }, |
54 | 126 | { |
55 | 127 | "metadata": {}, |
56 | 128 | "cell_type": "code", |
57 | 129 | "outputs": [], |
58 | 130 | "execution_count": null, |
59 | | - "source": "", |
60 | | - "id": "c2e3d3e1518509f8" |
| 131 | + "source": [ |
| 132 | + "# Show the final dataframe with new duration column\n", |
| 133 | + "df" |
| 134 | + ], |
| 135 | + "id": "e2ec1f8dca7ad3e8" |
61 | 136 | } |
62 | 137 | ], |
63 | 138 | "metadata": { |
|
0 commit comments