/// <summary> 增加重启时间 </summary> public static DATES AddSchDates(this SCHEDULE schDate, DateTime startTime, DateTime pTime) { BaseKey findKey = null; DateTime nowTime = startTime; if (nowTime > pTime) { throw new ArgumentException("插入的时间不能小于案例的起始时间!"); } schDate.Foreach( l => { if (l is DATES) { DATES date = l as DATES; nowTime = date.DateTime; // 记录比当前时间小的 if (nowTime < pTime) { findKey = l; } } //else if (l is TSTEP) //{ // TSTEP step = l as TSTEP; // int dayCount = step.DataCount; // nowTime.AddDays(dayCount); // // 记录比当前时间小的 // if (nowTime <= pTime) // { // findKey = l; // } //} } ); DATES insertDate = new DATES("DATES"); insertDate.SetDateTime(pTime); // 没有找到 = 插入END前面 if (findKey == null) { END endKey = schDate.Find <END>(); schDate.InsertBefore(endKey, insertDate); } // 找到了 = 插入指定关键字前面 else { schDate.InsertAfter(findKey, insertDate); } return(insertDate); }
/// <summary> 查找指定重启时间 </summary> public static DATES FindDates(this EclipseData eclData, DateTime pTime) { List <DATES> Dates = eclData.Key.FindAll <DATES>(); DATES findDate = Dates.Find(l => l.DateTime.Date == pTime.Date); return(findDate); }
/// <summary> 转换成SimON格式的项 </summary> public WELLCTRL ConvertToSimON(OPT.Product.SimalorManager.Item item, DATES date, List <NAME> histNames) { WELLCTRL well = new WELLCTRL("WELLCTRL"); if (item is WCONPROD.ItemHY) { WCONPROD.ItemHY nIt = item as WCONPROD.ItemHY; #region - 转换历史数据 - NAME name = histNames.Find(l => l.WellName == nIt.jm0); if (name == null) { LogProviderHandler.Instance.OnRunLog("当前日期:" + date.DateTime + "井" + nIt.jm0 + "未找到对应的历史信息!"); return(null); } DAYS days = name.Find <DAYS>(); if (days == null) { days = new DAYS("DAYS"); name.Add(days); } DAYS.Item dayitem = new DAYS.Item(); dayitem.Time0 = date.DateTime; dayitem.Csl1 = nIt.rcsl4; dayitem.Cql2 = nIt.rcql5; dayitem.Cyl3 = nIt.rcyl3; dayitem.Cyl7 = nIt.liqutPro6; days.Items.Add(dayitem); #endregion #region - 转换数模数据 - well.WellName0 = nIt.jm0; well.Jcyblxz2 = nIt.rcsl4; // 产水 if (nIt.kzms2 == "WATER") { well.Jcyblxz2 = nIt.rcsl4; well.ProType = SimONProductType.WRAT; } if (nIt.kzms2 == "GRAT") { // 产气 well.Jcyblxz2 = nIt.rcql5; well.ProType = SimONProductType.GRAT; } if (nIt.kzms2 == "ORAT") { // 产油 well.Jcyblxz2 = nIt.rcyl3; well.ProType = SimONProductType.ORAT; } if (nIt.kzms2 == "LRAT") { // 产液 well.Jcyblxz2 = (nIt.rcyl3.ToDouble() + nIt.rcsl4.ToDouble()).ToString(); well.ProType = SimONProductType.LRAT; } #endregion } else if (item is WCONHIST.Item) { WCONHIST.Item nIt = item as WCONHIST.Item; #region - 转换历史数据 - NAME name = histNames.Find(l => l.WellName == nIt.wellName0); if (name == null) { LogProviderHandler.Instance.OnRunLog("当前日期:" + date.DateTime + "井" + nIt.wellName0 + "未找到对应的历史信息!"); return(well); } DAYS days = name.Find <DAYS>(); if (days == null) { days = new DAYS("DAYS"); name.Add(days); } DAYS.Item dayitem = new DAYS.Item(); dayitem.Time0 = date.DateTime; dayitem.Csl1 = nIt.waterPro4; dayitem.Cql2 = nIt.gasPro5; dayitem.Cyl3 = nIt.oilPro3; dayitem.Cyl7 = (nIt.waterPro4.ToDouble() + nIt.oilPro3.ToDouble()).ToString(); days.Items.Add(dayitem); #endregion #region - 转换数模数据 - well.WellName0 = nIt.wellName0; well.Jcyblxz2 = nIt.waterPro4; // 产水 if (nIt.ctrlModel2 == "WATER") { well.Jcyblxz2 = nIt.waterPro4; well.ProType = SimONProductType.WRAT; } if (nIt.ctrlModel2 == "GRAT") { // 产气 well.Jcyblxz2 = nIt.gasPro5; well.ProType = SimONProductType.GRAT; } if (nIt.ctrlModel2 == "ORAT") { // 产油 well.Jcyblxz2 = nIt.oilPro3; well.ProType = SimONProductType.ORAT; } if (nIt.ctrlModel2 == "LRAT") { // 产液 well.Jcyblxz2 = (nIt.waterPro4.ToDouble() + nIt.oilPro3.ToDouble()).ToString(); well.ProType = SimONProductType.LRAT; } #endregion } else if (item is WCONINJE.ItemHY) { WCONINJE.ItemHY nIt = item as WCONINJE.ItemHY; #region - 转换历史数据 - NAME name = histNames.Find(l => l.WellName == nIt.jm0); if (name == null) { LogProviderHandler.Instance.OnRunLog("当前日期:" + date.DateTime + "井" + nIt.jm0 + "未找到对应的历史信息!"); return(well); } DAYS days = name.Find <DAYS>(); if (days == null) { days = new DAYS("DAYS"); name.Add(days); } DAYS.Item dayitem = new DAYS.Item(); dayitem.Time0 = date.DateTime; if (nIt.zrltlx1 == "WATER") { dayitem.Zsl4 = nIt.rzrl4; } else { dayitem.Zql5 = nIt.rzrl4; } days.Items.Add(dayitem); #endregion #region - 转换数模数据 - well.WellName0 = nIt.jm0; if (nIt.zrltlx1 == "WATER") { //well.Jcyblxz2 = nIt.rzrl4; well.Jcyblxz2 = nIt.rzrl4; well.ProType = SimONProductType.WIR; } else { //well.Jcyblxz2 = nIt.rzrl4; //well.Jkkz1 = "6"; well.Jcyblxz2 = nIt.rzrl4; well.ProType = SimONProductType.GIR; } #endregion } else if (item is WCONINJH.Item) { WCONINJH.Item nIt = item as WCONINJH.Item; #region - 转换历史数据 - NAME name = histNames.Find(l => l.WellName == nIt.jm0); if (name == null) { LogProviderHandler.Instance.OnRunLog("当前日期:" + date.DateTime + "井" + nIt.jm0 + "未找到对应的历史信息!"); return(well); } DAYS days = name.Find <DAYS>(); if (days == null) { days = new DAYS("DAYS"); name.Add(days); } DAYS.Item dayitem = new DAYS.Item(); dayitem.Time0 = date.DateTime; if (nIt.zrltlx1 == "WATER") { dayitem.Zsl4 = nIt.rzrl3; } else { dayitem.Zql5 = nIt.rzrl3; } days.Items.Add(dayitem); #endregion #region - 转换数模数据 - well.WellName0 = nIt.jm0; if (nIt.zrltlx1 == "WATER") { well.Jcyblxz2 = nIt.rzrl3; //well.Jkkz1 = "7"; well.ProType = SimONProductType.WIBHP; } else { well.Jcyblxz2 = nIt.rzrl3; //well.Jkkz1 = "8"; well.ProType = SimONProductType.GIBHP; } #endregion } return(well); }
/// <summary> 将Eclipse生产数据转换成SimON生产数据 </summary> public SCHEDULE ConvertToSimON(SCHEDULE sch, WELL location, DateTime startTime, BaseFile history) { // Todo :保存SCH SCHEDULE schedule = new SCHEDULE("SCHEDULE"); List <string> wellNames = new List <string>(); List <WELSPECS> ws = sch.FindAll <WELSPECS>(); // Todo :查找所有井名 ws.ForEach(l => wellNames.AddRange(l.Items.Select(k => k.jm0))); List <NAME> histNames = new List <NAME>(); // Todo :初始化名称 生产_historyproduction.dat wellNames.ForEach(l => histNames.Add(new NAME("NAME") { WellName = l })); histNames.ForEach(l => history.Key.Add(l)); // Todo :初始化完井WELL数据 List <NAME> names = new List <NAME>(); wellNames.ForEach(l => names.Add(new NAME("NAME") { WellName = l })); names.ForEach(l => location.Add(l)); List <DATES> ds = sch.FindAll <DATES>(); string format = "井名:{0} ({1},{2})"; // Todo :添加起始信息到时间步 DATES start = new DATES("DATES", startTime); sch.DeleteAll <DATES>(); start.AddRange <BaseKey>(sch.Keys); ds.Insert(0, start); List <PERF> comAllTemp = new List <PERF>(); foreach (DATES d in ds) { // Todo :对缓存中完井井名去重复取最后一条 var distincts = comAllTemp.GroupBy(l => l.WellName + l.I0 + l.J1 + l.K12).ToList(); comAllTemp.Clear(); foreach (var item in distincts) { comAllTemp.Add(item.Last()); } // 创建SimON日期 TIME time = new TIME("TIME"); time.Date = d.DateTime; schedule.Add(time); var wconprod = d.FindAll <WCONPROD>(); var wconhist = d.FindAll <WCONHIST>(); var wconinje = d.FindAll <WCONINJE>(); var wconinjh = d.FindAll <WCONINJH>(); // 完井数据(考虑到排序) List <BaseKey> compdats = d.FindAll <BaseKey>(l => l is COMPDAT || l is WELOPEN); List <WPIMULT> wpimult = d.FindAll <WPIMULT>(); List <WELOPEN> welopen = d.FindAll <WELOPEN>(); #region - 添加没有生产信息的完井 - // 添加完井数据 foreach (BaseKey c in compdats) { if (c is COMPDAT) { COMPDAT com = c as COMPDAT; foreach (COMPDAT.Item citem in com.Items) { // Todo :过滤有生产数据的,用后面方法处理 if (wconprod.Exists(l => l.Items.Exists(k => k.jm0 == citem.jm0))) { continue; } if (wconhist.Exists(l => l.Items.Exists(k => k.wellName0 == citem.jm0))) { continue; } if (wconinje.Exists(l => l.Items.Exists(k => k.jm0 == citem.jm0))) { continue; } if (wconinjh.Exists(l => l.Items.Exists(k => k.jm0 == citem.jm0))) { continue; } WELLCTRL well = time.Find <WELLCTRL>(l => l.WellName0 == citem.jm0); if (well == null) { // Todo :创建一个空的生产信息 well = new WELLCTRL("WELLCTRL"); well.ProType = SimONProductType.NA; well.WellName0 = citem.jm0; time.Add(well); } NAME name = names.Find(l => l.WellName == well.WellName0); #region - SCh数据 - PERF perf = new PERF("PERF"); perf.WellName = well.WellName0; perf.I0 = citem.i1; perf.J1 = citem.j2; perf.K12 = citem.swg3; perf.K23 = citem.xwg4; perf.Kgbs4 = citem.kgbz5; perf.Jzs6 = citem.ljyz7; perf.WjfxX7 = citem.skfx12 == "X" ? "DX" : "0"; perf.WjfxY8 = citem.skfx12 == "Y" ? "DY" : "0"; perf.WjfxZ9 = citem.skfx12 == "Z" ? "DZ" : "0"; perf.Bp10 = citem.bpxs10; // Todo :查找井指数乘子 foreach (WPIMULT wp in wpimult) { var v = wp.Items.Find(l => l.jm0 == well.WellName0); if (v != null) { perf.Jzscz5 = v.jzscz1; break; } } // Todo :增加前先删除存在的重复数据 well.DeleteAll <PERF>(l => l.I0 == perf.I0 && l.J1 == perf.J1 && l.K12 == perf.K12); well.Add(perf); #endregion #region - WELL数据 - NAME.Item nameItem = new NAME.Item(); nameItem.i0 = citem.i1; nameItem.j1 = citem.j2; nameItem.k12 = citem.swg3; nameItem.k23 = citem.xwg4; nameItem.kgbz4 = citem.kgbz5; //nameItem.wi5 = "NA";// v.Value.skin.Value.Value.ToString(); //nameItem.dx6 = v.Value.wellIndex.Value.GetValue(v.Value.wellIndex.GetUnitValue(_ecl)).ToString(); //nameItem.dy7 = v.Value.wellDirection.Value.Value == "X" ? "0" : v.Value.wellDirection.Value.Value == "Y" ? "1" : "2"; nameItem.bpxs9 = citem.bpxs10; nameItem.jj10 = (citem.jtnj8.ToDouble() / 2).ToString(); name.Items.Add(nameItem); #endregion comAllTemp.Add(perf); } } else if (c is WELOPEN) { WELOPEN wp = c as WELOPEN; foreach (var v in wp.Items) { // Todo :过滤有生产数据的,用后面方法处理 if (wconprod.Exists(l => l.Items.Exists(k => k.jm0 == v.jm0))) { continue; } if (wconhist.Exists(l => l.Items.Exists(k => k.wellName0 == v.jm0))) { continue; } if (wconinje.Exists(l => l.Items.Exists(k => k.jm0 == v.jm0))) { continue; } if (wconinjh.Exists(l => l.Items.Exists(k => k.jm0 == v.jm0))) { continue; } // WELOPEN //'G13' 'SHUT' 0 0 0 2 * / // / // Todo :查找之前所有完井 var coms = comAllTemp.FindAll(l => l.WellName == v.jm0); Predicate <PERF> match = l => true; // Todo :0 或 *表示默认值全都取 if (v.i2 != KeyConfiger.EclipseDefalt && v.i2 != "0") { match += l => l.I0 == v.i2; } if (v.j3 != KeyConfiger.EclipseDefalt && v.j3 != "0") { match += l => l.J1 == v.j3; } if (v.k4 != KeyConfiger.EclipseDefalt && v.k4 != "0") { match += l => l.K12 == v.k4; } var findComs = coms.FindAll(match); WELLCTRL well = time.Find <WELLCTRL>(l => l.WellName0 == v.jm0); if (well == null) { // Todo :创建一个空的生产信息 well = new WELLCTRL("WELLCTRL"); well.ProType = SimONProductType.NA; well.WellName0 = v.jm0; time.Add(well); } // Todo :增加WELOPEN控制的完井 foreach (var fitem in findComs) { PERF perf = fitem.Copy(); perf.Kgbs4 = v.jz1; // Todo :增加前先删除存在的重复数据 well.DeleteAll <PERF>(l => l.I0 == fitem.I0 && l.J1 == fitem.J1 && l.K12 == fitem.K12); well.Add(perf); } } } //this.ConvertCompadat(well, names, compdats, wpimult, comAllTemp); } #endregion foreach (var item in wconprod) { foreach (WCONPROD.ItemHY it in item.Items) { // 生产数据 WELLCTRL well = new WELLCTRL("WELLCTRL"); well.WellName0 = it.jm0; well = this.ConvertToSimON(it, d, histNames); if (well != null) { this.ConvertCompadat(well, names, compdats, wpimult, comAllTemp); time.Add(well); } } } foreach (var item in wconhist) { foreach (WCONHIST.Item it in item.Items) { // 生产数据 WELLCTRL well = new WELLCTRL("WELLCTRL"); well.WellName0 = it.wellName0; well = this.ConvertToSimON(it, d, histNames); this.ConvertCompadat(well, names, compdats, wpimult, comAllTemp); time.Add(well); } } foreach (var item in wconinje) { foreach (WCONINJE.ItemHY it in item.Items) { // 生产数据 WELLCTRL well = new WELLCTRL("WELLCTRL"); well.WellName0 = it.jm0; well = this.ConvertToSimON(it, d, histNames); this.ConvertCompadat(well, names, compdats, wpimult, comAllTemp); time.Add(well); } } foreach (var item in wconinjh) { foreach (WCONINJH.Item it in item.Items) { // 生产数据 WELLCTRL well = new WELLCTRL("WELLCTRL"); well.WellName0 = it.jm0; well = this.ConvertToSimON(it, d, histNames); this.ConvertCompadat(well, names, compdats, wpimult, comAllTemp); time.Add(well); } } //// Todo :将之前的完井信息都加入到缓存中 //foreach (var item in compdats) //{ // comAllTemp.AddRange(item.Items); //} } return(schedule); }
internal virtual bool Evaluate(GameEvent evnt) { if (evnt.Name != eventName) { return(false); } var parameters = evnt.parameters.AsDictionary(); var stack = new Stack <object>(); foreach (var token in condition) { if (token.ContainsKey("o")) { string op = (string)token["o"]; op = op.ToLower(); object right = stack.Pop(); object left = stack.Pop(); try{ if (right is bool) { if (left is bool) { stack.Push(BOOLS[op]((bool)left, (bool)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is long) { if (left is int) { stack.Push(LONGS[op]((int)left, (long)right)); } else if (left is long) { stack.Push(LONGS[op]((long)left, (long)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is double) { if (left is float) { stack.Push(DOUBLES[op]((float)left, (double)right)); } else if (left is double) { stack.Push(DOUBLES[op]((double)left, (double)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is string) { if (left is string) { stack.Push(STRINGS[op]((string)left, (string)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else if (right is DateTime) { if (left is string) { stack.Push(DATES[op]( DateTime.ParseExact( (string)left, Settings.EVENT_TIMESTAMP_FORMAT, System.Globalization.CultureInfo.InvariantCulture), (DateTime)right)); } else { Logger.LogWarning( left + " and " + right + " have mismatched types"); return(false); } } else { Logger.LogWarning("Unexpected type for " + right); return(false); } } catch (KeyNotFoundException) { Logger.LogWarning(string.Format( "Failed to find operation {0} for {1} and {2}", op, left, right)); return(false); } catch (FormatException) { Logger.LogWarning("Failed converting parameter " + left + " to DateTime"); return(false); } } else if (token.ContainsKey("p")) { var param = (string)token["p"]; if (parameters.ContainsKey(param)) { stack.Push(parameters[param]); } else { Logger.LogWarning("Failed to find " + param + " in event params"); return(false); } } else if (token.ContainsKey("b")) { stack.Push((bool)token["b"]); } else if (token.ContainsKey("i")) { // ints are double precision in JSON stack.Push((long)token["i"]); } else if (token.ContainsKey("f")) { var value = token["f"]; // serialiser inserts a whole double as a long if (value is long) { stack.Push((double)(long)token["f"]); } else { // floats are double precision in JSON stack.Push((double)token["f"]); } } else if (token.ContainsKey("s")) { stack.Push((string)token["s"]); } else if (token.ContainsKey("t")) { try{ stack.Push(DateTime.Parse((string)token["t"], null)); } catch (FormatException) { Logger.LogWarning("Failed converting " + token["t"] + " to DateTime"); return(false); } } else { stack.Push(token); } } var result = stack.Count == 0 || (stack.Pop() as bool? ?? false); if (result) { // Default to true if no conditions exist bool triggerConditionsReached = campaignTriggerConditions.Count == 0; // Only one condition needs to be true to flip conditions to true this.executionCountManager.incrementExecutionCount(this.variantId); foreach (TriggerCondition campaignTriggerCondition in campaignTriggerConditions) { if (campaignTriggerCondition.CanExecute()) { triggerConditionsReached = true; } } // If none reached return false if (!triggerConditionsReached) { return(false); } if (limit != -1 && runs >= limit) { return(false); } runs++; var eventTriggeredActionEvent = new GameEvent("ddnaEventTriggeredAction") .AddParam("ddnaEventTriggeredCampaignID", campaignId) .AddParam("ddnaEventTriggeredCampaignPriority", priority) .AddParam("ddnaEventTriggeredVariantID", variantId) .AddParam("ddnaEventTriggeredActionType", GetAction()) .AddParam("ddnaEventTriggeredSessionCount", runs); if (campaignName != null) { eventTriggeredActionEvent.AddParam("ddnaEventTriggeredCampaignName", campaignName); } if (variantName != null) { eventTriggeredActionEvent.AddParam("ddnaEventTriggeredVariantName", variantName); } ddna.RecordEvent(eventTriggeredActionEvent); } return(result); }