Ejemplo n.º 1
0
        public List<Recommendation_Meta_Item> GetListR1R4_ForNewUsers(Predict_DAO_MC dao, Dictionary<string, double> UCA)
        {
            double M = 1;
            if (UCA.ContainsKey("MEANS_VALUE"))
                M = UCA["MEANS_VALUE"];

            List<Recommendation_Meta_Item> list = new List<Recommendation_Meta_Item>();
            //Content is cleared by M.C. Nguyen 19.9.2015
            return list;
        }
Ejemplo n.º 2
0
        public List<ADDGAP> GetListOfNewGAP(Predict_DAO_MC a)
        {
            List<ADDGAP> lst = new List<ADDGAP>();
            try
            {
                lst = a.GetListOfNewGAP();
            }
            catch (Exception)
            {
                throw;
            }

            return lst;
        }
Ejemplo n.º 3
0
        public List<ClusterInfo> GetListCluster()
        {
            Predict_DAO_MC a = new Predict_DAO_MC();
            List<ClusterInfo> list = new List<ClusterInfo>();

            try
            {
                a.beginTransaction();
                list = a.GetListCluster();
                a.commitTransaction();
                return list;
            }
            catch (Exception ex)
            {
                a.rollbackTransaction();
                throw ex;
            }
        }
Ejemplo n.º 4
0
        public void RemoveDuplicateR3R1()
        {
            Predict_DAO_MC a = new Predict_DAO_MC();
            try
            {
                a.RemoveDuplicateR3R1();
            }
            catch (Exception)
            {

                throw;
            }
        }
Ejemplo n.º 5
0
 public void R3(Predict_DAO_MC dao, RecommdationSchedule schedule, int nbR3, Dictionary<string, double> UCA, List<QTY_GAP> lst)
 {
     List<Recommendation_Meta_Item> list = GetRecommendationR3(dao, nbR3);
     list = GetQuantityTraditionalUsersR3(dao, list, UCA);
     dao.RemoveDuplicateR3R1();
     Normaliser(list);
     AddGAPtoListRecommends(lst, list);
     dao.InsertList(list, schedule);
 }
Ejemplo n.º 6
0
 public void R4(Predict_DAO_MC dao, RecommdationSchedule schedule, double paramR4, Dictionary<string, double> UCA, List<QTY_GAP> lst)
 {
     List<Recommendation_Meta_Item> list = GetRecommendationR4(dao, paramR4, UCA);
     Normaliser(list);
     AddGAPtoListRecommends(lst, list);
     dao.InsertList(list, schedule);
 }
Ejemplo n.º 7
0
 //Corrected by MC. NGUYEN 22.10.2014
 public void R1(Predict_DAO_MC dao, RecommdationSchedule schedule, int nbR1, Dictionary<string, double> UCA, List<QTY_GAP> list)
 {
     //Get recommendations for traditional users
     List<Recommendation_Meta_Item> lrc_ForUserTra = getListRecommendation_R1_TraditionalUsers(dao, nbR1);
     lrc_ForUserTra = GetQuantityTraditionalUsers(dao, lrc_ForUserTra, UCA);
     Normaliser(lrc_ForUserTra);
     AddGAPtoListRecommends(list, lrc_ForUserTra);
     dao.InsertList(lrc_ForUserTra, schedule);
 }
Ejemplo n.º 8
0
 public void R1R4_FOR_NEW_USERS(Predict_DAO_MC dao, RecommdationSchedule schedule, Dictionary<string, double> UCA)
 {
     List<Recommendation_Meta_Item> lrc_ForNewUsers = GetListR1R4_ForNewUsers(dao, UCA);
     // lrc_ForNewUsers = GetQuantityNewUsers(dao, lrc_ForNewUsers);
     Normaliser(lrc_ForNewUsers);
     dao.InsertListNewUser(lrc_ForNewUsers, schedule);
 }
