diff --git a/__pycache__/views.cpython-310.pyc b/__pycache__/views.cpython-310.pyc index 2c95af9..7f83fd0 100644 Binary files a/__pycache__/views.cpython-310.pyc and b/__pycache__/views.cpython-310.pyc differ diff --git a/templates/pxy_city_digital_twins/city_digital_twin.html b/templates/pxy_city_digital_twins/city_digital_twin.html index 7ef66b1..a657d97 100644 --- a/templates/pxy_city_digital_twins/city_digital_twin.html +++ b/templates/pxy_city_digital_twins/city_digital_twin.html @@ -1,51 +1,195 @@ +{% load static %} LDS City - - + + + + + + - - - + - - {% load static %} - + + - - + + + {% for building in city_data.buildings %} - - + + + + + + + + + + + + {% endfor %} {% for lamp in city_data.lamps %} - - - + + + + + + + + + + + + {% endfor %} {% for tree in city_data.trees %} - - - + + + + + + + + + + + + {% endfor %} + + {% for tower in city_data.towers %} + + + + + + + + + + + + + + + + {% endfor %} + + + {% for fiber in city_data.fiber_paths %} + + + + + + + + + + + + {% endfor %} + + + {% for wifi in city_data.wifi_hotspots %} + + + + + + + + + + + + + + + + + {% endfor %} - diff --git a/views.py b/views.py index 925fbc7..f1f1edc 100644 --- a/views.py +++ b/views.py @@ -3,17 +3,35 @@ from django.http import Http404 import random import math +def get_environment_preset(lat, long): + """ + Determines the A-Frame environment preset based on latitude and longitude. + You can adjust the logic to suit your needs. + """ + # Example logic: adjust these thresholds as needed + if lat >= 60 or lat <= -60: + return 'snow' # Polar regions: snow environment + elif lat >= 30 or lat <= -30: + return 'forest' # Mid-latitudes: forest environment + elif long >= 100: + return 'goldmine' # Arbitrary example: for far east longitudes, a 'goldmine' preset + else: + return 'desert' # Default to desert for lower latitudes and moderate longitudes + def city_digital_twin(request, city_id, innovation_pct=None, technology_pct=None, science_pct=None): try: - if city_id == "random_city": + lat = float(request.GET.get('lat', 0)) + long = float(request.GET.get('long', 0)) + + if city_id == "com_con": + city_data = generate_com_con_city_data(lat, long) + elif city_id == "random_city": city_data = generate_random_city_data() elif city_id == "dream": - # Retrieve percentages from GET parameters if not in URL innovation_pct = innovation_pct or request.GET.get('innovation', 0) technology_pct = technology_pct or request.GET.get('technology', 0) science_pct = science_pct or request.GET.get('science', 0) - # Convert to integers innovation_pct = int(innovation_pct) technology_pct = int(technology_pct) science_pct = int(science_pct) @@ -21,22 +39,22 @@ def city_digital_twin(request, city_id, innovation_pct=None, technology_pct=None city_data = generate_random_city_data(innovation_pct, technology_pct, science_pct) else: city_data = get_city_data(city_id) - except ValueError: - raise Http404("City data not found.") - if not city_data: - city_data = get_example_data() + if not city_data: + city_data = get_example_data() - context = {'city_data': city_data} - return render(request, 'pxy_city_digital_twins/city_digital_twin.html', context) + preset = get_environment_preset(lat, long) + context = { + 'city_data': city_data, + 'environment_preset': preset, + 'lat': lat, + 'long': long, + } + return render(request, 'pxy_city_digital_twins/city_digital_twin.html', context) + except (ValueError, TypeError): + raise Http404("Invalid data provided.") - if not city_data: - # Fallback to example data if no city data is found - city_data = get_example_data() - - context = {'city_data': city_data} - return render(request, 'pxy_city_digital_twins/city_digital_twin.html', context) def get_city_data(city_id): # Implement fetching logic here @@ -164,7 +182,6 @@ def triangular_layout(num_elements): return positions - def generate_random_city_data(innovation_pct=100, technology_pct=100, science_pct=100, max_position=100, radius=50): num_buildings = random.randint(5, 35) num_lamps = random.randint(5, 100) @@ -241,3 +258,80 @@ def generate_random_city_data(innovation_pct=100, technology_pct=100, science_pc 'lamps': lamps, 'trees': trees, } + + +def get_environment_by_lat(lat): + if lat > 60 or lat < -60: + return 'yeti' + elif 30 < lat < 60 or -30 > lat > -60: + return 'forest' + else: + return 'desert' + + +import random + +def generate_com_con_city_data(lat, long): + random.seed(f"{lat},{long}") + + center_x = lat % 100 + center_z = long % 100 + + grid_size = 5 + spacing = 15 # Distance between objects + + # Towers in a grid + towers = [] + for i in range(grid_size): + for j in range(grid_size): + x = center_x + (i - grid_size // 2) * spacing + z = center_z + (j - grid_size // 2) * spacing + towers.append({ + 'id': len(towers) + 1, + 'status': 'Active' if random.random() > 0.2 else 'Inactive', + 'position_x': x, + 'position_y': 0, + 'position_z': z, + 'height': random.randint(40, 60), + 'range': random.randint(500, 1000), + 'color': '#ff4500' + }) + + # Fiber paths connect neighboring towers + fiber_paths = [] + for i in range(len(towers) - 1): + fiber_paths.append({ + 'id': i + 1, + 'start_x': towers[i]['position_x'], + 'start_z': towers[i]['position_z'], + 'end_x': towers[i + 1]['position_x'], + 'end_z': towers[i + 1]['position_z'], + 'mid_x': (towers[i]['position_x'] + towers[i + 1]['position_x']) / 2, + 'mid_y': 0.1, + 'mid_z': (towers[i]['position_z'] + towers[i + 1]['position_z']) / 2, + 'length': ((towers[i + 1]['position_x'] - towers[i]['position_x'])**2 + (towers[i + 1]['position_z'] - towers[i]['position_z'])**2)**0.5, + 'angle': random.uniform(0, 360), + 'status': 'Connected' if random.random() > 0.1 else 'Broken', + 'color': '#4682b4' + }) + + # Wi-Fi Hotspots scattered nearby but within grid bounds + wifi_hotspots = [] + for i in range(10): + x = center_x + random.uniform(-spacing * grid_size / 2, spacing * grid_size / 2) + z = center_z + random.uniform(-spacing * grid_size / 2, spacing * grid_size / 2) + wifi_hotspots.append({ + 'id': i + 1, + 'position_x': x, + 'position_y': 1.5, + 'position_z': z, + 'status': 'Online' if random.random() > 0.2 else 'Offline', + 'radius': random.randint(1, 3), + 'color': '#32cd32' + }) + + return { + 'towers': towers, + 'fiber_paths': fiber_paths, + 'wifi_hotspots': wifi_hotspots + }