public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            PerformanceParameterType s = obj as PerformanceParameterType;

            if ((System.Object)s == null)
            {
                return(false);
            }

            if (this.id != s.id)
            {
                return(false);
            }
            if (this.groupId != s.groupId)
            {
                return(false);
            }
            if (this.name != s.name)
            {
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public void PerformanceParameterType_Initialization_Test()
        {
            try
            {
                // Arrange and Act
                PerformanceParameterType performanceParameterType = new PerformanceParameterType();

                // Assert
                Assert.IsNotNull(performanceParameterType);
            }
            catch (Exception)
            {
                throw new AssertFailedException("PerformanceParameterType initialization failed.");
            }
        }
        public void PerformanceParameterEvaluation_Property_Set_Test()
        {
            try
            {
                // Arrange
                PlayerEvaluation playerEvaluation = new PlayerEvaluation();

                // Act
                playerEvaluation.sportId           = 1;
                playerEvaluation.playerId          = 1;
                playerEvaluation.perfParaName      = new PerformanceParameterName();
                playerEvaluation.perfParaName.id   = 1;
                playerEvaluation.perfParaName.name = "Perf Para 1";
                playerEvaluation.customName        = "Custom Name";
                playerEvaluation.perfParaTypes     = new List <PerformanceParameterType>();
                PerformanceParameterType perfParaType = new PerformanceParameterType();
                perfParaType.id      = 1;
                perfParaType.groupId = 1;
                perfParaType.name    = "Perf Para Type 1";
                playerEvaluation.perfParaTypes.Add(perfParaType);
                playerEvaluation.selectedType         = new PerformanceParameterType();
                playerEvaluation.selectedType.id      = 1;
                playerEvaluation.selectedType.groupId = 1;
                playerEvaluation.selectedType.name    = "Perf Para Type 1";
                playerEvaluation.value = "value";

                // Assert
                Assert.AreEqual <long>(playerEvaluation.sportId, 1);
                Assert.AreEqual <long>(playerEvaluation.perfParaName.id, 1);
                Assert.AreEqual <string>(playerEvaluation.perfParaName.name, "Perf Para 1");
                Assert.AreEqual <string>(playerEvaluation.customName, "Custom Name");
                Assert.AreEqual <long>(playerEvaluation.perfParaTypes[0].id, 1);
                Assert.AreEqual <long>(playerEvaluation.perfParaTypes[0].groupId, 1);
                Assert.AreEqual <string>(playerEvaluation.perfParaTypes[0].name, "Perf Para Type 1");
                Assert.AreEqual <long>(playerEvaluation.selectedType.id, 1);
                Assert.AreEqual <long>(playerEvaluation.selectedType.groupId, 1);
                Assert.AreEqual <string>(playerEvaluation.selectedType.name, "Perf Para Type 1");
                Assert.AreEqual <string>(playerEvaluation.value, "value");
            }
            catch (Exception)
            {
                throw new AssertFailedException("Setting PerformanceParameterEvaluation properties failed.");
            }
        }
        public ArrayList GetPerformanceParameterTypes(long performanceParameterNameId)
        {
            String                   sqlStr    = "SELECT id, group_id, name FROM perf_para_type WHERE group_id IN (SELECT group_id FROM perf_para_link WHERE name_id = " + performanceParameterNameId + ")";
            MySqlCommand             cmd       = new MySqlCommand(sqlStr, conn);
            MySqlDataReader          sqlReader = cmd.ExecuteReader();
            ArrayList                performanceParameterTypes = new ArrayList();
            PerformanceParameterType pp = null;

            while (sqlReader.Read())
            {
                pp         = new PerformanceParameterType();
                pp.id      = sqlReader.GetInt32(0);
                pp.groupId = sqlReader.GetInt32(1);
                pp.name    = sqlReader.GetString(2);
                performanceParameterTypes.Add(pp);
            }

            sqlReader.Close();
            return(performanceParameterTypes);
        }
Beispiel #5
0
        public void PerformanceParameterType_Property_Set_Test()
        {
            try
            {
                // Arrange
                PerformanceParameterType performanceParameterType = new PerformanceParameterType();

                // Act
                performanceParameterType.id      = 1;
                performanceParameterType.groupId = 1;
                performanceParameterType.name    = "parameterType";

                // Assert
                Assert.AreEqual <long>(performanceParameterType.id, 1);
                Assert.AreEqual <long>(performanceParameterType.groupId, 1);
                Assert.AreEqual <string>(performanceParameterType.name, "parameterType");
            }
            catch (Exception)
            {
                throw new AssertFailedException("Setting PerformanceParameterType properties failed.");
            }
        }
        public void Get_All_PerformanceParameterTypes_Test()
        {
            // Arrange
            ArrayList performanceParameterTypesObjsAsOuptut = new ArrayList();

            PerformanceParameterType performanceParameterTypeObj1AsOutput = new PerformanceParameterType();

            performanceParameterTypeObj1AsOutput.id      = 1;
            performanceParameterTypeObj1AsOutput.groupId = 1;
            performanceParameterTypeObj1AsOutput.name    = "Para Type 1";

            PerformanceParameterType performanceParameterTypeObj2AsOutput = new PerformanceParameterType();

            performanceParameterTypeObj2AsOutput.id      = 2;
            performanceParameterTypeObj2AsOutput.groupId = 2;
            performanceParameterTypeObj2AsOutput.name    = "Para Type 2";

            performanceParameterTypesObjsAsOuptut.Add(performanceParameterTypeObj1AsOutput);
            performanceParameterTypesObjsAsOuptut.Add(performanceParameterTypeObj2AsOutput);

            var mockRepository = new Mock <IPerformanceParameterTypeRepository>();

            mockRepository.Setup(x => x.GetPerformanceParameterTypes(1))
            .Returns(performanceParameterTypesObjsAsOuptut);

            var controller = new PerformanceParameterTypeController(mockRepository.Object);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            // Act
            ArrayList performanceParameterTypesObj = controller.Get(1);

            // Assert
            Assert.AreEqual <int>(performanceParameterTypesObj.Count, performanceParameterTypesObjsAsOuptut.Count);
            Assert.AreEqual(performanceParameterTypesObj[0], performanceParameterTypesObjsAsOuptut[0]);
            Assert.AreEqual(performanceParameterTypesObj[1], performanceParameterTypesObjsAsOuptut[1]);
        }
        public HighChart GetPlayerAnalysis(PlayerAnalysis playerAnalysis)
        {
            HighChart highChart = new HighChart();

            highChart.chart      = new Chart();
            highChart.chart.type = "line";

            highChart.title      = new Title();
            highChart.title.text = "Performance Analysis Report of " + playerAnalysis.perfPara.perfParaName.name + " for " + playerAnalysis.sport.name;

            highChart.subtitle = new Title();

            if (playerAnalysis.timeRange == "LAST1WEEK")
            {
                highChart.subtitle.text = "<strong>Duration</strong>: Last 1 Week";
                playerAnalysis.fromTime = DateTime.Now.AddDays(-7);
                playerAnalysis.toTime   = DateTime.Now;
            }
            else if (playerAnalysis.timeRange == "LAST1MONTH")
            {
                highChart.subtitle.text = "Duration: Last 1 Month";
                playerAnalysis.fromTime = DateTime.Now.AddMonths(-1);
                playerAnalysis.toTime   = DateTime.Now;
            }
            else if (playerAnalysis.timeRange == "LAST3MONTHS")
            {
                highChart.subtitle.text = "Duration: Last 3 Months";
                playerAnalysis.fromTime = DateTime.Now.AddMonths(-3);
                playerAnalysis.toTime   = DateTime.Now;
            }
            else if (playerAnalysis.timeRange == "LAST6MONTHS")
            {
                highChart.subtitle.text = "Duration: Last 6 Months";
                playerAnalysis.fromTime = DateTime.Now.AddMonths(-6);
                playerAnalysis.toTime   = DateTime.Now;
            }
            else
            {
                highChart.subtitle.text = "Duration: Custom";
                playerAnalysis.fromTime = DateTime.Now.AddDays(-7);
                playerAnalysis.toTime   = DateTime.Now;
            }

            highChart.xAxis            = new XAxis();
            highChart.xAxis.categories = new List <string>();

            highChart.yAxis            = new YAxis();
            highChart.yAxis.title      = new Title();
            highChart.yAxis.title.text = playerAnalysis.perfPara.perfParaName.name;

            highChart.tooltip = new ToolTip();

            highChart.series = new List <SeriesElement>();
            SeriesElement seriesElement;

            String       sqlStr = "select id, group_id, name from perf_para_type where group_id = @groupId";
            MySqlCommand cmd    = new MySqlCommand(sqlStr, conn);

            cmd.Parameters.AddWithValue("groupId", playerAnalysis.perfPara.perfParaTypeGroup.id);
            MySqlDataReader perfParaTypeSqlReader = cmd.ExecuteReader();

            List <PerformanceParameterType> perfParaTypes = new List <PerformanceParameterType>();
            PerformanceParameterType        perfParaType  = null;

            while (perfParaTypeSqlReader.Read())
            {
                perfParaType         = new PerformanceParameterType();
                perfParaType.id      = perfParaTypeSqlReader.GetInt32(0);
                perfParaType.groupId = perfParaTypeSqlReader.GetInt32(1);
                perfParaType.name    = perfParaTypeSqlReader.GetString(2);

                perfParaTypes.Add(perfParaType);
            }
            perfParaTypeSqlReader.Close();

            MySqlDataReader sqlReader;

            if (perfParaTypes.Count == 1)
            {
                highChart.tooltip.valueSuffix = " " + playerAnalysis.perfPara.perfParaTypeGroup.name;

                DateTime startTime = playerAnalysis.fromTime;
                while (startTime <= playerAnalysis.toTime)
                {
                    highChart.xAxis.categories.Add(startTime.Day.ToString() + "-" + startTime.Month.ToString());
                    startTime = startTime.AddDays(1);
                }

                for (int i = 0; i < playerAnalysis.players.Count; i++)
                {
                    seriesElement      = new SeriesElement();
                    seriesElement.name = playerAnalysis.players[i].firstName + " " + playerAnalysis.players[i].lastName;

                    seriesElement.data = new List <string>();

                    sqlStr = "select value from player_eval where sport_id = @sportId and player_id = @playerId and name_id = @nameId and type_id = @typeId and eval_date = @evalDate";
                    cmd    = new MySqlCommand(sqlStr, conn);
                    cmd.Parameters.AddWithValue("sportId", playerAnalysis.sport.id);
                    cmd.Parameters.AddWithValue("playerId", playerAnalysis.players[i].id);
                    cmd.Parameters.AddWithValue("nameId", playerAnalysis.perfPara.perfParaName.id);
                    cmd.Parameters.AddWithValue("typeId", ((PerformanceParameterType)perfParaTypes[0]).id);
                    MySqlParameter para;

                    startTime = playerAnalysis.fromTime;
                    while (startTime <= playerAnalysis.toTime)
                    {
                        if (cmd.Parameters.Contains("evalDate"))
                        {
                            cmd.Parameters.RemoveAt(4);
                        }

                        para       = new MySqlParameter("evalDate", MySqlDbType.Date);
                        para.Value = startTime;
                        cmd.Parameters.Add(para);
                        sqlReader = cmd.ExecuteReader();

                        if (sqlReader.Read())
                        {
                            string[] timeformats = { @"m\:ss", @"mm\:ss", @"h\:mm\:ss" };
                            TimeSpan duration;

                            if (playerAnalysis.perfPara.perfParaTypeGroup.name == "min:sec")
                            {
                                duration = TimeSpan.ParseExact(sqlReader.GetString(0), timeformats, CultureInfo.InvariantCulture);
                                seriesElement.data.Add(duration.TotalSeconds.ToString());
                                highChart.tooltip.valueSuffix = " total sec";
                            }
                            else if (playerAnalysis.perfPara.perfParaTypeGroup.name == "hr:min:sec")
                            {
                                duration = TimeSpan.ParseExact(sqlReader.GetString(0), timeformats, CultureInfo.InvariantCulture);
                                seriesElement.data.Add(duration.TotalSeconds.ToString());
                                highChart.tooltip.valueSuffix = " total sec";
                            }
                            else
                            {
                                seriesElement.data.Add(sqlReader.GetString(0));
                            }
                        }
                        else
                        {
                            seriesElement.data.Add(string.Empty);
                        }

                        sqlReader.Close();
                        startTime = startTime.AddDays(1);
                    }

                    highChart.series.Add(seriesElement);
                }
            }
            else
            {
                highChart.chart.type = "column";

                for (int i = 0; i < perfParaTypes.Count; i++)
                {
                    highChart.xAxis.categories.Add(((PerformanceParameterType)perfParaTypes[i]).name);
                }

                for (int i = 0; i < playerAnalysis.players.Count; i++)
                {
                    seriesElement      = new SeriesElement();
                    seriesElement.name = playerAnalysis.players[i].firstName + " " + playerAnalysis.players[i].lastName;

                    seriesElement.data = new List <string>();

                    sqlStr = "select count(*) from player_eval where sport_id = @sportId and player_id = @playerId and name_id = @nameId and type_id = @typeId and eval_date >= @evalFromDate";
                    cmd    = new MySqlCommand(sqlStr, conn);
                    cmd.Parameters.AddWithValue("sportId", playerAnalysis.sport.id);
                    cmd.Parameters.AddWithValue("playerId", playerAnalysis.players[i].id);
                    cmd.Parameters.AddWithValue("nameId", playerAnalysis.perfPara.perfParaName.id);

                    MySqlParameter para = new MySqlParameter("evalFromDate", MySqlDbType.Date);
                    para.Value = playerAnalysis.fromTime;
                    cmd.Parameters.Add(para);

                    //para = new MySqlParameter("evalToDate", MySqlDbType.Date);
                    //para.Value = playerAnalysis.toTime;
                    //cmd.Parameters.Add(para);

                    for (int j = 0; j < perfParaTypes.Count; j++)
                    {
                        if (cmd.Parameters.Contains("typeId"))
                        {
                            cmd.Parameters.RemoveAt(4);
                        }

                        cmd.Parameters.AddWithValue("typeId", ((PerformanceParameterType)perfParaTypes[j]).id);

                        seriesElement.data.Add(cmd.ExecuteScalar().ToString());
                    }

                    highChart.series.Add(seriesElement);
                }
            }

            return(highChart);
        }
Beispiel #8
0
        public ArrayList GetPlayerEvaluations(long sportsId, long playerId)
        {
            String       sqlStr = "select pp.id, pp.sport_id, pp.name_id, ppn.name, pp.custom_name, pp.group_id from perf_para pp join perf_para_name ppn on pp.name_id = ppn.id where pp.sport_id = @sportId";
            MySqlCommand cmd    = new MySqlCommand(sqlStr, conn);

            cmd.Parameters.AddWithValue("sportId", sportsId);
            MySqlDataReader  sqlReader         = cmd.ExecuteReader();
            ArrayList        playerEvaluations = new ArrayList();
            PlayerEvaluation pp       = null;
            List <int>       groupIds = new List <int>();

            while (sqlReader.Read())
            {
                pp          = new PlayerEvaluation();
                pp.id       = sqlReader.GetInt32(0);
                pp.sportId  = sqlReader.GetInt32(1);
                pp.playerId = playerId;

                pp.perfParaName      = new PerformanceParameterName();
                pp.perfParaName.id   = sqlReader.GetInt32(2);
                pp.perfParaName.name = sqlReader.GetString(3);

                pp.customName = sqlReader.GetString(4);

                groupIds.Add(sqlReader.GetInt32(5));

                playerEvaluations.Add(pp);
            }

            sqlReader.Close();

            for (int groupIdIndex = 0; groupIdIndex < groupIds.Count; groupIdIndex++)
            {
                int groupId = groupIds[groupIdIndex];
                sqlStr = "select id, group_id, name from perf_para_type where group_id = @groupId";
                cmd    = new MySqlCommand(sqlStr, conn);
                cmd.Parameters.AddWithValue("groupId", groupId);
                MySqlDataReader perfParaTypeSqlReader = cmd.ExecuteReader();

                List <PerformanceParameterType> perfParaTypes = new List <PerformanceParameterType>();
                PerformanceParameterType        perfParaType  = null;

                while (perfParaTypeSqlReader.Read())
                {
                    perfParaType         = new PerformanceParameterType();
                    perfParaType.id      = perfParaTypeSqlReader.GetInt32(0);
                    perfParaType.groupId = perfParaTypeSqlReader.GetInt32(1);
                    perfParaType.name    = perfParaTypeSqlReader.GetString(2);

                    perfParaTypes.Add(perfParaType);
                }
                perfParaTypeSqlReader.Close();

                ((PlayerEvaluation)playerEvaluations[groupIdIndex]).perfParaTypes = perfParaTypes;

                foreach (PerformanceParameterType paraType in perfParaTypes)
                {
                    sqlStr = "select pe.type_id, ppt.group_id, ppt.name, pe.value from player_eval pe join perf_para_type ppt on pe.type_id = ppt.id where pe.sport_id = @sportId and pe.player_id = @playerId and pe.type_id = @typeId and pe.eval_date = current_date()";
                    cmd    = new MySqlCommand(sqlStr, conn);
                    cmd.Parameters.AddWithValue("sportId", sportsId);
                    cmd.Parameters.AddWithValue("playerId", playerId);
                    cmd.Parameters.AddWithValue("typeId", paraType.id);
                    cmd.Parameters.AddWithValue("currentDate", DateTime.Now);
                    MySqlDataReader playerEvalSqlReader = cmd.ExecuteReader();

                    if (playerEvalSqlReader.Read())
                    {
                        ((PlayerEvaluation)playerEvaluations[groupIdIndex]).selectedType         = new PerformanceParameterType();
                        ((PlayerEvaluation)playerEvaluations[groupIdIndex]).selectedType.id      = playerEvalSqlReader.GetInt32(0);
                        ((PlayerEvaluation)playerEvaluations[groupIdIndex]).selectedType.groupId = playerEvalSqlReader.GetInt32(1);
                        ((PlayerEvaluation)playerEvaluations[groupIdIndex]).selectedType.name    = playerEvalSqlReader.GetString(2);
                        ((PlayerEvaluation)playerEvaluations[groupIdIndex]).value = playerEvalSqlReader.IsDBNull(3) ? string.Empty : playerEvalSqlReader.GetString(3);

                        playerEvalSqlReader.Close();
                        break;
                    }

                    playerEvalSqlReader.Close();
                }
            }

            return(playerEvaluations);
        }