Ejemplo n.º 1
0
        ///<summary>
        ///Reading the file to get the size of lines and columns of R and Y, which will be used in training colloborative filtering.
        ///</summary>
        ///<remarks>
        ///Number of Users(columns) and Number of Jobs(rows)
        ///</remarks>
        public bool detectSizeOfJobsColumns(TaskDimensions task, String path)
        {
            try
            {
                using (TextReader readerR = File.OpenText(path))
                {
                    task.num_jobs_init = 0;
                    string line = readerR.ReadLine();
                    string[] temp = line.Split('\t');
                    task.num_users_init = temp.Length;
                    while (line != null)
                    {
                        line = readerR.ReadLine();
                        task.num_jobs_init++;
                    }
                    readerR.Close();
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Ejemplo n.º 2
0
 public double[,] getNumberOfFeaturesX(String path, TaskDimensions task)
 {
     try
     {
         IFileSystemSvc svc = (IFileSystemSvc)this.getService(typeof(IFileSystemSvc).Name);
         return svc.getNumberOfFeaturesX(path, task);
     }
     catch (ServiceLoadException ex)
     {
         return null;
     }
 }
Ejemplo n.º 3
0
 public object[] executeFilter(TaskDimensions task, String[] job_list, String path, double[,] my_ratings, double[,] Y, double[,] R, double[,] X)
 {
     try
     {
         IMatlabSvc svc = (IMatlabSvc)this.getService(typeof(IMatlabSvc).Name);
         return svc.executeFilter(task, job_list, path, my_ratings, Y, R, X);
     }
     catch (ServiceLoadException ex)
     {
         return null;
     }
 }
Ejemplo n.º 4
0
 public bool detectSizeOfJobsColumns(TaskDimensions task, String path)
 {
     try
     {
         IFileSystemSvc svc = (IFileSystemSvc)this.getService(typeof(IFileSystemSvc).Name);
         return svc.detectSizeOfJobsColumns(task, path);
     }
     catch (ServiceLoadException ex)
     {
         return false;
     }
 }
Ejemplo n.º 5
0
        //Excecutes a filter in matlab to calculate the recommeded jobs for an user
        public object[] executeFilter(TaskDimensions task, String[] job_list, String path, double[,] my_ratings, double[,] Y, double[,] R, double[,] X)
        {
            try
            {
                // Define the output to print the final result
                object result_job_search = null;

                this.changeDirectory(path);

                // Job recommendations script that will give as result 6 objects described in matlab
                this.matlab.Feval("scriptGeneration", 6, out result_job_search, my_ratings, job_list, Y, R, X, task.num_features);
                object[] res = result_job_search as object[];

                return res;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Ejemplo n.º 6
0
        //This method writes global pieces of information about the averages for all users in the same averages file
        public bool writeGlobalAveragesInformation(double total_rating_avg_systemm, double total_similarity_avg_system,
            double total_inaccuracy_system, TaskDimensions task, 
            StreamWriter writeText, UserProfile[] user, double[] users_calculated_raitings)
        {
            try
            {
                double avg_self_rating = 0;
                int numOverTotal = 0, numActualyTotal = 0, numUnderTotal = 0;
                int numOverEstimated1 = 0, numActualy1 = 0, numUnderEstimated1 = 0;
                int numOverEstimated2 = 0, numActualy2 = 0, numUnderEstimated2 = 0;
                int numOverEstimated3 = 0, numActualy3 = 0, numUnderEstimated3 = 0;
                int numOverEstimated4 = 0, numActualy4 = 0, numUnderEstimated4 = 0;
                int numOverEstimated5 = 0, numActualy5 = 0, numUnderEstimated5 = 0;
                int num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0;
                int num1_after = 0, num2_after = 0, num3_after = 0, num4_after = 0, num5_after = 0;
                for (int i = 0; i < task.num_users_init; i++)
                {
                    avg_self_rating += user[i].UserRating;
                    switch ((int)user[i].UserRating)
                    {
                        case 1:
                            num1++;
                            if ((int)Math.Round(users_calculated_raitings[i], 0) == 1)
                            {
                                numActualy1++;
                                numActualyTotal++;
                            }
                            else
                            {
                                numUnderEstimated1++;
                                numUnderTotal++;
                            }
                            break;
                        case 2:
                            num2++;
                            if ((int)Math.Round(users_calculated_raitings[i], 0) < 2)
                            {
                                numOverEstimated2++;
                                numOverTotal++;
                            }
                            else if ((int)Math.Round(users_calculated_raitings[i], 0) == 2)
                            {
                                numActualy2++;
                                numActualyTotal++;
                            }
                            else
                            {
                                numUnderEstimated2++;
                                numUnderTotal++;
                            }
                            break;
                        case 3:
                            num3++;
                            if ((int)Math.Round(users_calculated_raitings[i], 0) < 3)
                            {
                                numOverEstimated3++;
                                numOverTotal++;
                            }
                            else if ((int)Math.Round(users_calculated_raitings[i], 0) == 3)
                            {
                                numActualyTotal++;
                                numActualy3++;
                            }
                            else
                            {
                                numUnderEstimated3++;
                                numUnderTotal++;
                            }
                            break;
                        case 4:
                            num4++;
                            if ((int)Math.Round(users_calculated_raitings[i], 0) < 4)
                            {
                                numOverEstimated4++;
                                numOverTotal++;
                            }
                            else if ((int)Math.Round(users_calculated_raitings[i], 0) == 4)
                            {
                                numActualy4++;
                                numActualyTotal++;
                            }
                            else
                            {
                                numUnderEstimated4++;
                                numUnderTotal++;
                            }
                            break;
                        default:
                            num5++;
                            if ((int)Math.Round(users_calculated_raitings[i], 0) < 5)
                            {
                                numOverEstimated5++;
                                numOverTotal++;
                            }
                            else
                            {
                                numActualy5++;
                                numActualyTotal++;
                            }
                            break;
                    }
                    switch ((int)Math.Round(users_calculated_raitings[i], 0))
                    {
                        case 1:
                            num1_after++;
                            break;
                        case 2:
                            num2_after++;
                            break;
                        case 3:
                            num3_after++;
                            break;
                        case 4:
                            num4_after++;
                            break;
                        default:
                            num5_after++;
                            break;
                    }
                }

                avg_self_rating /= task.num_users_init;

                writeText.WriteLine("Avgs total (ratings)\t" + total_rating_avg_systemm);
                writeText.WriteLine("Avgs total (self rating)\t" + avg_self_rating);
                writeText.WriteLine("Avgs total (similarity)\t" + total_similarity_avg_system);
                writeText.WriteLine("Community inaccuracy\t" + total_inaccuracy_system + "\n");
                writeText.WriteLine("Number of users that underestimated themselves\t" + numUnderTotal);
                writeText.WriteLine("Number of users that right estimated about themselves\t" + numActualyTotal);
                writeText.WriteLine("Number of users that overestimated themselves\t" + numOverTotal + "\n");

                writeText.WriteLine("Number of self ratings (before calculation)");
                writeText.WriteLine("amount of 1:\t" + num1);
                writeText.WriteLine("amount of 2:\t" + num2);
                writeText.WriteLine("amount of 3:\t" + num3);
                writeText.WriteLine("amount of 4:\t" + num4);
                writeText.WriteLine("amount of 5:\t" + num5);

                writeText.WriteLine("\nNumber of self ratings (after calculation)");
                writeText.WriteLine("amount of 1:\t" + num1_after);
                writeText.WriteLine("amount of 2:\t" + num2_after);
                writeText.WriteLine("amount of 3:\t" + num3_after);
                writeText.WriteLine("amount of 4:\t" + num4_after);
                writeText.WriteLine("amount of 5:\t" + num5_after);

                this.underAndOverEstimations(writeText, 1, num1, numOverEstimated1, numActualy1, numUnderEstimated1);
                this.underAndOverEstimations(writeText, 2, num2, numOverEstimated2, numActualy2, numUnderEstimated2);
                this.underAndOverEstimations(writeText, 3, num3, numOverEstimated3, numActualy3, numUnderEstimated3);
                this.underAndOverEstimations(writeText, 4, num4, numOverEstimated4, numActualy4, numUnderEstimated4);
                this.underAndOverEstimations(writeText, 5, num5, numOverEstimated5, numActualy5, numUnderEstimated5);

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Ejemplo n.º 7
0
 //Reads the file job _list to get the name of the Jobs
 public UserProfile[] readUserProfile(String path, TaskDimensions task)
 {
     UserProfile[] users = new UserProfile[task.num_users_init];
     using (TextReader reader_users_list = File.OpenText(path))
     {
         string line = reader_users_list.ReadLine();
         int i = 0;
         while (line != null)
         {
             string[] temp = line.Split('\t');
             users[i] = new UserProfile(temp[0], Convert.ToDouble(temp[1]));
             line = reader_users_list.ReadLine();
             i++;
         }
         reader_users_list.Close();
     }
     return users;
 }
Ejemplo n.º 8
0
        //Reads the file Y to fill out the matrix
        public double[,] readTrainingY(String path, TaskDimensions task, double[,] my_ratings, int user_number)
        {
            try
            {
                //Now we allocate R (num_users_init - 1 because the chosen user was removed from the matrix)
                double[,] Y = new double[task.num_jobs_init, task.num_users_init - 1];

                using (TextReader readerY = File.OpenText(path))
                {
                    int i = 0;
                    string line = readerY.ReadLine();
                    while (line != null)
                    {
                        string[] temp = line.Split('\t');
                        int k = 0;
                        for (int j = 0; j < task.num_users_init; j++)
                        {
                            if (j != (user_number - 1))
                            {
                                Y[i, k] = Convert.ToDouble(temp[j]);
                                k++;
                            }
                            else
                                my_ratings[i, 0] = Convert.ToDouble(temp[j]);
                        }
                        line = readerY.ReadLine();
                        i++;
                    }
                    readerY.Close();
                }
                return Y;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Ejemplo n.º 9
0
 //Reads the file job _list to get the name of the Jobs
 public String[] readJobNames(String path, TaskDimensions task)
 {
     string[] job_list = new string[task.num_jobs_init];
     using (TextReader reader_job_list = File.OpenText(path))
     {
         string line = reader_job_list.ReadLine();
         int i = 0;
         while (line != null)
         {
             job_list[i] = line;
             line = reader_job_list.ReadLine();
             i++;
         }
         reader_job_list.Close();
     }
     return job_list;
 }
Ejemplo n.º 10
0
        //Reads the binary rating for the Features for each one of the Jobs
        public bool readFeaturesX(double[,] X, String path, TaskDimensions task)
        {
            try
            {
                //reading X
                using (TextReader readerX = File.OpenText(path))
                {
                    int i = 0;
                    string line = readerX.ReadLine();
                    while (line != null)
                    {
                        string[] temp = line.Split('\t');
                        for (int j = 0; j < task.num_features; j++)
                        {
                            X[i, j] = Convert.ToDouble(temp[j]);
                        }
                        line = readerX.ReadLine();
                        i++;
                    }
                    readerX.Close();
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Ejemplo n.º 11
0
        //Reads the file X to get the number of features
        public double[,] getNumberOfFeaturesX(String path, TaskDimensions task)
        {
            try
            {
                task.num_features = 0;

                using (TextReader readerX = File.OpenText(path))
                {
                    string line = readerX.ReadLine();
                    if (line != null)
                    {
                        string[] temp = line.Split('\t');
                        task.num_features = temp.Length;
                    }
                    readerX.Close();
                }

                //allocating the X matriz
                return new double[task.num_jobs_init, task.num_features];
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Ejemplo n.º 12
0
 public bool readFeaturesX(double[,] X, String path, TaskDimensions task)
 {
     try
     {
         IFileSystemSvc svc = (IFileSystemSvc)this.getService(typeof(IFileSystemSvc).Name);
         return svc.readFeaturesX(X, path, task);
     }
     catch (ServiceLoadException ex)
     {
         return false;
     }
 }
Ejemplo n.º 13
0
        public bool ExecuteMainRoutine()
        {
            try
            {
                RecommendedJobManager recJobMgr = new RecommendedJobManager();
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    bool result_delete = recJobMgr.deleteAllRecommendedJob();
                }).Start();

                JobManager jobMgr = new JobManager();
                String[] job_list = jobMgr.selectExpressionNames(); //job_names
                double[] X = jobMgr.selectExpressionDifficulty(); //X
                double[,] new_X = new double[X.Length, 1];
                for (int i = 0; i < X.Length; i++)
                {
                    new_X[i, 0] = X[i];
                }

                //////User Profile (just the user ID, I still need the user self rating)
                //////RecruiteeSvcImpl r = new RecruiteeSvcImpl();
                RecruiteeManager recMgr = new RecruiteeManager();
                String[] recruitee_names = recMgr.selectRecruiteeNames();
                double[] recruitee_skill = recMgr.selectRecruiteeSkills();
                UserProfile[] users_profile = new UserProfile[recruitee_skill.Length];
                for (int i = 0; i < recruitee_skill.Length; i++)
                {
                    users_profile[i] = new UserProfile("", 0);
                    users_profile[i].UserID = recruitee_names[i];
                    users_profile[i].UserRating = recruitee_skill[i];
                }
                //////new_Y
                ElasticManager elasticMgr = new ElasticManager();
                double[,] Y = elasticMgr.SelectRatings(job_list, users_profile);

                ///////////// WRITING VARIABLES IN FILE ////////////
                //FromWebToFileManager file = new FromWebToFileManager();
                //file.writeFiles(job_list, new_X, users_profile, Y);

                //////Object to Hold Task Parameters
                TaskDimensions task = new TaskDimensions();
                task.num_features = new_X.GetLength(1); //1 is the number of columns
                task.num_jobs_init = job_list.Length;
                task.num_users_init = recruitee_names.Length;

                //////User number to start proccessing
                int user_number = 1;

                //////Load File System Service
                FileSystemManager fileSystemMgr = new FileSystemManager();

                //////Creating a variable to write in a File the job recommendations and comparisons
                //////Load File Writer
                StreamWriter writeTextResult = fileSystemMgr.getResultStreamWriter();
                StreamWriter writeTextAverages = fileSystemMgr.getAverageStreamWriter();
                StreamWriter writeText = fileSystemMgr.getIdandAvgStreamWriter();
                StreamWriter writeTextDiff = fileSystemMgr.getDifficultyStreamWriter();

                double[] users_calculated_raitings = new double[task.num_users_init];

                double total_rating_avg_system = 0;
                double total_similarity_avg_system = 0;
                double total_inaccuracy_system = 0;

                MatlabManager matlabMgr = new MatlabManager();

                while (user_number <= task.num_users_init)
                {
                    double[,] my_ratings = new double[task.num_jobs_init, 1];
                    double[,] new_Y = new double[task.num_jobs_init, task.num_users_init - 1];
                    double[,] R = new double[task.num_jobs_init, task.num_users_init - 1];

                    for (int i = 0; i < job_list.Length; i++)
                    {
                        int k = 0;
                        for (int n = 0; n < users_profile.Length; n++)
                        {
                            if (n != (user_number - 1))
                            {
                                new_Y[i, k] = Y[i, n];
                                if (Y[i, n] != 0)
                                    R[i, k] = 1;
                                else
                                    R[i, k] = 0;
                                k++;
                            }
                            else
                                my_ratings[i, 0] = Y[i, n];
                        }
                    }

                    object[] res = matlabMgr.executeFilter(task, job_list, path_fix + "files", my_ratings, new_Y, R, new_X);

                //    ////Each time creates a  to be used to write the recommended jobs in a file
                    List<TopJobData> mylist = fileSystemMgr.writeValuesToFile(writeTextResult, res, job_list, user_number, new_X);

                //    ////Calculate Averages for Jobs for a User
                    DataResult avgs = new DataResult(mylist, mylist.Count, users_profile[user_number - 1]);
                    avgs.AverageForEachJob();
                    fileSystemMgr.writeAveragesToFile(avgs, writeTextAverages, users_profile[user_number - 1]);

                    total_rating_avg_system += avgs.Rating_total_avg;
                    total_similarity_avg_system += avgs.Percentage_total_avg;
                    total_inaccuracy_system += avgs.Self_inaccuracy;
                //    ////adding the list at the Dictionary for each user

                //    ////ID and AVGs file
                    writeText.WriteLine(users_profile[user_number - 1].UserID + "\t" + avgs.Rating_total_avg);

                    users_calculated_raitings[user_number - 1] = avgs.Rating_total_avg;

                //    ////writing in the difficulty file
                    fileSystemMgr.writeDifficultyToFile(writeTextDiff, avgs);

                    new Thread(() =>
                        {
                            Thread.CurrentThread.IsBackground = true;
                            ////used to insert recommended jobs for a user in the database
                            bool result = elasticMgr.insertRecommenderJob(avgs);
                        }).Start();

                    user_number++;

                }

                total_rating_avg_system /= task.num_users_init;
                total_similarity_avg_system /= task.num_users_init;
                total_inaccuracy_system /= task.num_users_init;
                ////writing some more global information
                fileSystemMgr.writeGlobalAveragesInformation(total_rating_avg_system, total_similarity_avg_system, total_inaccuracy_system,
                    task, writeTextAverages, users_profile, users_calculated_raitings);

                //////closing the four files

                writeText.Close();
                writeTextResult.Close();
                writeTextAverages.Close();
                writeTextDiff.Close();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Ejemplo n.º 14
0
 public bool writeGlobalAveragesInformation(double total_rating_avg_systemm, double total_similarity_avg_system,
                                     double total_inaccuracy_system, TaskDimensions task,
                                     StreamWriter writeText, UserProfile[] user, double[] users_calculated_raitings)
 {
     try
     {
         IFileSystemSvc svc = (IFileSystemSvc)this.getService(typeof(IFileSystemSvc).Name);
         return svc.writeGlobalAveragesInformation(total_rating_avg_systemm, total_similarity_avg_system,
                                     total_inaccuracy_system, task,
                                     writeText, user, users_calculated_raitings);
     }
     catch (ServiceLoadException ex)
     {
         return false;
     }
 }
Ejemplo n.º 15
0
 public UserProfile[] readUserProfile(String path, TaskDimensions task)
 {
     try
     {
         IFileSystemSvc svc = (IFileSystemSvc)this.getService(typeof(IFileSystemSvc).Name);
         return svc.readUserProfile(path, task);
     }
     catch (ServiceLoadException ex)
     {
         return null;
     }
 }
Ejemplo n.º 16
0
 public double[,] readTrainingY(String path, TaskDimensions task, double[,] my_ratings, int user_number)
 {
     try
     {
         IFileSystemSvc svc = (IFileSystemSvc)this.getService(typeof(IFileSystemSvc).Name);
         return svc.readTrainingY(path, task, my_ratings, user_number);
     }
     catch (ServiceLoadException ex)
     {
         return null;
     }
 }
Ejemplo n.º 17
0
        public bool ExecuteMainRoutine()
        {
            try
            {
                ElasticManager elasticMgr = new ElasticManager();

                //Object to Hold Task Parameters
                TaskDimensions task = new TaskDimensions();

                //User number to start proccessing
                int user_number = 1;

                //Load File System Service
                FileSystemManager fileSystemMgr = new FileSystemManager();

                //Method call to get the number of jobs and users from the file Y
                fileSystemMgr.detectSizeOfJobsColumns(task, path_fix + "files/new_Y_53.txt");

                //Method call to get the number of features from the file X, and allocating the X matrix
                double[,] X = fileSystemMgr.getNumberOfFeaturesX(path_fix + "files/X.txt", task);
                fileSystemMgr.readFeaturesX(X, path_fix + "files/X.txt", task);

                //Method call to get the jobs names
                String[] job_list = fileSystemMgr.readJobNames(path_fix + "files/expressions.txt", task);

                //method that return the users profile
                UserProfile[] users_profile = fileSystemMgr.readUserProfile(path_fix + "files/new_user_table_53.txt", task);

                //Creating a variable to write in a File the job recommendations and comparisons
                //Load File Writer
                StreamWriter writeTextResult = fileSystemMgr.getResultStreamWriter();
                StreamWriter writeTextAverages = fileSystemMgr.getAverageStreamWriter();
                StreamWriter writeText = fileSystemMgr.getIdandAvgStreamWriter();
                StreamWriter writeTextDiff = fileSystemMgr.getDifficultyStreamWriter();

                double[] users_calculated_raitings = new double[task.num_users_init];

                double total_rating_avg_system = 0;
                double total_similarity_avg_system = 0;
                double total_inaccuracy_system = 0;

                //Creating a MatLab reference to execute the recommended job script
                MatlabManager matlabMgr = new MatlabManager();

                while (user_number <= task.num_users_init)
                {
                    // job rating file for a user
                    double[,] my_ratings = new double[task.num_jobs_init, 1];

                    //Now we read R and Y from theirs files (-1 because I will remove the chosen user from the matrixes)
                    double[,] Y = fileSystemMgr.readTrainingY(path_fix + "files/new_Y_53.txt", task, my_ratings, user_number);
                    double[,] R = fileSystemMgr.readTrainingR(path_fix + "files/new_R_53.txt", task, user_number);

                    object[] res = matlabMgr.executeFilter(task, job_list, path_fix + "files", my_ratings, Y, R, X);

                    //Each time creates a  to be used to write the recommended jobs in a file
                    List<TopJobData> mylist = fileSystemMgr.writeValuesToFile(writeTextResult, res, job_list, user_number, X);

                    //Calculate Averages for Jobs for a User
                    DataResult avgs = new DataResult(mylist, mylist.Count, users_profile[user_number - 1]);
                    avgs.AverageForEachJob();
                    fileSystemMgr.writeAveragesToFile(avgs, writeTextAverages, users_profile[user_number - 1]);

                    total_rating_avg_system += avgs.Rating_total_avg;
                    total_similarity_avg_system += avgs.Percentage_total_avg;
                    total_inaccuracy_system += avgs.Self_inaccuracy;
                    //adding the list at the Dictionary for each user

                    //ID and AVGs file
                    writeText.WriteLine(users_profile[user_number - 1].UserID + "\t" + avgs.Rating_total_avg);

                    users_calculated_raitings[user_number - 1] = avgs.Rating_total_avg;

                    //writing in the difficulty file
                    fileSystemMgr.writeDifficultyToFile(writeTextDiff, avgs);

                    new Thread(() =>
                    {
                        Thread.CurrentThread.IsBackground = true;
                        //    ////used to insert recommended jobs for a user in the database
                        bool result = elasticMgr.insertRecommenderJob(avgs);
                    }).Start();

                    user_number++;

                }

                total_rating_avg_system /= task.num_users_init;
                total_similarity_avg_system /= task.num_users_init;
                total_inaccuracy_system /= task.num_users_init;
                //writing some more global information
                fileSystemMgr.writeGlobalAveragesInformation(total_rating_avg_system, total_similarity_avg_system, total_inaccuracy_system,
                     task, writeTextAverages, users_profile, users_calculated_raitings);

                //closing the three files
                writeText.Close();
                writeTextResult.Close();
                writeTextAverages.Close();
                writeTextDiff.Close();

                return true;

                /*
                 * Used to insert rating for task performed by workers. (User interface need to be built)
                 *
                double[,] full_Y = svc.readFullY(Directory.GetCurrentDirectory() + "/files/Y.txt", task);
                IElasticSvc e = new ElasticSvcImpl();
                e.InsertRatings(job_list, users_profile, full_Y);
                */
            }
            catch (Exception ex)
            {
                return false;
            }
        }