Ejemplo n.º 9
0
        public void LoadRecommendation(string LoginID)
        {
            Predict_DAO_MC dao = null;

            RecommdationSchedule schedule = new RecommdationSchedule();
            schedule.Log = "Recommendation";
            schedule.LoginID = LoginID;
            Predict_MC predictMC = new Predict_MC();

            try
            {
                dao = new Predict_DAO_MC();
                dao.beginTransaction();
                RecommdationSchedule currentSchedule = dao.addRecommdationSchedule(schedule);

                // Settings st = getSettings();
                Settings r = predictMC.GetRecommendationSeting(dao);
                Dictionary<string, double> UCA = predictMC.getUCA(dao);

                //Data service
                IntergrationManager manager = new IntergrationManager(); manager.execute();

                //Learn the quantity GAP
                List<ADDGAP> lstADDGAP = predictMC.GetListOfNewGAP(dao);       //get list of new GAP
                List<QTY_GAP> lstGAP = predictMC.UpdateQTYGap(dao, lstADDGAP);   //Update new GAP and return the GAP Matrix

                //Clustering service
                new ClusterUsers().startClusteringAuto();

                /*
                 *
                 *
                 * this paragraph need to rewrite
                 *
                 * */
                //C4
                ComputeConfident(dao);
                // C5
                ComputeDIST(dao);

                //=====================================================================================

                //dao.CLEAN_RECOMMENDATION();

                //// C6 - MC
                DateTime startC6 = DateTime.Now;
                predictMC.R1(dao, currentSchedule, r.nbR1, UCA, lstGAP);
                DateTime endC6 = DateTime.Now;
                int time_Seconds_CLC6 = Convert.ToInt32((endC6 - startC6).TotalSeconds);

                //// C7 - NGO
                DateTime startC7 = DateTime.Now;
                setRCPurchasedItems(dao, currentSchedule, r.nbR2, lstGAP);
                DateTime endC7 = DateTime.Now;
                int time_Seconds_CLC7 = Convert.ToInt32((endC7 - startC7).TotalSeconds);

                //// C8 - MC
                DateTime startC8 = DateTime.Now;
                predictMC.R3(dao, currentSchedule, r.nbR3, UCA, lstGAP);
                DateTime endC8 = DateTime.Now;
                int time_Seconds_CLC8 = Convert.ToInt32((endC8 - startC8).TotalSeconds);

                //// C9 - MC
                DateTime startC9 = DateTime.Now;
                predictMC.R4(dao, currentSchedule, r.paramR4, UCA, lstGAP);
                DateTime endC9 = DateTime.Now;
                int time_Seconds_CLC9 = Convert.ToInt32((endC9 - startC9).TotalSeconds);

                ////Get R1R4 for new users
                DateTime startR1R4NewUsers = DateTime.Now;
                predictMC.R1R4_FOR_NEW_USERS(dao, currentSchedule, UCA);
                DateTime endR1R4NewUsers = DateTime.Now;
                int time_second_R1R4NewUsers = Convert.ToInt32((endR1R4NewUsers - startR1R4NewUsers).TotalSeconds);

                //GetPrice
                dao.GetPrice();

                Console.WriteLine("FINISH");

                // build statistic log
                List<string[]> lstStatic = dao.getStaticsData();
                foreach (string[] statics in lstStatic)
                {
                    schedule.Log += statics[0] + statics[1] + ". ";
                }

                schedule.Log += "Time to find LRS01 : " + time_Seconds_CLC6.ToString() + ". ";
                schedule.Log += "Time to find LRS02 : " + time_Seconds_CLC7.ToString() + ". ";
                schedule.Log += "Time to find LRS03 : " + time_Seconds_CLC8.ToString() + ". ";
                schedule.Log += "Time to find LRS04 : " + time_Seconds_CLC9.ToString() + ". ";
                schedule.Log += "Time to find recommendations for new clients : " + time_second_R1R4NewUsers.ToString() + ". ";
                schedule.Log += "System successfully stopped at " + DateTime.Now.ToString();

                dao.updateRecommdationSchedule(schedule);
                dao.commitTransaction();

            }
            catch (Exception ex)
            {
                dao.rollbackTransaction();
                throw ex;
            }
        }
Ejemplo n.º 10
0
        public Dictionary<string, double> getUCA(Predict_DAO_MC dao)
        {
            Dictionary<string, double> lstUCA = new Dictionary<string, double>();
            try
            {
                lstUCA = dao.getUCA();
            }
            catch (Exception)
            {

                lstUCA = null;
            }
            return lstUCA;
        }
