示例#1
0
        public ConsumptionData <string, decimal> GetConsumptionData(ConsumptionInput input)
        {
            var inp    = Mapper.Map <DataModels.Dashboard.ConsumptionInput>(input);
            var result = Repository.GetConsumptionData(inp);
            var ret    = new ConsumptionData <string, decimal>();
            var ret1   = new List <SeriesList <string, decimal> >();

            foreach (var item in result.Data)
            {
                var k   = item.Key;
                var val = item.Value;
                var row = new SeriesList <string, decimal>();
                row.name   = item.Key;
                row.series = new List <NameValuePair <string, decimal> >();
                foreach (var inner in val)
                {
                    var r = new NameValuePair <string, decimal>()
                    {
                        name = inner.Key, value = inner.Value
                    };
                    row.series.Add(r);
                }
                ret1.Add(row);
            }
            var ret2 = new List <SeriesList <string, decimal> >();

            foreach (var item in result.AlternateData)
            {
                var k   = item.Key;
                var val = item.Value;
                var row = new SeriesList <string, decimal>();
                row.name   = item.Key;
                row.series = new List <NameValuePair <string, decimal> >();
                foreach (var inner in val)
                {
                    var r = new NameValuePair <string, decimal>()
                    {
                        name = inner.Key, value = inner.Value
                    };
                    row.series.Add(r);
                }
                ret2.Add(row);
            }
            ret.Data          = ret1;
            ret.AlternateData = ret2;
            return(ret);
        }
示例#2
0
        private void OnReduceLoadTimerTick(object ignore)
        {
            int currentDeficit;

            lock (this.sync) {
                currentDeficit = (this.currentLoad.GetValueOrDefault(-1) < this.LoadFactor) ? 1 : 0;

                if (null != this.currentLoad)
                {
                    this.currentLoad = this.currentLoad.GetValueOrDefault() - 1;
                    if (0 > this.currentLoad.GetValueOrDefault())
                    {
                        this.currentLoad = null;
                    }
                }
            }

            if (1 == currentDeficit)
            {
                logger.InfoFormat("Element {0} of type {1} has deficit {2} with load {3}", this.ID, this.ElementType, currentDeficit, this.currentLoad);
            }

            ConsumptionData data;

            lock (this.deficitHistory) {
                this.deficitHistory.AddLast(currentDeficit);
                if (10 < this.deficitHistory.Count)
                {
                    this.deficitHistory.RemoveFirst();
                }

                var deficit = this.deficitHistory.Sum();

                data = new ConsumptionData(this.ID, deficit, this.ElementType);
            }

            this.consumptionBlock.SendAsync(data);
        }
示例#3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Lomake on lähetetty
        if (HttpContext.Current.Request.HttpMethod == "POST")
        {
            int days = 7;
            int.TryParse(Request["days"], out days);

            //Kutsutaan funktioita joka hakee Json säätiedot
            dynamic weather_data = get_weather_data(Request["town"], days);

            //Luodaan uusi objekti kaikelle kulutustiedolle
            consumption_data = new ConsumptionData[days];
            float eclass_lower = 0;
            float eclass_upper = 150;
            float temp_in      = 20;
            float.TryParse(Request["temperature"].Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out temp_in);
            float size = 100;
            float.TryParse(Request["size"].Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture, out size);
            switch (Request["eclass"])
            {
            case "A":
                break;

            case "B":
                eclass_lower = 151;
                eclass_upper = 170;
                break;

            case "C":
                eclass_lower = 171;
                eclass_upper = 190;
                break;

            case "D":
                eclass_lower = 191;
                eclass_upper = 230;
                break;

            case "E":
                eclass_lower = 231;
                eclass_upper = 270;
                break;

            case "F":
                eclass_lower = 271;
                eclass_upper = 320;
                break;

            case "G":
                eclass_lower = 321;
                eclass_upper = 370;
                break;
            }
            float eclass_lower_multiplier = (eclass_lower / 365) * size / 16.7f;
            float eclass_upper_multiplier = (eclass_upper / 365) * size / 16.7f;
            int   days_count = 0;

            //Käydään säätiedot läpi päivittäin
            foreach (dynamic day in weather_data.list)
            {
                float day_average = Convert.ToSingle(day.temp.day);
                if (Math.Abs(day_average) > max_temperature)
                {
                    max_temperature = Math.Abs(day_average);
                }
                float temp_difference = (temp_in - day_average);

                //Estetään negatiiviset sisälämpötilat ja virran kulku väärän suuntaan.
                if (temp_difference > 0)
                {
                    consumption_data[days_count] = new ConsumptionData(DateTime.Now.AddDays(days_count),
                                                                       Convert.ToSingle(day.temp.day),
                                                                       temp_difference * eclass_lower_multiplier,
                                                                       temp_difference * eclass_upper_multiplier,
                                                                       string.Format("http://openweathermap.org/img/w/{0}.png", day.weather[0].icon));
                    if (consumption_data[days_count].consumption_avg > max_consumption_avg)
                    {
                        max_consumption_avg = consumption_data[days_count].consumption_avg;
                    }
                }
                else
                {
                    consumption_data[days_count] = new ConsumptionData(DateTime.Now.AddDays(days_count),
                                                                       Convert.ToSingle(day.temp.day),
                                                                       0,
                                                                       0,
                                                                       string.Format("http://openweathermap.org/img/w/{0}.png", day.weather[0].icon));
                }
                days_count++;
            }
        }
    }
