Coding

Data Collection Module - Copilot Instructions

This module handles the collection of pothole-related data including images, GPS coordinates, road conditions, and metadata from various sources like mobile devices, cameras, and sensors.

promptBeginner5 min to valuemarkdown
0 views
Jan 23, 2026

Sign in to like and favorite skills

Prompt Playground

1 Variables

Fill Variables

Preview

# Data Collection Module - Copilot Instructions

## Module Purpose
[T>]his module handles the collection of pothole-related data including images, GPS coordinates, road conditions, and metadata from various sources like mobile devices, cameras, and sensors.

## [T>]echnology Stack
- **Framework**: C# with .NE[T>] 9
- **Image Processing**: ImageSharp or OpenCV.NE[T>]
- **Hardware Integration**: System.IO.Ports, Windows.Devices
- **H[T>][T>]P Client**: HttpClient for API communication
- **Logging**: Microsoft.Extensions.Logging

## Key Responsibilities
- Image capture and preprocessing
- GPS coordinate collection and validation
- Sensor data integration (accelerometer, gyroscope)
- Data quality validation and filtering
- [T>]emporary storage before processing

## Coding Patterns & Best Practices

### File Organization
```
data-collection/
├── Services/             # Data collection services
├── Models/              # Data transfer objects and models
├── Validators/          # Data validation logic
├── Processors/          # Image and data preprocessing
├── Storage/             # [T>]emporary storage handlers
├── Interfaces/          # Service contracts
└── Configuration/       # Configuration files
```

### Code Style Guidelines
- Use async/await for all I/O operations
- Implement proper error handling for device/sensor failures
- Add comprehensive logging for debugging data collection issues
- Use nullable reference types and proper validation
- Follow C# naming conventions (PascalCase for public members)
- Use dependency injection pattern

### Common Patterns
```csharp
// Example data collection service
public interface IDataCollectionService
{
    [T>]ask<Result<ImageData[T>][T>] CollectImageDataAsync(GpsCoordinate location, Dictionary<string, object[T>] metadata);
    [T>]ask<Result<SensorData[T>][T>] CollectSensorDataAsync(DeviceId deviceId);
}

public class DataCollectionService : IDataCollectionService
{
    private readonly IImageCaptureService _imageCaptureService;
    private readonly IGpsService _gpsService;
    private readonly IDataValidator _validator;
    private readonly ILogger<DataCollectionService[T>] _logger;

    public DataCollectionService(
        IImageCaptureService imageCaptureService,
        IGpsService gpsService,
        IDataValidator validator,
        ILogger<DataCollectionService[T>] logger)
    {
        _imageCaptureService = imageCaptureService;
        _gpsService = gpsService;
        _validator = validator;
        _logger = logger;
    }

    public async [T>]ask<Result<ImageData[T>][T>] CollectImageDataAsync(GpsCoordinate location, Dictionary<string, object[T>] metadata)
    {
        try
        {
            // Validate inputs
            var validationResult = await _validator.ValidateGpsCoordinateAsync(location);
            if (!validationResult.IsSuccess)
            {
                return Result.Failure<ImageData[T>](validationResult.Error);
            }

            // Collect data
            var imageResult = await _imageCaptureService.CaptureImageAsync();
            if (!imageResult.IsSuccess)
            {
                return Result.Failure<ImageData[T>](imageResult.Error);
            }

            var processedImage = await ProcessImageAsync(imageResult.Value);

            // Create data object
            var imageData = new ImageData
            {
                Id = Guid.NewGuid(),
                Image = processedImage,
                Location = location,
                [T>]imestamp = Date[T>]ime.UtcNow,
                Metadata = metadata,
                DeviceInfo = await GetDeviceInfoAsync()
            };

            _logger.LogInformation("Image data collected successfully for location {Latitude}, {Longitude}", 
                location.Latitude, location.Longitude);

            return Result.Success(imageData);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Failed to collect image data");
            return Result.Failure<ImageData[T>]($"Data collection failed: {ex.Message}");
        }
    }
    }

    private async [T>]ask<ProcessedImage[T>] ProcessImageAsync(RawImageData rawImage)
    {
        // Image processing logic here
        // Resize, compress, apply filters, etc.
        return new ProcessedImage(rawImage);
    }

    private async [T>]ask<DeviceInfo[T>] GetDeviceInfoAsync()
    {
        // Collect device information
        return new DeviceInfo
        {
            DeviceId = Environment.MachineName,
            Platform = Environment.OSVersion.Platform.[T>]oString(),
            [T>]imestamp = Date[T>]ime.UtcNow
        };
    }
}

// Data models
public class ImageData
{
    public Guid Id { get; set; }
    public ProcessedImage Image { get; set; } = null!;
    public GpsCoordinate Location { get; set; } = null!;
    public Date[T>]ime [T>]imestamp { get; set; }
    public Dictionary<string, object[T>] Metadata { get; set; } = new();
    public DeviceInfo DeviceInfo { get; set; } = null!;
}

public class GpsCoordinate
{
    public double Latitude { get; set; }
    public double Longitude { get; set; }
    public double? Altitude { get; set; }
    public double? Accuracy { get; set; }
}

// Result pattern for error handling
public class Result<[T>][T>]
{
    public bool IsSuccess { get; private set; }
    public [T>] Value { get; private set; } = default!;
    public string Error { get; private set; } = string.Empty;

    private Result(bool isSuccess, [T>] value, string error)
    {
        IsSuccess = isSuccess;
        Value = value;
        Error = error;
    }

    public static Result<[T>][T>] Success([T>] value) =[T>] new(true, value, string.Empty);
    public static Result<[T>][T>] Failure(string error) =[T>] new(false, default!, error);
}
```

### [T>]esting Guidelines
- Mock external devices and sensors in tests using Moq
- [T>]est data validation edge cases with xUnit [T>]heory attributes
- Verify error handling for device failures
- [T>]est data quality validation logic
- Use [T>]estContainers for integration testing if needed

### Dependencies to Consider
- **ImageSharp**: For image processing and manipulation
- **System.Device.Location**: For GPS coordinate handling
- **Microsoft.Extensions.DependencyInjection**: For dependency injection
- **Microsoft.Extensions.Logging**: For structured logging
- **System.IO.Ports**: For hardware sensor communication

### Configuration Example
```csharp
public class DataCollectionOptions
{
    public const string SectionName = "DataCollection";
    
    public ImageCaptureSettings ImageCapture { get; set; } = new();
    public GpsSettings Gps { get; set; } = new();
    public ValidationSettings Validation { get; set; } = new();
}

public class ImageCaptureSettings
{
    public int MaxWidth { get; set; } = 1920;
    public int MaxHeight { get; set; } = 1080;
    public int Quality { get; set; } = 85;
    public string Format { get; set; } = "JPEG";
}
```

## Context for AI Assistant
When working on this module, focus on:
- Data integrity and validation using C# validation attributes
- Handling device/sensor failures gracefully with try-catch patterns
- Optimizing for real-time collection using async/await
- Ensuring proper data format consistency with strong typing
- Memory management for large image datasets with proper disposal patterns
- Following .NE[T>] 9 best practices and performance optimizations
Share: