コード例 #1
0
        protected void PrintEmotionDimensions(string filePath)
        {
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            var allDimensions = new StatisticsCollection();

            allDimensions.Add(this.emotionalSTM.Mood.Id, this.emotionalSTM.Mood);
            allDimensions.Add(this.emotionalSTM.Clarity.Id, this.emotionalSTM.Clarity);
            foreach (var dimension in this.emotionalSTM.AppraisalSet.Dimensions.Values)
            {
                allDimensions.Add(dimension.Id, dimension);
            }

            allDimensions.PrintAllQuantitiesToCSV(filePath);
        }
コード例 #2
0
        protected virtual StatisticsCollection GetFitnessQuantityList()
        {
            var cumulativeFitnessAvgList = new StatisticsCollection();

            foreach (var testParameters in this)
            {
                var testMeasure = this[testParameters];
                if ((testMeasure.Quantity != null) &&
                    !cumulativeFitnessAvgList.ContainsKey(testMeasure.ToString()))
                {
                    cumulativeFitnessAvgList.Add(testMeasure.ToString(), testMeasure.Quantity);
                }
            }
            return(cumulativeFitnessAvgList);
        }
コード例 #3
0
        protected virtual StatisticsCollection GetPopulationStatsCollectionAvg(IPopulation population)
        {
            if ((population == null) || (population.Count == 0))
            {
                return(null);
            }
            var popStatsCollectionAvg = new StatisticsCollection();

            //for each agent statistic
            foreach (var statKey in population[0].StatisticsCollection.Keys)
            {
                //average statistic between all agents
                var stat = StatisticalQuantity.GetQuantitiesAverage(
                    population.Select(ag => ag.StatisticsCollection[statKey]).ToList());

                popStatsCollectionAvg.Add(statKey, stat);
            }
            return(popStatsCollectionAvg);
        }
コード例 #4
0
        protected override void PrintPerformanceResults()
        {
            //prints agents' cumulative fitness
            this.WriteLine(@"Printing agents' performances...");

            if (this.TestsConfig.StoreIndividualAgentStats)
            {
                var agentsFitnessList = new StatisticsCollection();
                for (uint i = 0; i < this.TestsConfig.NumAgents; i++)
                {
                    agentsFitnessList.Add($"Agent{i}",
                                          this.testStatisticsAvg[this.GetAgentFitnessStatID(i)]);
                }

                agentsFitnessList.PrintAllQuantitiesToCSV($"{this.FilePath}/AgentsCumulativeFitnessAvg.csv");
                //agentsFitnessList.PrintAllQuantitiesToImage($"{this.FilePath}/AgentsCumulativeFitnessAvg.png");
            }

            //prints overall cumulative fitness
            this.SimulationScoreAvg.PrintStatisticsToCSV($"{this.FilePath}/CumulativeFitnessAvg.csv");
            this.FinalScores.PrintStatisticsToCSV($"{this.FilePath}/CumulativeFitnessValues.csv", false, true, ChartType.Column);
        }
コード例 #5
0
        void _BGWTotalDisciplineAndAbsence_DoWork(object sender, DoWorkEventArgs e)
        {
            string reportName = "歷年功過及出席統計";

            _BGWTotalDisciplineAndAbsence.ReportProgress(0);

            #region 取得資料

            AccessHelper         helper   = new AccessHelper();
            List <StudentRecord> students = helper.StudentHelper.GetSelectedStudent();

            helper.StudentHelper.FillSemesterEntryScore(true, students);
            helper.StudentHelper.FillReward(students);
            helper.StudentHelper.FillAttendance(students);

            StatisticsCollection stat = new StatisticsCollection();
            Dictionary <string, List <string> > detailList = new Dictionary <string, List <string> >();

            Dictionary <string, int> rewardDict = new Dictionary <string, int>();

            foreach (StudentRecord each in students)
            {
                StatisticsData data = new StatisticsData();
                List <string>  list = new List <string>();

                //獎懲
                foreach (RewardInfo info in each.RewardList)
                {
                    int schoolyear = info.SchoolYear;
                    int semester   = info.Semester;

                    if (info.UltimateAdmonition == true)
                    {
                        data.AddItem(schoolyear, semester, "留校察看", 1);
                        list.Add(CDATE(info.OccurDate.ToShortDateString()) + " " + info.OccurReason + " 留校察看");
                        continue;
                    }

                    rewardDict.Clear();

                    data.AddItem(schoolyear, semester, "大功", (decimal)info.AwardA);
                    data.AddItem(schoolyear, semester, "小功", (decimal)info.AwardB);
                    data.AddItem(schoolyear, semester, "嘉獎", (decimal)info.AwardC);
                    rewardDict.Add("大功", info.AwardA);
                    rewardDict.Add("小功", info.AwardB);
                    rewardDict.Add("嘉獎", info.AwardC);

                    if (_print_cleared == true || info.Cleared == false)
                    {
                        data.AddItem(schoolyear, semester, "大過", (decimal)info.FaultA);
                        data.AddItem(schoolyear, semester, "小過", (decimal)info.FaultB);
                        data.AddItem(schoolyear, semester, "警告", (decimal)info.FaultC);
                        rewardDict.Add("大過", info.FaultA);
                        rewardDict.Add("小過", info.FaultB);
                        rewardDict.Add("警告", info.FaultC);
                    }

                    string rewardStat = "";
                    foreach (string var in new string[] { "大功", "小功", "嘉獎", "大過", "小過", "警告" })
                    {
                        if (rewardDict.ContainsKey(var) && rewardDict[var] > 0)
                        {
                            if (!string.IsNullOrEmpty(rewardStat))
                            {
                                rewardStat += ", ";
                            }
                            rewardStat += var + rewardDict[var] + "次";
                        }
                    }

                    //兩個條件可加入明細清單
                    //1.如果勾選消過也列印
                    //2.資料未消過
                    if (_print_cleared == true)
                    {
                        string all = "";
                        if (info.Cleared)
                        {
                            all = CDATE(info.OccurDate.ToShortDateString()) + " " + info.OccurReason + " " + rewardStat + " (已銷過)";
                        }
                        else
                        {
                            all = CDATE(info.OccurDate.ToShortDateString()) + " " + info.OccurReason + " " + rewardStat;
                        }
                        list.Add(all);
                    }
                    else if (info.Cleared == false)
                    {
                        string all = CDATE(info.OccurDate.ToShortDateString()) + " " + info.OccurReason + " " + rewardStat;
                        list.Add(all);
                    }

                    #region 註解掉了
                    //if (((info.OccurReason + " " + rewardStat) as string).Length >= 20)
                    //{
                    //    List<string> mini = new List<string>();
                    //    string reason = info.OccurReason;

                    //    while (reason.Length >= 20)
                    //    {
                    //        mini.Add(reason.Substring(0, 19));
                    //        reason = reason.Substring(19);
                    //    }
                    //    if (((reason + " " + rewardStat) as string).Length >= 20)
                    //    {
                    //        mini.Add(reason);
                    //        mini.Add(rewardStat);
                    //    }
                    //    else
                    //        mini.Add(reason + " " + rewardStat);

                    //    //mini.Add(CDATE(info.OccurDate.ToShortDateString()) + " ");

                    //    for (int i = 0; i < mini.Count; i++)
                    //    {
                    //        if (i == 0)
                    //            list.Add(CDATE(info.OccurDate.ToShortDateString()) + " " + mini[i]);
                    //        else
                    //            list.Add("   " + mini[i]);
                    //    }
                    //}
                    //else
                    //    list.Add(all);
                    #endregion
                }
                detailList.Add(each.StudentID, list);

                //缺曠
                foreach (AttendanceInfo info in each.AttendanceList)
                {
                    int schoolyear = info.SchoolYear;
                    int semester   = info.Semester;
                    if (PrintDic.ContainsKey(info.Period))
                    {
                        data.AddItem(schoolyear, semester, PrintDic[info.Period] + "_" + info.Absence, 1);
                    }
                }

                //德行成績
                foreach (SemesterEntryScoreInfo info in each.SemesterEntryScoreList)
                {
                    if (info.Entry == "德行")
                    {
                        int schoolyear = info.SchoolYear;
                        int semester   = info.Semester;

                        data.AddItem(schoolyear, semester, "德行成績", info.Score);
                    }
                }

                data.MendSemester();

                stat.Add(each.StudentID, data);
            }

            #endregion

            #region 產生範本

            int AsbCount = 0;
            foreach (string each in _print_types.Keys)
            {
                AsbCount += _print_types[each].Count;
            }

            totalRow = detailRow + 11 + AsbCount;

            foreach (StudentRecord each in students)
            {
                if (detailRow < detailList[each.StudentID].Count / 2 + 1)
                {
                    detailRow = detailList[each.StudentID].Count / 2 + 1;

                    totalRow = detailRow + 11 + AsbCount;
                }
            }


            Workbook pt1 = GetTemplate(6);
            Workbook pt2 = GetTemplate(8);
            Workbook pt3 = GetTemplate(10);

            Dictionary <int, Workbook> pts = new Dictionary <int, Workbook>();
            pts.Add(6, pt1);
            pts.Add(8, pt2);
            pts.Add(10, pt3);

            Range ptr1 = pt1.Worksheets[0].Cells.CreateRange(0, totalRow, false);
            Range ptr2 = pt2.Worksheets[0].Cells.CreateRange(0, totalRow, false);
            Range ptr3 = pt3.Worksheets[0].Cells.CreateRange(0, totalRow, false);

            Dictionary <int, Range> ptrs = new Dictionary <int, Range>();
            ptrs.Add(6, ptr1);
            ptrs.Add(8, ptr2);
            ptrs.Add(10, ptr3);

            #endregion

            #region 產生報表

            Workbook wb = new Workbook();
            wb.Copy(pt1);
            wb.Worksheets[0].Copy(pt1.Worksheets[0]);

            int wsCount = wb.Worksheets.Count;
            for (int i = wsCount - 1; i > 0; i--)
            {
                wb.Worksheets.RemoveAt(i);
            }
            wb.Worksheets[0].Name = "一般(6學期)";

            Dictionary <int, int>       sheetIndex = new Dictionary <int, int>();
            Dictionary <int, Worksheet> sheets     = new Dictionary <int, Worksheet>();
            sheets.Add(6, wb.Worksheets[0]);
            sheetIndex.Add(6, 0);

            Worksheet ws = wb.Worksheets[0];

            int index = 0;
            int cur   = 6;

            int pages = 500;

            //
            int start = 1;
            int limit = pages;

            int studentCount = 0;

            //學生數
            int allStudentCount = students.Count;

            foreach (StudentRecord each in students)
            {
                //取得學生統計
                StatisticsData data = stat[each.StudentID];

                #region 判斷學期數
                if (data.GetSemesterNumber() > 6 && data.GetSemesterNumber() <= 8)
                {
                    //學期數大於6小於8
                    //特殊報表
                    if (!sheets.ContainsKey(8))
                    {
                        int new_ws_index = wb.Worksheets.Add();
                        wb.Worksheets[new_ws_index].Copy(pt2.Worksheets[0]);
                        wb.Worksheets[new_ws_index].Name = "特殊(8學期)";
                        sheets.Add(8, wb.Worksheets[new_ws_index]);
                        sheetIndex.Add(8, 0);
                    }

                    //變更預設報表位置
                    ws = sheets[8];
                    //取得報表定位
                    index = sheetIndex[8];
                    //取得報表定位?
                    cur = 8;
                    studentCount++;
                }
                else if (data.GetSemesterNumber() == 6)
                {
                    ws    = sheets[6];
                    index = sheetIndex[6];
                    cur   = 6;
                    studentCount++;
                }
                else
                {
                    //學期數大於8小於10
                    //特殊1報表
                    if (!sheets.ContainsKey(10))
                    {
                        int new_ws_index = wb.Worksheets.Add();
                        wb.Worksheets[new_ws_index].Copy(pt3.Worksheets[0]);
                        wb.Worksheets[new_ws_index].Name = "特殊(其它)";
                        sheets.Add(10, wb.Worksheets[new_ws_index]);
                        sheetIndex.Add(10, 0);
                    }
                    ws    = sheets[10];
                    index = sheetIndex[10];
                    cur   = 10;
                    studentCount++;
                }
                #endregion

                //取得畫面範圍 Range(0~TotalRow)
                ws.Cells.CreateRange(index, totalRow, false).Copy(ptrs[cur]);

                //填入標題
                ws.Cells[index + 1, 0].PutValue(string.Format("班級:{0}    學號:{1}    姓名:{2}", (each.RefClass != null) ? each.RefClass.ClassName : "", each.StudentNumber, each.StudentName));

                //第一行位置(標題+2)
                int firstRow = index + 2;

                //第一列位置
                int col = 2;

                //處理每個學期的統計
                foreach (string semsString in data.Semesters)
                {
                    //填入學年度/學期
                    ws.Cells[firstRow, col].PutValue(DisplaySemester(semsString));

                    //取得學期統計資料
                    Dictionary <string, decimal> semsDict = data.GetItem(semsString);

                    foreach (string item in semsDict.Keys)
                    {
                        if (rowIndexTable.ContainsKey(item))
                        {
                            ws.Cells[index + rowIndexTable[item], col].PutValue((semsDict[item] <= 0) ? "" : semsDict[item].ToString());
                        }
                    }

                    col++;
                }

                if (rowIndexTable.ContainsKey("明細"))
                {
                    //資料一律由第二列進行列印
                    int detailColIndex = 2;

                    //
                    int detailIndex = index + rowIndexTable["明細"];

                    //明細定位點
                    int detailCount = 0;

                    //取得學生明細清單
                    foreach (string var in detailList[each.StudentID])
                    {
                        //明細定位點+1
                        detailCount++;
                        //定位點大於明細畫面範圍時
                        //將換為第二區進行列印
                        if (detailCount > detailRow)
                        {
                            detailColIndex += (cur / 2);
                            detailIndex     = index + rowIndexTable["明細"];
                            detailCount     = 0;
                        }
                        ws.Cells[detailIndex++, detailColIndex].PutValue(var);
                    }
                }

                //?
                index          += totalRow;
                sheetIndex[cur] = index;

                //增加列印分割線
                ws.HPageBreaks.Add(index, 0);

                //當學生大於極限值 , 並且列印完所有學生
                if (studentCount >= limit && studentCount < allStudentCount)
                {
                    //取得工作表名稱
                    //string orig_name = ws.Name;

                    //
                    //ws.Name = ws.Name + " (" + start + " ~ " + studentCount + ")";
                    ws = wb.Worksheets[wb.Worksheets.Add()];
                    ws.Copy(pts[cur].Worksheets[0]);
                    //ws.Name = orig_name;
                    start          += pages;
                    limit          += pages;
                    index           = 0;
                    sheetIndex[cur] = index;
                    sheets[cur]     = ws;
                }

                //回報進度
                _BGWTotalDisciplineAndAbsence.ReportProgress((int)(((double)studentCount * 100.0) / (double)allStudentCount));
            }

            //if (cur == 6)
            //ws.Name = ws.Name + " (" + start + " ~ " + studentCount + ")";

            #endregion

            string path = Path.Combine(Application.StartupPath, "Reports");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            path     = Path.Combine(path, reportName + ".xlt");
            e.Result = new object[] { reportName, path, wb };
        }