public void PlaceDeposit(BankAccount account, decimal _transaction_amt) { if (_transaction_amt <= 0) { _msgPrinter.PrintMessage("Amount needs to be more than zero. Try again.", false); } else if (_transaction_amt % 10 != 0) { _msgPrinter.PrintMessage($"Key in the deposit amount only with multiply of 10. Try again.", false); } else if (!PreviewBankNotesCount(_transaction_amt)) { _msgPrinter.PrintMessage($"You have cancelled your action.", false); } else { // Bind transaction_amt to Transaction object // Add transaction record - Start var transaction = new Transaction() { AccountID = account.Id, BankAccountNoTo = account.AccountNumber, TransactionType = TransactionType.Deposit, TransactionAmount = _transaction_amt, TransactionDate = DateTime.Now }; _repoTransaction.InsertTransaction(transaction); // Add transaction record - End account.Balance = account.Balance + _transaction_amt; //ctx.SaveChanges(); //_msgPrinter.PrintMessage($"You have successfully deposited {Utility.FormatAmount(_transaction_amt)}", true); } }
/// <summary> /// Evaluate how good (or bad) training went on test data /// </summary> protected virtual void EvaluateModel(ITrainingDatasetDefinition datasetDefinition, string persistedTrainingModelPath, int howManySamplesToUseFromTestDataset) { using (var evaluationMinibatchSourceModel = MinibatchSource.TextFormatMinibatchSource (TrainingDataset.TestingDatasetPath, GetStreamConfigFrom(datasetDefinition), MinibatchSource.FullDataSweep)) { Function model = Function.Load(persistedTrainingModelPath, Device); var imageInput = model.Arguments[0]; var labelOutput = model.Outputs.Single(o => o.Name == ClassifierName); var featureStreamInfo = evaluationMinibatchSourceModel.StreamInfo(FeatureStreamName); var labelStreamInfo = evaluationMinibatchSourceModel.StreamInfo(LabelsStreamName); int batchSize = 50; int miscountTotal = 0, totalCount = 0; while (true) { var minibatchData = evaluationMinibatchSourceModel.GetNextMinibatch((uint)batchSize, Device); if (minibatchData == null || minibatchData.Count == 0) { break; } totalCount += (int)minibatchData[featureStreamInfo].numberOfSamples; // expected lables are in the minibatch data. var labelData = minibatchData[labelStreamInfo].data.GetDenseData <float>(labelOutput); var expectedLabels = labelData.Select(l => l.IndexOf(l.Max())).ToList(); var inputDataMap = new Dictionary <Variable, Value>() { { imageInput, minibatchData[featureStreamInfo].data } }; var outputDataMap = new Dictionary <Variable, Value>() { { labelOutput, null } }; model.Evaluate(inputDataMap, outputDataMap, Device); var outputData = outputDataMap[labelOutput].GetDenseData <float>(labelOutput); var actualLabels = outputData.Select(l => l.IndexOf(l.Max())).ToList(); int misMatches = actualLabels.Zip(expectedLabels, (a, b) => a.Equals(b) ? 0 : 1).Sum(); miscountTotal += misMatches; MessagePrinter.PrintMessage($"Validating Model: Total Samples = {totalCount}, Misclassify Count = {miscountTotal}"); if (totalCount > howManySamplesToUseFromTestDataset) { break; } } float errorRate = 1.0F * miscountTotal / totalCount; MessagePrinter.PrintMessage($"Model Validation Error = {errorRate}"); } }
public bool SayHello() { if (_printer != null) { return(_printer.PrintMessage()); } return(false); }
public void MessageReceived(object model, BasicDeliverEventArgs eventArgs) { try { var messageBytes = eventArgs.Body; var message = Encoding.UTF8.GetString(messageBytes); _logger.LogDebug($"Received: \"{message}\" on channel: {eventArgs.RoutingKey}"); _messagePrinter.PrintMessage(message); } catch (Exception ex) { _logger.LogError(ex, "Exception in MessageReceived"); throw; } }
public void RemoveComponentIfAllowed(string component, IMessagePrinter printer) { if (!HasBeenExtracted()) { ExtractAndLock(); } printer.PrintHeading($"Running install-wim-tweak to remove {component}..."); int exitCode = SystemUtils.RunProcessBlockingWithOutput(extractedFilePath, $"/o /c {component} /r", printer); if (exitCode == SystemUtils.EXIT_CODE_SUCCESS) { printer.PrintMessage("Install-wim-tweak executed successfully!"); } else { printer.PrintError($"An error occurred during the removal of {component}: " + "install-wim-tweak exited with a non-zero status."); } }
public static int RunProcessBlockingWithOutput(string name, string args, IMessagePrinter printer) { using var process = CreateProcessInstance(name, args); process.OutputDataReceived += (_, evt) => { if (!string.IsNullOrEmpty(evt.Data)) { printer.PrintMessage(evt.Data); } }; process.ErrorDataReceived += (_, evt) => { if (!string.IsNullOrEmpty(evt.Data)) { printer.PrintError(evt.Data); } }; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); process.WaitForExit(); return(process.ExitCode); }