Example #1
0
        public JsonResult GetDailyProductionChart(int stationId, string beginDate)
        {
            CultureHelper.SetCultureInfo();
            var                 startDate    = DateTimeHelper.BeginDate(beginDate);
            var                 endDate      = DateTimeHelper.EndDate(beginDate);
            DateTime            reqDateParam = DateTime.Parse(@beginDate);
            Production_Main_DTO oDTO         = new Production_Main_DTO();
            DateTime            nowDate      = DateTime.Now;

            if (nowDate.Date == startDate.Date)
            {
                oDTO.isToday = true;
            }
            try
            {
                var stDetail = DB.Stations.Where(a => a.ID == stationId).FirstOrDefault();

                oDTO.station = stDetail;

                float?scale;
                if (stDetail.IRRADIATION_SCALE != null)
                {
                    scale = (stDetail.AC_INSTALLED_POWER) + ((stDetail.AC_INSTALLED_POWER) * (stDetail.IRRADIATION_SCALE) / 100);
                }
                else
                {
                    scale = null;
                }

                oDTO._irradiationScale = scale;
                oDTO._acInstalledPower = stDetail.AC_INSTALLED_POWER;
                oDTO.isEKK             = stDetail.IS_EKK;
                oDTO.isMeteorology     = stDetail.IS_METEOROLOGY;
                oDTO.stationName       = stDetail.NAME;//demo için tatmamla
                oDTO.isPyranometer     = stDetail.IS_PYRANOMETER;
                oDTO.stationType       = stDetail.STATION_TYPE;

                var dList = DB.Summaries.Where(p => p.STATION_ID == stationId &&
                                               p.tarih >= startDate && p.tarih <= endDate)
                            .OrderBy(a => a.tarih).ThenBy(t => t.Id).Select(a =>
                                                                            new Production_DTO
                {
                    id          = a.Id,
                    date        = a.tarih,
                    powerAc     = a.gunlukUretim <= 0 ? 0 : (float)Math.Round((double)a.gunlukUretim / 1000, 1),
                    powerDc     = a.Dc_Guc == null ? 0 : (float)Math.Round((double)a.Dc_Guc / 1000, 1),
                    energy      = a.Enerji <= 0f ? 0f : (float)Math.Round((double)a.Enerji / 1000000, 2),
                    irradiation = (float)Math.Round(a.isinim.Value, 1),
                    wind        = (float)Math.Round(a.ruzgarHizi.Value, 1),
                    cellTemp    = (float)Math.Round(a.hucreSicakligi.Value, 1),
                    extTemp     = (float)Math.Round(a.sicaklik.Value, 1),
                    ekkPowerAc  = (float)Math.Round(Math.Abs(a.H2_P.Value), 1)
                }
                                                                            ).ToList();


                if (dList.Count > 0)
                {
                    oDTO.endData         = dList[dList.Count() - 1];
                    oDTO.endData.powerDc = oDTO.endData.powerDc;
                    oDTO.efficiency      = oDTO.endData.powerDc == 0 ? 0 : oDTO.endData.powerAc / oDTO.endData.powerDc * 100;

                    DateTime abFirstDate = startDate;
                    DateTime abLastDate  = startDate.AddHours(23).AddMinutes(59).AddSeconds(59);
                    if (dList != null && dList.Count > 0)
                    {
                        DateTime lastDate = dList[dList.Count - 1].date;
                        DateTime FirsDate = dList[0].date;

                        while (abFirstDate < FirsDate)
                        {
                            Production_DTO ozet = new Production_DTO();
                            ozet.date = abFirstDate;
                            dList.Add(ozet);
                            abFirstDate = abFirstDate.AddMinutes(5);
                        }

                        while (abLastDate > lastDate)
                        {
                            lastDate = lastDate.AddMinutes(5);
                            Production_DTO ozet = new Production_DTO();
                            ozet.date = lastDate;
                            dList.Add(ozet);
                        }
                        dList = dList.OrderBy(x => x.date).ToList();
                    }

                    for (int i = 0; i < dList.Count(); i++)
                    {
                        dList[i].maxPowerAc = stDetail.AC_INSTALLED_POWER;

                        if ((dList[i].powerDc <= 0 && dList[i].irradiation <= 1) || (dList[i].irradiation == null && dList[i].powerDc == null))
                        {
                            dList[i].energy = null;
                        }
                    }

                    foreach (var item in dList)
                    {
                        item.dateUTC = DateTimeHelper.convertDateUTC(item.date);
                    }
                }
                else
                {
                    oDTO.ErrorMessage = "No Data";
                }


                var summaryProductionList = DB.PRSum.Where(p => p.STATION_ID == stationId && p.date.Value >= stDetail.START_DATE).ToList();

                var target = TargetHelpers.GetDailyTarget(DB, stationId, nowDate.Month);

                if (summaryProductionList.Count > 0)
                {
                    var daily = summaryProductionList.Where(p => p.STATION_ID == stationId && p.date.Value.Year == nowDate.Year && p.date.Value.Month == nowDate.Month && p.date.Value.Day == nowDate.Day).FirstOrDefault();
                    oDTO._dailyProduction = daily == null ? 0 : daily.enerji;
                    oDTO._dailyPr         = daily == null ? 0 : daily.pr;
                    oDTO._dailyKF         = ((oDTO._dailyProduction * 1000) / (nowDate.Hour * oDTO._acInstalledPower)) * 100;
                    oDTO._dailyIncome     = stDetail.EXCHANGE_RATE == null || oDTO._dailyProduction == null ? 0 : (oDTO._dailyProduction * stDetail.EXCHANGE_RATE * 1000);

                    var monthlyList = summaryProductionList.Where(p => p.STATION_ID == stationId && p.date.Value.Year == nowDate.Year && p.date.Value.Month == nowDate.Month).ToList();
                    oDTO._monthlyProduction = monthlyList.Count > 0 ? monthlyList.Sum(s => s.enerji).Value : 0;
                    oDTO._monthlyPr         = monthlyList.Count > 0 ? monthlyList.Average(s => s.pr).Value : 0;
                    oDTO._monthlyKF         = ((oDTO._monthlyProduction * 1000) / ((((nowDate.Day - 1) * 24) + (DateTime.Now.Hour)) * oDTO._acInstalledPower)) * 100;
                    oDTO._monthlyIncome     = stDetail.EXCHANGE_RATE == null || oDTO._monthlyProduction == null ? 0 : (oDTO._monthlyProduction * stDetail.EXCHANGE_RATE * 1000);

                    var annualList = summaryProductionList.Where(p => p.STATION_ID == stationId && p.date.Value.Year == nowDate.Year).ToList();
                    oDTO._annualProduction = annualList.Count > 0 ? annualList.Sum(a => a.enerji).Value : 0;
                    oDTO._annualPr         = annualList.Count > 0 ? annualList.Average(s => s.pr).Value : 0;
                    oDTO._annualKF         = ((oDTO._annualProduction * 1000) / ((((nowDate.Month - 1) * 30 * 24) + (nowDate.Day * 24)) * oDTO._acInstalledPower)) * 100;
                    oDTO._annualIncome     = stDetail.EXCHANGE_RATE == null || oDTO._annualProduction == null ? 0 : (oDTO._annualProduction * stDetail.EXCHANGE_RATE * 1000);

                    oDTO._totalProduction = summaryProductionList.Count > 0 ? summaryProductionList.Sum(a => a.enerji).Value : 0;
                    oDTO._totalPr         = summaryProductionList.Count > 0 ? summaryProductionList.Average(s => s.pr).Value : 0;
                    oDTO._totalIncome     = stDetail.EXCHANGE_RATE == null || oDTO._totalProduction == null ? 0 : (oDTO._totalProduction * stDetail.EXCHANGE_RATE * 1000);


                    oDTO.specificYield = (float)(oDTO._dailyProduction.Value / stDetail.DC_INSTALLED_POWER * 1000);
                    oDTO.actualValue   = target == 0 ? 0 : (oDTO._dailyProduction * 100) / target;
                }


                oDTO.listData = dList;
            }
            catch (Exception ex)
            {
                oDTO.ErrorMessage = "Error";
            }

            return(Json(oDTO, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public JsonResult GetMonthlyProduction(int stationId, string beginDate)
        {
            CultureHelper.SetCultureInfo();
            var             userId = User.Identity.GetUserId();
            bool?           money  = false;
            ApplicationUser usr    = DB.Database.SqlQuery <ApplicationUser>("select \"AspNetUsers\".\"Id\",\"AspNetUsers\".\"UserName\",\"AspNetUsers\".\"Email\",\"AspNetUsers\".\"SHOW_MONEY\",\"AspNetUsers\".\"REPORT_SEND_MAIL\",\"AspNetUsers\".\"ALARM_SEND_MAIL\" from \"AspNetUsers\" where \"AspNetUsers\".\"IS_DELETED\" = 0  and \"AspNetUsers\".\"Id\" = '" + userId + "'")
                                     .Select(a =>
                                             new ApplicationUser
            {
                Id               = a.Id,
                UserName         = a.UserName,
                Email            = a.Email,
                SHOW_MONEY       = a.SHOW_MONEY,
                REPORT_SEND_MAIL = a.REPORT_SEND_MAIL,
                ALARM_SEND_MAIL  = a.ALARM_SEND_MAIL
            }).OrderBy(a => a.UserName).FirstOrDefault();

            if (usr.SHOW_MONEY != null)
            {
                if (usr.SHOW_MONEY.Value == 1)
                {
                    money = true;
                }
                else
                {
                    money = false;
                }
            }
            string[] dateArr = beginDate.Split('-');
            int      ay      = Int32.Parse(dateArr[1]);
            int      yil     = Int32.Parse(dateArr[0]);
            float    target  = TargetHelpers.GetDailyTarget(DB, stationId, ay);

            var _stationDetail = DB.Stations.Where(a => a.ID == stationId).FirstOrDefault();
            var installedDC    = _stationDetail.DC_INSTALLED_POWER;
            var _stExchange    = _stationDetail.EXCHANGE_RATE;

            TBL_PR_DTO mm = new TBL_PR_DTO();

            mm._target = target;
            var prList = (from p in DB.PRSum
                          where p.STATION_ID == stationId && p.date.Value.Month == ay &&
                          p.date.Value.Year == yil
                          orderby p.date
                          select p).ToList();

            var howDays = DateTime.DaysInMonth(yil, ay);


            var exchangeList = DB.exchange.Where(a => a.EXCHANGE_DATE.Month == ay && a.EXCHANGE_DATE.Year == yil).ToList();


            mm.listPR = (from p in prList.ToList()
                         join ex in exchangeList.ToList() on p.date.Value.Date.ToString("yyyy-MM-dd") equals ex.EXCHANGE_DATE.Date.ToString("yyyy-MM-dd")
                         into abc
                         from b in abc.DefaultIfEmpty()
                         select new TBL_PR
            {
                _tarih = p.date.Value,
                _enerji = p.enerji == null ? 0 : (float)Math.Round((double)p.enerji, 2),
                _IrradiationSum = p.isinim_ortalama == null ? 0 : (float)Math.Round((double)p.isinim_ortalama, 2),
                _pr = p.pr == null ? 0 : (float)Math.Round((double)p.pr, 1),
                _exchangeTL = b == null ? 0 : b.BUYING_VALUE,
                _incomeUS = (p.enerji == null || _stExchange == null) ? 0 : (float)Math.Round((_stExchange * (float)p.enerji.Value * 1000), 2),
                _incomeTL = (b == null || _stExchange == null || p.enerji == null) ? 0 : (float)Math.Round(((_stExchange) * (b.BUYING_VALUE.Value) * (p.enerji.Value) * 1000), 2)
            }).OrderBy(o => o._tarih).ToList();


            for (int k = 1; k <= howDays; k++)
            {
                var isThere = mm.listPR.Where(w => w._tarih.Day == k).FirstOrDefault();
                if (isThere == null)
                {
                    mm.listPR.Add(new TBL_PR {
                        _tarih = new DateTime(yil, ay, k), _enerji = 0, _IrradiationSum = 0, _pr = 0, _incomeTL = 0, _incomeUS = 0, _exchangeTL = 0
                    });
                }
            }

            mm.listPR = mm.listPR.OrderBy(o => o._tarih).ToList();

            if (mm.listPR.Count == 0)
            {
                mm.ortalamaPR   = 0;
                mm.toplamIsinim = 0;
            }
            else
            {
                for (int i = 0; i < mm.listPR.Count; i++)
                {
                    if (money.Value == false)
                    {
                        mm.listPR[i]._incomeUS = 0;
                        mm.listPR[i]._incomeTL = 0;
                        mm.toplamKazancUS      = 0;
                        mm.toplamKazancTL      = 0;
                    }
                    else
                    {
                        mm.toplamKazancUS += mm.listPR[i]._incomeUS.Value;
                        mm.toplamKazancTL += mm.listPR[i]._incomeTL.Value;
                    }
                    mm.toplamEnerji += mm.listPR[i]._enerji.Value;
                    mm.toplamIsinim += mm.listPR[i]._IrradiationSum.Value;
                }
                mm.ortalamaPR = mm.listPR.Where(a => a._pr > 0).FirstOrDefault() == null ? 0 : mm.listPR.Where(a => a._pr > 0).Average(a => a._pr).Value;
            }

            return(Json(mm, JsonRequestBehavior.AllowGet));
        }