public IHttpActionResult MakePrediction(PredictionSeed seed) { NNPredictor predictor = BlobConverter <NNPredictor> .Decode(db.Stocks.Find(seed.id).Data); List <StockHistory> history = new List <StockHistory>(); StockHistory firstDay = new StockHistory { Close = seed.day1.Close, Volume = seed.day1.Volume }; history.Add(firstDay); StockHistory secondDay = new StockHistory { Close = seed.day2.Close, Volume = seed.day2.Volume }; history.Add(secondDay); StockHistory thirdDay = new StockHistory { Close = seed.day3.Close, Volume = seed.day3.Volume }; history.Add(thirdDay); var output = predictor.Predict(history)[0][0]; return(Ok(output)); }
/// <summary> /// Run BLOBPointer converter before mapping /// </summary> /// <param name="manager"></param> /// <param name="sourceDatabase"></param> /// <param name="destinationDatabase"></param> /// <param name="obj"></param> public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj) { // // Cast type DatabaseConversion.CleanerTool.EclipseDataAccess.general_insurance_workbooks record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.general_insurance_workbooks; // // Run blob pointer converter if needed if (record.geninswb_document_object_eclipse != null && !IgnoreBlobs) { string blobPointer = BlobConverter.ConvertToFile(BlobStoreCategories.POLICY_TRANSACTION, BlobStoreCategories.POLICY_TRANSACTION, record.geninswb_document_object_eclipse); this._documentFilePath.Add(record.geninswb_id, blobPointer); } if (record.geninswb_portfolio_object_eclipse != null && !IgnoreBlobs) { string blobPointer = BlobConverter.ConvertToFile(BlobStoreCategories.POLICY_TRANSACTION, BlobStoreCategories.POLICY_TRANSACTION, record.geninswb_portfolio_object_eclipse); this._portfolioFilePath.Add(record.geninswb_id, blobPointer); } if (record.geninswb_coc_eclipse != null && !IgnoreBlobs) { string blobPointer = BlobConverter.ConvertToFile(BlobStoreCategories.POLICY_TRANSACTION, BlobStoreCategories.POLICY_TRANSACTION, record.geninswb_coc_eclipse); this._cocFilePath.Add(record.geninswb_id, blobPointer); } if (record.geninswb_object_eclipse != null && !IgnoreBlobs) { string blobPointer = BlobConverter.ConvertToFile(BlobStoreCategories.POLICY_TRANSACTION, BlobStoreCategories.POLICY_TRANSACTION, record.geninswb_object_eclipse); this._objectFilePath.Add(record.geninswb_id, blobPointer); } }
/// <summary> /// Saves Blob to file -> returns Blob pointer -> generates script insert for blobs as PK|BlobPointer to keep track /// After migrating data for a table (which contains Blob), will need this data to set Blob pointer /// </summary> /// <param name="blobMappings">The BLOB mappings.</param> /// <returns></returns> private bool HandleBlobFields(List <FieldMappingDefinition> blobMappings, out string blobScript) { Console.WriteLine("Handling Blob for " + _definition.SourceTable.Name); blobScript = ""; string insertScript = string.Format(SqlScriptTemplates.INSERT, "[TempDatabase].dbo.[BlobPointers]", "([PKValue], [BlobFieldName], [BlobPointer])"); StringBuilder valuesScriptBuilder = new StringBuilder(); blobMappings.ForEach(m => { var blobs = _sourceDatabase.GetBlobs(_definition.SourceTable.Name, m.SourceField.Name); blobs.ForEach(b => { byte[] data = b.Value; string blobPointer = BlobConverter.ConvertToFile(m.BlobCategory, m.BlobCategory, data); valuesScriptBuilder.Append(Environment.NewLine + string.Format("('{0}','{1}','{2}')", b.Key, m.SourceField.Name, blobPointer) + ","); }); }); if (valuesScriptBuilder.Length == 0) { return(false); } string valuesScript = valuesScriptBuilder.ToString().Trim(','); blobScript = insertScript + Environment.NewLine + string.Format(SqlScriptTemplates.INSERT_VALUES, valuesScript); return(true); }
public ActionResult HandleCSVForm(NetworkSeed seed) { var stream = seed.File.InputStream; List <StockHistory> history = parseCSV(stream); var historyForTrain = history.GetRange(0, (int)(history.Count * 0.8)); #region hide historyForTrain = history; #endregion NNPredictor predictor = new NNPredictor(historyForTrain, parameters); var stock = new Stock { Name = seed.Name, Ticker = seed.Ticker, Data = BlobConverter <NNPredictor> .Encode(predictor) }; db.Stocks.Add(stock); db.SaveChanges(); var stockId = stock.Id; db.StocksHistory.AddRange(history.Select(x => { x.StockId = stockId; return(x); })); savePredictedStockHistory(history, stockId, predictor); db.SaveChanges(); return(RedirectToAction("Edit")); }
/// <summary> /// Run BLOBPointer converter before mapping /// </summary> /// <param name="manager"></param> /// <param name="sourceDatabase"></param> /// <param name="destinationDatabase"></param> /// <param name="obj"></param> public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj) { // // Cast type DatabaseConversion.CleanerTool.EclipseDataAccess.confirmation_of_cover record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.confirmation_of_cover; // // Run blob pointer converter if needed if (record.coc_document_object_eclipse != null && !IgnoreBlobs) { string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.CONFIRMATION_OF_COVER, BlobStoreCategories.CONFIRMATION_OF_COVER, record.coc_document_object_eclipse); this._temporyFilePath.Add(record.coc_id, fullPath); } }
/// <summary> /// Run BLOBPointer converter before mapping /// </summary> /// <param name="manager"></param> /// <param name="sourceDatabase"></param> /// <param name="destinationDatabase"></param> /// <param name="obj"></param> public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj) { // // Cast type DatabaseConversion.CleanerTool.EclipseDataAccess.gen_ins_documents record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.gen_ins_documents; // // Run blob pointer converter if needed if (record.geninsdo_object_eclipse != null && !IgnoreBlobs) { string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.POLICY_TASK_TEMPLATE, BlobStoreCategories.POLICY_TASK_TEMPLATE, record.geninsdo_object_eclipse); this._temporyFilePath.Add(record.geninsdo_id, fullPath); } }
/// <summary> /// Run BLOBPointer converter before mapping /// </summary> /// <param name="manager"></param> /// <param name="sourceDatabase"></param> /// <param name="destinationDatabase"></param> /// <param name="obj"></param> public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj) { // // Cast type DatabaseConversion.CleanerTool.EclipseDataAccess.client_insurance_portfolio record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.client_insurance_portfolio; // // Run blob pointer converter if needed if (record.cip_document_object_eclipse != null && !IgnoreBlobs) { string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.CLIENT_INSURANCE_PORTFOLIO, BlobStoreCategories.CLIENT_INSURANCE_PORTFOLIO, record.cip_document_object_eclipse); this._temporyFilePath.Add(record.cip_id, fullPath); } }
/// <summary> /// Run BLOBPointer converter before mapping /// </summary> /// <param name="manager"></param> /// <param name="sourceDatabase"></param> /// <param name="destinationDatabase"></param> /// <param name="obj"></param> public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj) { // // Cast type DatabaseConversion.CleanerTool.EclipseDataAccess.tasks_sub_tasks record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.tasks_sub_tasks; // // Run blob pointer converter if needed if (record.tassubta_image != null && !IgnoreBlobs) { string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.CLIENT_TASK_DOCUMENT, BlobStoreCategories.CLIENT_TASK_DOCUMENT, record.tassubta_image); this._temporyFilePath.Add(record.tassubta_id, fullPath); } }
/// <summary> /// Run BLOBPointer converter before mapping /// </summary> /// <param name="manager"></param> /// <param name="sourceDatabase"></param> /// <param name="destinationDatabase"></param> /// <param name="obj"></param> public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj) { // // Cast type DatabaseConversion.CleanerTool.EclipseDataAccess.notes record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.notes; // // Run blob pointer converter if needed if (record.not_object != null && !IgnoreBlobs) { string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.NOTE, BlobStoreCategories.NOTE, record.not_object); this._temporyFilePath.Add(record.not_id, fullPath); } }
/// <summary> /// Run BLOBPointer converter before mapping /// </summary> /// <param name="manager"></param> /// <param name="sourceDatabase"></param> /// <param name="destinationDatabase"></param> /// <param name="obj"></param> public override void BeforeRunningAutoMapper(MappingManager manager, SourceDatabase sourceDatabase, DestinationDatabase destinationDatabase, object obj) { // // Cast type DatabaseConversion.CleanerTool.EclipseDataAccess.DocumentRepository record = obj as DatabaseConversion.CleanerTool.EclipseDataAccess.DocumentRepository; // // Run blob pointer converter if needed if (record.dr_document != null && !IgnoreBlobs) { string fullPath = BlobConverter.ConvertToFile(BlobStoreCategories.DOCUMENT_REPOSITORY, BlobStoreCategories.DOCUMENT_REPOSITORY, record.dr_document); this._temporyFilePath.Add(record.dr_id, fullPath); } }
public string GenerateBlobFieldUpdateScript() { string result = ""; List <FieldMappingDefinition> blobMappings = GetBlobMappings(); if (blobMappings.Any()) { // Create temp table to store blob pointer string createTempTableScript = @"CREATE TABLE #Temp (Id int, Value varchar(MAX))"; string insertScript = string.Format(SqlTemplates.INSERT, "#Temp", "[Id], [Value]"); string dropTempTableScript = @"DROP TABLE #Temp"; string truncateTempTableScript = @"TRUNCATE TABLE #Temp"; int emptyBlobsCount = 0; string script = ""; Field destPK = _definition.DestinationTable.GetPrimaryKey(); blobMappings.ForEach(m => { // Insert blob value into temp table List <KeyValuePair <int, byte[]> > blobs; if (!string.IsNullOrEmpty(m.GetBlobScriptPath)) // if explicit sql is provided to get blobs, use it { string sql = File.ReadAllText(m.GetBlobScriptPath); blobs = _definition.SourceTable.GetBlobs(m.SourceField.Name, sql); } else { blobs = _definition.SourceTable.GetBlobs(m.SourceField.Name); } if (blobs.Any()) { StringBuilder valuesScriptBuilder = new StringBuilder(); if (m.Type == FieldMappingType.BlobToBlobPointer) { blobs.ForEach(b => { byte[] data = b.Value; if (data != null) { string blobPointer = BlobConverter.ConvertToFile(m.BlobCategory, m.BlobCategory, data); valuesScriptBuilder.Append(Environment.NewLine + string.Format("('{0}','{1}')", b.Key, blobPointer) + ","); } }); } else if (m.Type == FieldMappingType.BlobToHtml) { blobs.ForEach(b => { byte[] data = b.Value; if (data != null) { string blobHtml = WordGenerator.ConvertRtfToHtml(WordGenerator.ConvertDocxToRTF(data)); valuesScriptBuilder.Append(Environment.NewLine + string.Format("('{0}','{1}')", b.Key, blobHtml) + ","); } }); } string valuesScript = valuesScriptBuilder.ToString().Trim(','); string insertBlobPointerScript = insertScript + NewLines(1) + string.Format(SqlTemplates.INSERT_VALUES, valuesScript); // Merge blob pointer into destination table string mergeBlobPointerScript = SqlTemplates.MERGE_UPDATE.Inject(new { TargetTable = _definition.DestinationTable.FullName, SourceTable = "#Temp", TargetPK = destPK.Name, SourcePK = "Id", TargetField = m.DestinationField.Name, SourceField = "Value" }); script += insertBlobPointerScript + NewLines(2) + mergeBlobPointerScript + NewLines(2) + truncateTempTableScript + NewLines(2); } else { emptyBlobsCount++; } }); // Prevent there is no blobs to update if (emptyBlobsCount < blobMappings.Count) { result = createTempTableScript + NewLines(2) + script + dropTempTableScript; } } return(result); }
internal string FormatStringData(StringBuilder npText, FormatType fType, bool isSel) { string npOut = ""; var view = npc.GetViewSettings(isSel); if (fType == FormatType.PrettyJson) { npOut = JsonFormatter.PrettyJson(npText, new JsonFormatSettings() { TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode }); npc.CheckSetLangType(view.Id, (int)LangType.L_JSON); } else if (fType == FormatType.PrettyJsonSorted) { npOut = JsonFormatter.PrettyJsonSorted(npText, new JsonFormatSettings() { TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode }); npc.CheckSetLangType(view.Id, (int)LangType.L_JSON); } else if (fType == FormatType.MiniJson) { npOut = JsonFormatter.MiniJson(npText); npc.CheckSetLangType(view.Id, (int)LangType.L_JSON); } else if (fType == FormatType.PrettyXml) { npOut = XmlFormatter.PrettyXml(npText, new XmlFormatSettings() { TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode, IsSelection = view.IsSelection }); npc.CheckSetLangType(view.Id, (int)LangType.L_XML); } else if (fType == FormatType.PrettyXmlSorted) { npOut = XmlFormatter.PrettyXmlSorted(npText, new XmlFormatSettings() { TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode, IsSelection = view.IsSelection }, nps.XmlSortExcludeAttributeValues.ValToString().Split(new string[] { nps.XmlSortExcludeValueDelimiter.ValToString() }, StringSplitOptions.RemoveEmptyEntries)); npc.CheckSetLangType(view.Id, (int)LangType.L_XML); } else if (fType == FormatType.MiniXml) { npOut = XmlFormatter.MiniXml(npText, new XmlFormatSettings() { TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode, IsSelection = view.IsSelection }); npc.CheckSetLangType(view.Id, (int)LangType.L_XML); } else if (fType == FormatType.B64GzipString) { if (npText.ToString(0, 5).StartsWith("Data=", StringComparison.OrdinalIgnoreCase)) { npText.Remove(0, 5); } npOut = Base64GzipConverter.ConvertToString(npText); } else if (fType == FormatType.B64GzipPrettyJson) { if (npText.ToString(0, 5).StartsWith("Data=", StringComparison.OrdinalIgnoreCase)) { npText.Remove(0, 5); } npOut = JsonFormatter.PrettyJson(new StringBuilder(Base64GzipConverter.ConvertToString(npText)), new JsonFormatSettings() { TabWidth = view.TabWidth, UseTabs = view.UseTabs, EolMode = view.EolMode }); npc.CheckSetLangType(view.Id, (int)LangType.L_JSON); } else if (fType == FormatType.B64GzipPayload) { npOut = Base64GzipConverter.ConvertToPayload(npText); } else if (fType == FormatType.BlobString) { npOut = BlobConverter.ConvertToString(npText); } else if (fType == FormatType.BlobPayload) { npOut = BlobConverter.ConvertToPayload(npText); } else { throw new Exception("Invalid command."); } return(npOut); }