public List <ProcedureList> FillProcedure(IEntryCollection entryCollection)
        {
            List <ProcedureList> procedureList = new List <ProcedureList>();

            foreach (IEntry entryitem in entryCollection)
            {
                IProcedure entryProcedure = entryitem.AsProcedure;
                if (entryProcedure != null)
                {
                    IObservation entryObservatio = entryitem.AsObservation;
                    ICD          meterialCode;
                    //if (entryProcedure != null)
                    //{
                    //    meterialCode = entryProcedure.Code;
                    //}
                    //else
                    //{
                    //    meterialCode = entryObservatio.Code;
                    //}
                    meterialCode = entryProcedure.Code;
                    ProcedureList ptprocedureList = new ProcedureList();
                    ptprocedureList.CPTCodes    = meterialCode.Code;
                    ptprocedureList.Description = meterialCode.DisplayName;
                    procedureList.Add(ptprocedureList);
                }
            }

            return(procedureList);
        }
        public List <LabResult> FillLabResults(IEntryCollection entryCollection)
        {
            List <LabResult> labResult = new List <LabResult>();

            foreach (IEntry entryitem in entryCollection)
            {
                IOrganizer            entryOrganizer = entryitem.AsOrganizer;
                IComponent4Collection entryComponent = entryOrganizer.Component;
                LabResult             ptLabResult    = new LabResult();
                foreach (IComponent4 obserComponent in entryComponent)
                {
                    IObservation    entryObservation = obserComponent.AsObservation;
                    IReferenceRange referenceRange   = entryObservation.ReferenceRange.FirstOrDefault();
                    meterialCode = entryObservation.Code;
                    try{ valueCode = (IPQ)entryObservation.Value[0]; }catch (Exception) {}
                    ptLabResult.TestPerformed = meterialCode.DisplayName;
                    ptLabResult.ReportDate    = entryObservation.EffectiveTime == null ? null : new DateTime?(Convert.ToDateTime(entryObservation.EffectiveTime.AsDateTime));
                    ptLabResult.LonicCode     = meterialCode.Code;
                    ptLabResult.Units         = valueCode != null?valueCode.Unit.ToString() : string.Empty;

                    ptLabResult.TestResultn = valueCode != null?valueCode.Value.ToString():string.Empty;

                    ptLabResult.NormalFindings = referenceRange != null ? referenceRange.ObservationRange.Text != null ? referenceRange.ObservationRange.Text.Text : null : null;
                }
                labResult.Add(ptLabResult);
            }

            return(labResult);
        }
        public List <PatientProblemes> FillProblems(IEntryCollection entryCollection)
        {
            List <PatientProblemes> Problemes = new List <PatientProblemes>();

            foreach (IEntry singleentry in entryCollection)
            {
                IObservation     probObservation = singleentry.AsAct.EntryRelationship.FirstOrDefault().AsObservation;
                IIVL_TS          effectivetime   = probObservation.EffectiveTime;
                IANY             probValue       = probObservation.Value[0];
                ICD              itemVlues       = (ICD)probValue;
                PatientProblemes ptproblem       = new PatientProblemes();
                ptproblem.ProblemCode = itemVlues.Code != null ? itemVlues.Code : null;
                IEntryRelationship ObserentryRelation = probObservation.EntryRelationship.Where(e => e.AsObservation.Code.Code.ToString() == "33999-4").FirstOrDefault();
                if (ObserentryRelation != null)
                {
                    IANY probStatusVal = ObserentryRelation.AsObservation.Value.FirstOrDefault();
                    ICD  StatusVlues   = (ICD)probStatusVal;
                    ptproblem.Status = StatusVlues.DisplayName;
                }
                else
                {
                    ptproblem.Status = null;
                }
                ptproblem.DateDiagnosed = effectivetime.Low != null ? effectivetime.Low.Value != null?effectivetime.Low.AsDateTime.ToString() : null : null;

                ptproblem.Description = itemVlues.DisplayName != null ? itemVlues.DisplayName : null;
                Problemes.Add(ptproblem);
            }
            return(Problemes);
        }
        public List <Encounters> FillEncounters(IEntryCollection entryCollection, string name)
        {
            List <Encounters> encounters = new List <Encounters>();

            foreach (IEntry entryitem in entryCollection)
            {
                Encounters         ptEncounters      = new Encounters();
                IEncounter         entryEncounter    = entryitem.AsEncounter;
                IEntryRelationship entryRelationItem = entryEncounter.EntryRelationship.FirstOrDefault();
                if (entryRelationItem != null)
                {
                    IObservation observation = entryRelationItem.AsObservation;
                    IIVL_TS      efftime     = observation.EffectiveTime;
                    if (efftime == null)
                    {
                        throw new InvalidOperationException();
                    }
                    IANY   observationvalue = observation.Value.FirstOrDefault();
                    ICD    str      = (ICD)observationvalue;
                    string location = observation.Participant.Count > 0 ? observation.Participant[0].ParticipantRole.AsPlayingEntity.Name[0].Text : null;
                    ptEncounters.Code = str.Code;
                    ptEncounters.EncounterDescription = str.DisplayName;
                    ptEncounters.PerformerName        = name;
                    //ptEncounters.EncounterDate = efftime != null ? efftime.Low != null ? efftime.Low.Value != null ? new DateTime?(Convert.ToDateTime(efftime.Low.AsDateTime)) : null : null : efftime.Value != null ? new DateTime?(Convert.ToDateTime(efftime.AsDateTime)) : null;
                }
                encounters.Add(ptEncounters);
            }

            return(encounters);
        }
        public SocialHistoryModel FillSocialHistory(IEntryCollection entryCollection)
        {
            SocialHistoryModel ptSocialHistory = new SocialHistoryModel();

            foreach (IEntry singleentry in entryCollection)
            {
                IObservation socialObservation = singleentry.AsObservation;
                if (socialObservation.TemplateId.Select(s => s.Root.ToString()).FirstOrDefault() == "2.16.840.1.113883.10.20.22.4.38")
                {
                    ICD     socialCode    = socialObservation.Code;
                    IIVL_TS effectiveTime = socialObservation.EffectiveTime;
                    if (socialCode.Code == "230056004" || socialCode.Code == "229819007")
                    {
                        ptSocialHistory.Smoker = socialCode.Code != null ? socialCode.Code : null;
                    }
                    if (socialCode.Code == "160573003")
                    {
                        //ptSocialHistory.EntryDate = effectiveTime != null ? effectiveTime.Low != null ? effectiveTime.Low.Value != null ? effectiveTime.Low.Value.ToString() : null : null : null;
                        ptSocialHistory.Alcohol = socialCode.Code != null ? socialCode.Code : null;
                    }
                    if (socialCode.Code == "363908000")
                    {
                        //ptSocialHistory.EntryDate = effectiveTime != null ? effectiveTime.Low != null ? effectiveTime.Low.Value != null ? effectiveTime.Low.Value.ToString() : null : null : null;
                        ptSocialHistory.Drugs = socialCode.Code != null ? socialCode.Code : null;
                    }
                    if (socialCode.Code == "81703003")
                    {
                        //ptSocialHistory.EntryDate = effectiveTime != null ? effectiveTime.Low != null ? effectiveTime.Low.Value != null ? effectiveTime.Low.Value.ToString() : null : null : null;
                        ptSocialHistory.Tobacoo = socialCode.Code != null ? socialCode.Code : null;
                    }
                    ptSocialHistory.EntryDate = effectiveTime != null ? effectiveTime.Low != null ? effectiveTime.Low.Value != null?effectiveTime.Low.Value.ToString() : null : null : null;
                }
            }
            return(ptSocialHistory);
        }
示例#6
0
        public double GetEmission([NotNull] IState state, [NotNull] IObservation observation)
        {
            var si = GetStateIndex(state);
            var oi = GetObservationIndex(observation);

            return(GetEmission(state: si, observation: oi));
        }
        private MeasurementV1 CreateMeasurementFromVariable(Variable variable, IObservation observation, Metadata metadata)
        {
            // Look up property based on string, get value
            var value = observation.GetType().GetProperty(variable.FieldName).GetValue(observation, null);

            Nsar.Common.Measure.Models.PhysicalQuantity pq = new Nsar.Common.Measure.Models.PhysicalQuantity(
                Convert.ToDecimal(value),
                variable.Units);

            // TODO: create interface, use constructor injection
            Nsar.Common.Measure.PhysicalQuantityConverter pqConverter = new Nsar.Common.Measure.PhysicalQuantityConverter();

            Nsar.Common.Measure.Models.PhysicalQuantity pqMetric = pqConverter.Convert(pq);
            string   name = map.GetMeasurementName(variable.FieldName);
            DateTime measurementDateTime = new DateTime(observation.TIMESTAMP.Ticks, DateTimeKind.Utc);

            List <PhysicalQuantityV1> physicalQuantitis = new List <PhysicalQuantityV1>()
            {
                new PhysicalQuantityV1(pqMetric.Value, pqMetric.Unit, 0, 0, 0, DateTime.UtcNow, "CosmosDBSqlApiTransformer")
            };

            LocationV1 location = new LocationV1("Point",
                                                 map.GetLatFromStation(metadata),
                                                 map.GetLonFromStation(metadata));

            string fieldId = map.GetFieldID(metadata);

            string partitionKey = "EcTower_" + fieldId + "_" + name;
            string id           = fieldId + "_" + name + "_" + measurementDateTime.ToString("o");

            return(new MeasurementV1(partitionKey, id, DocumentType, name, TargetSchemaVersion, metadataId,
                                     "", "", "", "", null, fieldId, location, measurementDateTime, physicalQuantitis));
        }
        public List <PlanOfCare> FillPlanOfCare(IEntryCollection entryCollection)
        {
            List <PlanOfCare> planOfCare = new List <PlanOfCare>();

            foreach (IEntry singleRecord in entryCollection)
            {
                IObservation observation  = singleRecord.AsObservation;
                IAct         entryAct     = singleRecord.AsAct;
                string       goal         = null;
                string       instructions = null;
                if (observation != null)
                {
                    meterialCode = observation.Code;
                    goal         = meterialCode.DisplayName;
                    datetime     = observation.EffectiveTime;
                }
                if (entryAct != null)
                {
                    instructions = entryAct.Text.Text;
                }
                PlanOfCare ptPlanOfCare = new PlanOfCare();
                ptPlanOfCare.Goal         = goal;
                ptPlanOfCare.PlannedDate  = datetime != null ? datetime.Center != null ? new DateTime?(datetime.Center.AsDateTime) : null : null;
                ptPlanOfCare.Instructions = instructions;
                planOfCare.Add(ptPlanOfCare);
            }


            return(planOfCare);
        }
        public List <VitalSigns> FillVitalSigns(IEntryCollection entryCollection)
        {
            List <VitalSigns> vitalSigns = new List <VitalSigns>();

            foreach (IEntry singleentry in entryCollection)
            {
                IOrganizer            organizer = singleentry.AsOrganizer;
                IComponent4Collection component = organizer.Component;
                IIVL_TS effectivetime           = organizer.EffectiveTime;
                if (effectivetime == null)
                {
                    throw new InvalidOperationException();
                }
                VitalSigns ptvitalSigns = new VitalSigns();
                try
                {
                    ptvitalSigns.VitalDate = effectivetime.AsDateTime;
                }
                catch (Exception)
                {
                    ptvitalSigns.VitalDate = effectivetime != null ? effectivetime.Low != null ? effectivetime.Low.Value != null ? new DateTime?(effectivetime.Low.AsDateTime) : null : null : effectivetime.Value != null ? new DateTime?(effectivetime.AsDateTime) : new DateTime?(effectivetime.AsDateTime);
                }


                foreach (IComponent4 orgComponent in component)
                {
                    IObservation orgObservation             = orgComponent.AsObservation;
                    ICD          itemCode                   = orgObservation.Code;
                    IANY         vitalSignsObservationValue = orgObservation.Value[0];
                    IPQ          itemVlues                  = (IPQ)vitalSignsObservationValue;

                    if (itemCode.Code != null)
                    {
                        if (itemCode.Code.ToString() == "8302-2")
                        {
                            ptvitalSigns.Height     = Convert.ToInt16(itemVlues.Value);
                            ptvitalSigns.HeightUnit = Convert.ToString(itemVlues.Unit);
                        }
                        if (itemCode.Code.ToString() == "3141-9")
                        {
                            ptvitalSigns.WEIGHT     = Convert.ToInt16(itemVlues.Value);
                            ptvitalSigns.WeightUnit = Convert.ToString(itemVlues.Unit);
                        }
                        if (itemCode.Code.ToString() == "8480-6")
                        {
                            ptvitalSigns.BloodPressure         = itemVlues.Value.ToString() + " " + itemVlues.Unit.ToString();
                            ptvitalSigns.BloodPressureSystolic = itemVlues.Value.ToString();
                        }

                        if (itemCode.Code.ToString() == "8462-4")
                        {
                            ptvitalSigns.BloodPressureDiastolic = itemVlues.Value.ToString();
                        }
                    }
                }
                vitalSigns.Add(ptvitalSigns);
            }
            return(vitalSigns);
        }
