private System.Data.Objects.ObjectQuery <SingleLogSet> GetSingleLogSetQuery(PowerLogDBEntities powerLogDBEntities) { // Auto generated code System.Data.Objects.ObjectQuery <proba.SingleLogSet> singleLogSetQuery = powerLogDBEntities.SingleLogSet; // To explicitly load data, you may need to add Include methods like below: // singleLogSetQuery = singleLogSetQuery.Include("SingleLogSet.VariableSet"). // For more information, please see http://go.microsoft.com/fwlink/?LinkId=157380 // Returns an ObjectQuery. return(singleLogSetQuery); }
public MainWindow() { InitializeComponent(); using (var context = new PowerLogDBEntities()) { DateTime Sad = DateTime.UtcNow; DateTime SadBezMiliSec = (Sad.AddSeconds(-Sad.Second)).AddMilliseconds(-Sad.Millisecond); foreach (var variable in context.VariableSet) { var date = (from log in variable.SingleLogSet group log by log.TimeStamp.Date); foreach (var day in date) { var hours = (from h in day group h by h.TimeStamp.Hour); foreach (var hour in hours) { var minutes = (from min in hour group min by min.TimeStamp.Minute); foreach (var m in minutes) { Single average = m.Average(s => s.SingleValue); var mPoredanPoVremenu = m.OrderBy(s => s.TimeStamp.Second); Single a = 0; Single Energy = 0; DateTime timeA = new DateTime(); bool prva = true; foreach (var log in mPoredanPoVremenu) { if (prva) { prva = false; a = log.SingleValue; timeA = log.TimeStamp; if (mPoredanPoVremenu.Count() == 1) { Energy = log.SingleValue; } } else { Single trapez = ((a + log.SingleValue) / 2) * (Single)(log.TimeStamp - timeA).TotalSeconds; a = log.SingleValue; timeA = log.TimeStamp; Energy = Energy + trapez; } } Single snaga; if (mPoredanPoVremenu.Count() == 1) { snaga = Energy; } else { snaga = Energy / (Single)(mPoredanPoVremenu.Last().TimeStamp - mPoredanPoVremenu.First().TimeStamp).TotalSeconds; } DateTime d = m.First().TimeStamp; DateTime TimeStamp = new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, 0); SingleHistogramSet histogram = SingleHistogramSet.CreateSingleHistogramSet(-1, snaga, TimeStamp, -1); if (!variable.SingleHistogramSet.Any(s => s.TimeStamp == TimeStamp)) { variable.SingleHistogramSet.Add(histogram); } } } } } // context.SaveChanges(); } }