Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions fix_xml_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env python3
"""Fix XML files to have XML declaration at the beginning"""

import os
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'os' is not used.

Suggested change
import os

Copilot uses AI. Check for mistakes.
import re
from pathlib import Path
Comment on lines +1 to +6
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] If this is a one-time utility script used to fix the XML files (as the PR description suggests), it should be removed from the repository after being run, or clearly documented in comments or a README that it's a maintenance script not meant for regular use. Consider adding a comment at the top explaining its purpose and when it should be used.

Copilot uses AI. Check for mistakes.

def fix_xml_file(filepath):
"""Fix a single XML file"""
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()

# Check if file starts with XML declaration
if content.strip().startswith('<?xml'):
print(f"βœ“ {filepath.name} - Already correct")
return False

# Find the XML declaration
xml_decl_pattern = r'<\?xml[^?]*\?>'
match = re.search(xml_decl_pattern, content)

if not match:
print(f"βœ— {filepath.name} - No XML declaration found")
return False

# Extract XML declaration
xml_decl = match.group(0)

# Remove the XML declaration from its current position
content_without_decl = content.replace(xml_decl, '', 1)

# Remove leading whitespace/newlines but keep copyright comments
content_without_decl = content_without_decl.lstrip('\n')

# Put XML declaration at the beginning
new_content = xml_decl + '\n' + content_without_decl

# Write back
with open(filepath, 'w', encoding='utf-8') as f:
f.write(new_content)

print(f"βœ“ {filepath.name} - Fixed")
return True
Comment on lines +8 to +43
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function lacks proper error handling. If the file cannot be read, written, or if regex operations fail, the script will crash without helpful error messages. Consider adding try-except blocks and logging errors:

def fix_xml_file(filepath):
    """Fix a single XML file"""
    try:
        with open(filepath, 'r', encoding='utf-8') as f:
            content = f.read()
    except Exception as e:
        print(f"βœ— {filepath.name} - Error reading file: {e}")
        return False
    
    # ... rest of the logic ...
    
    try:
        with open(filepath, 'w', encoding='utf-8') as f:
            f.write(new_content)
    except Exception as e:
        print(f"βœ— {filepath.name} - Error writing file: {e}")
        return False

Copilot uses AI. Check for mistakes.

def main():
# Path to Nga4ThuDuc directory
nga4_dir = Path('/home/thaianh/Study/GreenWave/src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc')
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded absolute path /home/thaianh/Study/GreenWave/src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc makes this script non-portable. Use a relative path or make the path configurable via command-line arguments. For example:

nga4_dir = Path(__file__).parent / 'src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc'

or accept it as a command-line argument.

Copilot uses AI. Check for mistakes.

print("Fixing XML files in Nga4ThuDuc directory...\n")

fixed_count = 0

# Fix all .xml and .sumocfg files
for pattern in ['*.xml', '*.sumocfg']:
for filepath in nga4_dir.glob(pattern):
if fix_xml_file(filepath):
fixed_count += 1

print(f"\nTotal files fixed: {fixed_count}")

if __name__ == '__main__':
main()
Comment on lines +1 to +62
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This utility script should be placed in the scripts/ directory instead of the repository root to maintain better organization and consistency with other utility scripts like check_sumo.py and connect_sumo.py.

Copilot uses AI. Check for mistakes.
67 changes: 67 additions & 0 deletions resolve_conflicts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python3
"""
Resolve Git merge conflicts in XML files
Keeps the HEAD version (current branch) and removes conflict markers
"""

Comment on lines +1 to +6
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] If this is a one-time utility script used to fix the XML files (as the PR description suggests), it should be removed from the repository after being run, or clearly documented in comments or a README that it's a maintenance script not meant for regular use. Consider adding a comment at the top explaining its purpose and when it should be used.

Copilot uses AI. Check for mistakes.
import os
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'os' is not used.

Suggested change
import os

Copilot uses AI. Check for mistakes.
import re
from pathlib import Path

def resolve_conflict(content):
"""
Remove Git conflict markers and keep HEAD version

Handles multiple patterns:
1. <<<<<<< HEAD ... ======= ... >>>>>>> branch
2. Standalone markers that weren't cleaned up
"""
# First pass: Remove complete conflict blocks, keep HEAD content
conflict_pattern = r'<<<<<<< HEAD\n(.*?)\n=======\n(.*?)\n>>>>>>> .*?\n'
resolved = re.sub(
conflict_pattern,
r'\1\n',
content,
flags=re.DOTALL
)

