Пример #1
0
 //This functions receives two strings, the first is the job id, the second is the recruitee id.
 //then, it looks at the expressions array (all jobs ids) to find the index of the given JobID,
 //then, it looks at the users array (all users ids and self ratings) to find the index of the given recruitee id.
 //then it returns the value of the rating for that job and recruitee on the Y matrix.
 public int[,] GetYIndex(String jobID, String recruiteeID, String[] expressions, UserProfile[] users)
 {
     try
     {
         int column = 0, row = 0;
         for (int i = 0; i < expressions.Length; i++)
         {
             if ((expressions[i].ToUpper()).Equals(jobID.ToUpper()))
             {
                 row = i;
                 break;
             }
         }
         for (int i = 0; i < users.Length; i++)
         {
             if ((users[i].UserID.ToUpper()).Equals(recruiteeID.ToUpper()))
             {
                 column = i;
                 break;
             }
         }
         int[,] result = new int[1, 2];
         result[0, 0] = row;
         result[0, 1] = column;
         return result;
     }
     catch (Exception ex)
     {
         return null;
     }
 }
Пример #2
0
 public double[,] SelectRatings(String[] expressions, UserProfile[] users)
 {
     try
     {
         IElasticSvc svc = (IElasticSvc)this.getService(typeof(IElasticSvc).Name);
         return svc.SelectRatings(expressions, users);
     }
     catch (ServiceLoadException ex)
     {
         return null;
     }
 }
Пример #3
0
 public bool InsertRatings(String[] expressions, UserProfile[] users, double[,] Y)
 {
     try
     {
         IElasticSvc svc = (IElasticSvc)this.getService(typeof(IElasticSvc).Name);
         return svc.InsertRatings(expressions, users, Y);
     }
     catch (ServiceLoadException ex)
     {
         return false;
     }
 }
Пример #4
0
 public int[,] GetYIndex(String jobID, String recruiteeID, String[] expressions, UserProfile[] users)
 {
     try
     {
         IElasticSvc svc = (IElasticSvc)this.getService(typeof(IElasticSvc).Name);
         return svc.GetYIndex(jobID, recruiteeID, expressions, users);
     }
     catch (ServiceLoadException ex)
     {
         return null;
     }
 }
