private static BatteryTable getDatabaseValue(SqlConnectionStringBuilder connectionString) { BatteryTable dataPoint = null; using (SqlConnection conn = new SqlConnection(connectionString.ToString())) { using (SqlCommand command = conn.CreateCommand()) { conn.Open(); string query = "SELECT * FROM dbo.BatteryTable WHERE DateStamp = (SELECT MAX(DateStamp) FROM dbo.BatteryTable)"; string commandText = query; command.CommandText = commandText; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { dataPoint = new BatteryTable(); dataPoint.DateStamp = reader.GetDateTime(0); dataPoint.BatteryCurrent = (double)reader.GetSqlDouble(1); dataPoint.BatteryVoltage = (double)reader.GetSqlDouble(2); dataPoint.BatteryPower = (double)reader.GetSqlDouble(3); } } } return(dataPoint); }
private static List <BatteryTable> getDatabaseValues(SqlConnectionStringBuilder connectionString) { List <BatteryTable> dataPoints = new List <BatteryTable>(); using (SqlConnection conn = new SqlConnection(connectionString.ToString())) { using (SqlCommand command = conn.CreateCommand()) { conn.Open(); string query = "Select * From dbo.BatteryTable"; string commandText = query; command.CommandText = commandText; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { BatteryTable dataPoint = new BatteryTable() { DateStamp = reader.GetDateTime(0), BatteryTemperature = reader.GetInt32(1), BatteryCurrent = (double)reader.GetSqlDouble(2), BatteryVoltage = (double)reader.GetSqlDouble(3), BatteryPower = (double)reader.GetSqlDouble(4) }; dataPoints.Add(dataPoint); } } } return(dataPoints); }
private static List <BatteryTable> getDatabaseValue(SqlConnectionStringBuilder connectionString, int seed) { List <BatteryTable> dataPoints = new List <BatteryTable>(); using (SqlConnection conn = new SqlConnection(connectionString.ToString())) { using (SqlCommand command = conn.CreateCommand()) { conn.Open(); string builder = "SELECT * From(SELECT TOP {0} * FROM dbo.BatteryTable ORDER BY DateStamp DESC) Q ORDER BY DateStamp ASC"; string query = String.Format(builder, seed); string commandText = query; command.CommandText = commandText; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { BatteryTable dataPoint = new BatteryTable(); dataPoint.DateStamp = reader.GetDateTime(0); dataPoint.BatteryCurrent = (double)reader.GetSqlDouble(1); dataPoint.BatteryVoltage = (double)reader.GetSqlDouble(2); dataPoint.BatteryPower = (double)reader.GetSqlDouble(3); dataPoints.Add(dataPoint); } } } return(dataPoints); }
private static async Task <MLResponse> makeRequest(object scoreRequest, BatteryTable dataPoint) { using (var client = new HttpClient()) { const string apiKey = "9eKcgSItZYwTQTPujl42shH+QfoNhlU16vGXSrPT/B3IJGsJonA6n/qyy0I2m8XR10Ty/0xMS0XsjAZbAagi2A=="; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey); client.BaseAddress = new Uri("https://ussouthcentral.services.azureml.net/subscriptions/4769386f1cdf4fb6bc3250b9336fc5bc/services/15086b35646f42c6a3ddb43193821092/execute?api-version=2.0&format=swagger"); HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest); if (response.IsSuccessStatusCode) { string result = await response.Content.ReadAsStringAsync(); MLResponse mlResponse = new MLResponse() { StatusCode = response.StatusCode, Response = result, dateStamp = dataPoint.DateStamp }; return(mlResponse); } else { string responseBuilder = string.Format("The request failed with status code: {0}", response.StatusCode); MLResponse mlResponse = new MLResponse() { StatusCode = response.StatusCode, Response = responseBuilder }; return(mlResponse); } } }
public ActionResult DeleteConfirmed(DateTime id) { BatteryTable batteryTable = db.BatteryTables.Find(id); db.BatteryTables.Remove(batteryTable); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "DateStamp,BatteryTemperature,BatteryCurrent,BatteryVoltage,BatteryPower")] BatteryTable batteryTable) { if (ModelState.IsValid) { db.Entry(batteryTable).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(batteryTable)); }
public ActionResult Create([Bind(Include = "DateStamp,BatteryTemperature,BatteryCurrent,BatteryVoltage,BatteryPower")] BatteryTable batteryTable) { if (ModelState.IsValid) { db.BatteryTables.Add(batteryTable); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(batteryTable)); }
public static async Task <List <MLResponse> > GetMLResponse(int seed) { SqlConnectionStringBuilder connectionString = buildConnectionString(); List <BatteryTable> dataPoints = getDatabaseValue(connectionString, seed); List <MLResponse> responses = new List <MLResponse>(); for (int i = 0; i < dataPoints.Count; i++) { BatteryTable currentPoint = dataPoints[i]; string currentDateTime = currentPoint.DateStamp.ToString("yyyy-MM-dd HH:mm:ss"); string futureDateTime = currentPoint.DateStamp.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss"); var scoreRequest = new { Inputs = new Dictionary <string, List <Dictionary <string, string> > >() { { "input1", new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "DateTime", futureDateTime }, } } }, { "input2", new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "DateTime", currentDateTime }, } } }, }, GlobalParameters = new Dictionary <string, string>() { } }; MLResponse response = await makeRequest(scoreRequest, currentPoint); responses.Add(response); } return(responses); }
// GET: BatteryTables/Edit/5 public ActionResult Edit(DateTime id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } BatteryTable batteryTable = db.BatteryTables.Find(id); if (batteryTable == null) { return(HttpNotFound()); } return(View(batteryTable)); }
public void Execute() { lock (BatteryViewModel.Batteries) { BatteryViewModel.Batteries.Remove(batteryToDelete); //program ne dodje dovde using (dbSHESEntities entity = new dbSHESEntities()) { BatteryTable bmt = entity.BatteryTables.Where(x => x.Name == batteryToDelete.Name).SingleOrDefault(); if (bmt != null) { entity.BatteryTables.Remove(bmt); entity.SaveChanges(); } }; } }
private void ButtonAdd_Click(object sender, RoutedEventArgs e) { if (Validate(textBoxName) && Validate(textBoxMaxPower) && Validate(textBoxCapacity)) { bool p = false, c = false; double pp = 0, cc = 0; p = double.TryParse(textBoxMaxPower.Text, out pp); c = double.TryParse(textBoxCapacity.Text, out cc); if (p && c && pp >= 0 && cc >= 0) { lock (BatteryViewModel.Batteries) { BatteryViewModel.Batteries.Add(new BatteryModel(textBoxName.Text, Double.Parse(textBoxMaxPower.Text), Double.Parse(textBoxCapacity.Text), 0)); using (dbSHESEntities entity = new dbSHESEntities()) { BatteryTable bmt = new BatteryTable() { Name = textBoxName.Text, MaxPower = Double.Parse(textBoxMaxPower.Text), Capacity = Double.Parse(textBoxCapacity.Text), CurrentCapacity = 0, CapacityMin = 0, State = Enums.BatteryEnum.IDLE.ToString() }; entity.BatteryTables.Add(bmt); entity.SaveChanges(); } BatteryViewModel.Refresh(); } } else { MessageBox.Show("Incorrect input", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Incorrect input", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
//--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\ #region --Set-, Get- Methods-- public void setBatteryMeasurement(BatteryTable battery) { update(battery); }
public static async Task <MLResponse> GetMLResponse() { SqlConnectionStringBuilder connectionString = buildConnectionString(); BatteryTable dataPoint = getDatabaseValue(connectionString); string currentDateTime = dataPoint.DateStamp.ToString("yyyy-MM-dd HH:mm:ss"); string futureDateTime = dataPoint.DateStamp.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss"); var scoreRequest = new { Inputs = new Dictionary <string, List <Dictionary <string, string> > >() { { "input1", new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "DateTime", futureDateTime }, } } }, { "input2", new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "DateTime", currentDateTime }, } } }, }, GlobalParameters = new Dictionary <string, string>() { } }; using (var client = new HttpClient()) { const string apiKey = "9eKcgSItZYwTQTPujl42shH+QfoNhlU16vGXSrPT/B3IJGsJonA6n/qyy0I2m8XR10Ty/0xMS0XsjAZbAagi2A=="; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey); client.BaseAddress = new Uri("https://ussouthcentral.services.azureml.net/subscriptions/4769386f1cdf4fb6bc3250b9336fc5bc/services/15086b35646f42c6a3ddb43193821092/execute?api-version=2.0&format=swagger"); HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest); if (response.IsSuccessStatusCode) { string result = await response.Content.ReadAsStringAsync(); MLResponse mlResponse = new MLResponse() { StatusCode = response.StatusCode, Response = result, dateStamp = dataPoint.DateStamp }; return(mlResponse); } else { string responseBuilder = string.Format("The request failed with status code: {0}", response.StatusCode); MLResponse mlResponse = new MLResponse() { StatusCode = response.StatusCode, Response = responseBuilder }; return(mlResponse); } } }