File size: 3,415 Bytes
4fa360a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
license: apache-2.0
language:
  - en
pretty_name: "VehicleWorld Database Snippets"
tags:
  - code
  - simulation
  - autonomous-driving

# --- 这是驱动数据预览器的关键部分 ---
dataset_info:
  features:
    - name: path
      dtype: string
    - name: execute.py
      dtype: string
    - name: inits
      dtype: string
    - name: modules
      dtype: string
    - name: querys
      dtype: string
    - name: raw
      dtype: string
    - name: worlds.json
      dtype: string
  splits:
    - name: train
      num_bytes: 155973757 
      num_examples: 1291 
  download_size: 155973757 
  dataset_size: 1291 
# ------------------------------------

---

# VehicleWorld Database
Run the following code to convert csv to raw dataset

```python
import os
import csv
import sys

def csv_to_directory(csv_file, target_dir):
    """
    Reads a CSV file and creates a directory structure based on its content.

    Args:
        csv_file (str): The path to the input CSV file.
        target_dir (str): The path to the target directory where the structure will be created.
    """
    if not os.path.isfile(csv_file):
        # Using sys.stderr for error messages is a good practice.
        sys.stderr.write(f"Error: CSV file '{csv_file}' not found.\n")
        return

    os.makedirs(target_dir, exist_ok=True)

    # Handle large fields in CSV
    max_int = sys.maxsize
    while True:
        try:
            csv.field_size_limit(max_int)
            break
        except OverflowError:
            max_int = int(max_int / 10)

    try:
        with open(csv_file, 'r', encoding='utf-8') as csvfile:
            reader = csv.DictReader(csvfile)
            
            if not reader.fieldnames:
                sys.stderr.write("Error: CSV file is empty or has no header row.\n")
                return
                
            filenames = [header for header in reader.fieldnames if header != 'path']
            
            for row in reader:
                subdir_name = row.get('path')
                if not subdir_name:
                    # It's better to inform about skipped rows.
                    sys.stderr.write("Warning: Skipping a row because 'path' value is missing.\n")
                    continue
                
                full_subdir_path = os.path.join(target_dir, subdir_name)
                os.makedirs(full_subdir_path, exist_ok=True)

                for filename in filenames:
                    file_path = os.path.join(full_subdir_path, filename)
                    content = row.get(filename, "")
                    
                    try:
                        with open(file_path, 'w', encoding='utf-8') as f:
                            f.write(content)
                    except IOError as e:
                        sys.stderr.write(f"Error: Could not write to file '{file_path}': {e}\n")
                        
    except Exception as e:
        sys.stderr.write(f"An unexpected error occurred while processing the CSV file: {e}\n")

if __name__ == "__main__":
    # It is recommended to use command-line arguments for file paths
    # for better script reusability.
    if len(sys.argv) != 3:
        print("Usage: python your_script_name.py <path_to_csv> <target_directory>")
        sys.exit(1)
        
    csv_input_file = sys.argv[1]
    output_directory = sys.argv[2]

    csv_to_directory(csv_input_file, output_directory)
```