Example #1
0
        public static void ComputeCommuneLevelStatisticsCars(string poplFile,
                            string fileNam, string comList)
        {
            using (StreamReader currReader = new StreamReader(poplFile))
            using (StreamReader currComuneList = new StreamReader(comList))
            using (StreamWriter currOutputFile = new StreamWriter(fileNam))
            {
                Hashtable currCarZero = new Hashtable();
                Hashtable currCarOne = new Hashtable();
                Hashtable currCarTwo = new Hashtable();
                Hashtable currCarThree = new Hashtable();

                string currHhld;
                currReader.ReadLine();
                while (!currReader.EndOfStream)
                {
                    currHhld = currReader.ReadLine();
                    string[] currHhldTok = currHhld.Split(',');
                    string currsector = currHhldTok[1].Substring(0, 5);
                    int cntUn = int.Parse(currHhldTok[7]);
                    if (currCarZero.Contains(currsector) && cntUn == 0)
                    {
                        ZonalStat currStat = (ZonalStat)currCarZero[currsector];
                        currStat.Count++;
                        currCarZero[currsector] = currStat;
                    }
                    else if (cntUn == 0)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currCarZero.Add(currsector, currStat);

                    }
                    if (currCarOne.Contains(currsector) && cntUn == 1)
                    {
                        ZonalStat currStat = (ZonalStat)currCarOne[currsector];
                        currStat.Count++;
                        currCarOne[currsector] = currStat;
                    }
                    else if (cntUn == 1)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currCarOne.Add(currsector, currStat);

                    }
                    if (currCarTwo.Contains(currsector) && cntUn == 2)
                    {
                        ZonalStat currStat = (ZonalStat)currCarTwo[currsector];
                        currStat.Count++;
                        currCarTwo[currsector] = currStat;
                    }
                    else if (cntUn == 2)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currCarTwo.Add(currsector, currStat);
                    }
                    if (currCarThree.Contains(currsector) && cntUn == 3)
                    {
                        ZonalStat currStat = (ZonalStat)currCarThree[currsector];
                        currStat.Count++;
                        currCarThree[currsector] = currStat;
                    }
                    else if (cntUn == 3)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currCarThree.Add(currsector, currStat);

                    }
                }
                currOutputFile.WriteLine("Commune,Car0,Car1,Car2,Car3");
                string str = currComuneList.ReadLine();

                while (!currComuneList.EndOfStream)
                {
                    str = currComuneList.ReadLine();
                    string strConcat = str;
                    if (currCarZero.Contains(str))
                    {
                        ZonalStat curSt = (ZonalStat)currCarZero[str];
                        strConcat += "," + curSt.Count.ToString();
                    }
                    else
                    {
                        strConcat += ",0";
                    }

                    if (currCarOne.Contains(str))
                    {
                        ZonalStat curSt = (ZonalStat)currCarOne[str];
                        strConcat += "," + curSt.Count.ToString();
                    }
                    else
                    {
                        strConcat += ",0";
                    }

                    if (currCarTwo.Contains(str))
                    {
                        ZonalStat curSt = (ZonalStat)currCarTwo[str];
                        strConcat += "," + curSt.Count.ToString();
                    }
                    else
                    {
                        strConcat += ",0";
                    }

                    if (currCarThree.Contains(str))
                    {
                        ZonalStat curSt = (ZonalStat)currCarThree[str];
                        strConcat += "," + curSt.Count.ToString();
                    }
                    else
                    {
                        strConcat += ",0";
                    }
                    currOutputFile.WriteLine(strConcat);
                }
            }
        }