示例#10
0
 internal Observer(Specification specification, Product initialAnchor, FactManager factManager, IObservation observation)
 {
     this.specification = specification;
     this.initialAnchor = initialAnchor;
     this.factManager   = factManager;
     this.observation   = observation;
     this.inverses      = specification.ComputeInverses();
 }
 private static void PublishObservation <T>(IObservation <T> observation)
 {
     Console.WriteLine("  " + observation.Name);
     Console.WriteLine("    Took: {0} ms, Exception Thrown: {1}{2}, Output Value: {3}",
                       observation.ElapsedMilliseconds, observation.ExceptionThrown, observation.ExceptionThrown ?
                       string.Format("(Exception: {0})", observation.ExperimentError.LastException.Message) : string.Empty,
                       observation.Value);
 }
示例#12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StateProbability" /> struct.
        /// </summary>
        /// <param name="observation">The observation.</param>
        /// <param name="state">The state.</param>
        /// <param name="probability">The probability.</param>
        /// <exception cref="System.ArgumentNullException">state
        /// or
        /// observation</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">state
        /// or
        /// observation</exception>
        /// <exception cref="System.NotFiniteNumberException">probability;The probability value must be in range 0..1</exception>
        public ObservedStateProbability([NotNull] IObservation observation, [NotNull] IState state, double probability) : base(state, probability)
        {
            if (observation == null)
            {
                throw new ArgumentNullException("observation");
            }

            Observation = observation;
        }
示例#13
0
        public int GetObservationIndex([NotNull] IObservation observation)
        {
            int index;

            if (_observations.TryGetValue(observation, out index))
            {
                return(index);
            }
            throw new ArgumentException("The given observation was not previously registered", "observation");
        }
示例#14
0
        public TOA5 GetTOA5(IObservation datatable)
        {
            TOA5 toa5 = new TOA5();

            toa5.Metadata = GetMetadata();

            toa5.Observations = GetObservations(datatable).ToList();

            return(toa5);
        }
 private static void AddObservationStats <T>(string experimentName, IObservation <T> observation, Statsd statsd)
 {
     experimentName = ReplaceWhitespace(experimentName);
     statsd.Add <Statsd.Timing>(string.Format("{0}.{1}.Results.Microseconds", experimentName, observation.Name),
                                (int)(observation.ElapsedTime.TotalMilliseconds * 1000)); // use microseconds because required to sent int
     if (observation.IsMismatched)
     {
         // Gauge, Meter, or Count -- use Count for now, gives us # of mismatches / second
         statsd.Add <Statsd.Counting>(string.Format("{0}.{1}.Results.Mismatches", experimentName,
                                                    observation.Name), 1);
     }
 }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LabeledObservation"/> struct.
 /// </summary>
 /// <param name="state">The state.</param>
 /// <param name="observation">The observation.</param>
 /// <exception cref="System.ArgumentNullException">
 /// state
 /// or
 /// observation
 /// </exception>
 public LabeledObservation([NotNull] IState state, [NotNull] IObservation observation)
 {
     if (state == null)
     {
         throw new ArgumentNullException("state");
     }
     if (observation == null)
     {
         throw new ArgumentNullException("observation");
     }
     State       = state;
     Observation = observation;
 }
示例#17
0
        /// <summary>
        /// Sets the <see cref="System.Double" /> probability of emitting the state.
        /// </summary>
        /// <param name="state">The state's index.</param>
        /// <param name="observation">The observation.</param>
        /// <param name="probability">The transition probability.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">probability;The probability value must be in range 0..1</exception>
        /// <exception cref="System.NotFiniteNumberException">The value must be a finite number.</exception>
        public void SetEmission([NotNull] IState state, [NotNull] IObservation observation, double probability)
        {
            if (probability < 0 || probability > 1)
            {
                throw new ArgumentOutOfRangeException("probability", probability, "The probability value must be in range 0..1");
            }
            if (Double.IsNaN(probability) || Double.IsInfinity(probability))
            {
                throw new NotFiniteNumberException("The value must be a finite number.", probability);
            }

            var si = GetStateIndex(state);
            var oi = GetObservationIndex(observation);

            SetEmission(state: si, observation: oi, probability: probability);
        }
        public List <FunctionalStatus> FillFunctionalStatus(IEntryCollection entryCollection)
        {
            List <FunctionalStatus> functionalStatus = new List <FunctionalStatus>();

            foreach (IEntry entryitem in entryCollection)
            {
                IObservation     entryObservation = entryitem.AsObservation;
                IIVL_TS          effectiveDate    = entryObservation.EffectiveTime;
                IANY             functionalValue  = entryObservation.Value[0];
                ICD              cD = (ICD)functionalValue;
                FunctionalStatus ptfunctionalStatus = new FunctionalStatus();
                ptfunctionalStatus.StatusDate  = effectiveDate != null ? effectiveDate.Low != null ? effectiveDate.Low.Value != null ? new DateTime?(effectiveDate.Low.AsDateTime) : null : null : null;
                ptfunctionalStatus.Description = cD.DisplayName;
                ptfunctionalStatus.Code        = cD.Code;
                functionalStatus.Add(ptfunctionalStatus);
            }

            return(functionalStatus);
        }
