Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace WTWProgram
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Open file and declare lists to store the data columns
- var reader = new StreamReader(File.OpenRead(@"C:\Users\Harald\Documents\CVs\WTW TEST\InputData.csv"));
- List<string> Products = new List<string>();
- List<int> Origins = new List<int>();
- List<int> Developments = new List<int>();
- List<double> IncValues = new List<double>();
- //Read from file and split columns on commas
- while (!reader.EndOfStream)
- {
- var line = reader.ReadLine();
- var values = line.Split(',');
- int i;
- double j;
- //TryParse is used to return values of 0 for the column headings.
- Products.Add(values[0]);
- if (int.TryParse(values[1], out i)) Origins.Add(i);
- if (int.TryParse(values[2], out i)) Developments.Add(i);
- if (double.TryParse(values[3], out j)) IncValues.Add(j);
- }
- //Calculate the range of years, the starting year and the quantity of different products
- int Range = Developments.Max() - Origins.Min() + 1;
- int Start = Origins.Min();
- int ProductCount = Products.Distinct().ToList().Count() -1;
- Console.Write(Start + "," + Range);
- //Calculate the size of the triangles to be filled
- int TriangleSize=0;
- for(int i=0;i<Range;i++)
- {
- TriangleSize = TriangleSize + Range - i;
- }
- //Create an array to hold the triangles of cumulative values
- double[,] CumuValues = new double[ProductCount,TriangleSize];
- //This index will be used to increment the row of the above array
- int Row = 0;
- for (int i=1;i<Products.Count();i++)
- {
- int k = i - 1; //Index for the year lists and Incvalues
- //Calculate the appropriate starting point in the row using the triangle number equation.
- int Diff = Origins[k] - Start;
- Diff = Diff * (Diff + 1) / 2;
- //Calculate the number of development years from the origin
- int DevYrs = Developments[k] - Origins[k];
- //Calculate the cumulative value
- double Cumu = 0.0;
- for (int j = 0; j <= DevYrs; j++)
- {
- Cumu = Cumu + IncValues[k - j];
- }
- CumuValues[Row, Diff + DevYrs - 1] = Cumu;
- if(Products[k]!=Products[i])
- {
- Console.Write("\n" + Products[i]);
- }
- if (Developments[i] == Developments.Max())
- {
- for (int x = 0; x < TriangleSize; x++)
- {
- Console.Write("," + CumuValues[Row, x]);
- }
- Row++;
- }
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement