コード例 #1
0
        private void PrepareWorkingSet()
        {
            Wst = new WorkingSet
            {
                Folder = this.RespoPath
            };
            FileInfo f     = new FileInfo(this.ImagesFile);
            string   drive = Path.GetPathRoot(f.FullName);

            Wst.part       = new DriveInfo(drive);
            Wst.ImagesSize = Partion.FB(new FileInfo(this.ImagesFile).Length);
            Wst.VideosSize = Partion.FB(Partion.DirSize(new DirectoryInfo(this.VideoFolder)) + new FileInfo(this.VideosTumb).Length);
            Wst.AllSize    = Partion.FB(Partion.DirSize(new DirectoryInfo(this.respo)));

            Wst.iMGsCount   = this.Photos.Items.Count.ToString();
            Wst.VidsCount   = this.Videos.Items.Count.ToString();
            Wst.OthersCount = "0";


            string tot;

            tot =
                (Partion.FB(Wst.part.TotalSize));

            _ =
                (Partion.FB(Wst.part.AvailableFreeSpace));



            Wst.dirSizeString = Partion.FB(Wst.part.TotalSize - Wst.part.AvailableFreeSpace) + " - " + tot;
        }
コード例 #2
0
ファイル: Clustering_Users_DAO.cs プロジェクト: vutiendung/RS
        public void addPARTION_TBL(Partion item)
        {
            string strSelect = "INSERT INTO [RS].[PARTION_TBL] ([ClusterID] ,[UserID]) VALUES (@ClusterID ,@UserID) ";
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@ClusterID", item.ClusterID);
            parameters.Add("@UserID", item.UserID);
            executeNonQuery(strSelect, parameters);
        }
コード例 #3
0
    /// <summary>
    /// Places sign at gridpos pos of type cellType
    /// </summary>
    /// <param name="gridPos">Grid pos of click</param>
    /// <param name="cellType"></param>
    /// <returns> whether the sign could be placed or not></returns>
    public virtual bool PlaceSign(int[] gridPos, Cell.CellOcc cellType, bool disabled = false)
    {
        // The partion's pos
        int[] partionPos = Partion.GetPartionPosOfCell(gridPos);

        // The cell's partion
        Partion currP;

        // We don't have a partion yet for this pos
        if (!partions.ContainsKey(partionPos))
        {
            currP = new Partion(partionPos);

            partions.Add(partionPos, currP);
        }
        else     // we already store the partion in the dictionary
        {
            partions.TryGetValue(partionPos, out currP);
        }

        // At this point we should surely have the partion in p

        // We need to convert the click's world pos to partion local pos
        int[] localPos = Partion.GetLocalPosOfCell(gridPos);

        // We need to place the sign in the partion
        bool couldBePlaced = currP.PlaceSign(localPos, cellType, disabled);

        if (couldBePlaced && !disabled)   // If we could place the sign store it's gridPos
        {
            if (previousGridPos != null)
            {
                secondToPreviousGridPos = new int[] { previousGridPos[0], previousGridPos[1] }
            }
            ;
            previousGridPos = new int[] { gridPos[0], gridPos[1] };

            // Increase amount of cells in game
            numberOfSignsInGame++;
            removeCount = 0; // Reset removecount to be able to remove sign again

            // move marker
            if (lastPlacedMarker != null)
            {
                lastPlacedMarker.MoveMarkerTo(new Vector2(gridPos[0], gridPos[1]), SignResourceStorage.Instance.GetColorRelatedTo(gameLogic.WhoseTurn == Cell.CellOcc.X ? Cell.CellOcc.O : Cell.CellOcc.X));
            }

            if (SignWasPlacedEvent != null)
            {
                SignWasPlacedEvent(gridPos, cellType);
            }
        }
        return(couldBePlaced);
    }
