Example #1
0
        public void ExportRatingBeforeGamePlay(int preGameCount, GamePos pos, DateTime gameTime, string awayId, string homeId)
        {
            string[] strArray = new string[7]
            {
                "Team_Id",
                "ORtg",
                "DRtg",
                "Opp_ORtg",
                "Opp_DRtg",
                "Act_ORtg",
                "Home"
            };
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(string.Join(",", strArray));
            IEnumerable <NBAGameInfo> source = Enumerable.Where <NBAGameInfo>((IEnumerable <NBAGameInfo>) this.handler.GetGamesBySeason("214"), (Func <NBAGameInfo, bool>)(g => !string.IsNullOrWhiteSpace(g.FinalScore)));

            if (gameTime != DateTime.MinValue)
            {
                source = Enumerable.Where <NBAGameInfo>(source, (Func <NBAGameInfo, bool>)(g => g.GameTime < gameTime));
            }
            if (!string.IsNullOrEmpty(awayId) && !string.IsNullOrEmpty(homeId))
            {
                source = Enumerable.Where <NBAGameInfo>(source, (Func <NBAGameInfo, bool>)(g => g.AwayId == Convert.ToInt32(awayId) || g.HomeId == Convert.ToInt32(awayId) || (g.AwayId == Convert.ToInt32(homeId) || g.HomeId == Convert.ToInt32(homeId))));
            }
            Dictionary <int, Tuple <Decimal, Decimal> > eachGameRating = this.handler.GetEachGameRating("214");

            foreach (NBAGameInfo nbaGameInfo in (IEnumerable <NBAGameInfo>)Enumerable.OrderBy <NBAGameInfo, int>(source, (Func <NBAGameInfo, int>)(g => g.GameId)))
            {
                List <NBAGameStats> list = this.PrepareTeamsData(nbaGameInfo.AwayId.ToString(), nbaGameInfo.AwayEnName, nbaGameInfo.HomeId.ToString(), nbaGameInfo.HomeEnName, 2014, nbaGameInfo.GameTime, pos, preGameCount);
                if (list.Count != 0 && list.Count != 1)
                {
                    NBAGameStats nbaGameStats1 = Enumerable.FirstOrDefault <NBAGameStats>((IEnumerable <NBAGameStats>)list, (Func <NBAGameStats, bool>)(g => g.Home == 1));
                    NBAGameStats nbaGameStats2 = Enumerable.FirstOrDefault <NBAGameStats>((IEnumerable <NBAGameStats>)list, (Func <NBAGameStats, bool>)(g => g.Home == 0));
                    stringBuilder.AppendLine();
                    stringBuilder.AppendFormat("{0},{1},{2},{3},{4},{5},{6}", (object)nbaGameInfo.HomeAbbr, (object)nbaGameStats1.ORtg, (object)nbaGameStats1.DRtg, (object)nbaGameStats2.ORtg, (object)nbaGameStats2.DRtg, (object)eachGameRating[nbaGameInfo.GameId].Item1, (object)1);
                    stringBuilder.AppendLine();
                    stringBuilder.AppendFormat("{0},{1},{2},{3},{4},{5},{6}", (object)nbaGameInfo.AwayAbbr, (object)nbaGameStats2.ORtg, (object)nbaGameStats2.DRtg, (object)nbaGameStats1.ORtg, (object)nbaGameStats1.DRtg, (object)eachGameRating[nbaGameInfo.GameId].Item2, (object)0);
                }
            }
            if (pos == GamePos.None)
            {
                preGameCount = 5;
            }
            File.WriteAllText(string.Format("D:\\Derek\\NBA\\Ratings{0}.csv", (object)preGameCount), stringBuilder.ToString(), Encoding.GetEncoding("GB2312"));
        }