示例#19
0
        public Func <double[], double> this[IObservation observation]
        {
            get
            {
                var zc = observation as Zc;
                if (zc != null)
                {
                    return(Zc(zc));
                }

                var eqtySpot = observation as EquitySpot;
                if (eqtySpot != null)
                {
                    return(EquitySpot(eqtySpot));
                }

                throw new NotImplementedException(observation.ToString());
            }
        }
        public List <PatientAllergies> FillAllergies(IEntryCollection entryCollection)
        {
            List <PatientAllergies> alleryies = new List <PatientAllergies>();

            foreach (IEntry entryitem in entryCollection)
            {
                IAct entryact = entryitem.AsAct;
                IEntryRelationship entryRelationship  = entryact.EntryRelationship[0];
                IObservation       entryobservation   = entryRelationship.AsObservation;
                IIVL_TS            effectivetime      = entryact.EffectiveTime;
                IParticipant2      allergyParticipant = entryobservation.Participant[0];
                IParticipantRole   participantRole    = allergyParticipant.ParticipantRole;
                IPlayingEntity     playingEntity      = participantRole.AsPlayingEntity;
                ICE              code        = playingEntity.Code;
                IPNCollection    name        = playingEntity.Name;
                string           substance   = name != null && name.Count() > 0 ? name[0].Text : code.DisplayName;
                PatientAllergies ptallergies = new PatientAllergies();
                ptallergies.substance = substance;
                IEntryRelationship entryRelationshipMFST = entryobservation.EntryRelationship.Where(r => r.TypeCode.ToString() == "MFST").FirstOrDefault();
                if (entryRelationshipMFST != null && entryRelationshipMFST.AsObservation.Value != null)
                {
                    IANY Reactionvaluecollection = entryRelationshipMFST.AsObservation.Value.FirstOrDefault();
                    CD   valuesReaction          = (CD)Reactionvaluecollection;
                    ptallergies.reaction = valuesReaction.DisplayName;
                }
                ptallergies.rxNorm = code.Code;
                IEntryRelationship entryRelationshipSUBJ = entryobservation.EntryRelationship.Where(r => r.TypeCode.ToString() == "SUBJ").FirstOrDefault();
                if (entryRelationshipSUBJ != null && entryRelationshipSUBJ.AsObservation.Value != null)
                {
                    IANY Statusvaluecollection = entryRelationshipSUBJ.AsObservation.Value.FirstOrDefault();
                    ICE  values = (ICE)Statusvaluecollection;
                    ptallergies.status = values.DisplayName;
                }
                if (effectivetime != null && effectivetime.Value != null)
                {
                    ptallergies.allergyDate = effectivetime.AsDateTime.ToString();
                }
                alleryies.Add(ptallergies);
            }

            return(alleryies);
        }
 public LoggerNetMetToCosmosDBSqlApiMeasurement(
     Stream myBlob,
     string name,
     ILogger log,
     string functionName,
     string blobPath,
     int timestep,
     DocumentClient client,
     IObservation observation)
 {
     this.myBlob       = myBlob;
     this.name         = name;
     this.log          = log;
     this.functionName = functionName;
     this.version      = "2.0.3";
     this.blobPath     = blobPath;
     this.timestep     = timestep;
     this.client       = client;
     this.observation  = observation;
 }
示例#22
0
    public List <IObservation> MakeDense(List <IObservation> sparse)
    {
        List <IObservation> dense = new List <IObservation>();

        if (!(sparse?.Any() ?? false))
        {
            return(dense);
        }

        foreach (var grp in sparse.GroupBy(x => x.Symbol))
        {
            List <IObservation> sparseGrp = grp.OrderBy(x => x.VintageDate).ThenBy(x => x.ObsDate).ToList();
            IVintage            vintage   = new Vintage {
                VintageDate = DateTime.MinValue
            };
            Dictionary <DateTime, IObservation> dict = new Dictionary <DateTime, IObservation>();

            for (int i = 0; i < sparseGrp.Count; i++)
            {
                IObservation o = sparseGrp[i];

                if (o.VintageDate != vintage.VintageDate)
                {
                    CopyDictToDenseObs(vintage, dict, dense);
                    vintage.VintageDate = o.VintageDate;
                }

                dict.TryGetValue(o.ObsDate, out IObservation existing);

                if (existing == null || existing.Value != o.Value)
                {
                    dict[o.ObsDate] = o;
                }
            }
            CopyDictToDenseObs(vintage, dict, dense);
        }
        return(dense);
    }
示例#23
0
        public List <IObservation> GetObservations(IObservation datatable)
        {
            if (this.FileContent.Length <= 0)
            {
                throw new Exception("No content");
            }

            List <IObservation> observations = new List <IObservation>();

            using (TextReader sr = new StringReader(cleanNulls(cleanHeaders(trimMetaData(this.FileContent)))))
            {
                CsvReader csv = new CsvReader(sr);
                csv.Configuration.HasHeaderRecord   = true;
                csv.Configuration.IgnoreQuotes      = false;
                csv.Configuration.HeaderValidated   = null;
                csv.Configuration.MissingFieldFound = null;

                try
                {
                    observations = csv.GetRecords(datatable.GetType()).Cast <IObservation>().ToList();
                }
                catch (Exception e)
                {
                    throw new Exception("Error parsing observations.", e);
                }
            }

            // Datetimes were in unknown timezone (most likely PST, or UTC-08), so convert to UTC
            foreach (IObservation obs in observations)
            {
                obs.TIMESTAMP =
                    new DateTime(
                        obs.TIMESTAMP.AddHours((-1 * UtcOffset)).Ticks,
                        DateTimeKind.Utc);
            }

            return(observations);
        }
        /// <summary>
        ///     If this reader is in a series, this will return true if the series has any more observation values.
        /// </summary>
        /// <returns> true if series has more observation values </returns>
        public bool MoveNextObservation()
        {
            this._currentObs = null;

            // If we are at the end of the file, or the observations for the key, then return false, there is no point in processing anything
            if (!this._hasNext && !this._hasNextObs)
            {
                return false;
            }

            this._obsIndex++;

            if (this._currentKey == null)
            {
                this._currentKey = this.CurrentKey;
            }

            this._hasNextObs = this.MoveNextObservationInternal();
            return this._hasNextObs;
        }