Пример #5
0
        //To fill Y
        public bool InsertRatings(String[] expressions, UserProfile[] users, double[,] Y)
        {
            try
            {
                TaskManager mgr = new TaskManager();
                List<Task> tasks = mgr.selectAllTask();
                foreach (Task task in tasks)
                {

                    int[,] result = this.GetYIndex(task.JobId.ToString(), task.RecruiteeId.ToString(), expressions, users);
                    task.Rating = (decimal)Y[result[0, 0], result[0, 1]];
                    mgr.updateTask(task);
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Пример #6
0
        public bool writeFiles(String[] job_list, double[,] new_X, UserProfile[] users_profile, double[,] Y)
        {
            try
            {

                StreamWriter write_job_list = new StreamWriter(path_fix+"NEW_expression.txt");
                StreamWriter write_new_X = new StreamWriter(path_fix + "NEW_X.txt");
                StreamWriter write_users_profile = new StreamWriter(path_fix + "NEW_user_table.txt");
                StreamWriter write_Y = new StreamWriter(path_fix + "NEW_Y.txt");
                StreamWriter write_R = new StreamWriter(path_fix + "NEW_R.txt");

                for (int i = 0; i < job_list.Length; i++)
                {
                    write_job_list.Write(job_list[i]);
                    if (i != job_list.Length - 1)
                        write_job_list.Write("\n");
                }

                for (int i = 0; i < new_X.GetLength(0); i++)
                {
                    for (int j = 0; j < new_X.GetLength(1); j++)
                    {
                        write_new_X.Write(new_X[i, j]);
                        if (j != new_X.GetLength(1) - 1)
                        {
                            write_new_X.Write("\t");
                        }
                    }
                    if (i != new_X.GetLength(0) - 1)
                    {
                        write_new_X.Write("\n");
                    }
                }

                for (int i = 0; i < users_profile.Length; i++)
                {
                    write_users_profile.Write(users_profile[i].UserID + "\t" + users_profile[i].UserRating);
                    if (i != users_profile.Length - 1)
                    {
                        write_users_profile.Write("\n");
                    }
                }

                for (int i = 0; i < Y.GetLength(0); i++)
                {
                    for (int j = 0; j < Y.GetLength(1); j++)
                    {
                        write_Y.Write(Y[i, j] + "\t");
                        if (Y[i, j] != 0)
                        {
                            write_R.Write("1\t");
                        }
                        else
                        {
                            write_R.Write("0\t");
                        }
                    }
                    if (i != new_X.GetLength(0) - 1)
                    {
                        write_Y.Write("\n");
                        write_R.Write("\n");
                    }
                }

                write_job_list.Close();
                write_new_X.Close();
                write_users_profile.Close();
                write_Y.Close();
                write_R.Close();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Пример #7
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;
            }
        }
Пример #8
0
 //For each one of the users, writes averages analysis to a file. Everything has 2 decimal places (ToString("N2")).
 public bool writeAveragesToFile(DataResult result, StreamWriter writeText, UserProfile user)
 {
     try
     {
         writeText.WriteLine("USER: "******" with rating:\t" + user.UserRating);
         for (int k = 0; k < result.Number_top_jobs; k++)
         {
             writeText.WriteLine("Job " + result.TopJobNames[k] + "\t" + result.TopJobDiff[k].ToString("N2") + "\t" +
                     result.Mylist.ElementAt(k).PredRecJob.ToString("N2") + "\t" + result.Rating_average[k].ToString("N2") + "\t" +
                     result.Percentage_average[k].ToString("N2") + "\t" + result.SimilarJobsDifficulty[k].ToString("N2"));
         }
         writeText.WriteLine("RATING AVGS TOTAL\t" + result.Rating_total_avg.ToString("N2"));
         writeText.WriteLine("PERCENTAGE AVGS TOTAL\t" + result.Percentage_total_avg.ToString("N2"));
         writeText.WriteLine("JOB DIFFICULTY AVGS TOTAL\t" + result.Avg_topJobDiff.ToString("N2"));
         writeText.WriteLine("SIMILAR JOBS DIFFICULTY AVGS TOTAL\t" + result.Avg_similarJobsDifficulty.ToString("N2"));
         writeText.WriteLine("SELF INACCURACY\t" + result.Self_inaccuracy.ToString("N2") + "\n");
         return true;
     }
     catch (Exception ex)
     {
         return false;
     }
 }
Пример #9
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;
 }
Пример #10
0
 //Constructor
 public DataResult(List<TopJobData> myList, int number_top_jobs, UserProfile user_profile)
 {
     this.mylist = myList;
     this.number_top_jobs = number_top_jobs;
     this.user_profile = user_profile;
 }
Пример #11
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;
     }
 }
Пример #12
0
 public bool writeAveragesToFile(DataResult result, StreamWriter writeText, UserProfile user)
 {
     try
     {
         IFileSystemSvc svc = (IFileSystemSvc)this.getService(typeof(IFileSystemSvc).Name);
         return svc.writeAveragesToFile(result, writeText, user);
     }
     catch (ServiceLoadException ex)
     {
         return false;
     }
 }
Пример #13
0
        //getting Y from data base
        public double[,] SelectRatings(String[] expressions, UserProfile[] users)
        {
            try
            {
                double[,] Y = new double[expressions.Length, users.Length];
                TaskManager mgr = new TaskManager();
                TaskRatingDTO[] tasks = mgr.selectRatings();

                foreach (TaskRatingDTO task in tasks)
                {
                    int[,] result = this.GetYIndex(task.JobId.ToString(), task.RecruiteeId.ToString(), expressions, users);
                    Y[result[0, 0], result[0, 1]] = (double)task.Rating;
                }
                return Y;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
Пример #14
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;
            }
        }