public static void Main(string[] args)
        {
            //Object to Hold Task Parameters
            TaskDimensions task = new TaskDimensions();

            //Dictionary that contains a list of top ten jobs compared with other jobs for each user
            Dictionary<int, List<TopJobData>> finalList = new Dictionary<int, List<TopJobData>>();

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

            IFileSystemSvc svc = new FileSystemSvcImpl();

            //Method call to get the number of jobs and users from the file Y
            svc.detectSizeOfJobsColumns(task, Directory.GetCurrentDirectory()+"/files/Y1.txt");

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

            //Method call to get the jobs names
            String[] job_list = svc.readJobNames(Directory.GetCurrentDirectory() + "/files/job_names1.txt", task);

            //Creating a variable to write in a File the job recommendations and comparisons
            StreamWriter writeText = svc.getResultStreamWriter();

            while (user_number <= task.num_users_init)
            {
                // Movie 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 = svc.readTrainingY(Directory.GetCurrentDirectory() + "/files/Y1.txt", task, my_ratings, user_number);
                double[,] R = svc.readTrainingR(Directory.GetCurrentDirectory() + "/files/R1.txt", task, user_number);

                //Creating a MatLab reference to execute the recommended job script
                IMatlabSvc matSvc = new MatlabSvcImpl();
                object[] res = matSvc.executeFilter(task, job_list, Directory.GetCurrentDirectory()+ "/files", my_ratings, Y, R, X, user_number);

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

                //adding the list at the Dictionary for each user
                finalList.Add(user_number, mylist);

                user_number++;
            }

            writeText.Close();

            //creating a instance of DataResult to be used to write the averages in a file
            DataResult avgs = new DataResult(finalList, 10);
            avgs.calculateAverages();

            Console.WriteLine("DONE");

            // Wait until fisnih
            Console.ReadLine();
        }
 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;
     }
 }
 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;
     }
 }
 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;
     }
 }
        //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, int user_number)
        {
            // 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;
        }
 ///<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 void detectSizeOfJobsColumns(TaskDimensions task, String path)
 {
     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();
     }
 }
        //Reads the file X to get the number of features
        public double[,] getNumberOfFeaturesX(String path, TaskDimensions task)
        {
            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];
        }
 //Reads the binary rating for the Features for each one of the Jobs
 public void readFeaturesX(double[,] X, String path, TaskDimensions task)
 {
     //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();
     }
 }
 ///<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;
     }
 }
 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;
     }
 }
        //Reads the file R to fill out the matrix
        public double[,] readTrainingR(String path, TaskDimensions task, int user_number)
        {
            try
            {
                //Now we allocate R (num_users_init - 1 because the chosen user was removed from the matrix)
                double[,] R = new double[task.num_jobs_init, task.num_users_init - 1];

                using (TextReader readerR = File.OpenText(path))
                {
                    int i = 0;
                    string line = readerR.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))
                            {
                                R[i, k] = Convert.ToDouble(temp[j]);
                                k++;
                            }
                        }
                        line = readerR.ReadLine();
                        i++;
                    }
                    readerR.Close();
                }
                return R;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
        public static void Main(string[] args)
        {
            //Object to Hold Task Parameters
            TaskDimensions task = new TaskDimensions();

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

            //Load File System Service
            IFileSystemSvc svc = new FileSystemSvcImpl();

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

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

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

            //method that return the users profile
            UserProfile[] users_profile = svc.readUserProfile(Directory.GetCurrentDirectory() + "/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 = svc.getResultStreamWriter();
            StreamWriter writeTextAverages = svc.getAverageStreamWriter();
            StreamWriter writeText = svc.getIdandAvgStreamWriter();
            StreamWriter writeTextDiff = svc.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;

            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 = svc.readTrainingY(Directory.GetCurrentDirectory() + "/files/new_Y_53.txt", task, my_ratings, user_number);
                double[,] R = svc.readTrainingR(Directory.GetCurrentDirectory() + "/files/new_R_53.txt", task, user_number);

                //Creating a MatLab reference to execute the recommended job script
                IMatlabSvc matSvc = new MatlabSvcImpl();
                object[] res = matSvc.executeFilter(task, job_list, Directory.GetCurrentDirectory()+ "/files", my_ratings, Y, R, X, user_number);

                //Each time creates a  to be used to write the recommended jobs in a file
                List<TopJobData> mylist = svc.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();
                svc.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
                svc.writeDifficultyToFile(writeTextDiff, avgs);

                //used to inC:\Users\larissaf\Desktop\FinaleVersionCrowd\recommenderSystems\Driver.cssert recommended jobs for a user in the database
                IElasticSvc es = new ElasticSvcImpl();
                es.insertRecommenderJob(avgs);

                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
            svc.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();

            /*
             * 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);
            */

            Console.WriteLine("DONE");

            //Wait until fisnih
            Console.ReadLine();
        }
        public bool MainRoutine()
        {
            try
            {

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

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

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

                //Method call to get the number of jobs and users from the file Y
                fileMgr.detectSizeOfJobsColumns(task, Directory.GetCurrentDirectory() + DirectoryPaths.Y);

                //Method call to get the number of features from the file X, and allocating the X matrix
                double[,] X = fileMgr.getNumberOfFeaturesX(Directory.GetCurrentDirectory() + DirectoryPaths.X, task);
                fileMgr.readFeaturesX(X, Directory.GetCurrentDirectory() + DirectoryPaths.X, task);

                //Method call to get the jobs names
                String[] job_list = fileMgr.readJobNames(Directory.GetCurrentDirectory() + DirectoryPaths.EXPRESSIONS, task);

                //method that return the users profile
                UserProfile[] users_profile = fileMgr.readUserProfile(Directory.GetCurrentDirectory() + DirectoryPaths.USER_TABLE, task);

                //Creating a variable to write in a File the job recommendations and comparisons
                //Load File Writer
                StreamWriter writeTextResult = fileMgr.getResultStreamWriter();
                StreamWriter writeTextAverages = fileMgr.getAverageStreamWriter();
                StreamWriter writeText = fileMgr.getIdandAvgStreamWriter();
                StreamWriter writeTextDiff = fileMgr.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;

                ElasticManager elaMgr = new ElasticManager();

                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 = fileMgr.readTrainingY(Directory.GetCurrentDirectory() + DirectoryPaths.Y, task, my_ratings, user_number);
                    double[,] R = fileMgr.readTrainingR(Directory.GetCurrentDirectory() + DirectoryPaths.R, task, user_number);

                    //Creating a MatLab reference to execute the recommended job script
                    MatlabManager matlabMgr = new MatlabManager();
                    object[] res = matlabMgr.executeFilter(task, job_list, Directory.GetCurrentDirectory() + DirectoryPaths.MATLAB, my_ratings, Y, R, X);

                    //Each time creates a  to be used to write the recommended jobs in a file
                    List<TopJobData> mylist = fileMgr.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();
                    fileMgr.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
                    fileMgr.writeDifficultyToFile(writeTextDiff, avgs);

                    //used to inC:\Users\larissaf\Desktop\FinaleVersionCrowd\recommenderSystems\Driver.cssert recommended jobs for a user in the database

                    new Thread(() =>
                    {
                        Thread.CurrentThread.IsBackground = true;
                        ////used to insert recommended jobs for a user in the database
                        bool result = elaMgr.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
                fileMgr.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();

                /*
                 * 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);
                elaMgr.insertRatings(job_list, users_profile, full_Y);
                */

                Console.WriteLine("DONE");
                //Wait until fisnih
                Console.ReadLine();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        //This method writes global pieces of information about the averages for all users in the same averages file
        public void writeGlobalAveragesInformation(double total_rating_avg_systemm, double total_similarity_avg_system,
            double total_inaccuracy_system, int numUnderEstimated, int numOverEstimated, TaskDimensions task, 
            StreamWriter writeText, UserProfile[] user, double[] users_calculated_raitings)
        {
            double avg_self_rating = 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++;
                        else
                            numUnderEstimated1++;
                        break;
                    case 2:
                        num2++;
                        if ((int)Math.Round(users_calculated_raitings[i], 0) < 2)
                            numOverEstimated2++;
                        else if ((int)Math.Round(users_calculated_raitings[i], 0) == 2)
                            numActualy2++;
                        else
                            numUnderEstimated2++;
                        break;
                    case 3:
                        num3++;
                        if ((int)Math.Round(users_calculated_raitings[i], 0) < 3)
                            numOverEstimated3++;
                        else if ((int)Math.Round(users_calculated_raitings[i], 0) == 3)
                            numActualy3++;
                        else
                            numUnderEstimated3++;
                        break;
                    case 4:
                        num4++;
                        if ((int)Math.Round(users_calculated_raitings[i], 0) < 4)
                            numOverEstimated4++;
                        else if ((int)Math.Round(users_calculated_raitings[i], 0) == 4)
                            numActualy4++;
                        else
                            numUnderEstimated4++;
                        break;
                    default:
                        num5++;
                        if ((int)Math.Round(users_calculated_raitings[i], 0) < 5)
                            numOverEstimated5++;
                        else
                            numActualy5++;
                        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" + numUnderEstimated);
            writeText.WriteLine("Number of users that overestimated themselves\t" + numOverEstimated + "\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);
        }
 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;
     }
 }
 //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;
 }
        //Reads the file Y to fill out the matrix
        public double[,] readTrainingY(String path, TaskDimensions task, double[,] my_ratings, int user_number)
        {
            //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;
        }
 //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;
 }
        public bool MainRoutine()
        {
            try
            {
                //Load File System Service
                FileSystemManager fileMgr = new FileSystemManager();

                NewElasticService.ServiceWCFClient svc = new ServiceWCFClient();
                bool delete = svc.deleteAllRecommendedJob();

                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)
                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 elaMgr = new ElasticManager();
                double[,] Y = elaMgr.selectRatings(job_list, users_profile);

                /////// WRITING VARIABLES IN FILE ////////////
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    ////used to insert recommended jobs for a user in the database
                    fileMgr.writeFiles(job_list, new_X, users_profile, Y);
                }).Start();

                //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;

                //Creating a variable to write in a File the job recommendations and comparisons
                //Load File Writer
                StreamWriter writeTextResult = fileMgr.getResultStreamWriter();
                StreamWriter writeTextAverages = fileMgr.getAverageStreamWriter();
                StreamWriter writeText = fileMgr.getIdandAvgStreamWriter();
                StreamWriter writeTextDiff = fileMgr.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];
                        }
                    }

                    //Creating a MatLab reference to execute the recommended job script
                    object[] res = matlabMgr.executeFilter(task, job_list, Directory.GetCurrentDirectory() + DirectoryPaths.MATLAB, 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 = fileMgr.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();
                    fileMgr.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
                    fileMgr.writeDifficultyToFile(writeTextDiff, avgs);

                    //used to insert recommended jobs for a user in the database
                    new Thread(() =>
                    {
                        Thread.CurrentThread.IsBackground = true;
                        ////used to insert recommended jobs for a user in the database
                        bool result = elaMgr.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
                fileMgr.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();

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

                Console.WriteLine("DONE");
                //Wait until fisnih
                Console.ReadLine();

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
 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;
     }
 }
 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;
     }
 }