示例#25
0
 public void ShouldSee(IObservation observation)
 {
     Assert.That(observation.CanBeSeen(this));
 }
示例#26
0
 private Message PerformMapping(IObservation source)
 {
     return Mapping.Map<IObservation, Observation>(source);
 }
        private MeasurementV2 CreateMeasurementFromVariable(
            Variable variable,
            IObservation observation,
            Metadata metadata)
        {
            // Look up property based on string, get value
            var value = observation
                        .GetType()
                        .GetProperty(
                variable.FieldName
                .Replace("(", "")
                .Replace(")", ""))
                        .GetValue(observation, null);

            // Ensure value is a number
            if (!(value is double? ||
                  value is decimal?||
                  value is int? ||
                  value is null))
            {
                return(null);
            }

            string name = map.GetMeasurementName(variable.FieldName);

            // Check if variable is in list to be mapped
            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }

            DateTime measurementDateTime =
                new DateTime(observation.TIMESTAMP.Ticks, DateTimeKind.Utc);

            List <PhysicalQuantityV2> physicalQuantities =
                new List <PhysicalQuantityV2>()
            {
                new PhysicalQuantityV2(
                    (double?)value,
                    variable.Units,
                    DateTime.UtcNow,
                    EtlEventId)
            };

            LocationV2 location = new LocationV2("Point",
                                                 map.GetLatFromStation(metadata),
                                                 map.GetLonFromStation(metadata));

            string areaOfInterest = map.GetFieldID(metadata);

            MeasurementV2 m = new MeasurementV2(
                DocumentType,
                name,
                Schema,
                Project,
                areaOfInterest,
                location,
                measurementDateTime,
                physicalQuantities,
                Timestep);

            return(m);
        }
示例#28
0
 /// <summary>
 /// Gets a <see cref="LabeledObservation"/> containing the <paramref name="state"/> seen as the given <seealso cref="observation"/>.
 /// </summary>
 /// <param name="state">The state.</param>
 /// <param name="observation">The observation.</param>
 /// <returns>StateObservationPair.</returns>
 public static LabeledObservation From([NotNull] this IState state, [NotNull] IObservation observation)
 {
     return(new LabeledObservation(state, observation));
 }
示例#29
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="context"></param>
 public ObservationLogic(IObservation context)
 {
     _context = context;
 }
示例#30
0
 public void SetObservation(IObservation ob)
 {
     _Observation = ob;
 }
        /// <summary>
        ///     Processes the attribute segment
        /// </summary>
        /// <returns>
        ///     true if the attribute was not a dataset attribute.  If the attribute was a dataset attribute, then it can be
        ///     retrieved from the getDatasetAttribute method
        /// </returns>
        private bool ProcessEDIAttributeSegment()
        {
            // TODO Process FNS+ - current line, does this need any processing?

            // Move to the attribute scope line
            if (EDIUtil.AssertPrefix(this._ediDataReader, EdiPrefix.DatasetAttributeScope, false))
            {
                int scope = int.Parse(this._ediDataReader.CurrentLine, CultureInfo.InvariantCulture);

                // 1 = dataset, 4=mix of dimensions, 5=observation
                if (scope == 1)
                {
                    // This is a Dataset attribute which we want to ignore because this reader is passed all the dataset attribtues up front.  
                    // Move to the next line and return false to ensure this is not processed
                    this._ediDataReader.MoveNext();
                    EDIUtil.AssertPrefix(this._ediDataReader, EdiPrefix.DatasetDataAttribute, true);
                    return false;
                }
            }
            else
            {
                this._ediDataReader.MoveBackLine();
            }

            // Move to the dimension/key pointer line
            this.AssertMoveNext();
            EDIUtil.AssertPrefix(this._ediDataReader, EdiPrefix.DatasetDataAttribute, true);
            string currentLine = this._ediDataReader.CurrentLine;
            string[] posKeySplit = EDIUtil.SplitOnPlus(currentLine);

            if (posKeySplit.Length != 2)
            {
                // TODO Exception should be caught and full line + line position put on
                throw new SdmxSyntaxException("Can not parse current line '" + currentLine + "' expecting integer+key example 5+A:B:C:D");
            }

            // TODO These two attributes gives the key of the attribute attachment, if the key is not a full key then it is a group key and the group muse be 
            // determined
            // string lastDimensionPosition = posKeySplit[0];  //TODO What does this mean?  
            string key = posKeySplit[1];

            string[] keySplit = EDIUtil.SplitOnColon(key);
            IList<IKeyValue> keyableKey = new List<IKeyValue>();
            if (keySplit.Length < this._dimensions.Length)
            {
                throw new SdmxSemmanticException("Reported attributes '" + key + "' are less then key length '" + this._dimensions.Length + "' ");
            }

            bool isGroup = false;
            for (int i = 0; i < this._dimensions.Length; i++)
            {
                string val = keySplit[i];
                if (val.Length == 0)
                {
                    isGroup = true;
                }
                else
                {
                    keyableKey.Add(new KeyValueImpl(val, this._dimensions[i]));
                }
            }

            IList<IKeyValue> attributes = this.ProcessAttributeValues();
            this._currentObs = null;

            var obsDateAsSdmxString = this.BuildObsDateAsSdmxString(keySplit, key, isGroup);

            if (isGroup)
            {
                if (obsDateAsSdmxString != null)
                {
                    this._currentKey = new KeyableImpl(this._dataflowObject, this._dataStructureObject, keyableKey, null, this._siblingGroup);
                }
                else
                {
                    this._currentKey = new KeyableImpl(this._dataflowObject, this._dataStructureObject, keyableKey, attributes, this._siblingGroup);
                }
            }
            else
            {
                if (obsDateAsSdmxString != null)
                {
                    // TODO It is not 100% sure what ctor is used in Java. There is a warning there also.
                    this._currentKey = new KeyableImpl(this._dataflowObject, this._dataStructureObject, keyableKey, null);
                    this._currentObs = new ObservationImpl(this._currentKey, obsDateAsSdmxString, null, attributes);
                }
                else
                {
                    // TODO It is not 100% sure what ctor is used in Java. There is a warning there also.
                    this._currentKey = new KeyableImpl(this._dataflowObject, this._dataStructureObject, keyableKey, attributes);
                }
            }

            return true;
        }
        /// <summary>
        ///     Moves the read position back to the start of the Data Set (<see cref="IDataReaderEngine.KeyablePosition" /> moved
        ///     back to -1)
        /// </summary>
        public override void Reset()
        {
            base.Reset();
            this.CloseStreams();
            this._lastCall = LastCall.Null;
            this.GroupId = null;
            this._flatObs = null;
            try
            {
                this._parseInputStream = this.DataLocation.InputStream;
                this._parser = this._xmlReaderBuilder.Build(this._parseInputStream);
                this._runAheadParserInputStream = this.DataLocation.InputStream;
                this._runAheadParser = this._xmlReaderBuilder.Build(this._runAheadParserInputStream);
                IHeaderRetrievalManager headerRetrievalManager = new DataHeaderRetrievalManager(this._parser, this.DefaultDsd);
                this.Header = headerRetrievalManager.Header;
                string dimensionAll = DimensionAtObservation.GetFromEnum(DimensionAtObservationEnumType.All).Value;

                // .NET Implementation note. Because we need to share the ProcessHeader with CrossSectionalDataReaderEngine
                this._noSeries = this.Header.Structures.Any(reference => string.Equals(reference.DimensionAtObservation, dimensionAll));
            }
            catch (XmlException e)
            {
                _log.Error("While reseting the reader and processing the header", e);
                this.Close();
                throw;
            }
        }
        /// <summary>
        ///     Builds the current observation.
        /// </summary>
        private void BuildCurrentObservation()
        {
            var attributes = new List<IKeyValue>();

            foreach (var key in this._observationAttributes)
            {
                IKeyValue keyValue = new KeyValueImpl(key.Value, key.Key);
                attributes.Add(keyValue);
            }

            IKeyValue crossSectionValue = null;
            if (this._crossSectionalObservation != null)
            {
                crossSectionValue = new KeyValueImpl(this._crossSectionalObservation, this._availableMeasureDimensions[0]);
            }

            this._currentObs = new ObservationImpl(this._currentKey, this._currentKey.ObsTime, this._observationValue, attributes, crossSectionValue);
        }
        /// <summary>
        ///     Processes the EDI observation.
        /// </summary>
        /// <exception cref="System.ArgumentException">
        ///     No observation attribute ' <c> GesmesConstants.ObsStatus </c> ' present on DSD, but the data contains a value for
        ///     this attribute
        ///     or
        ///     No observation attribute ' <c> _obsConf </c> ' present on DSD, but the data contains a value for this attribute
        ///     or
        ///     No observation attribute ' <c> GesmesConstants.ObsPreBreak </c> ' present on DSD, but the data contains a value for
        ///     this attribute
        /// </exception>
        private void ProcessEDIObservation()
        {
            while (true)
            {
                this._currentObsPos++;
                this._currentObs = null;
                if (this._observations == null)
                {
                    if (this._obsDates.Count > this._currentObsPos)
                    {
                        // Observations is null, but this does not mean that there was not a reported date, or dates.  
                        // In this case, the observation is just a date, with no reported value.  This can be the case in delete messages
                        string obsDate = this._obsDates.Count > this._currentObsPos ? this._obsDates[this._currentObsPos] : null;
                        this._currentObs = new ObservationImpl(this._currentKey, obsDate, null, null);
                    }
                }
                else if (this._observations.Length > this._currentObsPos)
                {
                    string currentObsLine = this._observations[this._currentObsPos];

                    // 1. Set up variables
                    string obsDate = this._obsDates.Count > this._currentObsPos ? this._obsDates[this._currentObsPos] : null;
                    IList<IKeyValue> attributes = new List<IKeyValue>();

                    // If there is no observation, and no date, don't output anything.
                    if (!ObjectUtil.ValidString(currentObsLine))
                    {
                        if (!ObjectUtil.ValidString(obsDate))
                        {
                            this._currentObsPos++;
                            continue;
                        }
                    }

                    string[] obsArr = EDIUtil.SplitOnColon(currentObsLine);

                    // 0 = ObsValue
                    // 1 = ObsStatus
                    // 2 = ObsConf
                    // 3 = ObsPreBreak
                    string obsVal = obsArr[0];

                    bool obsStatusPresent = obsArr.Length > 1 && ObjectUtil.ValidString(obsArr[1]);
                    bool obsConfPresent = obsArr.Length > 2 && ObjectUtil.ValidString(obsArr[2]);
                    bool obsPreBreakPresent = obsArr.Length > 3 && ObjectUtil.ValidString(obsArr[3]);

                    if (obsStatusPresent)
                    {
                        if (this._hasObsStatus)
                        {
                            attributes.Add(new KeyValueImpl(obsArr[1], EdiConstants.ObsStatus));
                        }
                        else
                        {
                            throw new ArgumentException("No observation attribute '" + EdiConstants.ObsStatus + "' present on Dsd, but the data contains a value for this attribute");
                        }
                    }
                    else
                    {
                        // If there is no ObsStatus and no ObsValue skip to the next entry
                        if (!ObjectUtil.ValidString(obsVal))
                        {
                            continue;
                        }
                    }

                    if (obsConfPresent)
                    {
                        if (this._hasObsConf)
                        {
                            attributes.Add(new KeyValueImpl(obsArr[2], this._obsConf));
                        }
                        else
                        {
                            throw new ArgumentException("No observation attribute '" + this._obsConf + "' present on Dsd, but the data contains a value for this attribute");
                        }
                    }

                    if (obsPreBreakPresent)
                    {
                        if (this._hasObsPreBeak)
                        {
                            string obsAttr = obsArr[3].Equals(this._missingValue) ? SdmxConstants.MissingDataValue : obsArr[3];
                            attributes.Add(new KeyValueImpl(obsAttr, EdiConstants.ObsPreBreak));
                        }
                        else
                        {
                            throw new ArgumentException("No observation attribute '" + EdiConstants.ObsPreBreak + "' present on Dsd, but the data contains a value for this attribute");
                        }
                    }

                    if (obsVal == null)
                    {
                        obsVal = string.Empty;
                    }

                    if (obsVal.Equals(this._missingValue))
                    {
                        obsVal = SdmxConstants.MissingDataValue;
                    }

                    this._currentObs = new ObservationImpl(this._currentKey, obsDate, obsVal, attributes);
                }
                else
                {
                    // Check if the next key is the same as the last key
                    IKeyable prevKey = this._currentKey;
                    if (this.MoveNextKeyable())
                    {
                        if (this._inFootNoteSection)
                        {
                            this._lookedAhead = true;
                            break;
                        }

                        if (this._currentKey.Equals(prevKey))
                        {
                            continue;
                        }

                        this._lookedAhead = true;
                    }
                }

                break;
            }
        }
