Ejemplo n.º 1
0
 public void Update(CalculatedDataModel CalculatedData)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 2
0
        // Main Repository method GetAllCalculatedDataRepository whcih reads the contents of the Params.txt file and assign to local variabales.
        // Output the newly calculatated list to the local variable this.CalculatedList.
        // Add all the CalculatedData to an IEnumerable<CalculatedDataModel>.  This list is then returns to the CalculationController.

        public List <CalculatedDataModel> GetAllCalculatedDataRepository()
        {
            // Read the Params file and update the 2 private variables m and c.
            try
            {
                this.ParamReader = new StreamReader(this.ParamFile.FullName);
                while (!ParamReader.EndOfStream)
                {
                    string line = ParamReader.ReadLine();
                    if (line.Contains("m ="))
                    {
                        this.m = Convert.ToDecimal(line.Substring(4));
                    }
                    if (line.Contains("c ="))
                    {
                        this.c = Convert.ToDecimal(line.Substring(4));
                    }
                }
            }
            catch (IOException e)
            {
                Console.WriteLine("The Params file could not be read,  It must be in the wrong format.");
                Console.WriteLine(e.Message);
            }

            // Read the raw Data file and update the private list RawDataListTotalItems
            try
            {
                this.RawDataReader = new StreamReader(this.RawDataFile.FullName);
                while (!RawDataReader.EndOfStream)
                {
                    string line = RawDataReader.ReadLine();
                    if (!line.Contains("X ="))
                    {
                        this.RawDataListTotalItems = line.Split(',')
                                                     .Where(m => decimal.TryParse(m, out _))
                                                     .Select(m => decimal.Parse(m))
                                                     .ToList();
                        Console.WriteLine("The number of items in Raw Data File: " + RawDataListTotalItems.Count());
                    }
                }
            }
            catch (IOException e)
            {
                Console.WriteLine("The Raw Data file could not be read,  It must be in the wrong format.");
                Console.WriteLine(e.Message);
            }

            // Calculated the Output list
            this.CalculatedList = Calculate_New_Data_Results(RawDataListTotalItems, m, c);


            //Create the models.
            int RawDataCount = RawDataListTotalItems.Count();

            for (int i = 0; i < RawDataCount; i++)
            {
                CalculatedDataModel _CalculatedDataModel = new CalculatedDataModel()
                {
                    Id         = i + 1,
                    RawData    = this.RawDataListTotalItems[i],
                    c          = this.c,
                    m          = this.m,
                    Calculated = this.CalculatedList[i]
                };

                this.CalculatedDataModels.Add(_CalculatedDataModel);
            }

            return(this.CalculatedDataModels.ToList());
        }