Esempio n. 22
0
        public static void Main(string[] args)
        {
            //Object to Hold Task Parameters
            TaskDimensions task = new TaskDimensions();

            //Dictionary that contains a list of top ten jobs compared with other jobs for each user
            Dictionary<int, List<TopJobData>> finalList = new Dictionary<int, List<TopJobData>>();

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

            //Load File System Service
            IFileSystemSvc svc = new FileSystemSvcImpl();

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

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

            //Method call to get the jobs names
            String[] job_list = svc.readJobNames(Directory.GetCurrentDirectory() + "/files/job_names.txt", task);

            //method that return the users profile
            UserProfile[] users_profile = svc.readUserProfile(Directory.GetCurrentDirectory() + "/files/user_table.txt", task);

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

            double total_avg_system = 0;
            double total_user_inaccuracy = 0;

            while (user_number <= task.num_users_init)
            {
                // Movie 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 = svc.readTrainingY(Directory.GetCurrentDirectory() + "/files/Y.txt", task, my_ratings, user_number);
                double[,] R = svc.readTrainingR(Directory.GetCurrentDirectory() + "/files/R.txt", task, user_number);

                //Creating a MatLab reference to execute the recommended job script
                IMatlabSvc matSvc = new MatlabSvcImpl();
                object[] res = matSvc.executeFilter(task, job_list, Directory.GetCurrentDirectory()+ "/files", my_ratings, Y, R, X, user_number);

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

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

                total_avg_system += avgs.Percentage_total_avg;
                total_user_inaccuracy += avgs.Self_inaccuracy;
                //adding the list at the Dictionary for each user

                user_number++;
            }

            total_avg_system /= task.num_users_init;
            writeTextAverages.WriteLine("AVGS TOTAL\t" + total_avg_system);
            total_user_inaccuracy /= task.num_users_init;
            writeTextAverages.WriteLine("COMMUNITY INACCURACY\t" + total_user_inaccuracy);

            writeTextResult.Close();
            writeTextAverages.Close();

            //creating a instance of DataResult to be used to write the averages in a file
            Console.WriteLine("DONE");

            //Wait until fisnih
            Console.ReadLine();
        }
        public static void Main(string[] args)
        {
            //JOBS LIST and X is working but the order is different
            JobSvcImpl j = new JobSvcImpl();
            String[] job_list = j.selectExpressionNames(); //job_names
            double[] X = j.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();
            String[] recruitee_names = r.selectRecruiteeNames();
            double[] recruitee_skill = r.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
            IElasticSvc es = new ElasticSvcImpl();
            double[,] Y = es.SelectRatings(job_list, users_profile);

            ///////// WRITING VARIABLES IN FILE ////////////
            FromWebToFile file = new FromWebToFile();
            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
            IFileSystemSvc svc = new FileSystemSvcImpl();

            //Creating a variable to write in a File the job recommendations and comparisons
            //Load File Writer
            StreamWriter writeTextResult = svc.getResultStreamWriter();
            StreamWriter writeTextAverages = svc.getAverageStreamWriter();
            StreamWriter writeText = svc.getIdandAvgStreamWriter();
            StreamWriter writeTextDiff = svc.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;

            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];
                    }
                }

                //Creating a MatLab reference to execute the recommended job script
                IMatlabSvc matSvc = new MatlabSvcImpl();
                object[] res = matSvc.executeFilter(task, job_list, Directory.GetCurrentDirectory()+ "/files", my_ratings, new_Y, R, new_X, user_number);

                //Each time creates a  to be used to write the recommended jobs in a file
                List<TopJobData> mylist = svc.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();
                svc.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
                svc.writeDifficultyToFile(writeTextDiff, avgs);

                //used to insert recommended jobs for a user in the database
                es.insertRecommenderJob(avgs);

                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
            svc.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();

            /*
             * 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);
            */

            Console.WriteLine("DONE");

            //Wait until fisnih
            Console.ReadLine();
        }