示例#35
0
        public void GeneratTasks(Definitions def, Dictionary <string, object> InputData = null, IObservation Ob = null)
        {
            this.OB = Ob;

            var startID = generatIds(def.Process.StartEvent.ID);

            this.StartTask = new StartTaskInstance()
            {
                Name     = def.Process.StartEvent.Name,
                SourceID = def.Process.StartEvent.ID,
                ID       = startID,
                To       = generatIds(def.Process.StartEvent.OutGoing),
                Status   = TaskStatus.Empty,
                Type     = TaskType.Start
            };

            // 开始节点
            this.Tasks.Add(startID, this.StartTask);

            // 用户手工任务
            def.Process.UserTasks.ForEach(t =>
            {
                var taskID = generatIds(t.ID);
                var fromID = generatIds(t.Incoming);
                var toID   = generatIds(t.OutGoing);

                var mTask = new ManualTaskInstance()
                {
                    Name     = t.Name,
                    ID       = taskID,
                    SourceID = t.ID,
                    To       = toID,
                    From     = fromID,
                    Status   = TaskStatus.Empty,
                    Type     = TaskType.Manual,
                    Owner    = t.PotentialOwner
                };

                if (mTask.Owner != null && !string.IsNullOrEmpty(mTask.Owner.Name))
                {
                    if (mTask.Owner.Name == "ProcessUser")
                    {
                        mTask.UserID = this.CreateUser;
                    }
                    else if (InputData.ContainsKey(mTask.Owner.Name))
                    {
                        mTask.UserID = int.Parse(InputData[mTask.Owner.Name].ToString());
                    }
                    else if (this.ProcessResouces.ContainsKey(mTask.Owner.Name) && this.ProcessResouces[mTask.Owner.Name].Users.Count == 1)
                    {
                        mTask.UserID = int.Parse(this.ProcessResouces[mTask.Owner.Name].Users.First().Key);
                    }
                }

                if (Ob != null)
                {
                    mTask.SetObservation(Ob);
                }

                this.Tasks.Add(taskID, mTask);
            });

            // 自动调用Api任务
            def.Process.AutoTasks.ForEach(t =>
            {
                var taskID = generatIds(t.ID);
                var fromID = generatIds(t.Incoming);
                var toID   = generatIds(t.OutGoing);

                this.Tasks.Add(taskID, new AutoTaskInstance(UnityContainerHelper.GetServer <IAutoTaskExcute>(t.Name))
                {
                    Name     = t.Name,
                    ID       = taskID,
                    SourceID = t.ID,
                    To       = toID,
                    From     = fromID,
                    Status   = TaskStatus.Empty,
                    Type     = TaskType.CallApi
                });
            });

            // 会签任务
            def.Process.JointlySigns.ForEach(t =>
            {
                var taskID = generatIds(t.ID);
                var fromID = generatIds(t.Incoming);
                var toID   = generatIds(t.OutGoing);

                var mTask = new JointlySignTaskInstance()
                {
                    Name     = t.Name,
                    ID       = taskID,
                    SourceID = t.ID,
                    To       = toID,
                    From     = fromID,
                    Status   = TaskStatus.Empty,
                    Type     = TaskType.Sign,
                    Owner    = t.PotentialOwner
                };

                if (mTask.Owner != null && !string.IsNullOrEmpty(mTask.Owner.Name))
                {
                    if (InputData.ContainsKey(mTask.Owner.Name))
                    {
                        mTask.Users = InputData[mTask.Owner.Name].ToString();
                    }
                    else if (this.ProcessResouces.ContainsKey(mTask.Owner.Name) && this.ProcessResouces[mTask.Owner.Name].Users.Count == 1)
                    {
                        mTask.Users = this.ProcessResouces[mTask.Owner.Name].Users.First().Key;
                    }
                }

                if (Ob != null)
                {
                    mTask.SetObservation(Ob);
                }

                this.Tasks.Add(taskID, mTask);
            });

            // 连接线
            def.Process.SequenceFlows.ForEach(s =>
            {
                var taskID = generatIds(s.ID);
                var fromID = generatIds(s.SourceRef);
                var toID   = generatIds(s.TargetRef);

                this.Sequences.Add(taskID, new SequenceInstance()
                {
                    Name      = s.ID,
                    ID        = taskID,
                    To        = toID,
                    From      = fromID,
                    Condition = s.Condition
                });
            });

            // 独立网关
            def.Process.ExclusiveGateways.ForEach(g =>
            {
                var gid = generatIds(g.ID);

                this.Gateways.Add(gid, new ExclusiveGatewayInstance()
                {
                    ID      = gid,
                    Froms   = generatIds(g.Incoming),
                    Tos     = generatIds(g.Outgoing),
                    Type    = GatewayType.Exclusive,
                    Default = generatIds(g.Default)
                });
            });

            // 并行网关
            def.Process.ParallelGateways.ForEach(g =>
            {
                var gid = generatIds(g.ID);

                this.Gateways.Add(gid, new ParallelGatewayInstance()
                {
                    ID    = gid,
                    Froms = generatIds(g.Incoming),
                    Tos   = generatIds(g.Outgoing),
                    Type  = GatewayType.Parallel,
                    IsJointlySignBegin = g.Type != null && g.Type.Equals("JointlySignBegin"),
                    IsJointlySignEnd   = g.Type != null && g.Type.Equals("JointlySignEnd")
                });
            });

            var endId     = generatIds(def.Process.EndEvent.ID);
            var endFromID = generatIds(def.Process.EndEvent.Incoming);

            // 结束任务
            this.Tasks.Add(endId, new EndTaskInstance()
            {
                Name     = def.Process.EndEvent.Name,
                ID       = endId,
                SourceID = def.Process.EndEvent.ID,
                From     = endFromID,
                Status   = TaskStatus.Empty,
                Type     = TaskType.End
            });
        }
