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);
 }
Exemplo n.º 2
0
        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) { }
                        }

            }
        }
Exemplo n.º 3
0
        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);

                //cuong add if
                //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) { }
                            }
                }
            //}//cuong add
        }
        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;
        }
        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;
        }