Example #2
0
        public List<Dictionary<string, ZonalStat>> ComputeCommuneMCStatsCars(int runNum, int seed,
                            string poolFileName, bool delRealizations)
        {
            string poplFile = Constants.DATA_DIR +
                            "Household\\PopulationRealization" + runNum.ToString() + ".csv";
            CreatePopulationByDwellingType(seed, poolFileName, poplFile);
            var currCarZero = new Dictionary<string, ZonalStat>();
            var currCarOne = new Dictionary<string, ZonalStat>();
            var currCarTwo = new Dictionary<string, ZonalStat>();
            var currCarThree = new Dictionary<string, ZonalStat>();
            using (StreamReader currReader = new StreamReader(poplFile))
            {
                string currHhld;
                currReader.ReadLine();
                while (!currReader.EndOfStream)
                {
                    currHhld = currReader.ReadLine();
                    string[] currHhldTok = currHhld.Split(',');
                    string currsector = currHhldTok[1].Substring(0, 5);
                    int cntUn = int.Parse(currHhldTok[7]);
                    if (currCarZero.ContainsKey(currsector) && cntUn == 0)
                    {
                        var currStat = currCarZero[currsector];
                        currStat.Count++;
                        currCarZero[currsector] = currStat;
                    }
                    else if (cntUn == 0)
                    {
                        var currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currCarZero.Add(currsector, currStat);

                    }
                    if (currCarOne.ContainsKey(currsector) && cntUn == 1)
                    {
                        ZonalStat currStat = currCarOne[currsector];
                        currStat.Count++;
                        currCarOne[currsector] = currStat;
                    }
                    else if (cntUn == 1)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currCarOne.Add(currsector, currStat);

                    }
                    if (currCarTwo.ContainsKey(currsector) && cntUn == 2)
                    {
                        ZonalStat currStat = (ZonalStat)currCarTwo[currsector];
                        currStat.Count++;
                        currCarTwo[currsector] = currStat;
                    }
                    else if (cntUn == 2)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currCarTwo.Add(currsector, currStat);
                    }
                    if (currCarThree.ContainsKey(currsector) && cntUn == 3)
                    {
                        ZonalStat currStat = (ZonalStat)currCarThree[currsector];
                        currStat.Count++;
                        currCarThree[currsector] = currStat;
                    }
                    else if (cntUn == 3)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currCarThree.Add(currsector, currStat);

                    }
                }
            }
            var currArrayList = new List<Dictionary<string, ZonalStat>>(4);
            currArrayList.Add(currCarZero);
            currArrayList.Add(currCarOne);
            currArrayList.Add(currCarTwo);
            currArrayList.Add(currCarThree);

            if (delRealizations == true)
            {
                File.Delete(poplFile);
            }
            return currArrayList;
        }
Example #3
0
        public void ComputeCommuneLevelStatisticsIncome(string poplFile)
        {
            StreamReader currReader = new StreamReader(poplFile);

            Hashtable currIncome = new Hashtable();

            StreamWriter currOutputFile = new
                StreamWriter(Constants.DATA_DIR + "CommuneStatisticsIncome.csv");
            string currHhld;
            currReader.ReadLine();
            while (!currReader.EndOfStream)
            {
                currHhld = currReader.ReadLine();
                string[] currHhldTok = currHhld.Split(',');
                string currsector = currHhldTok[1].Substring(0, 5);
                if (currIncome.Contains(currsector))
                {
                    ZonalStat currStat = (ZonalStat)currIncome[currsector];
                    currStat.Count++;
                    currStat.Sum += Int32.Parse(currHhldTok[6]);
                    currIncome[currsector] = currStat;
                    int cntUn = int.Parse(currHhldTok[5]);
                    int cntTot = int.Parse(currHhldTok[2]);

                }
                else
                {
                    ZonalStat currStat = new ZonalStat();
                    currStat.ZoneName = currsector;
                    currStat.Sum = Int32.Parse(currHhldTok[6]);
                    currStat.Count = 1;
                    currIncome.Add(currsector, currStat);

                }
            }

            currOutputFile.WriteLine("Commune,Income");
            foreach (DictionaryEntry ent in currIncome)
            {
                ZonalStat curSt = (ZonalStat)ent.Value;
                currOutputFile.WriteLine(curSt.ZoneName + "," +
                    curSt.Sum / curSt.Count);
            }
            currReader.Close();
            currOutputFile.Close();
        }
Example #4
0
        public void ComputeCommuneLevelStatisticsPeople(string poplFile, int category)
        {
            using (var currReader = new StreamReader(poplFile))
            {
                Hashtable currEdu = new Hashtable();

                using (var currOutputFile = new
                    StreamWriter(Constants.DATA_DIR + "CommuneStatistics5Per.csv"))
                {
                    string currHhld;
                    currReader.ReadLine();
                    while (!currReader.EndOfStream)
                    {
                        currHhld = currReader.ReadLine();
                        string[] currHhldTok = currHhld.Split(',');
                        string currsector = currHhldTok[1].Substring(0, 5);
                        int cntUn = int.Parse(currHhldTok[2]);
                        if (currEdu.Contains(currsector) && cntUn == category)
                        {
                            ZonalStat currStat = (ZonalStat)currEdu[currsector];
                            currStat.Count++;
                            currEdu[currsector] = currStat;
                        }
                        else if (cntUn == category)
                        {
                            ZonalStat currStat = new ZonalStat();
                            currStat.ZoneName = currsector;
                            currStat.Count = 1;
                            currEdu.Add(currsector, currStat);

                        }
                    }

                    currOutputFile.WriteLine("Commune,People5");
                    foreach (DictionaryEntry ent in currEdu)
                    {
                        ZonalStat curSt = (ZonalStat)ent.Value;
                        currOutputFile.WriteLine(curSt.ZoneName + "," +
                            curSt.Count);
                    }
                }
            }
        }
