Ejemplo n.º 1
0
        public override double getTypeBestAnnualkWh(int benchmarkId)
        {
            BenchmarkProperty benchmark = emdb.Benchmarks.Find(benchmarkId);

            var annualTotals = from p in emdb.Properties
                               where p.PropertyType.Id == benchmark.PropertyType.Id && p.AnnualkWh != 0
                               select p.AnnualkWh;

            double lowestkWh = 0;

            foreach (var kWh in annualTotals)
            {
                ///prevent return of 0
                if (lowestkWh == 0)
                {
                    lowestkWh = kWh;
                }

                if (kWh < lowestkWh)
                {
                    lowestkWh = kWh;
                }
            }

            return(lowestkWh);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates benchmark graph
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public PartialViewResult Graph(int id)
        {
            try
            {
                ///get property object from API
                Property          property  = ResponseReader.convertTo <Property>(emAPI.getProperty(id));
                BenchmarkProperty benchmark = ResponseReader.convertTo <BenchmarkProperty>(emAPI.getBenchmarkForProperty(id));

                ///previous year's performance
                DateTime end     = DateTime.Now;
                TimeSpan oneYear = new TimeSpan(365, 0, 0, 0);
                DateTime start   = end - oneYear;

                ///set up graph object
                Graph graph = new Models.Graph();
                graph.Legend         = "none";
                graph.vAxisFormat    = "#,###";
                graph.vAxisTitle     = "Annual kWh";
                graph.Title          = "";
                graph.Width          = 450;
                graph.Height         = 300;
                graph.chartAreaWidth = 300;

                ///create data table
                ArrayList data = new ArrayList
                {
                    new ArrayList {
                        "", "Amount"
                    },
                    new ArrayList {
                        property.Postcode, Math.Ceiling(property.AnnualkWh)
                    },
                    new ArrayList {
                        "Typical Practice", benchmark.BenchmarkkWhTypical
                    },
                    new ArrayList {
                        "Good Practice", benchmark.BenchmarkkWhGood
                    }
                };

                ///serialise string for inclusion into javascript via Graph View
                string graphData = JsonConvert.SerializeObject(data);
                graphData = graphData.Replace("\"", "'");

                graph.Data = graphData;

                return(PartialView("GraphFromArray", graph));
            }
            catch
            {
                return(PartialView("Error"));
            }
        }
Ejemplo n.º 3
0
        public override BenchmarkProperty editBenchmark(int benchmarkId, BenchmarkProperty newBenchmark)
        {
            BenchmarkProperty oldBenchmark = emdb.Benchmarks.Find(benchmarkId);

            oldBenchmark.BenchmarkCO2Good    = newBenchmark.BenchmarkCO2Good;
            oldBenchmark.BenchmarkCO2Typical = newBenchmark.BenchmarkCO2Typical;
            oldBenchmark.BenchmarkkWhGood    = newBenchmark.BenchmarkkWhGood;
            oldBenchmark.BenchmarkkWhTypical = newBenchmark.BenchmarkkWhTypical;
            oldBenchmark.FloorArea           = newBenchmark.FloorArea;
            oldBenchmark.typeAveragekWh      = newBenchmark.typeAveragekWh;
            oldBenchmark.typeBestkWh         = newBenchmark.typeBestkWh;

            emdb.SaveChanges();
            return(oldBenchmark);
        }
Ejemplo n.º 4
0
        public double getFloorArea(int propertyId)
        {
            Property property  = mediator.DataManager.getProperty(propertyId);
            double   floorArea = 0;

            if (property.FloorArea == 0)
            {
                ///need to get standard floor area for this property type
                BenchmarkProperty benchmark = mediator.DataManager.getBenchmarkForProperty(propertyId);
                floorArea = benchmark.FloorArea;
            }
            else
            {
                floorArea = property.FloorArea;
            }

            return(floorArea);
        }
Ejemplo n.º 5
0
//* * * STATS METHODS - for extracting statistics from the database

        public override double getTypeAverageAnnualkWh(int benchmarkId)
        {
            double            averageAnnualkWh;
            BenchmarkProperty benchmark = emdb.Benchmarks.Find(benchmarkId);

            var annualTotals = from p in emdb.Properties
                               where p.PropertyType.Id == benchmark.PropertyType.Id && p.AnnualkWh != 0
                               select p.AnnualkWh;
            double totalKwh = 0;

            foreach (var kWh in annualTotals)
            {
                totalKwh += kWh;
            }

            averageAnnualkWh = totalKwh / annualTotals.Count();
            if (annualTotals.Count() == 0)
            {
                averageAnnualkWh = 0;
            }

            return(averageAnnualkWh);
        }
Ejemplo n.º 6
0
 public abstract BenchmarkProperty editBenchmark(int benchmarkId, BenchmarkProperty newBenchmark);
Ejemplo n.º 7
0
        public BenchmarkProperty getBenchmarkForProperty(int propertyId)
        {
            BenchmarkProperty benchmark = mediator.DataManager.getBenchmarkForProperty(propertyId);

            return(benchmark);
        }