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 <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); }
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); }