public void CheckTrackSum(uint trackId) { StockSum sum = StockSumList.Find(c => c.track_id == trackId); uint goodsid = StockList.Find(c => c.track_id == trackId && c.goods_id != 0)?.goods_id ?? 0; if (sum == null) { Track track = PubMaster.Track.GetTrack(trackId); sum = new StockSum() { track_id = trackId, goods_id = goodsid, produce_time = StockList.Find(c => trackId == c.track_id).produce_time, area = track.area, track_type = track.type }; StockSumList.Add(sum); SortSumList(); } if (goodsid > 0) { Goods goods = GoodsList.Find(c => c.id == goodsid); if (goods != null) { sum.count = (uint)StockList.Count(c => c.track_id == trackId); sum.stack = sum.count * goods.stack; sum.pieces = sum.stack * goods.pieces; SendSumMsg(sum, ActionTypeE.Update); } } }
private List <StockTotals> GetTotals() { List <StockTotals> result = new List <StockTotals>(); foreach (StockType stockType in Enum.GetValues(typeof(StockType))) { result.Add(new StockTotals() { StockType = stockType.ToString(), TotalMarketValue = StockList.Where(x => x.StockType == stockType).Sum(x => x.MarketValue), TotalStockWeight = StockList.Where(x => x.StockType == stockType).Sum(x => x.StockWeight), TotalNumber = StockList.Count(x => x.StockType == stockType) }); } result.Add(new StockTotals() { StockType = "All", TotalMarketValue = StockList.Sum(x => x.MarketValue), TotalStockWeight = StockList.Sum(x => x.StockWeight), TotalNumber = StockList.Count }); return(result); }
/// <summary> /// /// </summary> /// <param name="give_track_id"></param> /// <returns></returns> public bool IsTrackReachMinStackCount(uint goodid, uint trackid) { Goods goods = GetGoods(goodid); if (goods != null) { return(goods.minstack <= StockList.Count(c => c.track_id == trackid)); } return(true); }
/// <summary> /// 更新库存的Pos /// </summary> /// <param name="stock"></param> public void UpdateTrackPos(Stock stock) { short storecount = (short)StockList.Count(c => c.track_id == stock.track_id && c.id != stock.id); stock.pos = storecount; stock.PosType = StockPosE.其他; if (storecount == 0) { stock.PosType = StockPosE.顶部; } }
/// <summary> /// Populate metabolizable energy use array /// Note: these are an* ME* partition /// </summary> /// <param name="model">The animal model</param> /// <param name="energyValues">The energy use returned</param> public static void MakeEnergyUse(StockList model, ref EnergyUse[] energyValues) { double ME_Metab; double ME_MoveGraze; int idx; for (idx = 1; idx <= model.Count(); idx++) { AnimalGroup group = model.At(idx); ME_Metab = group.AnimalState.EnergyUse.Metab / group.AnimalState.Efficiency.Maint; ME_MoveGraze = group.AnimalState.EnergyUse.Maint - ME_Metab - group.AnimalState.EnergyUse.Cold; energyValues[idx].MaintBase = ME_Metab; energyValues[idx].MaintMoveGraze = ME_MoveGraze; // Separating E(graze) and E(move) requires work in AnimGRP.pas... energyValues[idx].MaintCold = group.AnimalState.EnergyUse.Cold; energyValues[idx].Conceptus = group.AnimalState.EnergyUse.Preg; energyValues[idx].Lactation = group.AnimalState.EnergyUse.Lact; energyValues[idx].Fleece = group.AnimalState.EnergyUse.Wool / group.AnimalState.Efficiency.Gain; energyValues[idx].Gain = group.AnimalState.EnergyUse.Gain / group.AnimalState.Efficiency.Gain; } }
/// <summary> /// Fill the double[] with values from the model. /// </summary> /// <param name="model">The animal model</param> /// <param name="varCode">The variable code</param> /// <param name="useYoung">For young animals</param> /// <param name="useAll">For all groups</param> /// <param name="useTag">Use the tag number</param> /// <param name="arrayValues">The returned double array</param> /// <returns>True if the varCode is valid</returns> public static bool PopulateRealValue(StockList model, int varCode, bool useYoung, bool useAll, bool useTag, ref double[] arrayValues) { int numPasses; AnimalGroup animalGroup; double value; double total; int denom; int passIdx, idx; bool result = true; Array.Clear(arrayValues, 0, arrayValues.Length); if (useTag) { numPasses = arrayValues.Length; } else { numPasses = 1; } for (passIdx = 1; passIdx <= numPasses; passIdx++) { total = 0.0; denom = 0; for (idx = 1; idx <= model.Count(); idx++) { if (!useTag || (model.GetTag(idx) == passIdx)) { if (!useYoung) { animalGroup = model.At(idx); } else { animalGroup = model.At(idx).Young; } value = 0.0; if (animalGroup != null) { int n = (int)GrazType.TOMElement.n; int p = (int)GrazType.TOMElement.p; int s = (int)GrazType.TOMElement.s; switch (varCode) { case StockProps.prpAGE: value = animalGroup.AgeDays; break; case StockProps.prpAGE_MONTHS: value = animalGroup.AgeDays / MONTH2DAY; break; case StockProps.prpLIVE_WT: value = animalGroup.LiveWeight; break; case StockProps.prpBASE_WT: value = animalGroup.BaseWeight; break; case StockProps.prpCOND_SCORE: value = animalGroup.fConditionScore(AnimalParamSet.Cond_System.csSYSTEM1_5); break; case StockProps.prpMAX_PREV_WT: value = animalGroup.MaxPrevWeight; break; case StockProps.prpFLEECE_WT: value = animalGroup.FleeceCutWeight; break; case StockProps.prpCFLEECE_WT: value = animalGroup.CleanFleeceWeight; break; case StockProps.prpFIBRE_DIAM: value = animalGroup.FibreDiam; break; case StockProps.prpPREGNANT: value = animalGroup.Pregnancy; break; case StockProps.prpLACTATING: value = animalGroup.Lactation; break; case StockProps.prpNO_FOETUSES: value = animalGroup.NoFoetuses; break; case StockProps.prpNO_SUCKLING: value = animalGroup.NoOffspring; break; case StockProps.prpBIRTH_CS: value = animalGroup.BirthCondition; break; case StockProps.prpDSE: value = animalGroup.DrySheepEquivs; break; case StockProps.prpWT_CHANGE: value = animalGroup.WeightChange; break; case StockProps.prpME_INTAKE: value = animalGroup.AnimalState.ME_Intake.Total; break; case StockProps.prpCPI_INTAKE: value = animalGroup.AnimalState.CP_Intake.Total; break; case StockProps.prpCFLEECE_GROWTH: value = animalGroup.CleanFleeceGrowth; break; case StockProps.prpDAY_FIBRE_DIAM: value = animalGroup.DayFibreDiam; break; case StockProps.prpMILK_WT: value = animalGroup.MilkYield; break; case StockProps.prpMILK_ME: value = animalGroup.MilkEnergy; break; case StockProps.prpRETAINED_N: value = (animalGroup.AnimalState.CP_Intake.Total / GrazType.N2Protein) - (animalGroup.AnimalState.InOrgFaeces.Nu[n] + animalGroup.AnimalState.OrgFaeces.Nu[n] + animalGroup.AnimalState.Urine.Nu[n]); break; case StockProps.prpRETAINED_P: value = animalGroup.AnimalState.Phos_Intake.Total - (animalGroup.AnimalState.InOrgFaeces.Nu[p] + animalGroup.AnimalState.OrgFaeces.Nu[p] + animalGroup.AnimalState.Urine.Nu[p]); break; case StockProps.prpRETAINED_S: value = animalGroup.AnimalState.Sulf_Intake.Total - (animalGroup.AnimalState.InOrgFaeces.Nu[s] + animalGroup.AnimalState.OrgFaeces.Nu[s] + animalGroup.AnimalState.Urine.Nu[s]); break; case StockProps.prpURINE_N: value = animalGroup.AnimalState.Urine.Nu[n]; break; case StockProps.prpURINE_P: value = animalGroup.AnimalState.Urine.Nu[p]; break; case StockProps.prpURINE_S: value = animalGroup.AnimalState.Urine.Nu[s]; break; case StockProps.prpCH4_OUTPUT: value = 0.001 * animalGroup.MethaneWeight; // Convert g/d to kg/d break; case StockProps.prpRDPI: value = animalGroup.AnimalState.RDP_Intake; break; case StockProps.prpRDPR: value = animalGroup.AnimalState.RDP_Reqd; break; case StockProps.prpRDP_EFFECT: value = animalGroup.AnimalState.RDP_IntakeEffect; break; case StockProps.prpINTAKE_MOD: value = animalGroup.IntakeModifier; break; default: result = false; break; } } if (!useTag && !useAll) { arrayValues[idx - 1] = value; } else if (varCode == StockProps.prpDSE) // Sum DSE's; take a weighted average of { total = total + value; // all other values } else if (animalGroup != null) { total = total + (animalGroup.NoAnimals * value); denom = denom + animalGroup.NoAnimals; } } // _ loop over animal groups _ } if ((varCode != StockProps.prpDSE) && (denom > 0)) { total = total / denom; } if (useAll) { arrayValues[0] = total; } else if (useTag) { arrayValues[passIdx - 1] = total; } } // _ loop over passes _ return(result); }
/// <summary> /// Populate the numbers array for the type of output required /// </summary> /// <param name="model">The Stock list model</param> /// <param name="code">The count type</param> /// <param name="useYoung">Report for young animals</param> /// <param name="useAll">Combined value</param> /// <param name="useTag">Use tag groups</param> /// <param name="numbers">The populated array of numbers</param> /// <returns>True if the code type is valid</returns> public static bool PopulateNumberValue(StockList model, CountType code, bool useYoung, bool useAll, bool useTag, ref int[] numbers) { int numPasses; AnimalGroup animalGroup; int value; int total; int p, idx; bool result = true; Array.Clear(numbers, 0, numbers.Length); if (useTag) { numPasses = numbers.Length; } else { numPasses = 1; } for (p = 1; p <= numPasses; p++) { total = 0; for (idx = 1; idx <= model.Count(); idx++) { if (!useTag || (model.GetTag(idx) == p)) { if (!useYoung) { animalGroup = model.At(idx); } else { animalGroup = model.At(idx).Young; } value = 0; if (animalGroup != null) { switch (code) { case CountType.eBoth: value = animalGroup.NoAnimals; break; case CountType.eFemale: value = animalGroup.FemaleNo; break; case CountType.eMale: value = animalGroup.MaleNo; break; case CountType.eDeaths: value = animalGroup.Deaths; break; default: result = false; break; } } if (!useTag && !useAll) { numbers[idx - 1] = value; } else { total = total + value; } } // _ loop over animal groups } if (useAll) { numbers[0] = total; } else if (useTag) { numbers[p - 1] = total; } } // _ loop over passes _ return(result); }
/// <summary> /// Fill a cattle init value /// </summary> /// <param name="model">The animal model</param> /// <param name="animal">The animal type</param> /// <param name="initValue">The cattle init value</param> public static void MakeCattleValue(StockList model, GrazType.AnimalType animal, ref CattleInit[] initValue) { AnimalGroup animalGroup; int count; int idx, jdx; count = 0; for (idx = 1; idx <= model.Count(); idx++) { if (model.At(idx).Genotype.Animal == animal) { count++; } } Array.Resize(ref initValue, count); jdx = 0; for (idx = 1; idx <= model.Count(); idx++) { if (model.At(idx).Genotype.Animal == animal) { animalGroup = model.At(idx); initValue[jdx] = new CattleInit(); initValue[jdx].Genotype = animalGroup.Genotype.sName; initValue[jdx].Number = animalGroup.NoAnimals; initValue[jdx].Sex = model.SexString(idx, false); initValue[jdx].Age = animalGroup.AgeDays; initValue[jdx].Weight = animalGroup.LiveWeight; initValue[jdx].MaxPrevWt = animalGroup.MaxPrevWeight; initValue[jdx].Pregnant = animalGroup.Pregnancy; initValue[jdx].Lactating = animalGroup.Lactation; /*if (Animal == GrazType.AnimalType.Sheep) * { * aValue[Jdx].fleece_wt = aGroup.FleeceCutWeight; * aValue[Jdx].fibre_diam = aGroup.FibreDiam; * aValue[Jdx].no_young = Math.Max(aGroup.NoFoetuses, aGroup.NoOffspring); * } * else*/ if (animal == GrazType.AnimalType.Cattle) { initValue[jdx].NumFoetuses = animalGroup.NoFoetuses; initValue[jdx].NumSuckling = animalGroup.NoOffspring; } if (animalGroup.Lactation > 0) { initValue[jdx].BirthCS = animalGroup.BirthCondition; } if ((animalGroup.Pregnancy > 0) || (animalGroup.Young != null)) { if (animalGroup.MatedTo != null) { initValue[jdx].MatedTo = animalGroup.MatedTo.sName; } else { initValue[jdx].MatedTo = string.Empty; } } else { initValue[jdx].MatedTo = string.Empty; } if (animalGroup.Young != null) { /*if (Animal == GrazType.AnimalType.Sheep) * { * aValue[Jdx].lamb_wt = aGroup.Young.LiveWeight; * aValue[Jdx].lamb_fleece_wt = aGroup.Young.FleeceCutWeight; * } * else*/ if (animal == GrazType.AnimalType.Cattle) { initValue[jdx].CalfWt = animalGroup.Young.LiveWeight; } initValue[jdx].Paddock = model.GetInPadd(idx); initValue[jdx].Tag = model.GetTag(idx); initValue[jdx].Priority = model.GetPriority(idx); } } jdx++; } // next animal }
/// <summary> /// Populate the dry matter pool /// </summary> /// <param name="model">The stock model</param> /// <param name="propCode">The property code</param> /// <param name="useYoung">For young</param> /// <param name="useAll">For all groups</param> /// <param name="useTag">For tag number</param> /// <param name="poolValues">The DM pool value returned</param> /// <returns>True if the propCode is valid</returns> public static bool PopulateDMPoolValue(StockList model, int propCode, bool useYoung, bool useAll, bool useTag, ref DMPoolHead[] poolValues) { int numPasses; AnimalGroup animalGroup; GrazType.DM_Pool pool = new GrazType.DM_Pool(); GrazType.DM_Pool totalPool = new GrazType.DM_Pool(); int denom; int passIdx, idx; bool result = true; for (int i = 0; i < poolValues.Length; i++) { poolValues[i] = new DMPoolHead(); } if (useTag) { numPasses = poolValues.Length; } else { numPasses = 1; } for (passIdx = 1; passIdx <= numPasses; passIdx++) { GrazType.ZeroDMPool(ref totalPool); denom = 0; for (idx = 1; idx <= model.Count(); idx++) { if (!useTag || (model.GetTag(idx) == passIdx)) { if (!useYoung) { animalGroup = model.At(idx); } else { animalGroup = model.At(idx).Young; } GrazType.ZeroDMPool(ref pool); if (animalGroup != null) { int n = (int)GrazType.TOMElement.n; int p = (int)GrazType.TOMElement.p; int s = (int)GrazType.TOMElement.s; switch (propCode) { case StockProps.prpINTAKE: pool.DM = animalGroup.AnimalState.DM_Intake.Total; pool.Nu[n] = animalGroup.AnimalState.CP_Intake.Total / GrazType.N2Protein; pool.Nu[p] = animalGroup.AnimalState.Phos_Intake.Total; pool.Nu[s] = animalGroup.AnimalState.Sulf_Intake.Total; pool.AshAlk = (animalGroup.AnimalState.PaddockIntake.AshAlkalinity * animalGroup.AnimalState.PaddockIntake.Biomass) + (animalGroup.AnimalState.SuppIntake.AshAlkalinity * animalGroup.AnimalState.SuppIntake.Biomass); break; case StockProps.prpINTAKE_PAST: pool.DM = animalGroup.AnimalState.DM_Intake.Herbage; pool.Nu[n] = animalGroup.AnimalState.CP_Intake.Herbage / GrazType.N2Protein; pool.Nu[p] = animalGroup.AnimalState.Phos_Intake.Herbage; pool.Nu[s] = animalGroup.AnimalState.Sulf_Intake.Herbage; pool.AshAlk = animalGroup.AnimalState.PaddockIntake.AshAlkalinity * animalGroup.AnimalState.PaddockIntake.Biomass; break; case StockProps.prpINTAKE_SUPP: pool.DM = animalGroup.AnimalState.DM_Intake.Supp; pool.Nu[n] = animalGroup.AnimalState.CP_Intake.Supp / GrazType.N2Protein; pool.Nu[p] = animalGroup.AnimalState.Phos_Intake.Supp; pool.Nu[s] = animalGroup.AnimalState.Sulf_Intake.Supp; pool.AshAlk = animalGroup.AnimalState.SuppIntake.AshAlkalinity * animalGroup.AnimalState.SuppIntake.Biomass; break; case StockProps.prpFAECES: GrazType.AddDMPool(animalGroup.AnimalState.OrgFaeces, pool); GrazType.AddDMPool(animalGroup.AnimalState.InOrgFaeces, pool); break; case StockProps.prpINORG_FAECES: GrazType.AddDMPool(animalGroup.AnimalState.InOrgFaeces, pool); break; default: result = false; break; } } if (!useTag && !useAll) { DMPool2Value(pool, ref poolValues[idx - 1], (propCode == StockProps.prpINORG_FAECES)); } else if (animalGroup != null) { GrazType.AddDMPool(GrazType.MultiplyDMPool(pool, animalGroup.NoAnimals), totalPool); denom = denom + animalGroup.NoAnimals; } } } // _ loop over animal groups _ if (useTag || useAll) { if (denom > 0) { totalPool = GrazType.PoolFraction(totalPool, 1.0 / denom); } if (useAll) { DMPool2Value(totalPool, ref poolValues[0], (propCode == StockProps.prpINORG_FAECES)); } else { DMPool2Value(totalPool, ref poolValues[passIdx - 1], (propCode == StockProps.prpINORG_FAECES)); } } } return(result); }
public ushort GetTrackStockCount(uint id) { return((ushort)StockList.Count(c => c.track_id == id)); }
public int GetStockCount(StockType stockType) { return(StockList.Count(x => x.StockType == stockType)); }
/// <summary> /// Fill an init array with animal details from the model /// </summary> /// <param name="model"></param> /// <param name="initValue"></param> public static void MakeAnimalValue(StockList model, ref AnimalInits[] initValue) { AnimalGroup animalGroup; int idx, jdx; Array.Resize(ref initValue, model.Count()); jdx = 0; for (idx = 1; idx <= model.Count(); idx++) { animalGroup = model.At(idx); initValue[jdx] = new AnimalInits(); initValue[jdx].Genotype = animalGroup.Genotype.Name; initValue[jdx].Number = animalGroup.NoAnimals; initValue[jdx].Sex = animalGroup.ReproState; initValue[jdx].AgeDays = animalGroup.AgeDays; initValue[jdx].Weight = animalGroup.LiveWeight; initValue[jdx].MaxPrevWt = animalGroup.MaxPrevWeight; initValue[jdx].Pregnant = animalGroup.Pregnancy; initValue[jdx].Lactating = animalGroup.Lactation; GrazType.AnimalType animal = model.At(idx).Genotype.Animal; if (animal == GrazType.AnimalType.Sheep) { initValue[jdx].FleeceWt = animalGroup.FleeceCutWeight; initValue[jdx].FibreDiam = animalGroup.FibreDiam; initValue[jdx].NumFoetuses = Math.Max(animalGroup.NoFoetuses, animalGroup.NoOffspring); } else if (animal == GrazType.AnimalType.Cattle) { initValue[jdx].NumFoetuses = animalGroup.NoFoetuses; initValue[jdx].NumSuckling = animalGroup.NoOffspring; } if (animalGroup.Lactation > 0) { initValue[jdx].BirthCS = animalGroup.BirthCondition; } if ((animalGroup.Pregnancy > 0) || (animalGroup.Young != null)) { if (animalGroup.MatedTo != null) { initValue[jdx].MatedTo = animalGroup.MatedTo.Name; } else { initValue[jdx].MatedTo = string.Empty; } } else { initValue[jdx].MatedTo = string.Empty; } if (animalGroup.Young != null) { initValue[jdx].YoungWt = animalGroup.Young.LiveWeight; if (animal == GrazType.AnimalType.Sheep) { initValue[jdx].YoungGFW = animalGroup.Young.FleeceCutWeight; } initValue[jdx].Paddock = model.GetInPadd(idx); initValue[jdx].Tag = model.GetTag(idx); initValue[jdx].Priority = model.GetPriority(idx); } jdx++; } // next animal }