Example #2
0
        public void ExportPaceBeforeGamePlay(int preGameCount, GamePos pos, DateTime gameTime, string awayId, string homeId)
        {
            string[] strArray = new string[5]
            {
                "Team_Id",
                "Home",
                "Pace",
                "Opp_Pace",
                "Act_Pace"
            };
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(string.Join(",", strArray));
            IEnumerable <NBAGameInfo> source = Enumerable.Where <NBAGameInfo>((IEnumerable <NBAGameInfo>) this.handler.GetGamesBySeason("214"), (Func <NBAGameInfo, bool>)(g => !string.IsNullOrWhiteSpace(g.FinalScore)));

            if (gameTime != DateTime.MinValue)
            {
                source = Enumerable.Where <NBAGameInfo>(source, (Func <NBAGameInfo, bool>)(g => g.GameTime < gameTime));
            }
            if (!string.IsNullOrEmpty(awayId) && !string.IsNullOrEmpty(homeId))
            {
                source = Enumerable.Where <NBAGameInfo>(source, (Func <NBAGameInfo, bool>)(g => g.AwayId == Convert.ToInt32(awayId) || g.HomeId == Convert.ToInt32(awayId) || (g.AwayId == Convert.ToInt32(homeId) || g.HomeId == Convert.ToInt32(homeId))));
            }
            Dictionary <int, Decimal> eachGamePace = this.handler.GetEachGamePace("214");

            foreach (NBAGameInfo nbaGameInfo in (IEnumerable <NBAGameInfo>)Enumerable.OrderBy <NBAGameInfo, int>(source, (Func <NBAGameInfo, int>)(g => g.GameId)))
            {
                List <NBAGameStats> list = this.PrepareTeamsData(nbaGameInfo.AwayId.ToString(), nbaGameInfo.AwayEnName, nbaGameInfo.HomeId.ToString(), nbaGameInfo.HomeEnName, 2014, nbaGameInfo.GameTime, pos, preGameCount);
                if (list.Count != 0 && list.Count != 1)
                {
                    Decimal num1 = list[0].Home == 0 ? Convert.ToDecimal(list[0].Pace) : Convert.ToDecimal(list[1].Pace);
                    Decimal num2 = list[0].Home == 0 ? Convert.ToDecimal(list[1].Pace) : Convert.ToDecimal(list[0].Pace);
                    stringBuilder.AppendLine();
                    stringBuilder.AppendFormat("{0},{1},{2},{3},{4}", (object)nbaGameInfo.HomeAbbr, (object)1, (object)num2, (object)num1, (object)eachGamePace[nbaGameInfo.GameId]);
                    stringBuilder.AppendLine();
                    stringBuilder.AppendFormat("{0},{1},{2},{3},{4}", (object)nbaGameInfo.AwayAbbr, (object)0, (object)num1, (object)num2, (object)eachGamePace[nbaGameInfo.GameId]);
                }
            }
            if (pos == GamePos.None)
            {
                preGameCount = 5;
            }
            File.WriteAllText(string.Format("D:\\Derek\\NBA\\Paces{0}.csv", (object)preGameCount), stringBuilder.ToString(), Encoding.GetEncoding("GB2312"));
        }
Example #3
0
        private NBAGameStats RetrieveGameStats(string teamId, int year, DateTime gameTime, GamePos pos, int gameCount)
        {
            List <int>   list = this.handler.GetPreviousGames(teamId, year, gameTime, pos);
            NBAGameStats team = (NBAGameStats)null;

            if (list.Count > 0)
            {
                if (gameCount > 0)
                {
                    list = Enumerable.ToList <int>(Enumerable.Take <int>((IEnumerable <int>)list, gameCount));
                }
                team        = this.RetrieveStatsFromTable(this.handler.GetSumStatistics(teamId, (IEnumerable <int>)list));
                team.TeamId = Convert.ToInt32(teamId);
                team.Home   = 1;
                NBAGameStats opponent = this.RetrieveStatsFromTable(this.handler.GetOppoSumStatistics(teamId, (IEnumerable <int>)list));
                opponent.Home = 0;
                this.CaclulateFourFactors(team, opponent);
            }
            return(team);
        }
Example #4
0
 private NBAGameStats RetrieveGameStats(string teamId, int year, DateTime gameTime, GamePos pos)
 {
     return(this.RetrieveGameStats(teamId, year, gameTime, pos, 0));
 }
Example #5
0
        private List <NBAGameStats> PrepareTeamsData(string awayId, string awayName, string homeId, string homeName, int year, DateTime gameTime, GamePos pos, int gameCount)
        {
            List <NBAGameStats> gameStats     = new List <NBAGameStats>();
            NBAGameStats        nbaGameStats1 = this.RetrieveGameStats(awayId, year, gameTime, pos == GamePos.None ? GamePos.Away : pos, gameCount);

            if (nbaGameStats1 != null)
            {
                nbaGameStats1.Home     = 0;
                nbaGameStats1.TeamName = awayName;
                gameStats.Add(nbaGameStats1);
            }
            NBAGameStats nbaGameStats2 = this.RetrieveGameStats(homeId, year, gameTime, pos == GamePos.None ? GamePos.Home : pos, gameCount);

            if (nbaGameStats2 != null)
            {
                nbaGameStats2.Home     = 1;
                nbaGameStats2.TeamName = homeName;
                gameStats.Add(nbaGameStats2);
            }
            if (gameStats.Count > 0)
            {
                this.CaclulateMixPace(gameStats);
            }
            return(gameStats);
        }
