Beispiel #1
0
 public void Add(ControlRecordList list)
 {
     this.CrData.Add(list);
 }
Beispiel #2
0
        public void Dowork(string arrpath, string srpath, string ctlpath, string outpupath)
        {
            DirectoryInfo arrFolder = new DirectoryInfo(arrpath);
            DirectoryInfo srFolder  = new DirectoryInfo(srpath);
            DirectoryInfo ctlFolder = new DirectoryInfo(ctlpath);

            FileInfo[] sr  = srFolder.GetFiles();
            FileInfo[] ctl = ctlFolder.GetFiles();

            Dictionary <SimStatic, double>         dic     = new Dictionary <SimStatic, double>();
            Dictionary <SimStatic, List <double> > listDic = new Dictionary <SimStatic, List <double> >();

            foreach (SimStatic s in IndexList)
            {
                if (s.Cal != null)
                {
                    dic.Add(s, 0);
                }
                else if (s.TCal != null)
                {
                    listDic.Add(s, new List <double>());
                }
            }

            int n     = 0;
            int total = arrFolder.GetFiles("*.arr").Length;
            int step  = (int)Math.Ceiling((double)arrFolder.GetFiles("*.arr").Length / 10000);

            Console.Write("进度 000.00%");
            foreach (FileInfo file in arrFolder.GetFiles("*.arr"))
            {
                Task ta = factory.StartNew(() =>
                {
                    PrimalArrivalList pal = new PrimalArrivalList();
                    pal.ReadFromArrFile(file.FullName);

                    FileInfo srFile  = sr.FirstOrDefault(i => i.Name == file.Name.Substring(0, file.Name.IndexOf('.')) + ".sr");
                    FileInfo ctlFile = ctl.FirstOrDefault(i => i.Name == file.Name.Substring(0, file.Name.IndexOf('.')) + ".cr");

                    ControlRecordList crl = GenCrl(ctlFile, pal);
                    SellingRecordList srl = GenSrl(srFile, pal);

                    lock (dic)
                    {
                        foreach (SimStatic s in IndexList)
                        {
                            if (s.Cal != null)
                            {
                                dic[s] += s.Cal(pal, srl, crl);
                            }
                            else if (s.TCal != null)
                            {
                                List <double> temp = s.TCal(pal, srl, crl);
                                for (int i = 0; i < temp.Count; i++)
                                {
                                    if (listDic[s].Count <= i)
                                    {
                                        listDic[s].Add(0);
                                    }
                                    listDic[s][i] += temp[i];
                                }
                            }
                        }
                    }

                    if (n++ % step == 0)
                    {
                        lock (arrFolder)
                        {
                            Console.SetCursorPosition(Console.CursorLeft - 7, Console.CursorTop);
                            Console.Write("{0}%", String.Format("{0:000.00}", Math.Round(((double)n / (double)total), 4) * 100));
                        }
                    }
                }, cts.Token);
                tasks.Add(ta);
            }
            Task.WaitAll(tasks.ToArray());
            tasks.Clear();
            Console.SetCursorPosition(Console.CursorLeft - 7, Console.CursorTop);
            Console.WriteLine("100.00 %  完成!");
            //输出
            StreamWriter sw = new StreamWriter(outpupath, true);

            sw.Write("\r\n" + arrFolder.FullName + ",");
            foreach (SimStatic s in IndexList)
            {
                if (s.Cal != null)
                {
                    if (s.IsAvg)
                    {
                        dic[s] = dic[s] / (double)total;
                    }
                    if (IndexList.IndexOf(s) < IndexList.Count - 1)
                    {
                        sw.Write("{0},", dic[s]);
                    }
                    else
                    {
                        sw.Write("{0}", dic[s]);
                    }
                }
                else if (s.TCal != null)
                {
                    if (s.IsAvg)
                    {
                        for (int i = 0; i < listDic[s].Count; i++)
                        {
                            listDic[s][i] = listDic[s][i] / (double)total;
                        }
                    }
                    sw.WriteLine();
                    sw.WriteLine(s.Name);
                    for (int i = 0; i < listDic[s].Count; i++)
                    {
                        sw.WriteLine("{0},", listDic[s][i]);
                    }
                }
            }
            sw.Close();
        }