示例#36
0
 private Message PerformMapping(IObservation source)
 {
     return(Mapping.Map <IObservation, Observation>(source));
 }
 /// <summary>
 ///     Moves the read position back to the start of the Data Set (<see cref="IDataReaderEngine.KeyablePosition" /> moved
 ///     back to -1)
 /// </summary>
 public virtual void Reset()
 {
     this._hasNext = true;
     this._keyableIndex = -1;
     this._datasetIndex = -1;
     this._obsIndex = -1;
     this._currentObs = null;
     this._currentKey = null;
 }
        /// <summary>
        ///     The lazy load key.
        /// </summary>
        /// <returns>
        ///     The <see cref="IKeyable" />.
        /// </returns>
        protected override IKeyable LazyLoadKey()
        {
            try
            {
                // If the last call was to read the next series, then we are reading the one after that, so move on,
                // Otherwise, if we're not on a series, group, or obs as series, move on
                if (this._lastCall == LastCall.NextSeries
                    || (this.DatasetPositionInternal != Api.Constants.DatasetPosition.Series && this.DatasetPositionInternal != Api.Constants.DatasetPosition.Group
                        && this.DatasetPositionInternal != Api.Constants.DatasetPosition.ObservationAsSeries))
                {
                    if (!this.MoveNextKeyable())
                    {
                        return null;
                    }
                }

                if (this.DatasetPositionInternal == Api.Constants.DatasetPosition.Group)
                {
                    IKeyable key = this.ProcessGroupNode();
                    if (_log.IsDebugEnabled)
                    {
                        _log.DebugFormat("Read Key {0}", key);
                    }

                    return key;
                }
                else if (this.DatasetPositionInternal == Api.Constants.DatasetPosition.Series || this.DatasetPositionInternal == Api.Constants.DatasetPosition.ObservationAsSeries)
                {
                    var key = this.ProcessSeriesNode();
                    this._flatObs = this.CurrentObs; // STORE THE OBSERVATION LOCALLY IN THIS CLASS THAT WAS CREATED AS PART OF GENERATING THE SERIES
                    if (_log.IsDebugEnabled)
                    {
                        _log.Debug(key);
                    }

                    return key;
                }

                return null;
            }
            catch (XmlException e)
            {
                throw new SdmxException("Unrecoverable error while reading SDMX data", e);
            }
            finally
            {
                this._lastCall = LastCall.NextSeries;
            }
        }
示例#39
0
        /// <summary>
        /// The compare to.
        /// </summary>
        /// <param name="other">
        /// The other. 
        /// </param>
        /// <returns>
        /// The <see cref="int"/> . 
        /// </returns>
        public virtual int CompareTo(IObservation other)
        {
            if (this.obsTime == null)
            {
                if (other.ObsTime == null)
                {
                    return 0;
                }

                return -1;
            }

            if (other.ObsTime == null)
            {
                return 1;
            }

            if (this.obsTime.Length == other.ObsTime.Length)
            {
                return string.CompareOrdinal(this.obsTime, other.ObsTime);
            }

            DateTime? obsAsTimeDate = this.ObsAsTimeDate;
            if (obsAsTimeDate != null)
            {
                return obsAsTimeDate.Value.CompareTo(other.ObsAsTimeDate);
            }

            return -1;
        }
示例#40
0
 /// <summary>
 /// Gets a <see cref="LabeledObservation"/> containing the <paramref name="state"/> seen as the given <seealso cref="observation"/>.
 /// </summary>
 /// <param name="state">The state.</param>
 /// <param name="observation">The observation.</param>
 /// <returns>StateObservationPair.</returns>
 public static LabeledObservation As([NotNull] this IObservation observation, [NotNull] IState state)
 {
     return(new LabeledObservation(state, observation));
 }
 /// <summary>
 ///     Moves the read position back to the start of the Data Set (<see cref="IDataReaderEngine.KeyablePosition" /> moved
 ///     back to -1)
 /// </summary>
 public void Reset()
 {
     this._currentlyProcessingReaderIndex = -1;
     this._ediDataReader = null;
     this._currentObsPos = -1;
     this._keyablePosition = -1;
     this._currentKey = null;
     this._currentObs = null;
 }