Example #6
0
    // Handler for the SurfaceMeshesToPlanes MakePlanesComplete event.
    private void SurfaceMeshesToPlanes_MakePlanesComplete(object source, System.EventArgs args)
    {
        Debug.Log("plane complete");
        SurfacePlane floorSurface = null, ceilSurface = null;

        Bounds floorbd = new Bounds();
        Bounds ceilbd  = new Bounds();

        //walls = meshToPlanes.GetActivePlanes(PlaneTypes.Wall);

        foreach (GameObject plane in meshToPlanes.ActivePlanes)
        {
            SurfacePlane surfacePlane = plane.GetComponent <SurfacePlane>();
            if (surfacePlane != null)
            {
                if ((surfacePlane.PlaneType & PlaneTypes.Floor) == surfacePlane.PlaneType)
                {
                    //OrientedBoundingBox flr = surfacePlane.Plane.Bounds;
                    //Debug.Log(flr);

                    /*
                     * GameObject obj = Instantiate(resourcePlane);
                     * obj.transform.localPosition = surfacePlane.transform.localPosition;
                     * obj.transform.localRotation = surfacePlane.transform.localRotation;
                     * obj.transform.localScale = surfacePlane.transform.localScale;
                     */
                    Bounds bd = surfacePlane.GetComponent <Renderer>().bounds;
                    if (floorSurface == null || bd.extents.x * bd.extents.z > floorbd.extents.x * floorbd.extents.z)
                    {
                        floorSurface = surfacePlane;
                        floorbd      = floorSurface.GetComponent <Renderer>().bounds;
                    }
                }
                else
                {
                    //surfacePlane.IsVisible = false;
                    if ((surfacePlane.PlaneType & PlaneTypes.Ceiling) == surfacePlane.PlaneType)
                    {
                        Bounds bd = surfacePlane.GetComponent <Renderer>().bounds;
                        if (ceilSurface == null || bd.extents.x * bd.extents.z > ceilbd.extents.x * ceilbd.extents.z)
                        {
                            ceilSurface = surfacePlane;
                            ceilbd      = ceilSurface.GetComponent <Renderer>().bounds;
                        }
                    }
                }
                surfacePlane.IsVisible = false;
            }
        }

        if (floorSurface == null)
        {
            Debug.LogError("floor not found");
            return;
        }

        trancord = new transform_coord();
        GamePos nm = trancord.tranformxyz(4, new Point3D[4] {
            new Point3D(floorbd.center.x - floorbd.extents.x / 2, floorbd.center.y, floorbd.center.z - floorbd.extents.z / 2),
            new Point3D(floorbd.center.x + floorbd.extents.x / 2, floorbd.center.y, floorbd.center.z - floorbd.extents.z / 2),
            new Point3D(floorbd.center.x + floorbd.extents.x / 2, floorbd.center.y, floorbd.center.z + floorbd.extents.z / 2),
            new Point3D(floorbd.center.x - floorbd.extents.x / 2, floorbd.center.y, floorbd.center.z + floorbd.extents.z / 2)
        });

        gameMap = new SuccesiveGameMap(nm.x + 1, nm.y + 1);
        gameMap.setPlayer(new Point3D(mixedRealityCamera.transform.localPosition));

        /*List<Mesh> meshes = SpatialMappingManager.Instance.GetMeshes();
         * Point3D pmnx, pmnz, pmxx, pmxz;
         * pmnx = new Point3D(FloatCmp.INF, 0, 0);
         * pmnz = new Point3D(0, 0, FloatCmp.INF);
         * pmxx = new Point3D(-FloatCmp.INF, 0, 0);
         * pmxz = new Point3D(0, 0, -FloatCmp.INF);
         * float mny = FloatCmp.INF, mxy = -FloatCmp.INF;
         *
         * for (int i = 0; i < meshes.Count; i++)
         * {
         *  Vector3[] vertices = meshes[i].vertices;
         *  int[] tris = meshes[i].triangles;
         *  for (int j = 0; j < tris.Length; j += 3)
         *  {
         *      Vector3 p1 = vertices[tris[j]];
         *      Vector3 p2 = vertices[tris[j + 1]];
         *      Vector3 p3 = vertices[tris[j + 2]];
         *      Vector3 center = (p1 + p2 + p3) / 3;
         *      if (floorbd.center.x - floorbd.extents.x / 2 <= center.x && center.x <= floorbd.center.x + floorbd.extents.x / 2
         *          && floorbd.center.z - floorbd.extents.z / 2 <= center.z && center.z <= floorbd.center.z + floorbd.extents.z / 2
         *          )//&& System.Math.Abs(floorbd.center.y - center.y) < 0.01)
         *      {
         *          if (center.x < pmnx.x)
         *              pmnx = new Point3D(center);
         *          if (center.x > pmxx.x)
         *              pmxx = new Point3D(center);
         *          if (center.z < pmnz.z)
         *              pmnz = new Point3D(center);
         *          if (center.z > pmxz.z)
         *              pmxz = new Point3D(center);
         *      }
         *      mny = System.Math.Min(mny, center.y);
         *      mxy = System.Math.Max(mxy, center.y);
         *  }
         * }
         * pmnx = trancord.WorldToGame(pmnx);
         * pmxx = trancord.WorldToGame(pmxx);
         * pmnz = trancord.WorldToGame(pmnz);
         * pmxz = trancord.WorldToGame(pmxz);*/
        /*gameMap.addBorder(new Line[4] {
         *      new Line(pmnx, pmnz),
         *      new Line(pmxx, pmnz),
         *      new Line(pmnx, pmxz),
         *      new Line(pmxx, pmxz)
         *  });*/
        gameMap.addBorder(new Line[4] {
            new Line(new Point3D(0, 0), new Point3D(nm.x, 0)),
            new Line(new Point3D(nm.x, 0), new Point3D(nm.x, nm.y)),
            new Line(new Point3D(nm.x, nm.y), new Point3D(0, nm.y)),
            new Line(new Point3D(0, nm.y), new Point3D(0, 0))
        });

        /*for (int i = 0; i < meshes.Count; i++)
         * {
         *  Vector3[] vertices = meshes[i].vertices;
         *  int[] tris = meshes[i].triangles;
         *  for (int j = 0; j < tris.Length; j += 3)
         *  {
         *      Vector3 p1 = vertices[tris[j]];
         *      Vector3 p2 = vertices[tris[j+1]];
         *      Vector3 p3 = vertices[tris[j+2]];
         *      Vector3 center = (p1 + p2 + p3) / 3;
         *      if (floorbd.center.x - floorbd.extents.x / 2 <= center.x && center.x <= floorbd.center.x + floorbd.extents.x / 2
         *          && floorbd.center.z - floorbd.extents.z / 2 <= center.z && center.z <= floorbd.center.z + floorbd.extents.z / 2
         *          )//&& FloatCmp.cmp(floorbd.center.y, center.y) == 0)
         *          continue;
         *      if (ceilSurface != null && ceilbd.center.x - ceilbd.extents.x / 2 <= center.x && center.x <= ceilbd.center.x + ceilbd.extents.x / 2
         *          && ceilbd.center.z - ceilbd.extents.z / 2 <= center.z && center.z <= ceilbd.center.z + ceilbd.extents.z / 2
         *          )//&& FloatCmp.cmp(ceilbd.center.y, center.y) == 0)
         *          continue;
         *      gameMap.addTriangle(new Triangle(trancord.WorldToGame(new Point3D(p1)), trancord.WorldToGame(new Point3D(p2)), trancord.WorldToGame(new Point3D(p3))));
         *  }
         * }*/

        gameMap.generateMap();
        gameMapFinish = true;

        Debug.Log("Finish Generating Map");
    }
Example #7
0
        public List <int> GetPreviousGames(string teamId, int year, DateTime gameTime, GamePos pos)
        {
            string str = string.Format("select [id] from GameInfo\r\nwhere [time] > '{0}-10-1' \r\nand [time] < '{1}'\r\nand [type] = 2", (object)year, (object)gameTime);

            using (IDataReader dataReader = (IDataReader)this._helper.ExecuteReader(CommandType.Text, pos != GamePos.Home ? (pos != GamePos.Away ? str + string.Format("and (away={0} or home={0}) order by [id] desc", (object)teamId) : str + string.Format("and away={0} order by [id] desc", (object)teamId)) : str + string.Format("and home={0} order by [id] desc", (object)teamId), new SqlParameter[0]))
            {
                List <int> list = new List <int>();
                while (dataReader.Read())
                {
                    list.Add(dataReader.GetInt32(0));
                }
                return(list);
            }
        }