public static DataSetDetail Run(DateTimeOffset startDate, DateTimeOffset endDate, string targetKey, bool implicitTimestamp = false) { var tscol = implicitTimestamp ? "timeStamp" : "time"; var rand = new Random(); var dates = Enumerable.Range(0, (endDate.Date - startDate.Date).Days).Select(i => startDate.UtcDateTime.Date.AddDays(i)); var ds = new DataSetDetail { Data = dates.Select(d => new Dictionary <string, string> { { tscol, d.ToString("O") }, { targetKey, (rand.NextDouble() * 100).ToString() } }).ToList(), Columns = new Dictionary <string, ColumnMetadata> { { targetKey, new ColumnMetadata { DataType = ColumnType.Numeric, Role = ColumnRole.Target } } } }; if (!implicitTimestamp) { ds.Columns.Add(tscol, new ColumnMetadata { DataType = ColumnType.Date, Role = ColumnRole.Timestamp }); } return(ds); }
public void Search_when_todate_is_not_null_and_date_is_more_than_min_datevalue_returns_datasetdetail_with_correct_filtered_smaller_than_todate_list_of_DataSetDetail() { //arrange string to = "01/01/2010";// new DateTime(2010, 1, 1); string from = null; var searchText = "dstitle"; int schemaId = 0; var schema = new DataSetSchema() { Title = "dstitle", Id = 0 }; var dsd1 = new DataSetDetail() { DateUpdated = new DateTime(2010, 11, 1), Schema = schema }; var dsd2 = new DataSetDetail() { DateUpdated = new DateTime(2009, 12, 2), Schema = schema }; _repositoryDataSetDetail.Add(dsd1); _repositoryDataSetDetail.Add(dsd2); var sut = new DataSetDetailService(_systemConfigurationService, _repositoryDataSetDetail, _dataSetSchemaService, _sqlRepo, _sqlColumnTextFormatter); //act var result = sut.Search(schemaId, searchText, from, to); //assert Assert.AreEqual(new DateTime(2009, 12, 2), result[0].DateUpdated); //cleanup _repositoryDataSetDetail.Delete(dsd1); _repositoryDataSetDetail.Delete(dsd2); }
public void Search_when_fromdate_and_todate_isemptyString_returns_all_datasetdetail() { //arrange var searchText = "dstitle"; int schemaId = 0; var schema = new DataSetSchema() { Title = "dstitle", Id = 0 }; var dsd1 = new DataSetDetail() { DateUpdated = new DateTime(2010, 11, 1), Schema = schema }; var dsd2 = new DataSetDetail() { DateUpdated = new DateTime(2009, 12, 2), Schema = schema }; _repositoryDataSetDetail.Add(dsd1); _repositoryDataSetDetail.Add(dsd2); var sut = new DataSetDetailService(_systemConfigurationService, _repositoryDataSetDetail, _dataSetSchemaService, _sqlRepo, _sqlColumnTextFormatter); //act var result = sut.Search(schemaId, searchText, "", ""); //assert Assert.AreEqual(2, result.Count); //cleanup _repositoryDataSetDetail.Delete(dsd1); _repositoryDataSetDetail.Delete(dsd2); }
public static DataSetDetail Run(int rowCount, int columns, string targetKey) { var rand = new Random(); var columnNames = Enumerable.Range(0, columns).Select(i => i.ToString()).ToList(); if (targetKey != null) { columnNames.Add(targetKey); } var rows = Enumerable.Range(0, rowCount).Select(r => columnNames.ToDictionary(k => k, v => (rand.NextDouble() * 100).ToString())).ToList(); var ds = new DataSetDetail { Data = rows, Columns = columnNames.ToDictionary(k => k, v => new ColumnMetadata { DataType = ColumnType.String, Role = ColumnRole.Feature }) }; if (targetKey != null) { ds.Columns[targetKey] = new ColumnMetadata { DataType = ColumnType.Numeric, Role = ColumnRole.Target }; } return(ds); }
public void DatasetExistsAlready_when_title_isnot_found_and_alldataisoverwrittenonupload_true_returns_false() { //arrange var schema = new DataSetSchema() { Id = 1, IsAllDataOverwittenOnUpload = true }; var dsd1 = new DataSetDetail() { Title = "title", Schema = schema }; _repositoryDataSetDetail.Add(dsd1); var mock = new Mock <IDataSetSchemaService>(); mock.Setup(x => x.Get(1)).Returns(schema); _dataSetSchemaService = mock.Object; var sut = new DataSetDetailUploaderService(_dataSetSchemaService, _repositoryDataSetDetail, _csvProcessor, _sqlRepo); //act var result = sut.DatasetExistsAlready(1, "tidsatle"); //assert Assert.AreEqual(false, result); //cleanup _repositoryDataSetDetail.Delete(dsd1); }
public async Task <DataSetSummary> Create(string dataSetName, DataSetDetail data, Action <HttpRequestMessage, HttpResponseMessage> httpMessageTransformer, CancellationToken cancellationToken) { Argument.IsNotNullOrEmpty(dataSetName, nameof(dataSetName)); Argument.IsNotNull(data, nameof(data)); return(await apiConnection.Put <DataSetSummary>($"data/{dataSetName}", null, data, httpMessageTransformer, cancellationToken).ConfigureAwait(false)); }
private DataSetDetail AddDataSetDetailToDatabase(int schemaId, string title, FileInfo uploadedFile) { var datasetDetail = new DataSetDetail { Schema = _dataSetSchemaService.Repository.Query(s => s.Id == schemaId).FirstOrDefault(), Title = title, VersionNumber = 1, XmlFileSize = (uploadedFile.Length * 2), CsvFileSize = uploadedFile.Length }; _repository.Add(datasetDetail); _repository.SaveChanges(); return(datasetDetail); }
public DataSetDetail AddExternalDataSet(int schemaId, string title, string url, string type) { var datasetDetail = new DataSetDetail { Schema = _dataSetSchemaService.Repository.Query(s => s.Id == schemaId).FirstOrDefault(), Title = title, VersionNumber = 1, FileUrl = url, FileType = type.ToUpper(), CsvFileSize = 0, XmlFileSize = 0 }; _repositoryDataSetDetails.Add(datasetDetail); _repositoryDataSetDetails.SaveChanges(); return(datasetDetail); }
public void Get_will_return_dataset_detail_based_on_selected_id() { //arrange var datasetdetail = new DataSetDetail() { Id = 1, Title = "datasetdetail1" }; _repositoryDataSetDetail.Add(datasetdetail); var sut = new DataSetDetailService(_systemConfigurationService, _repositoryDataSetDetail, _dataSetSchemaService, _sqlRepo, _sqlColumnTextFormatter); //act var result = sut.Get(1); //assert Assert.AreEqual("datasetdetail1", result.Title); //cleanup _repositoryDataSetDetail.Delete(datasetdetail); }
public void GetData_when_datasetdetail_is_not_null_returns_datatable() { //arrange var datasetdetail = new DataSetDetail() { Title = "datasetdetail title here", Schema = new DataSetSchema() { Title = "schema title here", Definition = new DataSetSchemaDefinition() { TableName = "table1", Columns = new List <DataSetSchemaColumn>() { new DataSetSchemaColumn() { Title = "col1" } } } } }; _repositoryDataSetDetail.Add(datasetdetail); var ds = new DataSet(); ds.Tables.Add(new DataTable()); var mock = new Mock <IDataSetDetailSqlRepo>(); mock.Setup(x => x.ExecuteQueryDatasetDetailId(_repositoryDataSetDetail.DbConnectionString, datasetdetail.Schema.Definition, datasetdetail.Id)).Returns(ds); _sqlRepo = mock.Object; var sut = new DataSetDetailService(_systemConfigurationService, _repositoryDataSetDetail, _dataSetSchemaService, _sqlRepo, _sqlColumnTextFormatter); //act var result = sut.GetData("datasetdetail-title-here", "schema-title-here"); //assert Assert.AreEqual(typeof(DataTable), result.GetType()); //cleanup }
/// <summary> /// Create a Data Source from a <see cref="DataSetDetail"/> /// </summary> /// <param name="name">The name of the DataSet to be created</param> /// <param name="data">The data</param> /// <returns>An IDataSetSource to be used for creating the data set</returns> public static IDataSetSource From(string name, DataSetDetail data) { return(new DataSetDetailSource(name, data)); }
public void DeleteExternalDataSetDetail(DataSetDetail dataSetDetail) { var deleteSql = String.Format(@"exec DS_DataSet_Delete ""{0}"", {1}", dataSetDetail.Schema.Definition.TableName, dataSetDetail.Id); _dataSetDetailSqlRepo.ExecuteQuery(_repositoryDataSetDetails.DbConnectionString, deleteSql, null); }
public void DeleteDataSetDetail(DataSetDetail dataSetDetail) { _repositoryDataSetDetails.Delete(dataSetDetail); _repositoryDataSetDetails.SaveChanges(); }
public Task <DataSetSummary> Create(string dataSetName, DataSetDetail data, Action <HttpRequestMessage, HttpResponseMessage> httpMessageTransformer) { return(Create(dataSetName, data, httpMessageTransformer, CancellationToken.None)); }
public Task <DataSetSummary> Create(string dataSetName, DataSetDetail data) { return(Create(dataSetName, data, null)); }
public string CreateDataSet() { try { var data = Request.Form["datasetdata"]; var moduleid = Request.Form["module"].toInt(); var datasetobject = JsonConvert.DeserializeObject <List <DatasetObject> >(data); bool isduplicateTable = datasetobject.GroupBy(d => d.TableName).Count() < datasetobject.Count; if (isduplicateTable) { return("1"); } StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); int tcounter = 0; int ccounter = 0; string[] tags = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; foreach (DatasetObject tbitem in datasetobject) { if (tcounter == 0) //handling the first table { sb2.Append(" from \"" + tbitem.TableName + "\" " + tags[0]); } else { var pretag = tags[tcounter - 1]; //setting previous table values var pretable = datasetobject[tcounter - 1]; sb2.Append(" inner join \"" + tbitem.TableName + "\" " + tags[tcounter] + " on (" + pretag + ".\"" + pretable.NxtTable + "\"=" + tags[tcounter] + ".\"" + tbitem.PreTable + "\") "); } ccounter = 0; if (tbitem.Columns.isNull()) { sb.Append(tags[tcounter] + ".*"); } else { foreach (string column in tbitem.Columns) { ccounter++; sb.Append(tags[tcounter] + ".\"" + column + "\""); if (ccounter < tbitem.Columns.Length) { sb.Append(","); } } } tcounter++; if (tcounter < datasetobject.Count) { sb.Append(","); } } string cols = sb.ToString(); string tabs = sb2.ToString(); var db = new InlaksBIContext(); var script = "CREATE MATERIALIZED VIEW public." + datasetobject[0].DataSetName + " AS Select "; var dataset = new DataSetDetail(); dataset.Script = script + cols + tabs; dataset.DataSetName = datasetobject[0].DataSetName; DBInterface dbinterface = new PostgreSQLDBInterface(new Settings().warehousedb); int resp = dbinterface.Execute(dataset.Script); var sql = "select * from \"" + dataset.DataSetName + "\" LIMIT 1"; var dt = dbinterface.getData(sql); dataset.Module = db.Modules.Where(m => m.ModuleID == moduleid).FirstOrDefault(); db.DataSets.Add(dataset); db.SaveChanges(); if (dt.Rows.Count > 0) { return("0"); } else { return("DataSet Created sucessfully but has no data"); } } catch (Exception e) { return(e.Message); } }
public DataSetDetailSource(string name, DataSetDetail data) { this.data = data; this.name = name; }