示例#4
0
 public void BigTest(Consumption expected)
 {
     var data = ConsumptionData.Get()
 }
示例#5
0
        public ConsumptionData GetConsumptionData(ConsumptionInput input)
        {
            var from     = input.From.Split('-');
            var to       = input.To.Split('-');
            var fromDate = new DateTime(Convert.ToInt32(from[0]), Convert.ToInt32(from[1]), 1);
            var lastday  = DateTime.DaysInMonth(Convert.ToInt32(to[0]), Convert.ToInt32(to[1]));
            var toDate   = new DateTime(Convert.ToInt32(to[0]), Convert.ToInt32(to[1]), lastday);

            var result  = new ConsumptionData();
            var result1 = new List <KeyValuePair <string, List <KeyValuePair <string, decimal> > > >();
            var result2 = new List <KeyValuePair <string, List <KeyValuePair <string, decimal> > > >();

            var isAdmin = false;
            var user    = (from emp in Employee
                           join el in EmployeeLoginMap
                           on emp.employeeid equals el.employeeid
                           join lm in LoginMaster
                           on el.loginname equals lm.loginname
                           join rol in Roles
                           on lm.roles equals rol.roleid
                           where emp.employeeid == input.UserId
                           select rol.rolename).FirstOrDefault();

            isAdmin = user == "Admin";
            IQueryable <ConsumptionResult> qry;

            if (isAdmin)
            {
                qry = from ucd in UnitsConsumptionDetails
                      join us in UnitSummary
                      on ucd.unitid equals us.id
                      where ucd.daterecorded <= toDate &&
                      ucd.daterecorded >= fromDate
                      //where ucd.daterecorded >= DateTime.Now.AddYears(-1)
                      orderby ucd.daterecorded
                      group ucd by new { Month = ucd.daterecorded.Month, Year = ucd.daterecorded.Year, unitId = us.unitid } into d
                    select new ConsumptionResult {
                    period = new DateTime(d.Key.Year, d.Key.Month, 1), month = d.Key.Month, year = d.Key.Year, unitid = d.Key.unitId, consumption = d.Max(c => c.consumptioninmcube) - d.Min(e => e.consumptioninmcube)
                }
                ;
            }
            else
            {
                qry = from ucd in UnitsConsumptionDetails
                      join us in UnitSummary
                      on ucd.unitid equals us.id
                      where ucd.daterecorded <= toDate &&
                      ucd.daterecorded >= fromDate &&
                      us.consumerid == input.UserId
                      //where ucd.daterecorded >= DateTime.Now.AddYears(-1)
                      orderby ucd.daterecorded
                      group ucd by new { Month = ucd.daterecorded.Month, Year = ucd.daterecorded.Year, unitId = us.unitid } into d
                    select new ConsumptionResult {
                    period = new DateTime(d.Key.Year, d.Key.Month, 1), month = d.Key.Month, year = d.Key.Year, unitid = d.Key.unitId, consumption = d.Max(c => c.consumptioninmcube) - d.Min(e => e.consumptioninmcube)
                }
                ;
            }

            var distinctRows = (from m in qry
                                select m.unitid).Distinct()
            ;

            foreach (var dr in distinctRows)
            {
                var sub = from row in qry
                          where row.unitid == dr
                          select new KeyValuePair <string, decimal>(row.period.ToString("MMM-yyyy"), row.consumption);

                var r1 = new KeyValuePair <string, List <KeyValuePair <string, decimal> > >(dr.ToString(), sub.ToList());
                result1.Add(r1);
            }

            var distinctRows1 = (from m in qry
                                 select m.period).Distinct()
            ;

            foreach (var dr in distinctRows1)
            {
                var sub = from row in qry
                          where row.period == dr
                          select new KeyValuePair <string, decimal>(row.unitid, row.consumption);

                var r1 = new KeyValuePair <string, List <KeyValuePair <string, decimal> > >(dr.ToString("MMM-yyyy"), sub.ToList());
                result2.Add(r1);
            }

            result.Data          = result1;
            result.AlternateData = result2;
            return(result);
        }