using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Haoliang.Models.Models.System;
using Haoliang.Models.Models.Production;
namespace Haoliang.Core.Services
{
public interface IProductionStatisticsService
{
///
/// Calculate production trends for a specific device and time range
///
Task CalculateProductionTrendsAsync(int deviceId, DateTime startDate, DateTime endDate);
///
/// Generate comprehensive production report
///
Task GenerateProductionReportAsync(ReportFilter filter);
///
/// Calculate efficiency metrics for devices or programs
///
Task CalculateEfficiencyMetricsAsync(EfficiencyFilter filter);
///
/// Perform quality analysis based on production data
///
Task PerformQualityAnalysisAsync(QualityFilter filter);
///
/// Get production summary for dashboard display
///
Task GetDashboardSummaryAsync(DashboardFilter filter);
///
/// Calculate OEE (Overall Equipment Effectiveness)
///
Task CalculateOeeAsync(int deviceId, DateTime date);
///
/// Get production forecasts based on historical data
///
Task GenerateProductionForecastAsync(ForecastFilter filter);
///
/// Analyze production anomalies and outliers
///
Task DetectProductionAnomaliesAsync(AnomalyFilter filter);
}
// Supporting models for statistics
public class ProductionTrendAnalysis
{
public int DeviceId { get; set; }
public string DeviceName { get; set; }
public DateTime PeriodStart { get; set; }
public DateTime PeriodEnd { get; set; }
public decimal TotalProduction { get; set; }
public decimal AverageDailyProduction { get; set; }
public decimal ProductionVariance { get; set; }
public double TrendCoefficient { get; set; }
public ProductionTrendDirection TrendDirection { get; set; }
public List DailyData { get; set; }
}
public class DailyProduction
{
public DateTime Date { get; set; }
public decimal Quantity { get; set; }
public decimal Target { get; set; }
public decimal Efficiency { get; set; }
public List Records { get; set; }
}
public class ProductionReport
{
public DateTime ReportDate { get; set; }
public ReportType ReportType { get; set; }
public List SummaryItems { get; set; }
public ReportMetadata Metadata { get; set; }
}
public class ProductionSummaryItem
{
public int DeviceId { get; set; }
public string DeviceName { get; set; }
public string ProgramName { get; set; }
public decimal Quantity { get; set; }
public decimal TargetQuantity { get; set; }
public decimal Efficiency { get; set; }
public decimal QualityRate { get; set; }
public TimeSpan Runtime { get; set; }
public TimeSpan Downtime { get; set; }
}
public class EfficiencyMetrics
{
public int DeviceId { get; set; }
public string DeviceName { get; set; }
public DateTime PeriodStart { get; set; }
public DateTime PeriodEnd { get; set; }
public decimal Availability { get; set; }
public decimal Performance { get; set; }
public decimal Quality { get; set; }
public decimal Oee { get; set; }
public EquipmentUtilization Utilization { get; set; }
public List HourlyData { get; set; }
}
public class HourlyEfficiency
{
public DateTime Hour { get; set; }
public decimal Availability { get; set; }
public decimal Performance { get; set; }
public decimal Quality { get; set; }
public decimal Oee { get; set; }
}
public class QualityAnalysis
{
public int DeviceId { get; set; }
public string DeviceName { get; set; }
public DateTime PeriodStart { get; set; }
public DateTime PeriodEnd { get; set; }
public decimal TotalProduced { get; set; }
public decimal TotalGood { get; set; }
public decimal QualityRate { get; set; }
public decimal DefectRate { get; set; }
public List QualityMetrics { get; set; }
public List DefectAnalysis { get; set; }
}
public class QualityMetric
{
public string MetricName { get; set; }
public decimal Value { get; set; }
public string Unit { get; set; }
public DateTime Timestamp { get; set; }
}
public class DefectAnalysis
{
public string DefectType { get; set; }
public int Count { get; set; }
public decimal Percentage { get; set; }
public List OccurrenceTimes { get; set; }
}
public class DashboardSummary
{
public DateTime GeneratedAt { get; set; }
public int TotalDevices { get; set; }
public int ActiveDevices { get; set; }
public int OfflineDevices { get; set; }
public decimal TotalProductionToday { get; set; }
public decimal TotalProductionThisWeek { get; set; }
public decimal TotalProductionThisMonth { get; set; }
public decimal OverallEfficiency { get; set; }
public decimal QualityRate { get; set; }
public List DeviceSummaries { get; set; }
public List ActiveAlerts { get; set; }
}
public class DeviceSummary
{
public int DeviceId { get; set; }
public string DeviceName { get; set; }
public DeviceStatus Status { get; set; }
public decimal TodayProduction { get; set; }
public decimal Efficiency { get; set; }
public decimal QualityRate { get; set; }
public TimeSpan Runtime { get; set; }
public string CurrentProgram { get; set; }
}
public class AlertSummary
{
public int AlertId { get; set; }
public string DeviceName { get; set; }
public AlertType AlertType { get; set; }
public string Message { get; set; }
public DateTime CreatedAt { get; set; }
public bool IsActive { get; set; }
}
public class OeeMetrics
{
public int DeviceId { get; set; }
public string DeviceName { get; set; }
public DateTime Date { get; set; }
public decimal Availability { get; set; }
public decimal Performance { get; set; }
public decimal Quality { get; set; }
public decimal Oee { get; set; }
public TimeSpan PlannedProductionTime { get; set; }
public TimeSpan ActualProductionTime { get; set; }
public TimeSpan Downtime { get; set; }
public decimal IdealCycleTime { get; set; }
public decimal TotalCycleTime { get; set; }
public decimal TotalPieces { get; set; }
public decimal GoodPieces { get; set; }
}
public class ProductionForecast
{
public int DeviceId { get; set; }
public string DeviceName { get; set; }
public DateTime ForecastStartDate { get; set; }
public DateTime ForecastEndDate { get; set; }
public List DailyForecasts { get; set; }
public decimal ForecastAccuracy { get; set; }
public ForecastModel ModelUsed { get; set; }
}
public class ForecastItem
{
public DateTime Date { get; set; }
public decimal ForecastedQuantity { get; set; }
public decimal ConfidenceLower { get; set; }
public decimal ConfidenceUpper { get; set; }
public decimal ActualQuantity { get; set; }
public decimal Variance { get; set; }
}
public class AnomalyAnalysis
{
public int DeviceId { get; set; }
public string DeviceName { get; set; }
public DateTime AnalysisStartDate { get; set; }
public DateTime AnalysisEndDate { get; set; }
public List Anomalies { get; set; }
public AnomalySeverity OverallSeverity { get; set; }
}
public class ProductionAnomaly
{
public DateTime Timestamp { get; set; }
public AnomalyType Type { get; set; }
public AnomalySeverity Severity { get; set; }
public decimal Deviation { get; set; }
public string Description { get; set; }
public AnomalyAction RecommendedAction { get; set; }
}
// Filter models
public class ReportFilter
{
public List DeviceIds { get; set; }
public List ProgramNames { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public ReportType ReportType { get; set; }
public GroupBy GroupBy { get; set; }
}
public class EfficiencyFilter
{
public List DeviceIds { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public EfficiencyMetric Metrics { get; set; }
public GroupBy GroupBy { get; set; }
}
public class QualityFilter
{
public List DeviceIds { get; set; }
public List ProgramNames { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public QualityMetricType MetricType { get; set; }
}
public class DashboardFilter
{
public List DeviceIds { get; set; }
public DateTime Date { get; set; }
public bool IncludeAlerts { get; set; } = true;
}
public class ForecastFilter
{
public int DeviceId { get; set; }
public int DaysToForecast { get; set; }
public ForecastModel Model { get; set; }
public DateTime HistoricalDataStart { get; set; }
public DateTime HistoricalDataEnd { get; set; }
}
public class AnomalyFilter
{
public List DeviceIds { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public AnomalyType? Type { get; set; }
public AnomalySeverity? MinSeverity { get; set; }
}
// Enum types
public enum ProductionTrendDirection
{
Increasing,
Decreasing,
Stable,
Volatile
}
public enum ReportType
{
Daily,
Weekly,
Monthly,
Custom
}
public enum ReportMetadata
{
GeneratedAt,
GeneratedBy,
Period,
DeviceCount,
TotalProduction,
AverageEfficiency
}
public enum EquipmentUtilization
{
Low,
Medium,
High,
Optimal
}
public enum AlertType
{
DeviceOffline,
ProductionAnomaly,
QualityIssue,
MaintenanceRequired,
SystemError
}
public enum GroupBy
{
Device,
Program,
Date,
Hour
}
public enum QualityMetricType
{
DefectRate,
FirstPassYield,
ReworkRate,
ScrapRate
}
public enum ForecastModel
{
Linear,
ExponentialSmoothing,
Seasonal,
MovingAverage,
MachineLearning
}
public enum AnomalyType
{
ProductionDrop,
QualitySpike,
DowntimeSpike,
EfficiencyDrop,
RuntimeAnomaly
}
public enum AnomalySeverity
{
Low,
Medium,
High,
Critical
}
public enum AnomalyAction
{
Monitor,
Investigate,
Alert,
Shutdown
}
public enum EfficiencyMetric
{
Availability,
Performance,
Quality,
Oee,
All
}
}