// using a time series to construct a Timeseries class public TSTypeDetector(List<DataPoint> sourceList, TimeSeriesType timeSerieType = TimeSeriesType.UNKNOWN) { this.timeSerieType = timeSerieType; // pre-assign the period list initialAccList(); if (sourceList == null) return; // transfer it to the list List<double> timeseries = this.dataPointToList(sourceList); // calculate the time interval this.interval = this.calculateInterval(this.dataPointToData(sourceList)); switch (timeSerieType) { case TimeSeriesType.LINEAR: this.LevelTrendEvaluation(timeseries); this.timeSerieType = TimeSeriesType.LINEAR; break; case TimeSeriesType.PERIODICAL: this.periodList.Add(this.PeriodEvaluation(timeseries)); int period = this.periodList[0] ; int index = 0 ; while (this.TypeDetection(this.smoothing(timeseries, period)) == TimeSeriesType.PERIODICAL) { index++; period *= this.periodList[index]; } this.timeSerieType = TimeSeriesType.PERIODICAL; break; default: TimeSeriesType type = this.TypeDetection(timeseries); this.timeSerieType = type ; if (type == TimeSeriesType.PERIODICAL) { period = this.periodList[0] ; index = 0 ; while (this.TypeDetection(this.smoothing(timeseries,period)) == TimeSeriesType.PERIODICAL) { index ++ ; period *= this.periodList[index] ; } } break; } }
public HttpResponseMessage PutType(TimeSeriesType type) { if (string.IsNullOrEmpty(type.Type) || type.Fields == null || type.Fields.Length < 1) { return(GetEmptyMessage(HttpStatusCode.BadRequest)); } using (var writer = TimeSeries.CreateWriter()) { writer.CreateType(type.Type, type.Fields); writer.Commit(); } TimeSeries.MetricsTimeSeries.ClientRequests.Mark(); return(new HttpResponseMessage(HttpStatusCode.Created)); }
/// <summary> /// Function: Convert a value from the Sell currency denomination to the Buy currency denomination on a given date. /// The conversion is dependent on the definition of the FX Instrument. /// </summary> /// <param name="value">Value to be converted. /// </param> /// <param name="date">Reference date. /// </param> /// <param name="type">Time series type of time series point. /// </param> /// <param name="provider">Provider of reference time series object (Standard is AQI). /// </param> /// <param name="timeSeriesRoll">Roll type of reference time series object. /// </param> public double Convert(double value, DateTime date, TimeSeriesType type, DataProvider provider, TimeSeriesRollType timeSeriesRoll) { double fxi = FXInstrument[date, type, provider, timeSeriesRoll]; if (double.IsNaN(fxi)) { CurrencyPair pair_inv = CurrencyPair.FindCurrencyPair(CurrencySell, CurrencyBuy); if (pair_inv != null) { return(pair_inv.ConvertInverse(value, date, type, provider, timeSeriesRoll)); } return(value); } return(value * fxi); }
/// <summary> /// gather and save Original Agency data from webservice to database /// </summary> /// <param name="variable">object from the database that contains all the details of the series we are trying to gather data for</param> /// <param name="start">date at the beginning of the interval</param> /// <param name="end">date at end of interval</param>1 public void AgencyDataFill(L1HarvestList variable, string start, string end, int count) { DBLogging.WriteLog(Properties.Settings.Default.projectName, "Log", "Level1Data1_0" + "." + (new StackTrace(true)).GetFrame(0).GetMethod().Name + "()", String.Format("{0} {1} {2}-{3} {4}\t{5}-{6} {7}/{8}", "Level1", variable.SiteName, start.Replace('-', '/'), end.Replace('-', '/'), variable.SiteCode, variable.VariableCode, "Level1", count, db.SummaryDB.Count)); TimeSeriesType dataVals = this.GetData(variable, start, end); if (dataVals != null) { if (Convert.ToInt32(dataVals.values.count) >= 1) { int siteID = this.SiteData(variable); if (variable.SiteID == 0) { this.db.SummaryDB.UpdateHarvestSite(variable, siteID); } this.noDataValue = Convert.ToDouble(dataVals.variable.NoDataValue); TsValuesSingleVariableType vals = dataVals.values; DateTime startDate = (from n in vals.value select Convert.ToDateTime(n.dateTime)).Min(); DateTime endDate = (from n in vals.value select Convert.ToDateTime(n.dateTime)).Max(); var data = from n in vals.value select n; foreach (ValueSingleVariable member in data) { TimeSpan utcoffset = member.dateTime - member.dateTime.ToUniversalTime(); // site, Method, variable, Source this.values.Rows.Add(SqlInt32.Null, Convert.ToDouble(member.Value), (member.accuracyStdDev == 0 ? SqlDouble.Null : member.accuracyStdDev), member.dateTime, utcoffset.Hours /*utcoffset*/, member.dateTime.ToUniversalTime(), siteID, variable.VariableID, (member.offsetValue == 0 ? SqlDouble.Null : member.offsetValue), (Convert.ToInt32(member.offsetTypeID) == 0 ? SqlInt32.Null : Convert.ToInt32(member.offsetTypeID)), this.CensorCodeToString(member), SqlInt32.Null, variable.MethodID, variable.SourceID, (Convert.ToInt32(member.sampleID) == 0 ? SqlInt32.Null : Convert.ToInt32(member.sampleID)), SqlInt32.Null, variable.QualityControlLevelID); } this.db.TooDB.InsertBulk(this.values); DBLogging.WriteLog(Properties.Settings.Default.projectName, "Log", "Level1Data1_0" + "." + (new StackTrace(true)).GetFrame(0).GetMethod().Name + "()", values.Rows.Count + " Rows Saved. " + "Level1" + " " + variable.SiteName + " " + variable.SiteCode + "\t" + variable.VariableCode + "-" + "Level1"); this.db.TooDB.SaveSeries(siteID, variable); } else { //DBLogging.WriteLog(Properties.Settings.Default.projectName, "Log", "Level1Data1_0" + "." + (new StackTrace(true)).GetFrame(0).GetMethod().Name + "()", "No Values Found. " + variable.DataTimePeriod + " " + variable.SiteName + " " + variable.SiteCode + "\t" + variable.VariableCode + "-" + variable.DataTimePeriod); } } else { DBLogging.WriteLog(Properties.Settings.Default.projectName, "Log", "Level1Data1_0" + "." + (new StackTrace(true)).GetFrame(0).GetMethod().Name + "()", 0 + " Rows Saved. " + "Level1" + " " + variable.SiteName + " " + variable.SiteCode + "\t" + variable.VariableCode + "-" + "Level1"); } }
public void VarianceRatioTest(double[] data, int lag = 1, TimeSeriesType cor = TimeSeriesType.HOM) { DenseVector x = new DenseVector(data); //Mean double mu = x.Mean(); //Variance for 1st Order Difference double s1 = (x.SubVector(lag, x.Count - lag) - x.SubVector(0, x.Count - 2)).Variance(); double dLag = lag; double varvrt = double.NaN; switch (cor) { case TimeSeriesType.HOM: { varvrt = 2 * (2 * dLag - 1) * (dLag - 1) / (3 * dLag * x.Count); break; } case TimeSeriesType.HET: { varvrt = 0; double sum2 = 0; for (int j = 0; j < lag; j++) { double sum1a = 0; //(x(j+2:n)-x(j+1:n-1)-mu).^2 double sum1b = 0; //(x(2:n-j)-x(1:n-j-1)-mu).^2; double sum1 = sum1a * sum1b; double delta = sum1 / (Math.Pow(sum2, 2)); varvrt += 0; //(2*(q(i)-j)/q(i))^2)*delta; } break; } } ZScore = (VRatio - 1) / Math.Sqrt(varvrt); PValue = NormCDF(ZScore); }
/// <summary> /// Function: Weighted average of contract value * liquidity for a given number of days. Liquidity type is usually volume. /// </summary> /// <param name="date">reference date</param> /// <param name="days">number of days in weighted average</param> /// <param name="liquidityType">type of liquidity. (Volume usually)</param> public double AverageDailyLiquidity(DateTime date, int days, TimeSeriesType liquidityType) { TimeSeries ts_close = this.GetTimeSeries(TimeSeriesType.Close); int idx_date_close = ts_close.GetClosestDateIndex(date, TimeSeries.DateSearchType.Previous); ts_close = ts_close.GetRange(Math.Max(0, idx_date_close - (days - 1)), idx_date_close); TimeSeries ts_liquidity = this.GetTimeSeries(liquidityType); int idx_date_liquidity = ts_liquidity.GetClosestDateIndex(date, TimeSeries.DateSearchType.Previous); ts_liquidity = ts_liquidity.GetRange(Math.Max(0, idx_date_liquidity - (days - 1)), idx_date_liquidity); if (ts_liquidity != null && ts_liquidity.Count != 0) { TimeSeries ts_dollar_liquidity = ts_close * ts_liquidity * this.ContractSize; double adl = ts_dollar_liquidity.Average(); return(adl); } return(0); }
public void VarianceRatioTest(double[] data, int lag = 1, TimeSeriesType cor = TimeSeriesType.HOM) { DenseVector x = new DenseVector(data); //Mean double mu = x.Mean(); //Variance for 1st Order Difference double s1 = (x.SubVector(lag, x.Count - lag) - x.SubVector(0, x.Count - 2)).Variance(); double dLag = lag; double varvrt = double.NaN; switch (cor) { case TimeSeriesType.HOM: { varvrt = 2*(2*dLag - 1)*(dLag - 1)/(3*dLag*x.Count); break; } case TimeSeriesType.HET: { varvrt = 0; double sum2 = 0; for (int j = 0; j < lag; j++) { double sum1a = 0; //(x(j+2:n)-x(j+1:n-1)-mu).^2 double sum1b = 0; //(x(2:n-j)-x(1:n-j-1)-mu).^2; double sum1 = sum1a*sum1b; double delta = sum1/(Math.Pow(sum2, 2)); varvrt += 0; //(2*(q(i)-j)/q(i))^2)*delta; } break; } } ZScore = (VRatio - 1)/Math.Sqrt(varvrt); PValue = NormCDF(ZScore); }
/// <summary> /// Creates modsim TimeSeries and sets VariesByYear /// </summary> /// <param name="tstype"></param> /// <param name="n"></param> public static void CreateModsimTimeSeries(TimeSeriesType tstype, Node n, bool variesByYear) { var ts = new Csu.Modsim.ModsimModel.TimeSeries(tstype); switch (tstype) { case TimeSeriesType.Demand: ts.units = n.m.adaDemandsM.units; n.m.adaDemandsM = ts; break; case TimeSeriesType.NonStorage: ts.units = n.m.adaInflowsM.units; n.m.adaInflowsM = ts; break; case TimeSeriesType.Targets: ts.units = n.m.adaTargetsM.units; n.m.adaTargetsM = ts; break; case TimeSeriesType.Evaporation: ts.units = n.m.adaEvaporationsM.units; n.m.adaEvaporationsM = ts; break; case TimeSeriesType.Forecast: ts.units = n.m.adaForecastsM.units; n.m.adaForecastsM = ts; break; default: throw new Exception("Only NonStorage, Demand, Targets, Forecast, and Evaporation supported"); } ts.VariesByYear = variesByYear; ts.MultiColumn = !variesByYear; }
private static void PrintResponse(TimeSeriesType type) { Console.WriteLine("Type ID: {0}", type.Id); Console.WriteLine(" Name: {0}", type.Name); Console.WriteLine(" Description: {0}", type.Description); foreach (KeyValuePair <string, Variable> variable in type.Variables) { Console.WriteLine(" Variable: {0}", variable.Key); Console.WriteLine(" Filter: {0}", variable.Value.Filter?.TsxProperty); var numericVariable = variable.Value as NumericVariable; if (numericVariable != null) { Console.WriteLine(" Value: {0}", numericVariable.Value?.TsxProperty); Console.WriteLine(" Aggregation: {0}", numericVariable.Aggregation?.TsxProperty); } var aggregateVariable = variable.Value as AggregateVariable; if (aggregateVariable != null) { Console.WriteLine(" Aggregation: {0}", aggregateVariable.Aggregation?.TsxProperty); } } }
/// <summary> /// Function: Convert a value from the Sell currency denomination to the Buy currency denomination on a given date. /// </summary> /// <param name="value">Value to be converted. /// </param> /// <param name="date">Reference date. /// </param> /// <param name="type">Time series type of time series point. /// </param> /// <param name="provider">Provider of reference time series object (Standard is AQI). /// </param> /// <param name="timeSeriesRoll">Roll type of reference time series object. /// </param> /// <param name="buy">Target currency in the conversion. /// </param> /// <param name="sell">Initial currency in the conversion. /// </param> public static double Convert(double value, DateTime date, TimeSeriesType type, DataProvider provider, TimeSeriesRollType timeSeriesRoll, Currency buy, Currency sell) { if (buy == sell) { return(value); } CurrencyPair pair = CurrencyPair.FindCurrencyPair(buy, sell); if (pair != null) { return(pair.Convert(value, date, type, provider, timeSeriesRoll)); } CurrencyPair pair_inv = CurrencyPair.FindCurrencyPair(sell, buy); if (pair_inv != null) { return(pair_inv.ConvertInverse(value, date, type, provider, timeSeriesRoll)); } return(0.0); }
private async Task IndexDocumentsAsync(IReadOnlyCollection <T> documents) { if (HasMultipleIndexes) { foreach (var documentGroup in documents.GroupBy(TimeSeriesType.GetDocumentIndex)) { await TimeSeriesType.EnsureIndexAsync(documentGroup.First()).AnyContext(); } } if (documents.Count == 1) { var document = documents.Single(); var response = await _client.IndexAsync(document, i => { i.Type(ElasticType.Name); if (GetParentIdFunc != null) { i.Parent(GetParentIdFunc(document)); } if (GetDocumentIndexFunc != null) { i.Index(GetDocumentIndexFunc(document)); } if (HasVersion) { var versionDoc = (IVersioned)document; i.Version(versionDoc.Version); } return(i); }).AnyContext(); _logger.Trace(() => response.GetRequest()); if (!response.IsValid) { string message = response.GetErrorMessage(); _logger.Error().Exception(response.ConnectionStatus.OriginalException).Message(message).Property("request", response.GetRequest()).Write(); throw new ApplicationException(message, response.ConnectionStatus.OriginalException); } if (HasVersion) { var versionDoc = (IVersioned)document; versionDoc.Version = response.Version != null?Int64.Parse(response.Version) : -1; } } else { var response = await _client.IndexManyAsync(documents, GetParentIdFunc, GetDocumentIndexFunc, ElasticType.Name).AnyContext(); _logger.Trace(() => response.GetRequest()); if (HasVersion) { foreach (var hit in response.Items) { var document = documents.FirstOrDefault(d => d.Id == hit.Id); if (document == null) { continue; } var versionDoc = (IVersioned)document; if (hit.Version != null) { versionDoc.Version = Int64.Parse(hit.Version); } } } if (!response.IsValid) { string message = response.GetErrorMessage(); _logger.Error().Exception(response.ConnectionStatus.OriginalException).Message(message).Property("request", response.GetRequest()).Write(); throw new ApplicationException(message, response.ConnectionStatus.OriginalException); } } }
public async Task RemoveAsync(IEnumerable <T> documents, bool sendNotification = true) { var docs = documents?.ToList(); if (docs == null || docs.Any(d => d == null)) { throw new ArgumentNullException(nameof(documents)); } if (docs.Count == 0) { return; } if (HasMultipleIndexes) { foreach (var documentGroup in docs.GroupBy(TimeSeriesType.GetDocumentIndex)) { await TimeSeriesType.EnsureIndexAsync(documentGroup.First()).AnyContext(); } } await OnDocumentsRemovingAsync(docs).AnyContext(); // TODO: support Parent and child docs. if (docs.Count == 1) { var document = docs.First(); var response = await _client.DeleteAsync(document, descriptor => descriptor.Index(GetDocumentIndexFunc?.Invoke(document)).Type(ElasticType.Name)).AnyContext(); _logger.Trace(() => response.GetRequest()); if (!response.IsValid) { string message = response.GetErrorMessage(); _logger.Error().Exception(response.ConnectionStatus.OriginalException).Message(message).Property("request", response.GetRequest()).Write(); throw new ApplicationException(message, response.ConnectionStatus.OriginalException); } } else { var documentsByIndex = docs.GroupBy(d => GetDocumentIndexFunc?.Invoke(d)); var response = await _client.BulkAsync(bulk => { foreach (var group in documentsByIndex) { bulk.DeleteMany <T>(group.Select(g => g.Id), (b, id) => b.Index(group.Key).Type(ElasticType.Name)); } return(bulk); }).AnyContext(); _logger.Trace(() => response.GetRequest()); if (!response.IsValid) { string message = response.GetErrorMessage(); _logger.Error().Exception(response.ConnectionStatus.OriginalException).Message(message).Property("request", response.GetRequest()).Write(); throw new ApplicationException(message, response.ConnectionStatus.OriginalException); } } await OnDocumentsRemovedAsync(docs, sendNotification).AnyContext(); }
static void InsertOneSource(OD_1_1_1DataSet.SourcesDataTable srcTable, SiteInfoType stinfo, seriesCatalogTypeSeries scts, TimeSeriesType tst, int metadataID, SqlConnection sqlConn) { OD_1_1_1DataSet.SourcesRow row = srcTable.NewSourcesRow(); row.SourceID = scts.source.sourceID; row.Organization = scts.source.organization; row.SourceDescription = scts.source.sourceDescription; row.MetadataID = metadataID; string tbd = "TBD"; row.SourceLink = tbd; if (scts.source.sourceLink != null) { row.SourceLink = scts.source.sourceLink[0]; } row.ContactName = row.Phone = row.Email = row.Address = row.City = row.State = row.ZipCode = row.Citation = tbd; for (int i = 0; (stinfo.note != null) && (i < stinfo.note.Count()); i++) { NoteType note = stinfo.note[i]; switch (note.title) { case "ContactName": row.ContactName = note.Value; break; case "Phone": row.Phone = note.Value; break; case "Email": row.Email = note.Value; break; case "Address": row.Address = note.Value; break; case "City": row.City = note.Value; break; case "State": row.State = note.Value; break; case "ZipCode": row.ZipCode = note.Value; break; case "Citation": row.Citation = note.Value; break; } } //srcTable.AddSourcesRow(row); string sql = string.Format(@"SET IDENTITY_INSERT [Sources] ON; INSERT INTO [Sources] ([SourceID], [Organization], [SourceDescription], [SourceLink], [ContactName], [Phone], [Email], [Address], [City], [State], [ZipCode], [Citation], [MetadataID]) VALUES ({0}, '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', {12}); SET IDENTITY_INSERT [Sources] OFF", row.SourceID, row.Organization, row.SourceDescription, row.SourceLink, row.ContactName, row.Phone, row.Email, row.Address, row.City, row.State, row.ZipCode, row.Citation, row.MetadataID); OD_Utils.RunNonQuery(sql, sqlConn); }
public IEnumerable<TimeSeriesType> GetTimesSeriesTypeForSiteVariable(string SiteNumber, string StartDate, string EndDate) { W3CDateTime? BeginDateTime; W3CDateTime? EndDateTime; int? variableId = null; int? siteID; VariableInfoType varInfoType = null; SiteInfoType siteType = null; BeginDateTime = GetBeginDateTime(StartDate); EndDateTime = GetEndDateTime(EndDate); locationParam sq = GetLocationParameter(SiteNumber); siteInfoDataSet sitDs = ODSiteInfo.GetSiteInfoDataSet(sq); if (sitDs != null && sitDs.sites.Count > 0) { siteID = sitDs.sites[0].SiteID; ValuesDataSet valuesDs = getValuesDataset(siteID, null, BeginDateTime, EndDateTime); DataTable variableTable = DataSetHelper.SelectDistinct("variableIds", valuesDs.DataValues, "VariableID"); if (variableTable.Rows.Count == 0) { throw new WaterOneFlowException("No Data Available for Time Period."); } foreach (DataRow dataRow in variableTable.Rows) { TimeSeriesType timeSeries = new TimeSeriesType(); timeSeries.sourceInfo = ODSiteInfo.row2SiteInfoElement(sitDs.sites[0], sitDs); int id = (int)dataRow[0]; VariableInfoType vit = ODvariables.GetVariableByID(id, variableDs); timeSeries.variable = vit; // DataView view = new DataView(valuesDs.DataValues, "VariableId = " + id, " DateTime ASC", DataViewRowState.CurrentRows); timeSeries.values = getValues(valuesDs, null, id); yield return timeSeries; } } }
/// <summary> /// This sample demonstrates getting Time Series model settings, updating model settings and changing the default type Id for a model. /// </summary> public async Task RunSamplesAsync(TimeSeriesInsightsClient client) { PrintHeader("TIME SERIES INSIGHTS MODEL SETTINGS SAMPLE"); #region Snippet:TimeSeriesInsightsSampleGetModelSettings TimeSeriesInsightsModelSettings modelSettingsClient = client.GetModelSettingsClient(); TimeSeriesInsightsTypes typesClient = client.GetTypesClient(); Response <TimeSeriesModelSettings> getModelSettingsResponse = await modelSettingsClient.GetAsync(); Console.WriteLine($"Retrieved Time Series Insights model settings \nname : '{getModelSettingsResponse.Value.Name}', " + $"default type Id: {getModelSettingsResponse.Value.DefaultTypeId}'"); IReadOnlyList <TimeSeriesIdProperty> timeSeriesIdProperties = getModelSettingsResponse.Value.TimeSeriesIdProperties; foreach (TimeSeriesIdProperty property in timeSeriesIdProperties) { Console.WriteLine($"Time Series Id property name : '{property.Name}', type : '{property.PropertyType}'."); } #endregion Snippet:TimeSeriesInsightsSampleGetModelSettings // Store the default type Id so it can be used during clean up string defaultTypeId = getModelSettingsResponse.Value.DefaultTypeId; #region Snippet:TimeSeriesInsightsSampleUpdateModelSettingsName Response <TimeSeriesModelSettings> updateModelSettingsNameResponse = await modelSettingsClient.UpdateNameAsync("NewModelSettingsName"); Console.WriteLine($"Updated Time Series Insights model settings name: " + $"{updateModelSettingsNameResponse.Value.Name}"); #endregion Snippet:TimeSeriesInsightsSampleUpdateModelSettingsName // For every Time Series Insights environment, there is a default type that any newly created Time Series instance will be associated with. // You can change the default type for a TSI environment by creating a new type and calling the API to update the default type Id. // Create a Time Series type. var aggregateVariable = new AggregateVariable(new TimeSeriesExpression("count()")); var variables = new Dictionary <string, TimeSeriesVariable> { { "aggregateVariableName", aggregateVariable }, }; var type = new TimeSeriesType("tsiTypeName", variables); var timeSeriesTypes = new List <TimeSeriesType> { type }; string tsiTypeId = null; Response <TimeSeriesTypeOperationResult[]> createTsiTypeResponse = await typesClient .CreateOrReplaceAsync(timeSeriesTypes); // Ensure no error was reported as part of the response if (createTsiTypeResponse.Value[0].Error == null) { // Store the Time Series type id to use it for updating default type in model settings tsiTypeId = createTsiTypeResponse.Value[0].TimeSeriesType.Id; #region Snippet:TimeSeriesInsightsSampleUpdateModelSettingsDefaultType Response <TimeSeriesModelSettings> updateDefaultTypeIdResponse = await modelSettingsClient .UpdateDefaultTypeIdAsync(tsiTypeId); Console.WriteLine($"Updated Time Series Insights model settings default type Id: " + $"{updateDefaultTypeIdResponse.Value.Name}"); #endregion Snippet:TimeSeriesInsightsSampleUpdateModelSettingsDefaultType } // Clean up try { // Revert back to the original default type Id await modelSettingsClient .UpdateDefaultTypeIdAsync(defaultTypeId); // Delete the type created if (tsiTypeId != null) { await typesClient .DeleteByIdAsync(new List <string> { tsiTypeId }); } } catch (Exception ex) { Console.WriteLine($"Failed at one of the clean up steps: {ex.Message}"); } }
protected string[] GetIndexesByQuery(IRepositoryQuery query, ICommandOptions options = null) { return(HasMultipleIndexes ? TimeSeriesType.GetIndexesByQuery(query) : new[] { ElasticIndex.Name }); }
internal TimeSeriesTypeOrError(TimeSeriesType timeSeriesType, TsiErrorBody error) { TimeSeriesType = timeSeriesType; Error = error; }
/// <summary> /// Function: Convert a value from the Sell currency denomination to the Buy currency denomination on a given date. /// The conversion is dependent on the definition of the inverse of the FX Instrument. /// </summary> /// <param name="value">Value to be converted. /// </param> /// <param name="date">Reference date. /// </param> /// <param name="type">Time series type of time series point. /// </param> /// <param name="provider">Provider of reference time series object (Standard is AQI). /// </param> /// <param name="timeSeriesRoll">Roll type of reference time series object. /// </param> public double ConvertInverse(double value, DateTime date, TimeSeriesType type, DataProvider provider, TimeSeriesRollType timeSeriesRoll) { return(value / FXInstrument[date, type, provider, timeSeriesRoll]); }
// we will need to add some features. public static TimeSeriesType TimeSeriesObjectSingleValue() { TimeSeriesType tst = new TimeSeriesType(); tst.values = new TsValuesSingleVariableType(); return tst; }
protected string GetIndexById(Id id) { return(HasMultipleIndexes ? TimeSeriesType.GetIndexById(id) : ElasticIndex.Name); }
internal TimeSeriesTypeOrError(TimeSeriesType timeSeriesType, InstancesOperationError error) { TimeSeriesType = timeSeriesType; Error = error; }
public async Task TimeSeriesInsightsTypes_Lifecycle() { // Arrange TimeSeriesInsightsClient client = GetClient(); var timeSeriesTypes = new List <TimeSeriesType>(); var tsiTypeNamePrefix = "type"; int numOfTypesCreated = 0; var timeSeriesTypesProperties = new Dictionary <string, string> { { Recording.GenerateAlphaNumericId(tsiTypeNamePrefix), Recording.GenerateId() }, { Recording.GenerateAlphaNumericId(tsiTypeNamePrefix), Recording.GenerateId() } }; // Build aggregate variable var countExpression = new TimeSeriesExpression("count()"); var aggregateVariable = new AggregateVariable(countExpression); var variables = new Dictionary <string, TimeSeriesVariable>(); var variableNamePrefix = "aggregateVariable"; variables.Add(Recording.GenerateAlphaNumericId(variableNamePrefix), aggregateVariable); foreach (var property in timeSeriesTypesProperties) { var type = new TimeSeriesType(property.Key, variables); type.Id = property.Value; timeSeriesTypes.Add(type); numOfTypesCreated++; } // Act and assert try { // Get all Time Series types in the environment AsyncPageable <TimeSeriesType> getAllTypesResponse = client.GetTimeSeriesTypesAsync(); await foreach (TimeSeriesType tsiType in getAllTypesResponse) { tsiType.Should().NotBeNull(); } // Create Time Series types Response <TimeSeriesOperationError[]> createTypesResult = await client .CreateOrReplaceTimeSeriesTypesAsync(timeSeriesTypes) .ConfigureAwait(false); // Assert that the result error array does not contain any object that is set createTypesResult.Value.Should().OnlyContain((errorResult) => errorResult == null); Response <TimeSeriesTypeOperationResult[]> getTypesByNamesResult; // This retry logic was added as the TSI types are not immediately available after creation await TestRetryHelper.RetryAsync <Response <TimeSeriesTypeOperationResult[]> >(async() => { // Get the created types by names getTypesByNamesResult = await client .GetTimeSeriesTypesByNamesAsync(timeSeriesTypesProperties.Keys) .ConfigureAwait(false); getTypesByNamesResult.Value.Should().OnlyContain((errorResult) => errorResult.Error == null); getTypesByNamesResult.Value.Length.Should().Be(timeSeriesTypes.Count); foreach (TimeSeriesTypeOperationResult typesResult in getTypesByNamesResult.Value) { typesResult.Error.Should().BeNull(); typesResult.TimeSeriesType.Should().NotBeNull(); typesResult.TimeSeriesType.Id.Should().NotBeNullOrEmpty(); typesResult.TimeSeriesType.Variables.Count.Should().Be(1); typesResult.TimeSeriesType.Variables.IsSameOrEqualTo(variables); } return(null); }, MaxNumberOfRetries, s_retryDelay); // Update variables with adding a new variable foreach (var type in timeSeriesTypes) { type.Description = "Description"; } Response <TimeSeriesOperationError[]> updateTypesResult = await client .CreateOrReplaceTimeSeriesTypesAsync(timeSeriesTypes) .ConfigureAwait(false); updateTypesResult.Value.Should().OnlyContain((errorResult) => errorResult == null); updateTypesResult.Value.Length.Should().Be(timeSeriesTypes.Count); // This retry logic was added as the TSI types are not immediately available after creation await TestRetryHelper.RetryAsync <Response <TimeSeriesTypeOperationResult[]> >(async() => { // Get type by Id Response <TimeSeriesTypeOperationResult[]> getTypeByIdResult = await client .GetTimeSeriesTypesByIdAsync(timeSeriesTypesProperties.Values) .ConfigureAwait(false); getTypeByIdResult.Value.Length.Should().Be(numOfTypesCreated); foreach (TimeSeriesTypeOperationResult typeOperationResult in getTypeByIdResult.Value) { typeOperationResult.TimeSeriesType.Should().NotBeNull(); typeOperationResult.Error.Should().BeNull(); typeOperationResult.TimeSeriesType.Name.Should().StartWith(tsiTypeNamePrefix); typeOperationResult.TimeSeriesType.Id.Should().NotBeNull(); } return(null); }, MaxNumberOfRetries, s_retryDelay); } finally { // clean up try { Response <TimeSeriesOperationError[]> deleteTypesResponse = await client .DeleteTimeSeriesTypesbyIdAsync(timeSeriesTypesProperties.Values) .ConfigureAwait(false); // Assert that the response array does not have any error object set deleteTypesResponse.Value.Should().OnlyContain((errorResult) => errorResult == null); } catch (Exception ex) { Console.WriteLine($"Test clean up failed: {ex.Message}"); throw; } } }
protected string[] GetIndexesByQuery(object query) { return(HasMultipleIndexes ? TimeSeriesType.GetIndexesByQuery(query) : new[] { ElasticIndex.Name }); }
internal TimeSeriesTypeOperationResult(TimeSeriesType timeSeriesType, TimeSeriesOperationError error) { TimeSeriesType = timeSeriesType; Error = error; }
// No one single data source provides enough data for Sources table, // so try all resources to put them together. public static void HandleSourceInfo(SqlConnection sqlConn, SiteInfoType stinfo, seriesCatalogTypeSeries scts, TimeSeriesType tst) { string cond = "SourceID = " + scts.source.sourceID; if (OD_Utils.Exists("Sources", cond, sqlConn)) { return; } SourcesTableAdapter srcAdapter = new SourcesTableAdapter(); srcAdapter.Connection = sqlConn; int metadataID = 0; string title = "Unknown"; OD_1_1_1DataSet.SourcesDataTable tblSources = new OD_1_1_1DataSet.SourcesDataTable(); // We currently don't have any information about ISOMetaDataTable. Just create // an unkown entry to resolve foreign key dependency. if (scts.source.metadata != null) { title = scts.source.metadata.title; } cond = string.Format("Title = '{0}'", title); metadataID = OD_Utils.GetPrimaryKey("ISOMetadata", "MetadataID", cond, sqlConn); if (metadataID < 0) { InsertOneMetadata(scts.source.metadata, sqlConn); metadataID = OD_Utils.GetPrimaryKey("ISOMetadata", "MetadataID", cond, sqlConn); } Console.WriteLine(">>>Parsing and inserting SOURCES"); InsertOneSource(tblSources, stinfo, scts, tst, metadataID, sqlConn); //srcAdapter.Update(tblSources); //PrintTable(srcAdapter, tblSites); }