public SearchLog(WorkingData wd, ISearch isp) { Plugins = isp; Config = wd.Config; Log = wd.Log; Station = new List <StationData>(); }
public SearchWindow(WorkingData wd, InterSet[] isp) { int ispl = isp.Length; sl = new SearchLog[ispl]; bw = new BackgroundWorker[ispl]; InitializeComponent(); DevideLog(wd); pbCondition1.Maximum = wdx[0].Log.Count; pbCondition2.Maximum = wdx[1].Log.Count; pbConditionA.Maximum = wd.Log.Count; pbCondition1.Value = pbCondition2.Value = pbConditionA.Value = 0; btStop.IsEnabled = true; for (int i = 0; i < ispl; i++) { sl[i] = new SearchLog(wdx[i], isp[i].Sea); bw[i] = new BackgroundWorker(); sl[i].SetWorker(bw[i]); bw[i].DoWork += new DoWorkEventHandler(sl[i].StartSearch); bw[i].ProgressChanged += new ProgressChangedEventHandler(ProgressChanged); bw[i].RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorkerCompleted); bw[i].WorkerReportsProgress = true; bw[i].WorkerSupportsCancellation = true; bw[i].RunWorkerAsync(); } }
public SearchWindow(WorkingData wd, InterSet[] isp) { int ispl = isp.Length; sl = new SearchLog[ispl]; bw = new BackgroundWorker[ispl]; InitializeComponent(); DevideLog(wd); pbCondition1.Maximum = wdx[0].Log.Count; pbCondition2.Maximum = wdx[1].Log.Count; pbConditionA.Maximum = wd.Log.Count; pbCondition1.Value = pbCondition2.Value = pbConditionA.Value = 0; btStop.IsEnabled = true; for(int i = 0;i < ispl; i++) { sl[i] = new SearchLog(wdx[i], isp[i].Sea); bw[i] = new BackgroundWorker(); sl[i].SetWorker(bw[i]); bw[i].DoWork += new DoWorkEventHandler(sl[i].StartSearch); bw[i].ProgressChanged += new ProgressChangedEventHandler(ProgressChanged); bw[i].RunWorkerCompleted += new RunWorkerCompletedEventHandler(RunWorkerCompleted); bw[i].WorkerReportsProgress = true; bw[i].WorkerSupportsCancellation = true; bw[i].RunWorkerAsync(); } }
public SearchLog(WorkingData wd, ISearch isp) { Plugins = isp; Config = wd.Config; Log = wd.Log; Station = new List<StationData>(); }
private void CreateHavestMoistureSpatialRecord(WorkingData workingData, double value) { var spatialRecord = new SpatialRecord(); var meter1Value1 = CreateHarvestMoisture(value); spatialRecord.SetMeterValue(workingData, meter1Value1); _spatialRecords.Add(spatialRecord); }
public void Setup() { _meter = new NumericWorkingData(); _meters = new List <WorkingData>(); _representationMapperMock = new Mock <IRepresentationMapper>(); _dlvHeaderMapper = new DlvHeaderMapper(_representationMapperMock.Object); }
private static void CreateNumericMeterCell(SpatialRecord spatialRecord, WorkingData workingData, int depth, DataRow dataRow) { var numericRepresentationValue = spatialRecord.GetMeterValue(workingData) as NumericRepresentationValue; var value = numericRepresentationValue != null ? numericRepresentationValue.Value.Value.ToString(CultureInfo.InvariantCulture) : ""; dataRow[GetColumnName(workingData, depth)] = value; }
/// <summary> /// ログデータからオペレータリストを作成 /// </summary> /// <param name="workData">作業データ</param> /// <returns>自動集計がtrueならカンマ区切りでオペレータリストを作成, そうでないなら入力されているもの</returns> public static string GetOpList(WorkingData workData) { if (!workData.Config.IsAutoOperatorEditEnabled) { return(workData.Config.Operator); } var op = workData.Log.Select(x => x.Operator).Where(x => x != "").Distinct().OrderBy(x => x).ToArray(); return(string.Join(",", op)); }
private void DevideLog(WorkingData wd) { wdx = new WorkingData[sl.Length]; int SkipCount = 0; for(int i = 0;i < sl.Length; i++) { wdx[i] = new WorkingData(); wdx[i].Config = wd.Config; wdx[i].Log = new ObservableCollection<LogData>(wd.Log.Skip(SkipCount).Take(wd.Log.Count / sl.Length)); SkipCount += wd.Log.Count / sl.Length; } }
private void LoadWork(string filename) { DataContractSerializer serial = new DataContractSerializer(typeof(WorkingData)); XmlReader xr = XmlReader.Create(filename); Work = new WorkingData(); Work = (WorkingData)serial.ReadObject(xr); ConfTab.DoLoad(Work.Config); UpdateData(); xr.Close(); }
public void onTick(WorkingData wd) { if (root == null) { return; } if (root.canDo(wd)) { root.onTick(wd); } }
public void SetMostRecentMeterValue(WorkingData meter, RepresentationValue value) { if (_meterToPreviousValue.ContainsKey(meter)) { _meterToPreviousValue[meter] = value; } else { _meterToPreviousValue.Add(meter, value); } }
public override void Process(ImageContext context) { base.Process(context); if (context != null && context.Eos) { MyEmguEvent?.Invoke(this, new EmguEventArgs { ImageData = WorkingData.ToArray() }); WorkingData.Clear(); } }
public OutputSummery(WorkingData wd, InterSet[] isp) { OutputLog ol = new OutputLog(wd, isp[0].Sum); if (!ol.Execute()) { MessageBox.Show("サマリ作成に失敗しました。", "通知"); return; } InitializeComponent(); tbOutput.Text = ol.Sheet; }
public List <WorkingData> Map(ISOTime time, IEnumerable <ISOSpatialRow> isoSpatialRows, DeviceElementUse deviceElementUse, DeviceElementHierarchy isoDeviceElementHierarchy, List <DeviceElementUse> pendingDeviceElementUses, Dictionary <string, List <ISOProductAllocation> > isoProductAllocations) { var workingDatas = new List <WorkingData>(); //Set orders on the collection of DLVs var allDLVs = time.DataLogValues; for (int order = 0; order < allDLVs.Count(); order++) { var dlv = allDLVs.ElementAt(order); dlv.Order = order; } //Create vrProductIndex on relevant device elements if more than one product on this OperationData if (TimeLogMapper.GetDistinctProductIDs(TaskDataMapper, isoProductAllocations).Count > 1 && isoProductAllocations.Keys.Contains(isoDeviceElementHierarchy.DeviceElement.DeviceElementId)) { WorkingData workingData = CreateProductIndexWorkingData(deviceElementUse.Id.ReferenceId); ISODeviceElementIDsByWorkingDataID.Add(workingData.Id.ReferenceId, isoDeviceElementHierarchy.DeviceElement.DeviceElementId); workingDatas.Add(workingData); } //Add the Working Datas for this DeviceElement IEnumerable <ISODataLogValue> deviceElementDLVs = allDLVs.Where(dlv => dlv.DeviceElementIdRef == isoDeviceElementHierarchy.DeviceElement.DeviceElementId); foreach (ISODataLogValue dlv in deviceElementDLVs) { IEnumerable <WorkingData> newWorkingDatas = Map(dlv, isoSpatialRows, deviceElementUse, dlv.Order, pendingDeviceElementUses, isoDeviceElementHierarchy); if (newWorkingDatas.Count() > 0) { int ddi = dlv.ProcessDataDDI.AsInt32DDI(); if (!EnumeratedMeterFactory.IsCondensedMeter(ddi)) { //We skip adding Condensed WorkingDatas to this DeviceElementUse since they were added separately below to their specific DeviceElementUse workingDatas.AddRange(newWorkingDatas); } } } return(workingDatas); }
private void DevideLog(WorkingData wd) { wdx = new WorkingData[sl.Length]; int SkipCount = 0; for (int i = 0; i < sl.Length; i++) { wdx[i] = new WorkingData(); wdx[i].Config = wd.Config; wdx[i].Log = new ObservableCollection <LogData>(wd.Log.Skip(SkipCount).Take(wd.Log.Count / sl.Length)); SkipCount += wd.Log.Count / sl.Length; } }
public OutputLog(WorkingData wd, ISummery isp) { Plugins = isp; freqNum = 15; areaMax = 500000; Multi = new List<Multiply>(); Work = wd; if (Plugins != null) { Plugins.config = Work.Config; Plugins.areaMax = areaMax; Plugins.freqNum = freqNum; Plugins.listMulti = Multi; } }
public static WorkingData createData(BaseEntity agent) { WorkingData wd = new WorkingData(); WorkingDataConfigConfig dt = WorkingDataConfigConfig.Get(agent.getWorkingDataId()); if (dt != null) { wd.dyAgent = agent as EntityDynamicActor; wd.orgPos = agent.CacheTrans.position; wd.seekTime = dt.seekTime; wd.seekRange = dt.seekRange; wd.partolRange = dt.partolRange; } return(wd); }
public OutputLog(WorkingData wd, ISummery isp) { Plugins = isp; freqNum = 15; areaMax = 500000; Multi = new List <Multiply>(); Work = wd; if (Plugins != null) { Plugins.config = Work.Config; Plugins.areaMax = areaMax; Plugins.freqNum = freqNum; Plugins.listMulti = Multi; } }
private void UpdateCondensedWorkingDatas(List <WorkingData> condensedWorkingDatas, ISODataLogValue dlv, DeviceElementUse deviceElementUse, List <DeviceElementUse> pendingDeviceElementUses, DeviceElementHierarchy isoDeviceElementHierarchy) { ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(dlv.DeviceElementIdRef); IEnumerable <ISODeviceElement> isoSectionElements = isoDeviceElement.ChildDeviceElements.Where(d => d.DeviceElementType == ISOEnumerations.ISODeviceElementType.Section); if (isoSectionElements.Count() > 0 && isoSectionElements.Count() <= condensedWorkingDatas.Count) { //We have found the expected number of sections in the DDOP List <ISODeviceElement> targetSections = isoSectionElements.ToList(); //Update the DeviceElementReference on the Condensed WorkingDatas for (int i = 0; i < isoSectionElements.Count(); i++) { WorkingData workingData = condensedWorkingDatas[i]; DeviceElementUse condensedDeviceElementUse = new DeviceElementUse(); condensedDeviceElementUse.OperationDataId = deviceElementUse.OperationDataId; ISODeviceElement targetSection = targetSections[i]; int?deviceElementID = TaskDataMapper.InstanceIDMap.GetADAPTID(targetSection.DeviceElementId); if (deviceElementID.HasValue) { DeviceElement deviceElement = DataModel.Catalog.DeviceElements.SingleOrDefault(d => d.Id.ReferenceId == deviceElementID.Value); if (deviceElement != null) { //Reference the device element in its hierarchy so that we can get the depth & order DeviceElementHierarchy deviceElementInHierarchy = isoDeviceElementHierarchy.FromDeviceElementID(targetSection.DeviceElementId); //Get the config id DeviceElementConfiguration deviceElementConfig = DeviceElementMapper.GetDeviceElementConfiguration(deviceElement, deviceElementInHierarchy, DataModel.Catalog); condensedDeviceElementUse.DeviceConfigurationId = deviceElementConfig.Id.ReferenceId; //Set the depth & order condensedDeviceElementUse.Depth = deviceElementInHierarchy.Depth; condensedDeviceElementUse.Order = deviceElementInHierarchy.Order; } } condensedDeviceElementUse.GetWorkingDatas = () => new List <WorkingData> { workingData }; workingData.DeviceElementUseId = condensedDeviceElementUse.Id.ReferenceId; pendingDeviceElementUses.Add(condensedDeviceElementUse); } } }
public IEnumerable <ISODataLogValue> ExportDataLogValues(List <WorkingData> workingDatas, List <DeviceElementUse> deviceElementUses) { if (workingDatas == null) { return(null); } List <ISODataLogValue> dlvs = new List <ISODataLogValue>(); for (int i = 0; i < workingDatas.Count(); i++) { WorkingData workingData = workingDatas[i]; //DDI int?mappedDDI = RepresentationMapper.Map(workingData.Representation); var dlv = new ISODataLogValue(); if (mappedDDI != null) { if (workingData.Representation != null && workingData.Representation.Code == "dtRecordingStatus" && workingData.DeviceElementUseId != 0) { dlv.ProcessDataDDI = 141.AsHexDDI(); //No support for exporting CondensedWorkState at this time } else { dlv.ProcessDataDDI = mappedDDI.Value.AsHexDDI(); } } else if (workingData.Representation.CodeSource == ApplicationDataModel.Representations.RepresentationCodeSourceEnum.ISO11783_DDI) { dlv.ProcessDataDDI = workingData.Representation.Code; } //DeviceElementIdRef DeviceElementUse use = deviceElementUses.FirstOrDefault(d => d.Id.ReferenceId == workingData.DeviceElementUseId); if (use != null) { DeviceElementConfiguration deviceElementConfiguration = DataModel.Catalog.DeviceElementConfigurations.FirstOrDefault(d => d.Id.ReferenceId == use.DeviceConfigurationId); if (deviceElementConfiguration != null) { //This requires the Devices will have been mapped prior to the LoggedData dlv.DeviceElementIdRef = TaskDataMapper.InstanceIDMap.GetISOID(deviceElementConfiguration.DeviceElementId); } } dlvs.Add(dlv); _dataLogValueOrdersByWorkingDataID.Add(workingData.Id.ReferenceId, i); } return(dlvs); }
private static void Callback(object o) { if (_isWork) { return; } try { _isWork = true; WorkingData.Create(new WorkOrderSQLServer()); } finally { _isWork = false; } }
public override ActionStatus onUpdate(WorkingData wd) { if (Time.timeSinceLevelLoad >= nextSeekTime && wd.dyAgent.Target == null) { //List<BaseEntity> players = EntityMgr.Instance.getEntityByType(EntityType.player); //if (players != null && players.Count > 0) //{ // for (int i = 0; i < players.Count; i++) // { // if (Vector3.Distance(players[i].CacheTrans.position, wd.dyAgent.CacheTrans.position) <= wd.seekRange) // { // wd.dyAgent.Target = players[i]; // return ActionStatus.finished; // } // } //} nextSeekTime = wd.seekTime + Time.timeSinceLevelLoad; } if (wd.dyAgent.SType == StateType.onHit) { return(ActionStatus.finished); } if (Time.timeSinceLevelLoad >= nextPartolTime) { if (Vector3.Distance(wd.dyAgent.CacheTrans.position, nextPartolPoint) > 1f) { this.dyAgent.onChangeState(StateType.run); wd.dyAgent.CacheTrans.LookAt(nextPartolPoint, Vector3.up); wd.dyAgent.moveTo((nextPartolPoint - wd.dyAgent.CacheTrans.position).normalized); } else { nextPartolPoint = getPartolPoint(wd); nextPartolTime = partolTime + Time.timeSinceLevelLoad; } } else { this.dyAgent.onChangeState(StateType.idle); } return(ActionStatus.running); }
public List <WorkingData> Map(ISOTime time, IEnumerable <ISOSpatialRow> isoSpatialRows, DeviceElementUse deviceElementUse, DeviceHierarchyElement isoDeviceElementHierarchy, List <DeviceElementUse> pendingDeviceElementUses, Dictionary <string, List <ISOProductAllocation> > isoProductAllocations) { var workingDatas = new List <WorkingData>(); //Create vrProductIndex on relevant device elements if more than one product on this OperationData if (TimeLogMapper.GetDistinctProductIDs(TaskDataMapper, isoProductAllocations).Count > 1 && isoProductAllocations.Keys.Contains(isoDeviceElementHierarchy.DeviceElement.DeviceElementId)) { WorkingData workingData = CreateProductIndexWorkingData(deviceElementUse.Id.ReferenceId); ISODeviceElementIDsByWorkingDataID.Add(workingData.Id.ReferenceId, isoDeviceElementHierarchy.DeviceElement.DeviceElementId); workingDatas.Add(workingData); } //Add the Working Datas for this DeviceElement IEnumerable <ISODataLogValue> deviceElementDLVs = time.DataLogValues.Where(dlv => dlv.DeviceElementIdRef == isoDeviceElementHierarchy.DeviceElement.DeviceElementId || //DLV DET reference matches the primary DET for the ADAPT element isoDeviceElementHierarchy.MergedElements.Any(e => e.DeviceElementId == dlv.DeviceElementIdRef)); //DLV DET reference matches one of the merged DETs on the ADAPT element foreach (ISODataLogValue dlv in deviceElementDLVs) { IEnumerable <WorkingData> newWorkingDatas = Map(dlv, isoSpatialRows, deviceElementUse, dlv.Index, pendingDeviceElementUses, isoDeviceElementHierarchy); if (newWorkingDatas.Count() > 0) { int ddi = dlv.ProcessDataDDI.AsInt32DDI(); if (!EnumeratedMeterFactory.IsCondensedMeter(ddi)) { //We skip adding Condensed WorkingDatas to this DeviceElementUse since they were added separately below to their specific DeviceElementUse workingDatas.AddRange(newWorkingDatas); } } } return(workingDatas); }
public RepresentationValue Interpolate(WorkingData meter) { if (!_meterToPreviousValue.ContainsKey(meter)) { return(null); } var previousValue = _meterToPreviousValue[meter]; var numericRepresentationValue = previousValue as NumericRepresentationValue; if (numericRepresentationValue != null) { var newNumericRepresentationValue = numericRepresentationValue.Copy(); if (numericRepresentationValue.Representation != null && _numericRepresentationTotals.Contains(numericRepresentationValue.Representation.Code)) { newNumericRepresentationValue.Value.Value = 0; } return(newNumericRepresentationValue); } var enumeratedValue = previousValue as EnumeratedValue; if (enumeratedValue != null) { var newEnumeratedValue = new EnumeratedValue { Code = enumeratedValue.Code, Value = new EnumerationMember { Code = enumeratedValue.Value.Code, Value = enumeratedValue.Value.Value }, Representation = enumeratedValue.Representation }; return(newEnumeratedValue); } return(null); }
/// <summary> /// 接收UDP数据包 /// </summary> /// <param name="token">取消任务标记</param> private void Listener(CancellationToken token) { while (true) { try { byte[] buff = new byte[512]; EndPoint client = new IPEndPoint(IPAddress.Loopback, 0); int read = server.ReceiveFrom(buff, ref client); TaskFactory task = new TaskFactory(); WorkingData data = new WorkingData(buff.Take(read).ToArray(), client); task.StartNew(new Action <object>(t => { Working(data); }), data); } catch { continue; } token.ThrowIfCancellationRequested(); } }
public WorkingData ConvertToBaseType(WorkingData meter) { if (meter is ISOEnumeratedMeter) { var enumMeter = (ISOEnumeratedMeter)meter; var newMeter = new EnumeratedWorkingData { AppliedLatency = enumMeter.AppliedLatency, DeviceElementUseId = enumMeter.DeviceElementUseId, ReportedLatency = enumMeter.ReportedLatency, Representation = enumMeter.Representation, ValueCodes = enumMeter.ValueCodes, }; newMeter.Id.ReferenceId = meter.Id.ReferenceId; newMeter.Id.UniqueIds = meter.Id.UniqueIds; return(newMeter); } return(meter); }
public MainWindow() { try { if (System.IO.File.Exists("check.ls")) { System.IO.StreamReader sr = new System.IO.StreamReader("check.ls", System.Text.Encoding.UTF8); if (sr.Peek() > 0) { if (Version != sr.ReadLine()) { sr.Close(); WarnRule(); } else { sr.Close(); } } } else { WarnRule(); } } catch { this.Close(); } Work = new WorkingData(); Work.Log = new ObservableCollection <LogData>(); InitializeComponent(); this.Title += "(Ver: " + Version + ")"; SetInterset(); List <IDefine> defPlugins = new List <IDefine>(); foreach (var i in Intersets[0]) { defPlugins.Add(i.Def); } ConfTab.Plugins = defPlugins.ToArray(); dgLog.ItemsSource = Work.Log; }
/// <summary> /// 选择节点 /// 当节点返回success 则返回success /// 当节点返回failure 则执行下一个节点 返回running /// 否则返回running /// </summary> /// <returns></returns> public override BTResult onTick(WorkingData wd) { BTResult status = this.children[this.currIndex].onTick(wd); if (status == BTResult.success) { clear(); return(BTResult.success); } if (status == BTResult.failure) { this.currIndex++; if (this.currIndex >= this.children.Count) { clear(); return(BTResult.success); } status = BTResult.running; } return(status); }
sealed public override BTResult onTick(WorkingData wd) { BTResult result = BTResult.running; if (actStatus == ActionStatus.ready) { onEnter(wd); actStatus = ActionStatus.running; } if (actStatus == ActionStatus.running) { actStatus = onUpdate(wd); if (actStatus == ActionStatus.finished) { onExit(wd); actStatus = ActionStatus.ready; result = BTResult.success; } } return(result); }
public WorkerViewModel() { _workOrderRepository = new WorkOrderSQLServer(); Worker1StartButton = new DelegateCommand(Worker1StartButtonExecute); Worker2StartButton = new DelegateCommand(Worker2StartButtonExecute); Worker3StartButton = new DelegateCommand(Worker3StartButtonExecute); _timeManagementRepository = new TimeManagementSQLServer(); observableTimer = Observable.Timer(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(2)) .Subscribe(_ => { LabelContent.Value += 1; WorkerWorkings.Value = new ObservableCollection <WorkingEntity>(WorkingData.GetWorkings(WorkId.Value, WorkerId.Value)); }); NextCommand = CanNext.Select(x => x == false).ToReactiveCommand(); NextCommand.Subscribe(_ => { _workOrderRepository.ToNext(WorkId.Value, WorkerId.Value); }); WorkerId.Subscribe(x => { }); }
public DLV Map(WorkingData meter) { var representation = _representationMapper.Map(meter.Representation); var dlv = new DLV(); if (representation == null) { dlv.A = null; } else { if (meter.Representation != null && meter.Representation.Code == "dtRecordingStatus" && meter.DeviceElementUseId != 0) { dlv.A = "161"; } else { dlv.A = representation.ToString(); } } return(dlv); }
private static void GetAsAppliedData(OperationData opData, Catalog catalog) { WorkingData areaMeter = null; WorkingData appRateMeter = null; IEnumerable <DeviceElementUse> headDEUs = opData.GetDeviceElementUses(1); foreach (DeviceElementUse deu in headDEUs) { IEnumerable <WorkingData> workingDatas = deu.GetWorkingDatas(); foreach (WorkingData meter in workingDatas) { switch (meter.Representation.Code) { case "vrDeltaArea": areaMeter = meter; break; case "vrAppRateVolumeActual": appRateMeter = meter; break; } } } double totalArea = 0; double totalAmount = 0; string rateUnits = ""; // Loop through all the spatial records to get total area and total amount IEnumerable <SpatialRecord> spatialRecords = opData.GetSpatialRecords(); foreach (SpatialRecord spatialRecord in spatialRecords) { // Calculate the area NumericRepresentationValue area = spatialRecord.GetMeterValue(areaMeter) as NumericRepresentationValue; double acres = area.Value.Value; totalArea += acres; NumericRepresentationValue appRate = spatialRecord.GetMeterValue(appRateMeter) as NumericRepresentationValue; rateUnits = appRate.Value.UnitOfMeasure.Code; double rate = appRate.Value.Value; // gal/ac double amount = rate * acres; // gal totalAmount += amount; } double averageRate = totalAmount / totalArea; Console.WriteLine("Application Summary:"); string result = String.Format("Area: {0:F2}\tAmount: {1:F2}\tRate: {2:F2} {3}", totalArea, totalAmount, averageRate, rateUnits); Console.WriteLine(result); if (opData.ProductIds.Count > 0) { Console.WriteLine("Product Details:"); Product product = catalog.Products.Find(x => x.Id.ReferenceId == opData.ProductIds[0]); result = String.Format("Product Description: {0}", product.Description); Console.WriteLine(result); if (product.ProductComponents.Count > 0) { Console.WriteLine("Product Components:"); // Calculate the total rates for each type of ProductComponent in the MixProduct double volumeTotalRate = 0; double massTotalRate = 0; foreach (ProductComponent component in product.ProductComponents) { if (component.Quantity.Value.UnitOfMeasure.Dimension == UnitOfMeasureDimensionEnum.Volume) { // gal volumeTotalRate += component.Quantity.Value.Value; } else if (component.Quantity.Value.UnitOfMeasure.Dimension == UnitOfMeasureDimensionEnum.Mass) { // lb massTotalRate += component.Quantity.Value.Value; } } // Determine the correct total applied date for the MixProduct double totalRate = volumeTotalRate; if (totalRate == 0) { // The volumeTotalRate will be 0 for dry product mixes totalRate = massTotalRate; } // Calculate the total units of tank mix actually applied to the field. // This is important to be able to determine the actual proportion of each ProductComponent double totalUnitsOfMixProduct = totalAmount / volumeTotalRate; foreach (ProductComponent component in product.ProductComponents) { Product componentProduct = catalog.Products.Find(x => x.Id.ReferenceId == component.IngredientId); double componentRate = component.Quantity.Value.Value; // Calculate the total amount of the product component double componentAmount = totalUnitsOfMixProduct * componentRate; double componentActualRate = componentAmount / totalArea; result = String.Format("Component: {0}\tAmount: {1:F2}\tRate: {2:F2} {3}/ac", componentProduct.Description, componentAmount, componentActualRate, component.Quantity.Value.UnitOfMeasure.Code); Console.WriteLine(result); } } } }
private static void GetHarvestData(OperationData opData, Catalog catalog) { WorkingData distanceMeter = null; WorkingData moistureMeter = null; WorkingData wetMassMeter = null; WorkingData dryYieldMeter = null; IEnumerable <DeviceElementUse> machineDEUs = opData.GetDeviceElementUses(0); foreach (DeviceElementUse deu in machineDEUs) { IEnumerable <WorkingData> workingDatas = deu.GetWorkingDatas(); foreach (WorkingData meter in workingDatas) { switch (meter.Representation.Code) { case "vrDistanceTraveled": distanceMeter = meter; break; case "vrHarvestMoisture": moistureMeter = meter; break; case "vrYieldWetMass": wetMassMeter = meter; break; case "vrYieldVolume": dryYieldMeter = meter; break; } } } // Active width is kept on Level 1 which indicates the header WorkingData widthMeter = null; IEnumerable <DeviceElementUse> headDEUs = opData.GetDeviceElementUses(1); foreach (DeviceElementUse deu in headDEUs) { IEnumerable <WorkingData> workingDatas = deu.GetWorkingDatas(); foreach (WorkingData meter in workingDatas) { switch (meter.Representation.Code) { case "vrEquipmentWidth": widthMeter = meter; break; } } } double totalArea = 0; double totalWetMass = 0; double totalDryBushels = 0; double totalMoisture = 0; // Loop through all the spatial records to get total area, wet mass, and moisture. IEnumerable <SpatialRecord> spatialRecords = opData.GetSpatialRecords(); foreach (SpatialRecord spatialRecord in spatialRecords) { // Calculate the area NumericRepresentationValue distance = spatialRecord.GetMeterValue(distanceMeter) as NumericRepresentationValue; NumericRepresentationValue width = spatialRecord.GetMeterValue(widthMeter) as NumericRepresentationValue; double distanceFt = distance.Value.Value; double widthFt = width.Value.Value; double squareFeet = distanceFt * widthFt; double acres = squareFeet / SQUARE_FEET_PER_ACRE; totalArea += acres; NumericRepresentationValue wetMass = spatialRecord.GetMeterValue(wetMassMeter) as NumericRepresentationValue; double wetMassLbs = wetMass.Value.Value; // lbs totalWetMass += wetMassLbs; NumericRepresentationValue moisture = spatialRecord.GetMeterValue(moistureMeter) as NumericRepresentationValue; double moisturePct = moisture.Value.Value; // % totalMoisture += moisturePct * wetMassLbs; // Only used for calculating weighted average NumericRepresentationValue dryVol = spatialRecord.GetMeterValue(dryYieldMeter) as NumericRepresentationValue; double dryVolBu = dryVol.Value.Value; // bu totalDryBushels += dryVolBu; } double averageMoisture = totalMoisture / totalWetMass; string result = String.Format("Area: {0:F2}\tWetMass: {1:F2}\tMoisture: {2:F2}\tDryBushels: {3:F2}", totalArea, totalWetMass, averageMoisture, totalDryBushels); Console.WriteLine(result); }