Exemplo n.º 1
0
        public static Timeseries GetMonthlyAverages(string identityName)
        {
            var repo       = new RegistryEntryRepoFactory().GetRegistryEntryRepo(identityName);
            var sortedTvqs = repo.GetRegistryEntries().OrderBy(x => x.Time);

            var tsWithRegisterEntries = new Timeseries();

            tsWithRegisterEntries.AddRange(sortedTvqs.ToList());

            var periodizer      = new Periodizer();
            var monthlyAverages = periodizer.MonthlyAverage(tsWithRegisterEntries);

            //const int minMonths = 2;
            //var tooFewEntries = monthlyRegisterEntries.Count < minMonths;
            //var areTooFewEntries = tooFewEntries;
            //if (areTooFewEntries)
            //{
            //    throw new TooFewEntriesException(minMonths);
            //}

            //var deltaOperator = new DeltaTsOperator();
            //var monthlyAverages = deltaOperator.Apply(monthlyRegisterEntries);

            return(monthlyAverages);
        }
Exemplo n.º 2
0
        public ActionResult ListEntriesView()
        {
            try
            {
                var repo = new RegistryEntryRepoFactory().GetRegistryEntryRepo();

                var entries = repo.GetRegistryEntries(Thread.CurrentPrincipal);
                var sortedTvqs = entries.OrderBy(x => x.Time);
                var tsWithRegisterEntries = new Timeseries();
                tsWithRegisterEntries.AddRange(sortedTvqs.ToList());

                return View(tsWithRegisterEntries);
            }
            catch (Exception e)
            {
                _logger.TrackException(e);
                return View("Error");
            }
        }
Exemplo n.º 3
0
        public ActionResult ListEntriesView()
        {
            try
            {
                var repo = new RegistryEntryRepoFactory().GetRegistryEntryRepo(User.Identity.Name);

                var entries               = repo.GetRegistryEntries();
                var sortedTvqs            = entries.OrderBy(x => x.Time);
                var tsWithRegisterEntries = new Timeseries();
                tsWithRegisterEntries.AddRange(sortedTvqs.ToList());

                return(View(tsWithRegisterEntries));
            }
            catch (Exception e)
            {
                _logger.TrackException(e);
                return(View("Error"));
            }
        }
Exemplo n.º 4
0
        public Task <AddRegistryEntryResult> Handle(AddRegistryEntryCommand request, CancellationToken cancellationToken)
        {
            DateTime t;
            var      ok = DateTime.TryParse(request.Model.DateString, out t);

            if (!ok)
            {
                return(Task.FromResult(new AddRegistryEntryResult(false, "Datum kunde ej tolkas")));
            } // TODO better error handling

            int v;

            ok = int.TryParse(request.Model.RegisterValue, out v);
            if (!ok)
            {
                return(Task.FromResult(new AddRegistryEntryResult(false, "Mätarställning kunde ej tolkas")));
            } // TODO better error handling

            var now     = DateTime.Now;
            var isToday =
                t.Year == now.Year &&
                t.Month == now.Month &&
                t.Day == now.Day;

            var isMidnight = t.Hour == 0 && t.Minute == 0;

            if (isToday && isMidnight)
            {
                t = now;
            }

            var tvq = new Tvq(t, v, Quality.Ok);

            var repo = new RegistryEntryRepoFactory().GetRegistryEntryRepo(request.IdentityName);

            repo.AddRegistryEntry(tvq);
            var result = new AddRegistryEntryResult();

            return(Task.FromResult(result));
        }
Exemplo n.º 5
0
        public ActionResult DeleteRegistryEntry([System.Web.Http.FromUri] string dateString)
        {
            DateTime t;
            var ok = DateTime.TryParse(dateString, out t);
            if (!ok)
            {
                ViewBag.Title = "Fel vid borttagning";
                ViewBag.SubTitle = "Datum kunde ej tolkas";
                return View("ListEntriesView");
            } // TODO better error handling

            var repo = new RegistryEntryRepoFactory().GetRegistryEntryRepo();
            ok = repo.DeleteRegistryEntry(t);
            if (!ok)
            {
                ViewBag.Title = "Fel vid borttagning";
                ViewBag.SubTitle = "Kunde ej ta bort registreringen";
                return View("ListEntriesView");
            }

            return RedirectToAction("ListEntriesView");
        }
Exemplo n.º 6
0
        public ActionResult SubmitRegisterEntries(RegisterEntriesModel model)
        {
            try
            {
                var timeseries = TsParser.ParseTimeseries(model.EntriesString);

                var repo = new RegistryEntryRepoFactory().GetRegistryEntryRepo(User.Identity.Name);
                foreach (var tvq in timeseries)
                {
                    repo.AddRegistryEntry(tvq);
                }

                ViewBag.Title    = "Mätarställningar registrerade";
                ViewBag.SubTitle = "Mätarställningarna blev registrerade";
                return(View(model));
            }
            catch (Exception e)
            {
                _logger.TrackException(e);
                return(View("Error"));
            }
        }
Exemplo n.º 7
0
        public static Timeseries GetMonthlyAverages()
        {
            var repo = new RegistryEntryRepoFactory().GetRegistryEntryRepo();
            var sortedTvqs = repo.GetRegistryEntries(Thread.CurrentPrincipal).OrderBy(x => x.Time);

            var tsWithRegisterEntries = new Timeseries();
            tsWithRegisterEntries.AddRange(sortedTvqs.ToList());

            var periodizer = new Periodizer();
            var monthlyRegisterEntries = periodizer.MonthlyAverage(tsWithRegisterEntries);

            const int minMonths = 2;
            var tooFewEntries = monthlyRegisterEntries.Count < minMonths;
            var areTooFewEntries = tooFewEntries;
            if (areTooFewEntries)
            {
                throw new TooFewEntriesException(minMonths);
            }

            var deltaOperator = new DeltaTsOperator();
            var monthlyAverages = deltaOperator.Apply(monthlyRegisterEntries);

            return monthlyAverages;
        }
Exemplo n.º 8
0
        public ActionResult DeleteRegistryEntry([System.Web.Http.FromUri] string dateString)
        {
            DateTime t;
            var      ok = DateTime.TryParse(dateString, out t);

            if (!ok)
            {
                ViewBag.Title    = "Fel vid borttagning";
                ViewBag.SubTitle = "Datum kunde ej tolkas";
                return(View("ListEntriesView"));
            } // TODO better error handling

            var repo = new RegistryEntryRepoFactory().GetRegistryEntryRepo(User.Identity.Name);

            ok = repo.DeleteRegistryEntry(t);
            if (!ok)
            {
                ViewBag.Title    = "Fel vid borttagning";
                ViewBag.SubTitle = "Kunde ej ta bort registreringen";
                return(View("ListEntriesView"));
            }

            return(RedirectToAction("ListEntriesView"));
        }
Exemplo n.º 9
0
        public ActionResult SubmitRegisterEntry(RegisterEntryModel model)
        {
            try
            {
                bool ok;
                DateTime t;
                int v;
                ok = DateTime.TryParse(model.DateString, out t);
                if (!ok)
                {
                    ViewBag.Title = "Fel vid registrering";
                    ViewBag.SubTitle = "Datum kunde ej tolkas";
                    return View(model);
                } // TODO better error handling

                ok = int.TryParse(model.RegisterValue, out v);
                if (!ok)
                {
                    ViewBag.Title = "Fel vid registrering";
                    ViewBag.SubTitle = "Mätarställning kunde ej tolkas";
                    return View(model);
                } // TODO better error handling

                var now = DateTime.Now;
                var isToday =
                    t.Year == now.Year
                    && t.Month == now.Month
                    && t.Day == now.Day;
                if (isToday)
                {
                    t = now;
                }

                var tvq = new Tvq(t, v, Quality.Ok);

                var repo = new RegistryEntryRepoFactory().GetRegistryEntryRepo();
                repo.AddRegistryEntry(tvq);
                ViewBag.Title = "Mätarställning registrerad";
                ViewBag.SubTitle = "Mätarställningen blev registrerad";
                return View(model);
            }
            catch (Exception e)
            {
                _logger.TrackException(e);
                ViewBag.Title = "Ett fel uppstod";
                ViewBag.SubTitle = "Ett fel uppstod vid registrering av mätarställning";
                return View(model);
            }
        }
Exemplo n.º 10
0
        public ActionResult SubmitRegisterEntries(RegisterEntriesModel model)
        {
            try
            {
                var timeseries = TsParser.ParseTimeseries(model.EntriesString);

                var repo = new RegistryEntryRepoFactory().GetRegistryEntryRepo();
                foreach (var tvq in timeseries)
                {
                    repo.AddRegistryEntry(tvq);
                }

                ViewBag.Title = "Mätarställningar registrerade";
                ViewBag.SubTitle = "Mätarställningarna blev registrerade";
                return View(model);
            }
            catch (Exception e)
            {
                _logger.TrackException(e);
                return View("Error");
            }
        }