Ejemplo n.º 11
0
        public List<QTY_GAP> UpdateQTYGap(Predict_DAO_MC a, List<ADDGAP> list)
        {
            List<QTY_GAP> lst = new List<QTY_GAP>();
            try
            {

                a.UpdateGAP(list);
                lst = a.GetGAP();
            }
            catch (Exception)
            {

                throw;
            }
            return lst;
        }
Ejemplo n.º 12
0
        //---------------------------------------------------------------------------------------
        //This function computes the Confident Matrix and Weight Matrix, forllowing the formulars
        //Created by Vuong Minh Tuan
        //Corrected by MC. NGUYEN 21.10.2014.
        //---------------------------------------------------------------------------------------
        public void ComputeConfident(Predict_DAO_MC dao)
        {
            dao.CLEAN_CONF_Matrix();
            dao.CLEAN_WEIG_Matrix();

            List<string> list_ClusterID = dao.getAllClusterID();
            foreach (var item in list_ClusterID)
            {
                List<Transac> u_transacs = dao.getTransac_ForMatrix_ByClusterID_V2(item);
                if (u_transacs.Count > 0)
                {
                    // Get QuantityMatrix - MC OK
                    Dictionary<string, int> QM_dic_users = new Dictionary<string, int>();
                    Dictionary<string, int> QM_dic_items = new Dictionary<string, int>();
                    double[][] QuantityMatrix = Util.getQuantityMatrix_FromTransac_ByMetaItemID(u_transacs, out QM_dic_users, out QM_dic_items);

                    if (QuantityMatrix[0].Length > 1)
                    {
                        // Compute Support One Item Matrix - MC OK
                        double[] S = new double[QuantityMatrix[0].Length];
                        for (int j = 0; j < QuantityMatrix[0].Length; j++)
                        {
                            double count = 0.0;
                            for (int i = 0; i < QuantityMatrix.Length; i++)
                                if (QuantityMatrix[i][j] > 0)
                                    count++;
                            S[j] = count;
                        }

                        // Compute Support Matrix - MC OK
                        double[][] SupportMatrix = new double[QuantityMatrix[0].Length][];
                        for (int i = 0; i < QuantityMatrix[0].Length; i++)
                            SupportMatrix[i] = new double[QuantityMatrix[0].Length];

                        for (int i = 0; i < QuantityMatrix.Length; i++)
                        {
                            for (int j = 0; j < QuantityMatrix[0].Length; j++)
                                for (int j2 = 0; j2 < QuantityMatrix[0].Length; j2++)
                                    if (QuantityMatrix[i][j] > 0 & QuantityMatrix[i][j2] > 0 & j != j2)
                                        SupportMatrix[j][j2]++;
                        }

                        // Compute CONF Matrix - MC OK
                        double[][] CONF = new double[QuantityMatrix[0].Length][];
                        for (int i = 0; i < QuantityMatrix[0].Length; i++)
                            CONF[i] = new double[QuantityMatrix[0].Length];

                        for (int i = 0; i < QuantityMatrix[0].Length; i++)
                        {
                            for (int j = 0; j < QuantityMatrix[0].Length; j++)
                                if (i == j)
                                    CONF[i][j] = 1.0;
                                else if (S[i] > 0)
                                    CONF[i][j] = SupportMatrix[i][j] / S[i];
                        }

                        // Compute WEIG Matrix - MC OK
                        double[][] WEIG = new double[QuantityMatrix[0].Length][];
                        for (int i = 0; i < QuantityMatrix[0].Length; i++)
                            WEIG[i] = new double[QuantityMatrix[0].Length];

                        for (int i = 0; i < QuantityMatrix[0].Length; i++)
                        {
                            for (int j = 0; j < QuantityMatrix[0].Length; j++)
                                if (i != j)
                                    WEIG[i][j] = computeWEIG(i, j, SupportMatrix, QuantityMatrix);
                        }

                        // Save CONF Matrix - MC - OK
                        for (int i = 0; i < CONF.Length; i++)
                            for (int j = 0; j < CONF[0].Length; j++)
                                if (CONF[i][j] > 0)
                                {
                                    MatrixItem matrixItem = new MatrixItem();
                                    matrixItem.Row = Util.FindKeyByValue(QM_dic_items, i);
                                    matrixItem.Column = Util.FindKeyByValue(QM_dic_items, j);
                                    matrixItem.Cell = CONF[i][j];
                                    matrixItem.ClusterID = item;
                                    dao.setCONF_Matrix(matrixItem);
                                }

                        // Save WEIG Matrix
                        for (int i = 0; i < WEIG.Length; i++)
                            for (int j = 0; j < WEIG[0].Length; j++)
                                if (WEIG[i][j] > 0)
                                {
                                    MatrixItem matrixItem = new MatrixItem();
                                    matrixItem.Row = Util.FindKeyByValue(QM_dic_items, i);
                                    matrixItem.Column = Util.FindKeyByValue(QM_dic_items, j);
                                    matrixItem.Cell = WEIG[i][j];
                                    matrixItem.ClusterID = item;
                                    dao.setWEIG_Matrix(matrixItem);
                                }
                    }
                }
            }
        }
