/// <summary> /// 添加判据记录,这是记录,需要重新定位数据库和Collection /// </summary> /// <param name="flight"></param> /// <param name="records"></param> /// <returns></returns> internal string AddDecisionRecordsBatch(FlightDataEntities.Flight flight, FlightDataEntities.Decisions.DecisionRecord[] records) { if (flight == null || records == null || records.Length == 0) return string.Empty; using (AircraftMongoDbDal dal = new AircraftMongoDbDal()) { MongoServer mongoServer = dal.GetMongoServer(); //不用判断是否为空,必须不能为空才能继续,否则内部要抛异常 try {//此方法操作的记录为跟架次密切相关,需要拆分存储的记录,最好在DAL里面去处理表名构建逻辑 MongoDatabase database = dal.GetMongoDatabaseByAircraftModel(mongoServer, flight.Aircraft.AircraftModel); if (database != null) { MongoCollection<FlightDataEntities.Decisions.DecisionRecord> modelCollection = dal.GetDecisionRecordMongoCollectionByFlight(database, flight); modelCollection.InsertBatch(records); } } catch (Exception e) { LogHelper.Error("AddDecisionRecordsBatch", e); return e.Message; } } return string.Empty; }
/// <summary> /// 添加或更新一个架次信息 /// 架次是实体,用Common库,Collection也可以直接取 /// </summary> /// <param name="flight"></param> /// <returns></returns> internal FlightDataEntities.Flight AddOrReplaceFlight( FlightDataEntities.Flight flight) { Flight flightResult = null; using (AircraftMongoDbDal dal = new AircraftMongoDbDal()) { MongoServer mongoServer = dal.GetMongoServer(); //不用判断是否为空,必须不能为空才能继续,否则内部要抛异常 try { MongoDatabase database = dal.GetMongoDatabaseCommon(mongoServer); //这是实体,直接取Common吧 //dal.GetMongoDatabaseByAircraftModel(mongoServer, flight.Aircraft.AircraftModel); if (database != null) { MongoCollection<Flight> modelCollection = database.GetCollection<Flight>(AircraftMongoDb.COLLECTION_FLIGHT); flightResult = InsertOrUpdateByFlightID(flight, flightResult, modelCollection); } } catch (Exception e) { LogHelper.Error("AddOrReplaceFlight", e); flightResult = null; } } return flightResult; }
internal string AddFlightConditionDecisionRecordsBatch(Flight flight, FlightDataEntities.Decisions.DecisionRecord[] records) { using (AircraftMongoDbDal dal = new AircraftMongoDbDal()) { MongoServer mongoServer = dal.GetMongoServer(); //不用判断是否为空,必须不能为空才能继续,否则内部要抛异常 try {//此方法操作的记录为跟架次密切相关,但肯定LevelTopRecord需要包含趋势分析等信息, //建议不要分表,存放在Common里面 MongoDatabase database = dal.GetMongoDatabaseByAircraftModel(mongoServer, flight.Aircraft.AircraftModel); if (database != null) { MongoCollection<FlightDataEntities.Decisions.DecisionRecord> modelCollection1 = dal.GetFlightConditionDecisionRecordMongoCollectionByFlight(database, flight); IMongoQuery q1 = Query.EQ("FlightID", new MongoDB.Bson.BsonString(flight.FlightID)); modelCollection1.Remove(q1); modelCollection1.InsertBatch(records); } } catch (Exception e) { LogHelper.Error("AddFlightConditionDecisionRecordsBatch", e); return e.Message; } } return string.Empty; }
public string AddFlightConditionDecisionRecordsBatch(Flight flight, FlightDataEntities.Decisions.DecisionRecord[] records) { try { LogHelper.Info("DataInputService.AddFlightConditionDecisionRecordsBatch Requested.", null); DataInputServiceBll bll = new DataInputServiceBll(); return bll.AddFlightConditionDecisionRecordsBatch(flight, records); } catch (Exception ex) { LogHelper.Error("AddFlightConditionDecisionRecordsBatch", ex); return ex.Message; } }
public FlightDataEntities.Flight AddOrReplaceFlight(FlightDataEntities.Flight flight) { try { LogHelper.Info("DataInputService.AddOrReplaceFlight Requested.", null); DataInputServiceBll bll = new DataInputServiceBll(); return bll.AddOrReplaceFlight(flight); } catch (Exception ex) { LogHelper.Error("AddOrReplaceFlight", ex); return null; } }
public string DeleteExistsData(FlightDataEntities.Flight flight) { try { LogHelper.Info("DataInputService.DeleteExistsData Requested.", null); DataInputServiceBll bll = new DataInputServiceBll(); return bll.DeleteExistsData(flight); } catch (Exception ex) { LogHelper.Error("DeleteExistsData", ex); return ex.Message; } }
public string AddLevelTopFlightRecords(FlightDataEntities.Flight flight, FlightDataEntities.LevelTopFlightRecord[] topRecords) { try { LogHelper.Info("DataInputService.AddLevelTopFlightRecords Requested.", null); DataInputServiceBll bll = new DataInputServiceBll(); return bll.AddLevelTopFlightRecords(flight, topRecords); } catch (Exception ex) { LogHelper.Error("AddLevelTopFlightRecords", ex); return ex.Message; } }
public string AddOneParameterValue(FlightDataEntities.Flight flight, string parameterID, FlightDataEntities.Level1FlightRecord[] reducedRecords) { try { LogHelper.Info("DataInputService.AddOneParameterValue Requested.", null); DataInputServiceBll bll = new DataInputServiceBll(); return bll.AddOneParameterValue(flight, parameterID, reducedRecords); } catch (Exception ex) { LogHelper.Error("AddOneParameterValue", ex); return ex.Message; } }
/// <summary> /// 根据FlightID插入或更新一个架次信息,插入的是实体,使用Common库 /// </summary> /// <param name="flight"></param> /// <param name="flightResult">flightResult才是真正要返回的结果,因为flight如果是需要新增的,则不会有MongoDB需要的ObjectId</param> /// <param name="modelCollection"></param> /// <returns></returns> private static Flight InsertOrUpdateByFlightID( FlightDataEntities.Flight flight, Flight flightResult, MongoCollection<Flight> modelCollection) { try { IMongoQuery q1 = Query.EQ("FlightID", new MongoDB.Bson.BsonString(flight.FlightID)); var cursor = modelCollection.Find(q1); //第一次查询,是判断是否需要UPDATE if (cursor != null && cursor.Count() > 0) { foreach (var value in cursor.AsEnumerable()) { value.FlightName = flight.FlightName; value.Aircraft = flight.Aircraft; value.EndSecond = flight.EndSecond; value.StartSecond = flight.StartSecond; value.FlightDate = flight.FlightDate; modelCollection.Save(value); flightResult = value; } } else {//如果INSERT,就必须插入之后才有ObjectId,需要返回带有ObjectId的对象(不单单只考虑WCF返回没带有ObjectId的情况) modelCollection.Insert(flight); var cursor2 = modelCollection.Find(q1); if (cursor2 != null && cursor2.Count() > 0) { flightResult = cursor2.First(); } else flightResult = null; } } catch (Exception e) { LogHelper.Error("InsertOrUpdateByFlightID", e); flightResult = null; } return flightResult; }
public string AddOrUpdateAircraftModel(FlightDataEntities.AircraftModel aircraftModel) { if (aircraftModel == null) return "没有机型。"; MongoServer mongoServer = this.GetMongoServer(); if (mongoServer != null) { MongoDatabase database = mongoServer.GetDatabase(AircraftMongoDb.DATABASE_COMMON); if (database != null) { MongoCollection<AircraftModel> modelCollection = database.GetCollection<AircraftModel>(AircraftMongoDb.COLLECTION_AIRCRAFT_MODEL); IQueryable<AircraftModel> models = modelCollection.AsQueryable<AircraftModel>(); var result = from one in models where one.ModelName == aircraftModel.ModelName select one; if (result != null && result.Count() > 0) { foreach (var oneModel in result) {//所有Property复制 oneModel.LastUsed = aircraftModel.LastUsed; oneModel.Caption = aircraftModel.Caption; modelCollection.Save(oneModel); } } else { modelCollection.Insert(aircraftModel); } return string.Empty; } } return string.Format( "No MongoServer {0} finded, or no MongoCollection {1} finded.", AircraftMongoDb.DATABASE_COMMON, AircraftMongoDb.COLLECTION_AIRCRAFT_MODEL); }
internal string AddOrReplaceFlightGlobeDataBatch(string flightId, AircraftModel model, int startIndex, int endIndex, FlightDataEntities.GlobeData[] globedatas) { using (AircraftMongoDbDal dal = new AircraftMongoDbDal()) { MongoServer mongoServer = dal.GetMongoServer(); //不用判断是否为空,必须不能为空才能继续,否则内部要抛异常 try {//此方法操作的记录为跟架次密切相关,但肯定LevelTopRecord需要包含趋势分析等信息, //建议不要分表,存放在Common里面 MongoDatabase database = dal.GetMongoDatabaseByAircraftModel(mongoServer, model); if (database != null) { MongoCollection<FlightDataEntities.GlobeData> modelCollection1 = dal.GetFlightGlobeDataMongoCollectionByFlight(database, flightId); IMongoQuery q1 = Query.EQ("FlightID", new MongoDB.Bson.BsonString(flightId)); IMongoQuery q2 = Query.GTE("Index", new MongoDB.Bson.BsonInt32(startIndex)); IMongoQuery q3 = Query.LTE("Index", new MongoDB.Bson.BsonInt32(endIndex)); IMongoQuery q4 = Query.EQ("AircraftModelName", new MongoDB.Bson.BsonString(model.ModelName)); IMongoQuery query = Query.And(q1, q2, q3, q4); modelCollection1.Remove(query); modelCollection1.InsertBatch(globedatas); } } catch (Exception e) { LogHelper.Error("AddOrReplaceFlightGlobeDataBatch", e); return e.Message; } } return string.Empty; }
/// <summary> /// 添加Level1、Level2数据点记录,这是记录,需要重新定位数据库和Collection /// </summary> /// <param name="flight"></param> /// <param name="parameterID"></param> /// <param name="reducedRecords"></param> /// <param name="level2Record"></param> /// <returns></returns> internal string AddOneParameterValue(FlightDataEntities.Flight flight, string parameterID, FlightDataEntities.Level1FlightRecord[] reducedRecords) { using (AircraftMongoDbDal dal = new AircraftMongoDbDal()) { MongoServer mongoServer = dal.GetMongoServer(); //不用判断是否为空,必须不能为空才能继续,否则内部要抛异常 try {//此方法操作的记录为跟架次密切相关,需要拆分存储的记录,最好在DAL里面去处理表名构建逻辑 MongoDatabase database = dal.GetMongoDatabaseByAircraftModel(mongoServer, flight.Aircraft.AircraftModel); if (database != null) { MongoCollection<FlightDataEntities.Level1FlightRecord> modelCollection1 = dal.GetLevel1FlightRecordMongoCollectionByFlight(database, flight); modelCollection1.InsertBatch(reducedRecords); //MongoCollection<FlightDataEntities.Level2FlightRecord> modelCollection2 // = dal.GetLevel2FlightRecordMongoCollectionByFlight(database, flight); //modelCollection2.InsertBatch(level2Records); } } catch (Exception e) { LogHelper.Error("AddOneParameterValue", e); return e.Message; } } return string.Empty; }
public string AddOrReplaceFlightGlobeDataBatch(string flightId, AircraftModel model, int startIndex, int endIndex, FlightDataEntities.GlobeData[] globedatas) { try { LogHelper.Info("DataInputService.AddOrReplaceFlightGlobeDataBatch Requested.", null); DataInputServiceBll bll = new DataInputServiceBll(); return bll.AddOrReplaceFlightGlobeDataBatch(flightId, model, startIndex, endIndex, globedatas); } catch (Exception ex) { LogHelper.Error("AddOrReplaceFlightGlobeDataBatch", ex); return ex.Message; } }
/// <summary> /// 删除的是实体,需要使用Common数据库。后面相关记录则根据分表原则找到数据库和Collection /// </summary> /// <param name="flight"></param> /// <returns></returns> internal string DeleteExistsData(FlightDataEntities.Flight flight) { using (AircraftMongoDbDal dal = new AircraftMongoDbDal()) { MongoServer mongoServer = dal.GetMongoServer(); //不用判断是否为空,必须不能为空才能继续,否则内部要抛异常 try { MongoDatabase database = mongoServer.GetDatabase(AircraftMongoDb.DATABASE_COMMON); if (database != null) { //不能删除架次 //MongoCollection<Flight> modelCollection // = database.GetCollection<Flight>(AircraftMongoDb.COLLECTION_FLIGHT); ////删除架次 IMongoQuery q1 = Query.EQ("FlightID", new MongoDB.Bson.BsonString(flight.FlightID)); //var writeResult = modelCollection.Remove(q1); //TODO:删除相关记录 this.RemoveRelatedRecords(mongoServer, flight, dal, q1); } } catch (Exception e) { LogHelper.Error("DeleteExistsData", e); return e.Message; } } return string.Empty; }
private static BsonValue GetParameterValue(FlightDataEntities.FlightParameter flightParameter, string value) { return null; //return DataTypeConverter.ToBsonType(value, flightParameter.ParameterDataType); }
private static void FormatMaxMinValueOutput(Dictionary<int, Dictionary<string, float[]>> valuesMap, FlightDataEntities.FlightParameter[] parameters) { var keys = from onekey in parameters select onekey.ParameterID; Dictionary<string, MaxHelper> maxHelperMap = new Dictionary<string, MaxHelper>(); Dictionary<string, MinHelper> minHelperMap = new Dictionary<string, MinHelper>(); foreach (var key in (from k in valuesMap.Keys orderby k ascending select k).Take(valuesMap.Keys.Count - 1)) { var oneSecMap = valuesMap[key]; foreach (var one in oneSecMap.Keys) { if (maxHelperMap.ContainsKey(one)) { MaxHelper helper = maxHelperMap[one]; float max = oneSecMap[one].Max(); if (max > helper.Value) { helper.Value = max; helper.Second = key; maxHelperMap[one] = helper; } } else { MaxHelper helper = new MaxHelper() { ParameterID = one, Second = key, Value = oneSecMap[one].Max() }; maxHelperMap.Add(one, helper); } if (minHelperMap.ContainsKey(one)) { MinHelper helper = minHelperMap[one]; float min = oneSecMap[one].Min(); if (min < helper.Value) { helper.Value = min; helper.Second = key; minHelperMap[one] = helper; } } else { MinHelper helper = new MinHelper() { ParameterID = one, Second = key, Value = oneSecMap[one].Min() }; minHelperMap.Add(one, helper); } } } string headers = string.Empty; //foreach (string kk in keys) //{ // headers += kk; //headers += "\t"; headers += "MaxValue"; headers += "\t"; headers += "Second"; headers += "\t"; headers += "MinValue"; headers += "\t"; headers += "Second"; headers += "\t"; //} System.Diagnostics.Debug.WriteLine(string.Empty); System.Diagnostics.Debug.WriteLine("MaxMin Value Report_____________________________________________________________________________________________________________________________________"); System.Diagnostics.Debug.WriteLine(string.Empty); string header = string.Format("ParameterID\t{0}", headers); System.Diagnostics.Debug.WriteLine(header); foreach (string paramID in keys) { StringBuilder output = new StringBuilder(); output.Append(paramID); output.Append("\t"); var max = maxHelperMap[paramID]; output.Append(max.Value); output.Append("\t"); output.Append(max.Second); output.Append("\t"); var min = minHelperMap[paramID]; output.Append(min.Value); output.Append("\t"); output.Append(min.Second); output.Append("\t"); System.Diagnostics.Debug.WriteLine(output.ToString()); } }
private static void FormatOutput(Dictionary<int, Dictionary<string, float[]>> valuesMap, FlightDataEntities.FlightParameter[] parameters) { var keys = from onekey in parameters select onekey.ParameterID; string headers = string.Empty; foreach (string kk in keys) { headers += kk; headers += "\t"; } System.Diagnostics.Debug.WriteLine(string.Empty); string header = string.Format("Secs\tIndex\t{0}", headers); System.Diagnostics.Debug.WriteLine(header); foreach (var key in (from k in valuesMap.Keys orderby k ascending select k)) { string line = ToOneLine(key, valuesMap[key], keys); System.Diagnostics.Debug.Write(line); } }