Ejemplo n.º 1
0
        public void DoTest()
        {
            var rdResult = Redistrict(30);
            var newSF    = new SpatialFile()
            {
                Districts = rdResult, PartyCount = PartyCount
            };
            var rdResult2 = newSF.Redistrict(this.Districts.Count);
            var newSF2    = new SpatialFile()
            {
                Districts = rdResult2, PartyCount = PartyCount
            };

            var env1 = this.GetENV();
            var env2 = newSF.GetENV();
            var env3 = newSF2.GetENV();
        }
Ejemplo n.º 2
0
        public static SpatialFile FromStream(Stream strm)
        {
            var result = new SpatialFile();
            var csv    = CSVReader.ReadFromStream(strm).ToList();

            var numberOfParties   = int.Parse(csv[0].First());
            var numberOfDistricts = int.Parse(csv[1].First());

            result.PartyCount = numberOfParties;

            int rowIndex = 2;

            if (csv[rowIndex][0] == "names")
            {
                rowIndex++;

                for (int i = 0; i < result.PartyCount; i++)
                {
                    result.PartyNames.Add(csv[rowIndex][i]);
                }

                rowIndex++;
            }

            for (int i = 0; i < numberOfDistricts; i++)
            {
                var row = csv[rowIndex];

                var d = new District();
                for (int j = 0; j < numberOfParties; j++)
                {
                    d.ResultsByParty.Add(double.Parse(row[j]));
                }

                double districtTotal = (from x in d.ResultsByParty select x).Sum();
                d.ResultsByParty = (from x in d.ResultsByParty.ToList() select x / districtTotal).ToList();

                result.Districts.Add(d);

                rowIndex++;
            }

            return(result);
        }