MCPcopy Create free account
hub / github.com/SalesforceAIResearch/perfcodegen / json2csv2

Method json2csv2

src/evaluate_prompt.py:1615–1642  ·  view source on GitHub ↗
(self, jsonfile)

Source from the content-addressed store, hash-verified

1613
1614
1615 def json2csv2(self, jsonfile):
1616 results = json.load(open(jsonfile, "r"))
1617 lines = []
1618 for dataset in results:
1619 lines.append(dataset + "="*20)
1620 for metric in results[dataset]:
1621 lines.append(metric+ "+"*10)
1622 if metric in ["gt_speedup", "gt_opt"]:
1623 lines.append("Strategy,Best@1,Best@5,Best@8,Best@10,Best@20,Avg")
1624 for name in results[dataset][metric]:
1625 line = "{},{},{},{},{},{},{}".format(name,
1626 format(results[dataset][metric][name]["1"] * (100 if "speedup" not in metric else 1), ".2f"),
1627 format(results[dataset][metric][name]["5"] * (100 if "speedup" not in metric else 1), ".2f"),
1628 format(results[dataset][metric][name]["8"] * (100 if "speedup" not in metric else 1), ".2f"),
1629 format(results[dataset][metric][name]["10"] * (100 if "speedup" not in metric else 1), ".2f"),
1630 format(results[dataset][metric][name]["20"] * (100 if "speedup" not in metric else 1), ".2f"),
1631 format(results[dataset][metric][name]["avg"] * (100 if "speedup" not in metric else 1), ".2f"))
1632 lines.append(line)
1633 else:
1634 lines.append("Strategy,Avg")
1635 for name in results[dataset][metric]:
1636 line = "{},{}".format(name,
1637 format(results[dataset][metric][name] * (100 if "speedup" not in metric else 1), ".2f"))
1638 lines.append(line)
1639
1640
1641 with open(jsonfile.replace(".json", ".csv"), "w", encoding = "utf-8") as f:
1642 f.write("\n".join(lines))
1643
1644
1645

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected