Ejemplo n.º 1
0
 public static void updateTransac_CheckPoint()
 {
     Clustering_Users_DAO dao = null;
     System_Setting transac_check_point = getTransac_CheckPoint();
     try
     {
         dao = new Clustering_Users_DAO();
         dao.beginTransaction();
         if (ConstantValues.SST_TRANSAC_CP.Equals(transac_check_point.Key))
         {
             if (transac_check_point.Values.Count > 0)
             {
                 dao.updateTransac_CheckPoint(ConstantValues.SST_TRANSAC_CP);
             }
             else
             {
                 dao.addTransac_CheckPoint(ConstantValues.SST_TRANSAC_CP);
             }
         }
         dao.commitTransaction();
     }
     catch (Exception ex)
     {
         dao.rollbackTransaction();
         throw ex;
     }
 }
Ejemplo n.º 2
0
        public static System_Setting getTransac_CheckPoint()
        {
            Clustering_Users_DAO dao = null;
            System_Setting transac_check_point = new System_Setting();
            try
            {
                dao = new Clustering_Users_DAO();
                dao.beginTransaction();
                List<System_Setting> listSystemSetting = dao.getListSystemSetting();
                foreach (var item in listSystemSetting)
                {
                    if (item.Key.Equals(ConstantValues.SST_TRANSAC_CP))
                    {
                        item.Values = dao.getListSystemSettingValue(ConstantValues.SST_TRANSAC_CP);
                        return item;
                    }
                }

                dao.commitTransaction();
            }
            catch (Exception ex)
            {
                dao.rollbackTransaction();
                throw ex;
            }
            return transac_check_point;
        }
Ejemplo n.º 3
0
 public bool checkClusterTableIsInProcess()
 {
     bool result = true;
     Clustering_Users_DAO dao = null;
     try
     {
         dao = new Clustering_Users_DAO();
         dao.beginTransaction();
         result = dao.checkLockedTable("USER_CLUSTER_TBL");
         dao.commitTransaction();
     }
     catch (Exception)
     {
         dao.rollbackTransaction();
         result = true;
     }
     return result;
 }
Ejemplo n.º 4
0
        public static void addNewTransacCheckpointKey()
        {
            Clustering_Users_DAO dao = null;
            try
            {
                dao = new Clustering_Users_DAO();
                dao.beginTransaction();
                // Add Key ConstantVariables.SST_TRANSAC_CHECK_POINT
                System_Setting transac_checkpoint = new System_Setting();
                transac_checkpoint.Key = ConstantValues.SST_TRANSAC_CP;
                transac_checkpoint.DataType = ConstantValues.SST_TRANSAC_CP_TYPE;
                transac_checkpoint.Description = ConstantValues.SST_TRANSAC_CP_DES;
                dao.addSystemSetting(transac_checkpoint);

                dao.commitTransaction();
            }
            catch (Exception ex)
            {
                dao.rollbackTransaction();
                throw ex;
            }
        }
Ejemplo n.º 5
0
        public int clusteringAllTransac(string LoginID)
        {
            Clustering_Users_DAO dao = null;
            ClusterSchedule clusterSchedule = new ClusterSchedule();
            clusterSchedule.ClusterType = ConstantValues.SCHE_CLUSTER_USER;
            clusterSchedule.Log = String.Empty;
            clusterSchedule.LoginID = LoginID;

            int processType = checkProcess();
            if (processType == 0)
            {
                Settings st = getSettings();
                try
                {
                    dao = new Clustering_Users_DAO();
                    dao.beginTransaction();

                    // Add to Schedule
                    clusterSchedule.Algorithm = st.cluster_type;
                    string log = "Clustering Client\n";
                    clusterSchedule.Log = log;
                    dao.addNewClusterSchedule(clusterSchedule);

                    // Clean data
                    dao.CLEAN_USER_CENTROID_TBL();
                    dao.CLEAN_PARTION_TBL();
                    dao.CLEAN_USER_CLUSTER_TBL();
                    dao.CLEAN_RATTING_MATRIX();

                    List<User_SubCategories> list_User_SubCategories = dao.getAllSubCategories();
                    bool existTransac = false;

                    List<string> list_User_Categories = get_User_Categories(list_User_SubCategories);
                    List<List<User_SubCategories>> list_SMALL_User_SubCategories = new List<List<User_SubCategories>>();
                    foreach (var item in list_User_Categories)
                        list_SMALL_User_SubCategories.Add(new List<User_SubCategories>());

                    #region Cluster For LargeGroup

                    int numUser = 0;
                    Dictionary<string, int> allItem = new Dictionary<string, int>();
                    foreach (User_SubCategories item in list_User_SubCategories)
                    {
                        string categoryName = item.U_SubCategoryID + "_";

                        // Convert Data to matrix
                        Dictionary<string, int> dic_users = new Dictionary<string, int>();
                        Dictionary<string, int> dic_items = new Dictionary<string, int>();

                        // Compute ratting matrix
                        List<MatrixItem> lstRMI = dao.computeRattingMatrixItem(item.U_SubCategoryID, st.Alpha);
                        double[][] x = Util.toMatrix_MatrixItem(lstRMI, out dic_users, out dic_items);

                        if (dic_users.Count > st.U_M/2)
                        {

                                numUser += dic_users.Count;
                                foreach (var it in dic_items)
                                    if (!allItem.ContainsKey(it.Key))
                                        allItem.Add(it.Key, it.Value);

                                LoadCluster(dao, st, ref existTransac, item.U_SubCategoryID, categoryName, dic_users, dic_items, x);

                        }
                        else
                            add_SMALL_User_SubCategories(list_User_Categories, ref list_SMALL_User_SubCategories, item);
                    }

                    #endregion

                    #region Cluster For SmallGroup

                    dao.delete_USER_CLUSTER_TBL_2("_MERGE_");
                    dao.delete_PARTION_TBL_2("_MERGE_");
                    dao.delete_USER_CENTROID_TBL_2("_MERGE_");

                    for (int i = 0; i < list_User_Categories.Count; i++)
                    {
                        string categoryName = list_User_Categories[i] + "_MERGE_";

                        // Convert Data to matrix
                        Dictionary<string, int> dic_users = new Dictionary<string, int>();
                        Dictionary<string, int> dic_items = new Dictionary<string, int>();

                        // Compute ratting matrix
                        List<MatrixItem> lstRMI = new List<MatrixItem>();
                        foreach (User_SubCategories item in list_SMALL_User_SubCategories[i])
                            lstRMI.AddRange(dao.computeRattingMatrixItem(item.U_SubCategoryID, st.Alpha));

                        double[][] x = Util.toMatrix_MatrixItem(lstRMI, out dic_users, out dic_items);

                        numUser += dic_users.Count;
                        foreach (var it in dic_items)
                            if (!allItem.ContainsKey(it.Key))
                                allItem.Add(it.Key, it.Value);

                        LoadCluster(dao, st, ref existTransac, list_User_Categories[i], categoryName, dic_users, dic_items, x);
                    }

                    #endregion

                    // Remove Excess USER_CLUSTER_TBL
                    dao.removeExcessCluster();

                    // Update USE_TBL
                    if (existTransac)
                        updateTransac_CheckPoint();

                    log += "\t Number of Client Categories: " + list_User_SubCategories.Count;
                    log += "\t Number of Client           : " + numUser;
                    log += "\t Number of Item             : " + allItem.Count;
                    log += "\n Parameter: \n";
                    log += "\t Algorithm:" + st.cluster_type;
                    log += "\t Epsilon  :" + st.epsilon;
                    log += "\t Max Loop :" + st.maxLoop;

                    // Update Success Schedule
                    clusterSchedule.Log = log;
                    dao.updateClusterSchedule(clusterSchedule);
                    dao.commitTransaction();
                }
                catch (Exception ex)
                {
                    dao.rollbackTransaction();
                    throw ex;
                }
            }
            return processType;
        }
Ejemplo n.º 6
0
 public int[] getStaticData()
 {
     int[] result = new int[4];
     Clustering_Users_DAO dao = null;
     try
     {
         dao = new Clustering_Users_DAO();
         dao.beginTransaction();
         result = dao.getStaticsData();
         dao.commitTransaction();
     }
     catch (Exception ex)
     {
         dao.rollbackTransaction();
         throw ex;
     }
     return result;
 }
Ejemplo n.º 7
0
 public List<ClusterSchedule> getListClusterSchedule_DESC()
 {
     Clustering_Users_DAO dao = null;
     try
     {
         dao = new Clustering_Users_DAO();
         dao.beginTransaction();
         List<ClusterSchedule> list = dao.getListClusterSchedule_DESC();
         dao.commitTransaction();
         return list;
     }
     catch (Exception ex)
     {
         dao.rollbackTransaction();
         throw ex;
     }
 }
Ejemplo n.º 8
0
 public List<ClusteredReport> getClusteredReport()
 {
     Clustering_Users_DAO dao = null;
     try
     {
         dao = new Clustering_Users_DAO();
         dao.beginTransaction();
         List<User_SubCategories> list_User_Categories = dao.getAllSubCategories();
         List<ClusteredReport> list = new List<ClusteredReport>();
         foreach (var item in list_User_Categories)
         {
             ClusteredReport cr = new ClusteredReport();
             cr.U_SubCategoryID = item.U_SubCategoryID;
             cr.lstCluster = dao.getClusterInfo_BySubCategory(item.U_SubCategoryID);
             list.Add(cr);
         }
         dao.commitTransaction();
         return list;
     }
     catch (Exception ex)
     {
         dao.rollbackTransaction();
         throw ex;
     }
 }
Ejemplo n.º 9
0
 public int checkProcess()
 {
     int processType = 0;
     Clustering_Users_DAO dao = null;
     try
     {
         dao = new Clustering_Users_DAO();
         dao.beginTransaction();
         ClusterSchedule cs = dao.getLastClusterSchedule();
         if (null != cs)
         {
             if (null == cs.StopTime)
             {
                 processType = 1;
             }
         }
         dao.commitTransaction();
         return processType;
     }
     catch (Exception ex)
     {
         dao.rollbackTransaction();
         throw ex;
     }
 }
Ejemplo n.º 10
0
 public DateTime getCurrentTime()
 {
     Clustering_Users_DAO dao = null;
     try
     {
         dao = new Clustering_Users_DAO();
         dao.beginTransaction();
         DateTime date = dao.getCurrentTime();
         dao.commitTransaction();
         return date;
     }
     catch (Exception ex)
     {
         dao.rollbackTransaction();
         throw ex;
     }
 }