Esempio n. 1
0
        public GenerationReport ReadInputFile(string fullPath)
        {
            //Get Generation Report
            GenerationReport generationReport = _dataAccessor.ReadInputFile(fullPath);

            return(generationReport);
        }
        private static GenerationOutput CalculateGenerationData(GenerationReport generationReport, ReferenceData referenceData)
        {
            Totals totals = new Totals();
            List <ActualHeatRates> actualHeatRates       = new List <ActualHeatRates>();
            MaxEmissionGenerators  maxEmissionGenerators = new MaxEmissionGenerators();

            foreach (var windGenerator in generationReport.Wind.WindGenerator)
            {
                var generator = new Generator
                {
                    Name  = windGenerator.Name,
                    Total = CalculateTotalGenerationValue(windGenerator.Generation, windGenerator.Name, referenceData, null)
                };

                totals.Generator.Add(generator);
            }

            foreach (var coalGenerator in generationReport.Coal.CoalGenerator)
            {
                var generator = new Generator
                {
                    Name  = coalGenerator.Name,
                    Total = CalculateTotalGenerationValue(coalGenerator.Generation, coalGenerator.Name, referenceData, coalGenerator.EmissionsRating)
                };

                var actualHeatRate = new ActualHeatRates
                {
                    Name     = coalGenerator.Name,
                    HeatRate = coalGenerator.TotalHeatInput / coalGenerator.ActualNetGeneration
                };

                totals.Generator.Add(generator);
                actualHeatRates.Add(actualHeatRate);
            }

            foreach (var gasGenerator in generationReport.Gas.GasGenerator)
            {
                var generator = new Generator
                {
                    Name  = gasGenerator.Name,
                    Total = CalculateTotalGenerationValue(gasGenerator.Generation, gasGenerator.Name, referenceData, gasGenerator.EmissionsRating)
                };

                totals.Generator.Add(generator);
            }

            maxEmissionGenerators.Day = MaxEmissionsDays.OrderByDescending(x => x.Emission).GroupBy(x => x.Date).Select(b => b.First()).ToList();

            return(new GenerationOutput()
            {
                Totals = totals, ActualHeatRates = actualHeatRates, MaxEmissionGenerators = maxEmissionGenerators
            });
        }
