├── LICENSE ├── README.md ├── code2 (runable) └── code /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 mahdieslaminet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # smart-control-traffic-system 2 | سیستم هوشمند کنترل ترافیک 3 | ### Read Me 4 | لینک فیلم بک اند و اجرای پروژه : 5 | https://drive.google.com/drive/folders/1hjSYSZesWQOOvJAjXUo3i2X-3ND0eDB1?usp=sharing 6 | 7 | 8 | # سامانه مدیریت ترافیک 9 | 10 | این برنامه نمونه‌ای از یک سامانه مدیریت ترافیک است که از PyQt5 برای رابط کاربری گرافیکی، Pandas و NumPy برای کار با داده‌ها، و scikit-learn برای تحلیل خوشه‌بندی استفاده می‌کند. 11 | 12 | ## توضیحات 13 | 14 | این برنامه شامل دو قسمت اصلی است: کلاس `TrafficManagementSystem` و کلاس `TrafficControlApp`. 15 | 16 | ### TrafficManagementSystem 17 | 18 | کلاس `TrafficManagementSystem` شامل متدهایی برای مدیریت داده‌ها و عملکردهای مرتبط با ترافیک است: 19 | 20 | - `collect_data()`: متد برای جمع‌آوری داده‌های ترافیک. 21 | - `process_data(data)`: متد برای پردازش داده‌های جمع‌آوری شده. 22 | - `read_data(input_path)`: متد برای خواندن داده‌های ورودی از یک فایل CSV. 23 | - `optimize_k(df, k_range)`: متد برای بهینه‌سازی خوشه‌بندی KMeans. 24 | - `run_kmeans(df, k)`: متد برای اجرای الگوریتم KMeans. 25 | - `write_output(df, output_path)`: متد برای نوشتن داده‌های پردازش‌شده به یک فایل CSV. 26 | - `execute_strategies(processed_data)`: متد برای اجرای استراتژی‌ها بر اساس داده‌های پردازش‌شده. 27 | - `monitor_performance(strategies)`: متد برای نظارت بر عملکرد سیستم. 28 | - `create_map()`: متد برای ایجاد یک نقشه. 29 | 30 | ### TrafficControlApp 31 | 32 | کلاس `TrafficControlApp` نمایشگر رابط کاربری برای کنترل ترافیک است: 33 | 34 | - این کلاس یک پنجره را با فیلدهای ورودی برای نام خیابان‌ها و زمان ایجاد می‌کند. 35 | - متد `get_routes()` اطلاعات وارد شده را دریافت کرده و مسیر انتخابی را نمایش می‌دهد. 36 | 37 | ## استفاده 38 | 39 | 1. اطمینان حاصل کنید که PyQt5، pandas، NumPy، scikit-learn و folium در محیط شما نصب شده باشند. 40 | 2. اسکریپت را در پایتون اجرا کنید تا برنامه راه‌اندازی شود. 41 | 42 | 43 | گروه NE : علی شمس / حسین پاتیمار 44 | منتور پروژه : امیر صدرا نام آور 45 | استاد راهنما : دکتر مهدی اسلامی 46 | --- 47 | برای سوالات و اطلاعات بیشتر، با(hsyngzwz@gmail.com, alishmas8309@gmail.com) تماس بگیرید. 48 | -------------------------------------------------------------------------------- /code2 (runable): -------------------------------------------------------------------------------- 1 | import threading 2 | import random 3 | import folium 4 | from geopy.geocoders import Nominatim 5 | from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout 6 | from PyQt5.QtCore import Qt 7 | import sys 8 | import webbrowser 9 | 10 | def simulate_traffic(): 11 | # Simulate some traffic data 12 | traffic_data = { 13 | 'Time': [random.randint(0, 23) for _ in range(100)], 14 | 'Traffic_Level': [random.choice(['Low', 'Medium', 'High']) for _ in range(100)] 15 | } 16 | 17 | # Start a new thread to monitor the traffic data 18 | thread = threading.Thread(target=monitor_traffic, args=(traffic_data,)) 19 | thread.start() 20 | 21 | return traffic_data 22 | 23 | def monitor_traffic(traffic_data): 24 | # Monitor the traffic data and update the map as needed 25 | while True: 26 | # Do some work here to monitor the traffic data and update the map 27 | pass 28 | 29 | def get_location(place_name): 30 | geolocator = Nominatim(user_agent="myapp") 31 | location = geolocator.geocode(place_name) 32 | if location: 33 | return location.latitude, location.longitude 34 | else: 35 | return None 36 | 37 | def create_traffic_map(location_coordinates): 38 | map_location = folium.Map(location=location_coordinates, zoom_start=12) 39 | 40 | # Add the openstreetmap traffic layer 41 | folium.TileLayer('openstreetmap').add_to(map_location) 42 | folium.LayerControl().add_to(map_location) 43 | 44 | # Display the clustered data on the map 45 | traffic_data = simulate_traffic() 46 | display_clustered_data(map_location, traffic_data) 47 | 48 | # Add a marker for the traffic location 49 | folium.Marker(location_coordinates, popup="Traffic Location", icon=folium.Icon(color='red')).add_to(map_location) 50 | 51 | return map_location 52 | 53 | def display_clustered_data(map_location, traffic_data): 54 | # Add function to display clustered data (I'm assuming you have this function implemented) 55 | pass 56 | 57 | def show_map(): 58 | place_name = entry.text() # خواندن ورودی از فیلد متنی 59 | 60 | place_coordinates = get_location(place_name) 61 | 62 | if place_coordinates: 63 | place_map = create_traffic_map(place_coordinates) 64 | map_file = "Traffic_Map.html" 65 | place_map.save(map_file) 66 | webbrowser.open(map_file) 67 | label_result.setText("نقشه ترافیک محل مورد نظر نمایش داده شد!") 68 | else: 69 | label_result.setText("مکانیت برای این مکان یافت نشد.") 70 | 71 | app = QApplication(sys.argv) 72 | window = QWidget() 73 | window.setWindowTitle("نقشه ترافیک") 74 | 75 | layout = QVBoxLayout() 76 | 77 | label = QLabel("نام مکان یا آدرس مورد نظر را وارد کنید:") 78 | layout.addWidget(label) 79 | 80 | entry = QLineEdit() 81 | layout.addWidget(entry) 82 | 83 | button = QPushButton("نمایش نقشه ترافیک") 84 | button.clicked.connect(show_map) 85 | layout.addWidget(button) 86 | 87 | label_result = QLabel("", alignment=Qt.AlignmentFlag.AlignRight) 88 | layout.addWidget(label_result) 89 | 90 | window.setLayout(layout) 91 | window.show() 92 | 93 | sys.exit(app.exec_()) 94 | -------------------------------------------------------------------------------- /code: -------------------------------------------------------------------------------- 1 | from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton 2 | import sys 3 | import pandas as pd 4 | import numpy as np 5 | from sklearn.cluster import KMeans 6 | from sklearn.metrics import silhouette_score 7 | import folium 8 | 9 | class TrafficManagementSystem: 10 | # کدهای مدیریت ترافیک 11 | # ... 12 | 13 | def collect_data(): 14 | pass 15 | # کدهای جمع‌آوری داده 16 | # ... 17 | 18 | def process_data(data): 19 | pass 20 | # کدهای پردازش داده 21 | # ... 22 | 23 | def read_data(input_path): 24 | pass 25 | # کدهای خواندن داده 26 | # ... 27 | 28 | def optimize_k(df, k_range): 29 | pass 30 | # کدهای بهینه‌سازی KMeans 31 | # ... 32 | 33 | def run_kmeans(df, k): 34 | pass 35 | # کدهای اجرای الگوریتم KMeans 36 | # ... 37 | 38 | def write_output(df, output_path): 39 | pass 40 | # کدهای نوشتن خروجی 41 | # ... 42 | 43 | def execute_strategies(processed_data): 44 | pass 45 | # کدهای اجرای استراتژی‌ها 46 | # ... 47 | 48 | def monitor_performance(strategies): 49 | pass 50 | # کدهای نظارت بر عملکرد 51 | # ... 52 | 53 | def create_map(): 54 | pass 55 | # کدهای ساخت نقشه 56 | # ... 57 | 58 | class TrafficControlApp(QWidget): 59 | def __init__(self): 60 | super().__init__() 61 | 62 | self.setWindowTitle("سیستم هوشمند کنترل ترافیک") 63 | self.layout = QVBoxLayout() 64 | 65 | self.info_label = QLabel("اطلاعات ترافیک") 66 | self.layout.addWidget(self.info_label) 67 | 68 | self.entry1 = QLineEdit() 69 | self.entry1.setPlaceholderText("نام خیابان مبدأ") 70 | self.layout.addWidget(self.entry1) 71 | 72 | self.entry2 = QLineEdit() 73 | self.entry2.setPlaceholderText("نام خیابان مقصد") 74 | self.layout.addWidget(self.entry2) 75 | 76 | self.entry3 = QLineEdit() 77 | self.entry3.setPlaceholderText("زمان حرکت") 78 | self.layout.addWidget(self.entry3) 79 | 80 | self.button1 = QPushButton("دریافت مسیر") 81 | self.button1.clicked.connect(self.get_routes) 82 | self.layout.addWidget(self.button1) 83 | 84 | self.label4 = QLabel() 85 | self.layout.addWidget(self.label4) 86 | 87 | self.setLayout(self.layout) 88 | 89 | def get_routes(self): 90 | source_street = self.entry1.text() 91 | destination_street = self.entry2.text() 92 | time = self.entry3.text() 93 | 94 | routes = f"مسیر انتخابی: {source_street} به {destination_street}" 95 | self.label4.setText(routes) 96 | 97 | 98 | def main(): 99 | data = collect_data() 100 | processed_data = process_data(data) 101 | 102 | input_path = 'data/input.csv' 103 | df = read_data(input_path) 104 | 105 | k_range = range(2, 11) 106 | output_path = 'data/output.csv' 107 | 108 | k = optimize_k(df, k_range) 109 | df = run_kmeans(df, k) 110 | write_output(df, output_path) 111 | 112 | strategies = execute_strategies(processed_data) 113 | performance_metrics = monitor_performance(strategies) 114 | 115 | map_Tehran = create_map() 116 | map_Tehran.save("Tehran_Map.html") 117 | 118 | print("Performance Metrics:") 119 | print(performance_metrics) 120 | 121 | if __name__ == "__main__": 122 | app = QApplication(sys.argv) 123 | window = TrafficControlApp() 124 | window.show() 125 | sys.exit(app.exec_()) 126 | --------------------------------------------------------------------------------