public JsonResult getAllStats()
 {
     //by defaults start year is 2015, end year = 2017
     string Company = ((ClaimsIdentity)User.Identity).Claims.First(x => x.Type == ClaimTypes.UserData).Value;
     ASKUEProvider AP = new ASKUEProvider(Company);
     List<Power> DT = AP.GetASKUEAllRecords(2015, 2017);
     return Json(new { startYear = 2015, endYear = 2017, data = DT }, JsonRequestBehavior.AllowGet);
 }
Exemplo n.º 2
0
        public List<Power> getMonthByDayPower(string company,int year,int month)
        {
            var month_data = (from rows in workFacade.DaySumDataList()
                              where rows.Date.Value.Year == year
                              where rows.Date.Value.Month == month
                              where rows.Company == company
                              select rows).ToList();
            string companyCode = workFacade.CompanyCodeList().Where(x => x.Company == company).First().Code;
            int? month_theory_data = (from expData in workFacade.MonthDataList()
                                     where expData.Year == year
                                     where expData.Month == month
                                     select expData.TheoryDayPower).ToList().First();
            List<Power> returned = new List<Power>();
            if (month_data.Count == 0)
            {
                workFacade.AddMonthToDaySumData(year,month, company);
            }

            DateTime date;

            var info = TimeZoneInfo.FindSystemTimeZoneById("E. Europe Standard Time");
            DateTimeOffset localServerTime = DateTimeOffset.Now;
            DateTimeOffset UkraineTime = TimeZoneInfo.ConvertTime(localServerTime, info);
            foreach (var item in month_data)
            {
                date = item.Date.Value.Date;
                if (!item.PowerInvertor.HasValue)
                {

                    if (date < UkraineTime.AddDays(-1))
                    {
                        try
                        {

                            var day_power = (from expData in workFacade.DayDataList()
                                             where expData.Date.Value.Year == item.Date.Value.Year
                                             where expData.Date.Value.Month == item.Date.Value.Month
                                             where expData.Date.Value.Day == item.Date.Value.Day
                                             where expData.Company == companyCode
                                             orderby expData.Date
                                             select expData).ToList().Last();

                            item.PowerInvertor = day_power.SumPowerDay / 1000;
                            workFacade.UpdateDaySumDataRow(item);

                        }
                        catch (Exception ex)
                        {

                        }
                    }
                }
                if ((!item.PowerASKUE.HasValue || !item.PowerKTP.HasValue)||(item.PowerASKUE == 0 || item.PowerKTP == 0))
                {

                    if (date < UkraineTime.AddDays(-1))
                    {
                        ASKUEProvider ASP = new ASKUEProvider(company);
                        Tuple<int, int> data = ASP.GetDayData(item.Date.Value);
                        item.PowerASKUE = data.Item1;
                        item.PowerKTP = data.Item2;
                        workFacade.UpdateDaySumDataRow(item);
                    }
                }
                returned.Add(new Power(month_theory_data ?? 0, item.PowerInvertor ?? 0, item.PowerKTP ?? 0, item.PowerASKUE ?? 0, item.Insolation ?? 0));

            }
            return returned;
        }
        public JsonResult GetYearStats(int year)
        {
            if (year < 2000)
            {
                year += 1900;
            }
            string Company = ((ClaimsIdentity)User.Identity).Claims.First(x => x.Type == ClaimTypes.UserData).Value;
            ASKUEProvider AP = new ASKUEProvider(Company);

            List<Power> returned = AP.GetYearRecords(year);

            return Json(returned, JsonRequestBehavior.AllowGet);
        }