Esempio n. 3
0
        public void GenerateOutputFile(GenerationReport incomingGeneratedReport)
        {
            FetchExistingGenerationOutput();
            //Get Generation Report
            var finalOutput = new GenerationOutput()
            {
                totals = TotalGeneratorsOutputPerDay(incomingGeneratedReport),
                maxEmissionGenerators = MaxEmissionGeneratorPerDay(incomingGeneratedReport),
                actualHeatRates       = GetActualHeatRates(incomingGeneratedReport.coal)
            };

            _dataAccessor.GenerateOutputFile(finalOutput);
        }
 /// <summary>
 /// Deserializes the XML data.
 /// </summary>
 /// <param name="fullPath">The full path.</param>
 /// <returns></returns>
 public static GenerationReport DeserializeXmlData(string fullPath)
 {
     try
     {
         XmlSerializer    xmlSerializer    = new XmlSerializer(typeof(GenerationReport));
         StreamReader     streamReader     = new StreamReader(fullPath);
         GenerationReport generationReport = (GenerationReport)xmlSerializer.Deserialize(streamReader);
         streamReader.Dispose();
         streamReader.Close();
         return(generationReport);
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 5
0
        public void GenerateSessionReport_GenerationGenerationBadStudentByGroup_GenerationBadStudentByGroup()
        {
            string           path             = @"..\..\..\..\..\Students\Resources\Report3.xlsx";
            string           pathFileStream   = @"..\..\..\..\Students\Resources\Report3.xlsx";
            int              sortableSheet    = 2;
            GenerationReport generationReport = new GenerationReport(_connectionString);

            generationReport.GenerationBadStudentByGroup(path, sortableSheet, SortOrder.Ascending);

            long result;

            using (var reader = new FileStream(pathFileStream, FileMode.Open))
            {
                result = reader.Length;
            }

            Assert.IsTrue(result != 0);
        }
Esempio n. 6
0
        /// <summary>
        /// Method to find out max emission each day and the generator name.
        /// Only Gas and coal generators as per wind generators do not have emission
        /// </summary>
        /// <param name="incomingGeneratedReport"></param>
        /// <returns></returns>
        private MaxEmissionGenerators MaxEmissionGeneratorPerDay(GenerationReport incomingGeneratedReport)
        {
            var maxEmissionGenerator = new MaxEmissionGenerators();

            foreach (var generator in incomingGeneratedReport.coal.coalGenerator)
            {
                foreach (var day in generator.generation.day)
                {
                    var coalDayOutput = new DayOutput
                    {
                        Name     = generator.name,
                        Date     = day.date,
                        Emission = TotalDailyEmissions(day.energy, generator.EmissionsRating,
                                                       GetGeneratorFactorMapping(generator.name).emissionsFactor)
                    };
                    SetMaxEmission(coalDayOutput);
                }
            }

            foreach (var generator in incomingGeneratedReport.gas.gasGenerator)
            {
                foreach (var day in generator.generation.day)
                {
                    var gasdayOutput = new DayOutput
                    {
                        Name     = generator.name,
                        Date     = day.date,
                        Emission = TotalDailyEmissions(day.energy, generator.emissionsRating,
                                                       GetGeneratorFactorMapping(generator.name).emissionsFactor)
                    };
                    SetMaxEmission(gasdayOutput);
                }
            }
            var dayOutput = _lsFinalMaxGenOutput.GroupBy(x => x.Date)
                            .OrderBy(g => g.Key);

            var lsfinalDayOutput = dayOutput.SelectMany(@group => @group.OrderByDescending(c => c.Emission).Take(1)).ToList();

            maxEmissionGenerator.Days = lsfinalDayOutput;

            return(maxEmissionGenerator);
        }
Esempio n. 7
0
        private Totals TotalGeneratorsOutputPerDay(GenerationReport reportGenerated)
        {
            foreach (var item in reportGenerated.wind.windGenerator)
            {
                var windGen = new GeneratorOutput
                {
                    Name  = item.name,
                    Total = item.generation.day.Sum(x => x.energy * x.price * GetGeneratorFactorMapping(item.name).valueFactor)
                };
                SetGeneratorInOutputGenerationList(windGen);
            }
            foreach (var item in reportGenerated.gas.gasGenerator)
            {
                var gasGen = new GeneratorOutput
                {
                    Name  = item.name,
                    Total = item.generation.day.Sum(x => x.energy * x.price * GetGeneratorFactorMapping(item.name).valueFactor)
                };
                SetGeneratorInOutputGenerationList(gasGen);
            }

            foreach (var item in reportGenerated.coal.coalGenerator)
            {
                var coalGen = new GeneratorOutput
                {
                    Name  = item.name,
                    Total = item.generation.day.Sum(x => x.energy * x.price * GetGeneratorFactorMapping(item.name).valueFactor)
                };
                SetGeneratorInOutputGenerationList(coalGen);
            }
            var totals = new Totals();

            return(new Totals()
            {
                GeneratorOutput = _lsFinalGenOutput
            });
        }
        public void CalculateGenerationOutput(FileSystemEventArgs fileSystemEventArgs, string referenceDataPath, string outputPath)
        {
            try
            {
                var xmlInputData = File.ReadAllText(fileSystemEventArgs.FullPath);
                GenerationReport generationReport = _serializer.Deserialize <GenerationReport>(xmlInputData);

                if (generationReport == null)
                {
                    throw new FileLoadException("Provided file was not loaded successfully, please check the format of the file!");
                }

                var           xmlReferenceData = File.ReadAllText(referenceDataPath);
                ReferenceData referenceData    = _serializer.Deserialize <ReferenceData>(xmlReferenceData);

                var generationOutput = CalculateGenerationData(generationReport, referenceData);
                SaveOutputInFile(generationOutput, outputPath);
            }
            catch (Exception ex)
            {
                Logger.Error($"An error occurred when processing your request: {ex.Message}", ex);
                throw new Exception($"An error occurred when processing your request: {ex.Message}");
            }
        }