Ejemplo n.º 13
0
 //----------------------------------------------------------------------------------------------
 //This function gives R3 AND QUANTITY (with a number of recommendations for each user as input)
 //Created by MC. NGUYEN
 //Corrected by MC. NGUYEN, 22.10.2014.
 //----------------------------------------------------------------------------------------------
 public List<Recommendation_Meta_Item> GetRecommendationR3(Predict_DAO_MC a, int nbR3)
 {
     List<Recommendation_Meta_Item> list = new List<Recommendation_Meta_Item>();
     //Content is cleared by M.C. Nguyen 19.9.2015
     return list;
 }
Ejemplo n.º 14
0
        public List<Recommendation_Meta_Item> GetQuantityTraditionalUsersR3(Predict_DAO_MC a, List<Recommendation_Meta_Item> list, Dictionary<string, double> UCA)
        {
            double QTY;
            double M = 1;
            if (UCA.ContainsKey("MEANS_VALUE"))
                M = UCA["MEANS_VALUE"];

            for (int i = 0; i < list.Count; i++)
            {
                QTY = a.GetQualtityTraditionalUser(list[i]);
                if (QTY != 0)
                    list[i].Quantity = (int)(list[i].Quantity + QTY) / 2;
                //----------------------------------------
                if (UCA.ContainsKey(list[i].UserID))
                {
                    list[i].Quantity = (int)list[i].Quantity * (UCA[list[i].UserID] / M);
                }
            }

            //--------------------
            //a.commitTransaction();
            return list;
            //}
            //catch (Exception ex)
            //{
            //    a.rollbackTransaction();
            //    throw ex;
            //}
        }
Ejemplo n.º 15
0
        //---------------------------------------------------------------------------------------------
        //This function call GetQualtityTraditionalUser to compute the quantity for each recommendations in the list
        //Created by: MC. NGUYEN
        //Corrected by: MC. NGUYEN 24.10.2014
        //---------------------------------------------------------------------------------------------
        public List<Recommendation_Meta_Item> GetQuantityTraditionalUsers(Predict_DAO_MC a, List<Recommendation_Meta_Item> list, Dictionary<string, double> UCA)
        {
            Int32 QTY;
            double M = 1;
            if (UCA.ContainsKey("MEANS_VALUE"))
                M = UCA["MEANS_VALUE"];

            for (int i = 0; i < list.Count; i++)
            {
                QTY = a.GetQualtityTraditionalUser(list[i]);
                if (QTY > 0)
                    list[i].Quantity = QTY;
                else
                    list[i].Quantity = 1;

                if (UCA.ContainsKey(list[i].UserID))
                {
                    list[i].Quantity = (int)list[i].Quantity * (UCA[list[i].UserID] / M);
                }
            }

            return list;
        }
Ejemplo n.º 16
0
        public List<Recommendation_Meta_Item> GetQuantityNewUsers(Predict_DAO_MC a, List<Recommendation_Meta_Item> list)
        {
            //Predict_DAO_MC a = new Predict_DAO_MC();
            //List<U_I_Q> Cate_Item_QTY = new List<U_I_Q>();
            //try
            //{
            //    a.beginTransaction();
            list = a.GetAllQuantity(list);
            //    a.commitTransaction();

            return list;
            //}
            //catch (Exception ex)
            //{
            //    a.rollbackTransaction();
            //    throw ex;
            //}
        }