# Second pass: Remove any remaining standalone markers
resolved = re.sub(r'<<<<<<< HEAD\n?', '', resolved)
resolved = re.sub(r'=======\n?', '', resolved)
resolved = re.sub(r'>>>>>>> .*?\n?', '', resolved)
Comment on lines +20 to +31
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern doesn't handle all edge cases properly. The pattern requires a newline after >>>>>>> but the marker might appear at the end of the file without a trailing newline. Consider using:

conflict_pattern = r'<<<<<<< HEAD\n(.*?)\n=======\n(.*?)\n>>>>>>> [^\n]*\n?'

Also, the second pass removals should use re.MULTILINE flag to properly handle line boundaries.

Copilot uses AI. Check for mistakes.

return resolved

def main():
nga4_dir = Path('/home/thaianh/Study/GreenWave/src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc')
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded absolute path /home/thaianh/Study/GreenWave/src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc makes this script non-portable. Use a relative path or make the path configurable via command-line arguments. For example:

nga4_dir = Path(__file__).parent / 'src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc'

or accept it as a command-line argument.

Copilot uses AI. Check for mistakes.

print("πŸ” Resolving Git merge conflicts in Nga4ThuDuc files...\n")

fixed_count = 0

# Process all XML and sumocfg files
for pattern in ['*.xml', '*.sumocfg']:
for filepath in nga4_dir.glob(pattern):
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()

# Check if file has conflicts
if '<<<<<<< HEAD' in content:
print(f"πŸ”§ Resolving {filepath.name}...")

# Resolve conflicts
resolved_content = resolve_conflict(content)

# Write back
with open(filepath, 'w', encoding='utf-8') as f:
f.write(resolved_content)

fixed_count += 1
print(f" βœ… Fixed")
else:
print(f" βœ“ {filepath.name} - No conflicts")

print(f"\nβœ… Resolved conflicts in {fixed_count} files")

if __name__ == '__main__':
main()
Comment on lines +1 to +67
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This utility script should be placed in the scripts/ directory instead of the repository root to maintain better organization and consistency with other utility scripts like check_sumo.py and connect_sumo.py.

Copilot uses AI. Check for mistakes.
2 changes: 1 addition & 1 deletion src/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM python:3.9-slim
WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir --timeout 600 -r requirements.txt

COPY . .

Expand Down
7 changes: 4 additions & 3 deletions src/backend/app/sumo_rl/agents/iot_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,10 @@ def get_status(self) -> Dict[str, Any]:
config_file = os.path.join("/app/sumo_files", config_rel_path)

# Explicitly construct arguments for subprocess
# num-clients=2 (REMOVED): Caused blocking/connection closed errors.
# We use explicit setOrder() in code to manage synchronization instead.
base_cmd = ["-c", config_file, "--remote-port", "8813"]
# num-clients=2: Allow multiple TraCI connections (IoT Agent + Backend)
# Order 1: Backend (Passive/Observer)
# Order 2: IoT Agent (Active/Driver)
base_cmd = ["-c", config_file, "--remote-port", "8813", "--num-clients", "2"]

# Try GUI first if requested and DISPLAY is set
success = False
Expand Down
1 change: 1 addition & 0 deletions src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc/.tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8"?>
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This .tmp file appears to be incomplete, containing only an XML declaration without any closing tags or content. This will cause XML parsing errors. Either complete the file with valid XML structure or remove it if it's not needed in the repository.

Suggested change
<?xml version="1.0" encoding="UTF-8"?>

Copilot uses AI. Check for mistakes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2025 Green Wave Team

This software is released under the MIT License.
https://opensource.org/licenses/MIT
-->



<!-- generated on 2025-11-17T21:25:14.051016+07:00 by Eclipse SUMO netedit 1.25.0
-->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2025 Green Wave Team

This software is released under the MIT License.
https://opensource.org/licenses/MIT
-->



<!-- generated on 2025-11-17T21:10:46.530571+07:00 by Eclipse SUMO netedit 1.25.0
<neteditConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/neteditConfiguration.xsd">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2025-11-17T21:25:14.052011+07:00 by Eclipse SUMO sumo 1.25.0
-->

