public Level1FlightRecord FromFlightRecordEntityToLevel1FlightRecord(FlightRawData data)
        {
            Level1FlightRecord record = new Level1FlightRecord()
            {
                ParameterID = data.ParameterID,
                FlightSecond = data.Second,
                AvgValue = data.Values.Average(),
                MaxValue = data.Values.Max(),
                MinValue = data.Values.Min(),
                Sum = Convert.ToDecimal(data.Values.Sum()),
                ValueCount = data.Values.Length
            };

            if (data.Values.Distinct().Count() == 1 //只有一个值,多个是重复
                && record.AvgValue == record.MaxValue
                && record.MaxValue == record.MinValue
                && record.AvgValue == record.MinValue) //三个汇总值全等
            {//可以视为能够精简,只保留第一个值
                record.Values = new float[] { data.Values[0] };
            }
            else
            {//保留全部值
                record.Values = data.Values;
            }

            return record;
        }
        public FlightRawData FromLevel1FlightRecordToFlightRawData(Level1FlightRecord record)
        {
            FlightRawData entity = new FlightRawData()
            {
                ParameterID = record.ParameterID,
                Second = record.FlightSecond,
            };

            if (record.ValueCount == record.Values.Length)
            {
                entity.Values = record.Values;
            }
            else
            {//如果不等,说明已经经过精简,要补充值
                float prevValue = 0;
                List<float> values = new List<float>();

                for (int i = 0; i < record.ValueCount; i++)
                {
                    if (i < record.Values.Length)
                    {
                        values.Add(record.Values[i]);
                        prevValue = record.Values[i];
                    }
                    else
                    {
                        values.Add(prevValue);
                    }
                }

                entity.Values = values.ToArray();
            }

            return entity;
        }
        public IEnumerable<FlightRawData> ToRawDatas()
        {
            if (this.StartSecond < this.EndSecond && this.Values != null && this.Values.Length > 0)
            {
                List<FlightRawData> dts = new List<FlightRawData>();
                int factor = this.Values.Length / (this.EndSecond - this.StartSecond);
                
                for (int i = this.StartSecond; i < this.EndSecond; i++)
                {
                    FlightRawData rd = new FlightRawData() { ParameterID = this.ParameterID, Second = i };
                    var values = this.Values.Skip((i - this.StartSecond) * factor).Take(factor);
                    rd.Values = values.ToArray();
                    dts.Add(rd);
                }

                return dts;
            }
            else
            {
                FlightRawData dt = new FlightRawData()
                {
                    ParameterID = this.ParameterID,
                    Second = this.StartSecond,
                    Values = this.Values
                };
                return new FlightRawData[] { dt };
            }
        }
 public static Level1FlightRecord FromFlightRawDataToLevel1FlightRecord(FlightRawData entity)
 {
     IFlightDataEntityTransformStrategy strategy = GetStrategy();
     return strategy.FromFlightRecordEntityToLevel1FlightRecord(entity);
 }
        public string InsertRawDataBatch(RawDataBatch batchData)
        {
            if (!this.IsValidAircraftInfo(batchData))
                return "缺少机型或架次信息。";
            if (batchData.Datas == null || batchData.Datas.Length <= 0)
                return "无数据输入。";

            MongoServer mongoServer = this.GetMongoServer();
            if (mongoServer != null)
            {
                MongoDatabase database = mongoServer.GetDatabase(batchData.Flight.Aircraft.AircraftModel.ModelName);
                if (database != null)
                {
                    MongoCollection<Level1FlightRecord> modelCollection
                        = database.GetCollection<Level1FlightRecord>(
                        AircraftMongoDb.COLLECTION_FLIGHT_RECORD_LEVEL1 +
                        batchData.Flight.FlightID);

                    List<Level1FlightRecord> level1Records = new List<Level1FlightRecord>();

                    foreach (var one in batchData.Datas)
                    {
                        //数据精简
                        FlightRawData entity = new FlightRawData()
                        {
                            ParameterID = one.ParameterID,
                            Values = one.Values,
                            Second = batchData.Second
                        };
                        //DEBUG
                        //level1Records.Add(entity.ToLevel1FlightRecord());
                    }

                    modelCollection.InsertBatch(level1Records);
                }
            }

            return string.Empty;
        }