Example #5
0
        public static void ComputeCommuneLevelStatisticsPeople(string poplFile,
                    string fileNam, string comList)
        {
            using (StreamReader currReader = new StreamReader(poplFile))
            using (StreamReader currComuneList = new StreamReader(comList))
            using (StreamWriter currOutputFile = new StreamWriter(fileNam))
            {
                Hashtable currPerM = new Hashtable();
                Hashtable currPerF = new Hashtable();
                Hashtable currPerTwo = new Hashtable();
                Hashtable currPerThree = new Hashtable();
                Hashtable currPerFour = new Hashtable();
                Hashtable currPerFive = new Hashtable();
                string currHhld;
                currReader.ReadLine();
                while (!currReader.EndOfStream)
                {
                    currHhld = currReader.ReadLine();
                    string[] currHhldTok = currHhld.Split(',');
                    string currsector = currHhldTok[1].Substring(0, 5);
                    int cntUn = int.Parse(currHhldTok[2]);
                    if (currPerM.Contains(currsector) && cntUn == 0)
                    {
                        ZonalStat currStat = (ZonalStat)currPerM[currsector];
                        currStat.Count++;
                        currPerM[currsector] = currStat;
                    }
                    else if (cntUn == 0)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currPerM.Add(currsector, currStat);

                    }
                    if (currPerF.Contains(currsector) && cntUn == 1)
                    {
                        ZonalStat currStat = (ZonalStat)currPerF[currsector];
                        currStat.Count++;
                        currPerF[currsector] = currStat;
                    }
                    else if (cntUn == 1)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currPerF.Add(currsector, currStat);

                    }
                    if (currPerTwo.Contains(currsector) && cntUn == 2)
                    {
                        ZonalStat currStat = (ZonalStat)currPerTwo[currsector];
                        currStat.Count++;
                        currPerTwo[currsector] = currStat;
                    }
                    else if (cntUn == 2)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currPerTwo.Add(currsector, currStat);
                    }
                    if (currPerThree.Contains(currsector) && cntUn == 3)
                    {
                        ZonalStat currStat = (ZonalStat)currPerThree[currsector];
                        currStat.Count++;
                        currPerThree[currsector] = currStat;
                    }
                    else if (cntUn == 3)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currPerThree.Add(currsector, currStat);

                    }
                    if (currPerFour.Contains(currsector) && cntUn == 4)
                    {
                        ZonalStat currStat = (ZonalStat)currPerFour[currsector];
                        currStat.Count++;
                        currPerFour[currsector] = currStat;
                    }
                    else if (cntUn == 4)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currPerFour.Add(currsector, currStat);

                    }
                    if (currPerFive.Contains(currsector) && cntUn == 5)
                    {
                        ZonalStat currStat = (ZonalStat)currPerFive[currsector];
                        currStat.Count++;
                        currPerFive[currsector] = currStat;
                    }
                    else if (cntUn == 5)
                    {
                        ZonalStat currStat = new ZonalStat();
                        currStat.ZoneName = currsector;
                        currStat.Count = 1;
                        currPerFive.Add(currsector, currStat);

                    }
                }
                currOutputFile.WriteLine("Commune,Male,Female,Per2,Per3,Per4,Per5");
                string str = currComuneList.ReadLine();

                while (!currComuneList.EndOfStream)
                {
                    str = currComuneList.ReadLine();
                    string strConcat = str;
                    if (currPerM.Contains(str))
                    {
                        ZonalStat curSt = (ZonalStat)currPerM[str];
                        strConcat += "," + curSt.Count.ToString();
                    }
                    else
                    {
                        strConcat += ",0";
                    }

                    if (currPerF.Contains(str))
                    {
                        ZonalStat curSt = (ZonalStat)currPerF[str];
                        strConcat += "," + curSt.Count.ToString();
                    }
                    else
                    {
                        strConcat += ",0";
                    }

                    if (currPerTwo.Contains(str))
                    {
                        ZonalStat curSt = (ZonalStat)currPerTwo[str];
                        strConcat += "," + curSt.Count.ToString();
                    }
                    else
                    {
                        strConcat += ",0";
                    }

                    if (currPerThree.Contains(str))
                    {
                        ZonalStat curSt = (ZonalStat)currPerThree[str];
                        strConcat += "," + curSt.Count.ToString();
                    }
                    else
                    {
                        strConcat += ",0";
                    }
                    if (currPerFour.Contains(str))
                    {
                        ZonalStat curSt = (ZonalStat)currPerFour[str];
                        strConcat += "," + curSt.Count.ToString();
                    }
                    else
                    {
                        strConcat += ",0";
                    }
                    if (currPerFive.Contains(str))
                    {
                        ZonalStat curSt = (ZonalStat)currPerFive[str];
                        strConcat += "," + curSt.Count.ToString();
                    }
                    else
                    {
                        strConcat += ",0";
                    }
                    currOutputFile.WriteLine(strConcat);
                }
            }
        }