Ejemplo n.º 17
0
        //THis function get a price of MetaItemID that correspondance with the quantity
        //----------------------------------------------------------------------------------
        public double GetPrice(string MetaItemID, int QTY)
        {
            double Price = 0;
            Predict_DAO_MC a = new Predict_DAO_MC();
            try
            {
                Price = a.GetPrice(MetaItemID, QTY);
            }
            catch (Exception)
            {

                throw;
            }

            return Price;
        }
Ejemplo n.º 18
0
 public List<Recommendation_Meta_Item> GetRecommendations(string sql)
 {
     Predict_DAO_MC a = new Predict_DAO_MC();
     try
     {
         a.beginTransaction();
         List<Recommendation_Meta_Item> list = a.GetRecommendations(sql);
         a.commitTransaction();
         return list;
     }
     catch (Exception ex)
     {
         a.rollbackTransaction();
         throw ex;
     }
 }
Ejemplo n.º 19
0
        public Settings GetRecommendationSeting(Predict_DAO_MC a)
        {
            Settings st = new Settings();

            try
            {
                List<Recommendation_Setting> listCs = a.GetRecommendationSetting();

                if (null != listCs && listCs.Count > 0)
                    foreach (var item in listCs)
                    {
                        if (item.Key.Equals(ConstantValues.nb_R1))
                        {
                            foreach (var cs_detail in item.Values)
                                if (cs_detail.isDedault.Equals(true))
                                {
                                    st.nbR1 = Convert.ToInt32(cs_detail.Value.Trim());
                                    break;
                                }
                        }
                        else
                            if (item.Key.Equals(ConstantValues.nb_R2))
                            {
                                foreach (var cs_detail in item.Values)
                                    if (cs_detail.isDedault.Equals(true))
                                    {
                                        st.nbR2 = Convert.ToInt32(cs_detail.Value.Trim());
                                        break;
                                    }
                            }
                            else if (item.Key.Equals(ConstantValues.nb_R3))
                            {
                                foreach (var cs_detail in item.Values)
                                    if (cs_detail.isDedault.Equals(true))
                                    {
                                        st.nbR3 = Convert.ToInt32(cs_detail.Value.Trim());
                                        break;
                                    }
                            }
                            else if (item.Key.Equals(ConstantValues.param_R4))
                            {
                                foreach (var cs_detail in item.Values)
                                    if (cs_detail.isDedault.Equals(true))
                                    {
                                        st.paramR4 = Convert.ToDouble(cs_detail.Value.Trim(), CultureInfo.CreateSpecificCulture("en-GB"));
                                        break;
                                    }
                            }
                    }

            }
            catch (Exception ex)
            {
                a.rollbackTransaction();
                throw ex;
            }
            return st;
        }
Ejemplo n.º 20
0
        //public List<Recommendation_Meta_Item> GetListRecommendC6_ForTraditionalUser()
        //{
        //    Predict_DAO_MC a = new Predict_DAO_MC();
        //    List<Recommendation_Meta_Item> list = new List<Recommendation_Meta_Item>();
        //    List<Recommendation_Meta_Item> RC = new List<Recommendation_Meta_Item>();
        //    try
        //    {
        //        a.beginTransaction();
        //        List<User> list_users_tra = a.getTraditionalUser_UnBlocked();
        //        foreach (User u in list_users_tra)
        //        {
        //            RC = a.GetRecommendC6_ForTraditionalUser(u, 1);
        //            list.AddRange(RC);
        //        }
        //        a.commitTransaction();
        //        return list;
        //    }
        //    catch (Exception ex)
        //    {
        //        a.rollbackTransaction();
        //        throw ex;
        //    }
        //}
        //----------------------------------------------------------------------------------------------
        //This function calls GetRecommendC6_ForTraditionalUser from Predict_DAO_MC to give R1
        //Created by MC. NGUYEN
        //Corrected by MC. NGUYEN, 22.10.2014
        //Changed: 24.10.2014: the formule to calculate SCORE for each Meta Produit (based on Count(*)).
        //----------------------------------------------------------------------------------------------
        public List<Recommendation_Meta_Item> getListRecommendation_R1_TraditionalUsers(Predict_DAO_MC a, int nbR1)
        {
            //Predict_DAO_MC a = new Predict_DAO_MC();
            List<Recommendation_Meta_Item> list = new List<Recommendation_Meta_Item>();
            List<Recommendation_Meta_Item> RC = new List<Recommendation_Meta_Item>();
            List<string> lstCluster = new List<string>();
            List<string> User_OfCluster = new List<string>();
            //Settings r = GetRecommendationSeting(a);
            lstCluster = a.GetListClusterID();
            //Check number of recommendations
            if (nbR1 <= 0) nbR1 = 1;

            //int i = 0;

            foreach (string cluster in lstCluster)
            {

                User_OfCluster = a.GetListUser_OfCluster(cluster);

                foreach (string u in User_OfCluster)
                {

                    RC = a.GetRecommendC6_ForTraditionalUser(u, nbR1);//2
                    list.AddRange(RC);

                }
            }
            return list;
        }
Ejemplo n.º 21
0
        //---------------------------------------------------------------------------------------
        //This function computes the DISTANCE matrix and inserts it into the database
        //This is the distance between the two columns of the Rating Matrix
        //Created by Vuong Minh Tuan
        //Corrected all errors by MC. NGUYEN 21.10.2014.
        //---------------------------------------------------------------------------------------
        public void ComputeDIST(Predict_DAO_MC dao)
        {
            dao.CLEAN_DIST_Matrix();

            List<string> list_ClusterID = dao.getAllClusterID();
            foreach (var item in list_ClusterID)
            {
                Dictionary<string, int> RM_dic_users = new Dictionary<string, int>();
                Dictionary<string, int> RM_dic_items = new Dictionary<string, int>();
                // Compute ratting matrix
                List<MatrixItem> lstRMI = dao.getRattingMatrixItem_ByClusterID(item);
                double[][] RattingMatrix = Util.toMatrix_MatrixItem(lstRMI, out RM_dic_users, out RM_dic_items);

                if (RattingMatrix.Length > 0 & RM_dic_items.Count > 1)
                {
                    double[][] DIST = new double[RattingMatrix[0].Length][];
                    for (int i = 0; i < RattingMatrix[0].Length; i++)
                        DIST[i] = new double[RattingMatrix[0].Length];

                    // Compute DIST Matrix
                    for (int i1 = 0; i1 < RattingMatrix[0].Length - 1; i1++)
                        for (int i2 = i1 + 1; i2 < RattingMatrix[0].Length; i2++)
                        {
                            double value = 0.0;
                            for (int t = 0; t < RattingMatrix.Length; t++)
                                value += Math.Pow(RattingMatrix[t][i1] - RattingMatrix[t][i2], 2);
                            value = Math.Sqrt(value);
                            DIST[i1][i2] = value;
                            DIST[i2][i1] = value;
                        }

                    if (DIST.Length > 0)
                    {
                        double max = DIST[0][0];
                        // Find Max
                        for (int i = 0; i < DIST.Length; i++)
                        {
                            double localMax = DIST[i].Max();
                            if (localMax > max)
                                max = localMax;
                        }

                        // Standardization
                        if (max != 0)
                        {
                            for (int i = 0; i < DIST.Length; i++)
                                for (int j = 0; j < DIST[0].Length; j++)
                                    DIST[i][j] /= max;
                        }

                        // Save to Database
                        for (int i = 0; i < DIST.Length; i++)
                            for (int j = 0; j < DIST[0].Length; j++)
                                if (DIST[i][j] > 0)
                                {
                                    MatrixItem matrixItem = new MatrixItem();
                                    matrixItem.Row = Util.FindKeyByValue(RM_dic_items, i);
                                    matrixItem.Column = Util.FindKeyByValue(RM_dic_items, j);
                                    matrixItem.Cell = DIST[i][j];
                                    matrixItem.ClusterID = item;
                                    dao.setDIST_Matrix(matrixItem);
                                }
                    }
                }
            }
        }