コード例 #4
0
    /// <summary>
    /// Calculates which partions should not be shown
    /// Updates quite frequently
    /// </summary>
    void ShowOnlyVisiblePartions()
    {
        if (!HasCameraMovedSince(partionLastExamineCamPos))
        {
            return;
        }

        partionLastExamineCamPos[0] = cameraCurrPosLB[0];
        partionLastExamineCamPos[1] = cameraCurrPosLB[1];

        int[] leftBottomPart = Partion.GetPartionPosOfCell(cameraCurrPosLB);
        int[] topRightPart   = Partion.GetPartionPosOfCell(cameraCurrPosTR);

        // Hide partions we can't see anymore
        for (int i = shownPartions.Count - 1; i >= 0; i--)
        {
            int[] at = shownPartions[i];

            // Out of visibility range
            if ((at[0] < leftBottomPart[0] || at[0] > topRightPart[0]) ||
                (at[1] < leftBottomPart[1] || at[1] > topRightPart[1]))
            {
                Partion p;
                partions.TryGetValue(at, out p);

                if (p != null)
                {
                    p.HidePartion();
                    shownPartions.RemoveAt(i);
                }
            }
        }

        // Show partions which are visible
        for (int i = leftBottomPart[0]; i <= topRightPart[0]; i++)
        {
            for (int k = leftBottomPart[1]; k <= topRightPart[1]; k++)
            {
                int[] temp = new int[] { i, k };

                Partion p;
                partions.TryGetValue(temp, out p);

                if (p != null && !p.IsShown)
                {
                    p.ShowPartion();
                    shownPartions.Add(temp);
                }
            }
        }
    }
コード例 #5
0
    /// <summary>
    /// Return cellHolder at gridPos
    /// </summary>
    /// <param name="gridPos">Position of cell in grid</param>
    /// <returns>May return null</returns>
    public CellHolder GetCellHolderAtGridPos(int[] gridPos)
    {
        int[] partionPos      = Partion.GetPartionPosOfCell(gridPos);
        int[] partionLocalPos = Partion.GetLocalPosOfCell(gridPos);

        Partion p;

        partions.TryGetValue(partionPos, out p);
        if (p != null)
        {
            return(p.GetCellHolderAt(partionLocalPos));
        }

        return(null);
    }
コード例 #6
0
ファイル: Clustering_Users_DAO.cs プロジェクト: vutiendung/RS
        public List <Partion> getPartion_ByU_CategoryID_ForMergeGreoup(string U_Category)
        {
            string strSelect = "SELECT [ClusterID] ,[UserID] FROM [RS].[PARTION_TBL] WHERE [ClusterID] LIKE @U_Category";
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@U_Category", U_Category + "%");
            SqlDataReader dr = executeReader(strSelect, parameters);

            List <Partion> list = new List <Partion>();

            while (dr.Read())
            {
                Partion obj = new Partion();
                obj.ClusterID = dr.GetString(dr.GetOrdinal("ClusterID"));
                obj.UserID    = dr.GetString(dr.GetOrdinal("UserID"));
                list.Add(obj);
            }
            dr.Close();
            return(list);
        }
コード例 #7
0
ファイル: Clustering_Users_DAO.cs プロジェクト: vutiendung/RS
        public List <Partion> getPartion_ByU_SubCategoryID(string U_SubCategoryID)
        {
            string strSelect = "SELECT [RS].[PARTION_TBL].[ClusterID] ,[UserID] FROM [RS].[PARTION_TBL],[RS].[USER_CLUSTER_TBL] WHERE [RS].[PARTION_TBL].[ClusterID] = [RS].[USER_CLUSTER_TBL].[ClusterID] and [RS].[USER_CLUSTER_TBL].[U_SubCategoryID] = @U_SubCategoryID ";
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@U_SubCategoryID", U_SubCategoryID);
            SqlDataReader dr = executeReader(strSelect, parameters);

            List <Partion> list = new List <Partion>();

            while (dr.Read())
            {
                Partion obj = new Partion();
                obj.ClusterID = dr.GetString(dr.GetOrdinal("ClusterID"));
                obj.UserID    = dr.GetString(dr.GetOrdinal("UserID"));
                list.Add(obj);
            }
            dr.Close();
            return(list);
        }
