File size: 2,011 Bytes
a4e4cb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "$0")"
PYTHON_BIN="${PYTHON_BIN:-python3}"
"$PYTHON_BIN" - <<'__SKILL_EVOL_SOLVE_PY_0__'
from __future__ import annotations

import os
from pathlib import Path
from textwrap import dedent

PROJECT_ROOT = Path(os.environ.get("PROJECT_ROOT", "/root/task")).resolve()

FILES = {
    "ordering_policy.py": dedent(
        """

        from __future__ import annotations



        import pandas as pd





        def sort_logs(df: pd.DataFrame) -> pd.DataFrame:

            return df.sort_values(["parsed_date", "time", "log_id"], kind="mergesort").reset_index(drop=True)

        """
    ),
    "process_logs.py": dedent(
        """

        from __future__ import annotations



        import json

        from pathlib import Path



        import pandas as pd



        from date_parser import parse_display_dates

        from ordering_policy import sort_logs



        CSV_PATH = Path("server_logs.csv")

        OUTPUT_PATH = Path("output.json")





        def run(csv_path: Path = CSV_PATH, output_path: Path = OUTPUT_PATH) -> dict:

            df = pd.read_csv(csv_path)

            df["parsed_date"] = parse_display_dates(df["date"])

            sorted_df = sort_logs(df)

            export_df = sorted_df.drop(columns=["parsed_date"], errors="ignore")

            payload = {

                "row_count": int(len(export_df)),

                "first_date": export_df.iloc[0]["date"],

                "last_date": export_df.iloc[-1]["date"],

                "records": export_df.to_dict(orient="records"),

            }

            output_path.write_text(json.dumps(payload, indent=2), encoding="utf-8")

            return payload





        if __name__ == "__main__":

            run()

        """
    ),
}

for relative_path, content in FILES.items():
    target = PROJECT_ROOT / relative_path
    target.write_text(content, encoding="utf-8")
    print(f"wrote {target}")
__SKILL_EVOL_SOLVE_PY_0__