<!-- generated on 2025-11-17T21:25:14.052011+07:00 by Eclipse SUMO sumo 1.25.0 -->
<sumoConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
Expand Down
7 changes: 6 additions & 1 deletion src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc/e1_0.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2025-12-07T13:31:38.439844+00:00 by Eclipse SUMO sumo 1.25.0
<!-- generated on 2025-12-07T15:04:56.440547+00:00 by Eclipse SUMO sumo 1.25.0
<sumoConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
Expand All @@ -11,6 +11,11 @@

<traci_server>
<remote-port value="8813"/>
<num-clients value="2"/>
</traci_server>

</sumoConfiguration>
-->

<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/det_e1_file.xsd">
</detector>
7 changes: 6 additions & 1 deletion src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc/e1_1.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2025-12-07T13:31:38.441590+00:00 by Eclipse SUMO sumo 1.25.0
<!-- generated on 2025-12-07T15:04:56.441018+00:00 by Eclipse SUMO sumo 1.25.0
<sumoConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
Expand All @@ -11,6 +11,11 @@

<traci_server>
<remote-port value="8813"/>
<num-clients value="2"/>
</traci_server>

</sumoConfiguration>
-->

<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/det_e1_file.xsd">
</detector>
7 changes: 6 additions & 1 deletion src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc/e1_2.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2025-12-07T13:31:38.443018+00:00 by Eclipse SUMO sumo 1.25.0
<!-- generated on 2025-12-07T15:04:56.441284+00:00 by Eclipse SUMO sumo 1.25.0
<sumoConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
Expand All @@ -11,6 +11,11 @@

<traci_server>
<remote-port value="8813"/>
<num-clients value="2"/>
</traci_server>

</sumoConfiguration>
-->

<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/det_e1_file.xsd">
</detector>
7 changes: 6 additions & 1 deletion src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc/e1_3.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2025-12-07T13:31:38.444258+00:00 by Eclipse SUMO sumo 1.25.0
<!-- generated on 2025-12-07T15:04:56.441488+00:00 by Eclipse SUMO sumo 1.25.0
<sumoConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
Expand All @@ -11,6 +11,11 @@

<traci_server>
<remote-port value="8813"/>
<num-clients value="2"/>
</traci_server>

</sumoConfiguration>
-->

<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/det_e1_file.xsd">
</detector>
7 changes: 6 additions & 1 deletion src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc/e1_4.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2025-12-07T13:31:38.445623+00:00 by Eclipse SUMO sumo 1.25.0
<!-- generated on 2025-12-07T15:04:56.441686+00:00 by Eclipse SUMO sumo 1.25.0
<sumoConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
Expand All @@ -11,6 +11,11 @@

<traci_server>
<remote-port value="8813"/>
<num-clients value="2"/>
</traci_server>

</sumoConfiguration>
-->

<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/det_e1_file.xsd">
</detector>
7 changes: 6 additions & 1 deletion src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc/e1_5.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2025-12-07T13:31:38.447214+00:00 by Eclipse SUMO sumo 1.25.0
<!-- generated on 2025-12-07T15:04:56.441890+00:00 by Eclipse SUMO sumo 1.25.0
<sumoConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
Expand All @@ -11,6 +11,11 @@

<traci_server>
<remote-port value="8813"/>
<num-clients value="2"/>
</traci_server>

</sumoConfiguration>
-->

<detector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/det_e1_file.xsd">
</detector>
7 changes: 6 additions & 1 deletion src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc/e1i_0.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2025-12-07T13:31:38.448378+00:00 by Eclipse SUMO sumo 1.25.0
<!-- generated on 2025-12-07T15:04:56.442079+00:00 by Eclipse SUMO sumo 1.25.0
<sumoConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
Expand All @@ -11,6 +11,11 @@

<traci_server>
<remote-port value="8813"/>
<num-clients value="2"/>
</traci_server>

</sumoConfiguration>
-->

<instantE1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/instant_e1_file.xsd">
</instantE1>
7 changes: 6 additions & 1 deletion src/backend/app/sumo_rl/sumo_files/Nga4ThuDuc/e1i_1.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2025-12-07T13:31:38.449620+00:00 by Eclipse SUMO sumo 1.25.0
<!-- generated on 2025-12-07T15:04:56.442320+00:00 by Eclipse SUMO sumo 1.25.0
<sumoConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
Expand All @@ -11,6 +11,11 @@

<traci_server>
<remote-port value="8813"/>
<num-clients value="2"/>
</traci_server>

</sumoConfiguration>
-->

<instantE1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/instant_e1_file.xsd">
</instantE1>
Loading
Loading