コード例 #8
0
    /// <summary>
    /// Gets the cellholder of the cell relative to gridpos with the eltolas of x and y on those axis
    /// Currently only using it for right, left, up and down
    /// In other cases may crash so be aware
    /// </summary>
    /// <param name="gridPos">Grid pos of cell</param>
    /// <param name="x">X axis relative</param>
    /// <param name="y">Y axis relative</param>
    /// <returns>Returns null if can't find cellholder</returns>
    public CellHolder GetCellHolderRelativeTo(int[] gridPos, int x, int y)
    {
        int[] relativePos = new int[] {
            gridPos[0] + x,
            gridPos[1] + y
        };

        // gets partion and local pos of relative cell
        int[] partionPos      = Partion.GetPartionPosOfCell(relativePos);
        int[] partionLocalPos = Partion.GetLocalPosOfCell(relativePos);

        Partion p;

        partions.TryGetValue(partionPos, out p);
        // There is no partion at this coord yet
        if (p == null)
        {
            return(null);
        }

        return(p.GetCellHolderAt(partionLocalPos));
    }
コード例 #9
0
    /// <summary>
    /// It disables all of the sign which belong to this game
    /// </summary>
    /// <param name="wonData">More data like cellgrid of current game pass in a wonData</param>
    public TTTGameLogic.GameWonData StopCurrentGame(TTTGameLogic.GameWonData wonData)
    {
        // We need to start a bejaras from the last placed sign's pos, which we happen to store in previousGridPos
        // Then set all of the found sign's cellholder to disabled

        // Disable marker
        if (lastPlacedMarker != null)
        {
            lastPlacedMarker.Disable();
        }

        // Ended game so reset the amount of cells in game
        numberOfSignsInGame = 0;

        // Store all of the cellholders which have signs in game

        List <CellHolder> listOfCells = new List <CellHolder>();

        listOfCells.Add(GetCellHolderAtGridPos(previousGridPos));

        Queue <CellHolder> queue = new Queue <CellHolder>();

        queue.Enqueue(listOfCells[0]);

        // Stores the min and max values of x and y (essentially bottomleft and topright corner points)
        int[] min = new int[] { int.MaxValue, int.MaxValue };
        int[] max = new int[] { int.MinValue, int.MinValue };

        // Go through cells in this game
        while (queue.Count > 0)
        {
            CellHolder currCH = queue.Dequeue();
            if (currCH.IsDisabled)
            {
                break;
            }

            // Store the min and max of x and y we examine
            if (currCH.WorldPos[0] < min[0])
            {
                min[0] = currCH.WorldPos[0];
            }
            if (currCH.WorldPos[0] > max[0])
            {
                max[0] = currCH.WorldPos[0];
            }
            if (currCH.WorldPos[1] < min[1])
            {
                min[1] = currCH.WorldPos[1];
            }
            if (currCH.WorldPos[1] > max[1])
            {
                max[1] = currCH.WorldPos[1];
            }

            // Disable cell
            currCH.Disable();

            // Get all af nthe neighbours af current cell
            CellHolder[] neighbours = GetAllNeighbourCellHolders(currCH.WorldPos);

            foreach (CellHolder ch in neighbours)
            {
                if (ch != null && !ch.IsDisabled && ch.IsFull())   // Found a cell which belongs to this game
                {
                    if (!queue.Contains(ch) && !listOfCells.Contains(ch))
                    {
                        queue.Enqueue(ch);
                        listOfCells.Add(ch);
                    }
                }
            }
        }

        wonData.table = new bool[Mathf.Abs(max[0] - min[0] + 1), Mathf.Abs(max[1] - min[1] + 1)];

        // Fill the thingy with true where there is a cell. Thingy defined in WonData class
        foreach (CellHolder ch in listOfCells)
        {
            wonData.table[ch.WorldPos[0] - min[0], ch.WorldPos[1] - min[1]] = true;
        }
        wonData.startPos = min;

        // Now we can fill the holes
        List <int[]> holes = wonData.GetFillableHoles();

        foreach (int[] pos in holes)
        {
            // Get the partion the cell is in (we surely have this one, because holes are between signs
            int[]   partionPos = Partion.GetPartionPosOfCell(pos);
            Partion p;

            // We don't have a partion yet for this pos
            if (!partions.ContainsKey(partionPos))
            {
                p = new Partion(partionPos);

                partions.Add(partionPos, p);
            }
            else     // we already store the partion in the dictionary
            {
                partions.TryGetValue(partionPos, out p);
            }

            // Place new BLOCKED cell in partion at pos
            p.PlaceSign(Partion.GetLocalPosOfCell(pos), Cell.CellOcc.BLOCKED, true);
        }

        return(wonData);
    }
コード例 #10
0
ファイル: ClusterUsers.cs プロジェクト: vutiendung/RS
        private void LoadCluster(Clustering_Users_DAO dao,
                                 Settings st,
                                 ref bool existTransac,
                                 string U_SubCategoryID,
                                 string categoryName,
                                 Dictionary <string, int> dic_users,
                                 Dictionary <string, int> dic_items,
                                 double[][] x)
        {
            if (x.Length > 0)
            {
                existTransac = true;

                // Clustering Data
                Cluster cluster = new Cluster();
                Dictionary <int, int> clustered_Data = new Dictionary <int, int>();

                cluster.addSetting(st.k, st.maxLoop, x, st.epsilon, st.Alpha, st.T, st.U_M);
                clustered_Data = cluster.Clustering(st.cluster_type);

                //if (clustered_Data.Count > 0)
                //{
                // Mapping UserID to clustered Data
                Dictionary <string, int> mapped_Data = map_ID_to_Index(dic_users, clustered_Data);

                // Get Destination V
                double[][] v = cluster.getV();

                // Add new data

                #region C1 - Ratting Matrix

                // Add Ratting Matrix
                for (int i = 0; i < x.Length; i++)
                {
                    for (int j = 0; j < x[0].Length; j++)
                    {
                        if (x[i][j] > 0)
                        {
                            try
                            {
                                MatrixItem matrixItem = new MatrixItem();
                                matrixItem.ClusterID = categoryName + (mapped_Data[Util.FindKeyByValue(dic_users, i)] + 1);
                                matrixItem.Row       = Util.FindKeyByValue(dic_users, i);
                                matrixItem.Column    = Util.FindKeyByValue(dic_items, j);
                                matrixItem.Cell      = x[i][j];
                                dao.setRattingMatrix(matrixItem);
                            }
                            catch (Exception) { }
                        }
                    }
                }

                #endregion

                // Add to USER_CLUSTER_TBL
                for (int i = 0; i < v.Length; i++)
                {
                    dao.addCluster(categoryName + (i + 1), U_SubCategoryID);
                }

                // Add to PARTION_TBL
                foreach (var map in mapped_Data)
                {
                    Partion detail = new Partion();
                    detail.UserID    = map.Key;
                    detail.ClusterID = categoryName + (map.Value + 1);
                    dao.addPARTION_TBL(detail);
                }

                // Add to USER_CENTROID_TBL
                for (int i = 0; i < v.Length; i++)
                {
                    for (int j = 0; j < v[0].Length; j++)
                    {
                        if (!Double.NaN.Equals(v[i][j]))
                        {
                            try
                            {
                                User_Centroid centroid = new User_Centroid();
                                centroid.Value      = v[i][j];
                                centroid.ClusterID  = categoryName + (i + 1);
                                centroid.MetaItemID = Util.FindKeyByValue(dic_items, j);
                                dao.add_User_Centroid(centroid);
                            }
                            catch (Exception) { }
                        }
                    }
                }
            }
            //}
        }
コード例 #11
0
ファイル: ClusterUsers.cs プロジェクト: vutiendung/RS
        private void LoadUpdateCluster(Clustering_Users_DAO dao,
                                       Settings st,
                                       ref bool existTransac,
                                       List <Partion> listPartion,
                                       string U_SubCategoryID,
                                       string categoryName,
                                       Dictionary <string, int> dic_users,
                                       Dictionary <string, int> dic_items,
                                       double[][] x)
        {
            if (x.Length > 0)
            {
                existTransac = true;
                List <string> listClusterID = getListClusterID(listPartion);

                // Get existed V
                double[][] v  = new double[listClusterID.Count][];
                Cluster    cl = new Cluster();
                cl.addSetting(v.Length, st.maxLoop, x, 0.0001, st.Alpha, st.T, st.U_M);
                Dictionary <int, int> clustered_Data;

                if (listPartion.Count > 0)
                {
                    v = get_V_ByNewItems_ReComputeAll(x, dic_items, dic_users, listPartion, listClusterID);
                    clustered_Data = cl.Clustering_Merge(st.cluster_type, v);
                }
                else
                {
                    clustered_Data = cl.Clustering_Merge(st.cluster_type);
                }

                v = cl.getV();

                // Mapping UserID to clustered Data
                Dictionary <string, int> mapped_Data = map_ID_to_Index(dic_users, clustered_Data);

                #region C1 - Ratting Matrix

                // Add Ratting Matrix
                for (int i = 0; i < x.Length; i++)
                {
                    for (int j = 0; j < x[0].Length; j++)
                    {
                        if (x[i][j] > 0)
                        {
                            try
                            {
                                MatrixItem matrixItem = new MatrixItem();
                                matrixItem.ClusterID = categoryName + (mapped_Data[Util.FindKeyByValue(dic_users, i)] + 1);
                                matrixItem.Row       = Util.FindKeyByValue(dic_users, i);
                                matrixItem.Column    = Util.FindKeyByValue(dic_items, j);
                                matrixItem.Cell      = x[i][j];
                                dao.setRattingMatrix(matrixItem);
                            }
                            catch (Exception) { }
                        }
                    }
                }

                #endregion

                // Remove old USER_CLUSTER_TBL
                dao.delete_USER_CLUSTER_TBL(categoryName);
                // Add to USER_CLUSTER_TBL
                for (int i = 0; i < v.Length; i++)
                {
                    dao.addCluster(categoryName + (i + 1), U_SubCategoryID);
                }

                // Remove old PARTION_TBL
                dao.delete_PARTION_TBL(categoryName);
                // Add to PARTION_TBL
                foreach (var map in mapped_Data)
                {
                    Partion detail = new Partion();
                    detail.UserID    = map.Key;
                    detail.ClusterID = categoryName + (map.Value + 1);
                    dao.addPARTION_TBL(detail);
                }

                // Remove old USER_CENTROID_TBL
                dao.delete_USER_CENTROID_TBL(categoryName);
                // Add to USER_CENTROID_TBL
                for (int i = 0; i < v.Length; i++)
                {
                    for (int j = 0; j < v[0].Length; j++)
                    {
                        if (!Double.NaN.Equals(v[i][j]))
                        {
                            try
                            {
                                User_Centroid centroid = new User_Centroid();
                                centroid.Value      = v[i][j];
                                centroid.ClusterID  = categoryName + (i + 1);
                                centroid.MetaItemID = Util.FindKeyByValue(dic_items, j);
                                dao.add_User_Centroid(centroid);
                            }
                            catch (Exception) { }
                        }
                    }
                }
            }
        }