Exemple #1
0
        public void Run()
        {
            ArgumentHandler arguments = ArgumentHandler.GetInstance();
            Randomizer      rnd       = Randomizer.GetInstance();

            #region Generiranje tema
            int maxNumberOfThemes = (int)arguments.GetArgument("MaxThemeNumber");
            int numberOfThemes    = rnd.GetNumber(1, maxNumberOfThemes);
            Console.WriteLine("\nBroj tema: " + numberOfThemes);

            List <Theme> listOfThemes = new List <Theme>();
            listOfThemes = GenerateThemes(numberOfThemes);
            Console.WriteLine("\nOdabrane teme:");
            foreach (Theme theme in listOfThemes)
            {
                Console.WriteLine(theme.Name);
            }
            #endregion

            #region Generiranje kategorija
            int numberOfCategories = rnd.GetNumber(1, 3);
            Console.WriteLine("\nBroj kategorija: " + numberOfCategories);

            List <string> listOfCategories = new List <string>();
            listOfCategories = GenerateCategories(numberOfCategories);
            Console.WriteLine("Odabrane kategorije:");
            foreach (string category in listOfCategories)
            {
                Console.WriteLine(category);
            }
            #endregion

            #region Generiranje natjecatelja
            int maxNumberOfCompetitors = (int)arguments.GetArgument("MaxCompetitorNumber");
            int numberOfCompetitors    = rnd.GetNumber(0, maxNumberOfCompetitors);
            Console.WriteLine("\nBroj natjecatelja: " + numberOfCompetitors);

            List <Competitor> listOfCompetitors = GenerateCompetitors(numberOfCompetitors);
            Console.WriteLine("\nNatjecatelji:");
            foreach (Competitor competitor in listOfCompetitors)
            {
                Console.WriteLine(competitor.Name);
            }
            #endregion

            #region Generiranje prijava
            int maxThemeNumberPerCompetitor         = (int)arguments.GetArgument("MaxThemeNumberPerCompetitor");
            int maxCategoryNumberPerCompetitor      = (int)arguments.GetArgument("MaxCategoryNumberPerCompetitor");
            List <Registration> listOfRegistrations = GenerateRegistrations(listOfCompetitors, maxThemeNumberPerCompetitor, maxCategoryNumberPerCompetitor, numberOfThemes, listOfThemes, numberOfCategories, listOfCategories);
            #endregion

            Competition competition = Competition.GetInstance();
            competition.UploadCompetitionData(listOfRegistrations, listOfThemes, listOfCategories, listOfCompetitors);
            Console.WriteLine("\nPrihvaćeno " + listOfRegistrations.Count.ToString() + " prijava");
        }
        public void Run()
        {
            ArgumentHandler arguments  = ArgumentHandler.GetInstance();
            string          resultFile = (string)arguments.GetArgument("ResultFile");

            Console.WriteLine(resultFile);
        }
Exemple #3
0
        /// <summary>
        /// Generira bodove ovisno o odabranom algoritmu bodovanja
        /// </summary>
        /// <param name="listOfRegistrations">Lista prijava</param>
        /// <param name="finalScores">Rječnik u koji se spremaju finalni bodovi</param>
        void GenerateFinalScores(List <Registration> listOfRegistrations, Dictionary <Registration, float> finalScores)
        {
            ArgumentHandler arguments    = ArgumentHandler.GetInstance();
            string          scoringClass = (string)arguments.GetArgument("ScoringClass");

            ScoringFactory scoringFactory;

            if (string.Equals(scoringClass, "SumAllScores"))
            {
                scoringFactory = new SumAllScoresFactory();
            }
            else if (string.Equals(scoringClass, "BalancedScoring"))
            {
                scoringFactory = new BalancedScoringFactory();
            }
            else
            {
                scoringFactory = new ScoreByAverageFactory();
            }

            ScoreAlgorhitm scoringAlgorhitm = scoringFactory.Create();

            Console.WriteLine("\n\nFinal Scores:");
            foreach (Registration registration in listOfRegistrations)
            {
                float finalScore = scoringAlgorhitm.GenerateScore(registration);
                finalScores[registration] = finalScore;
                Console.WriteLine(registration.ID + " od " + registration.Competitor.Name + ": " + finalScore.ToString());
                registration.FinalScore = finalScore;
            }
        }
Exemple #4
0
        public Deployer(ArgumentHandler argumentHandler)
        {
            var optionFile     = argumentHandler.GetArgument("px").Values[0];
            var deployerXmlDoc = new XmlDocument();

            deployerXmlDoc.Load(optionFile);
            var deployerNode = XmlHelper.GetUniqueNode(XmlNames.Deployer, deployerXmlDoc);

            /*
             * _projectRoot
             * 1. priority: command line argument -pr
             * 2. priority: projectRoot-attribute in profileXml: <deployer projectRoot="xxx">
             * 3. priority: auto-detect via PathToProfileXml (works if profile.xml is placed somewhere inside project tree)
             * else fail
             */
            _projectRoot = argumentHandler.GetArgument("pr")?.Values[0] ??
                           XmlHelper.GetOptionalAttr(XmlNames.ProjectRoot, deployerNode) ??
                           LocateProjectRoot(optionFile) ??
                           throw new LaravelProjectRootNotFoundException();

            /*
             * _projectName
             * 1. priority: command line argument -n
             * 2. priority: attribute "projectName" in <deployer> in profile.Xml
             * 3. priority: auto-detect via _profileRoot (use name of project folder as projectName)
             */
            _projectName = argumentHandler.GetArgument("pn")?.Values[0] ??
                           XmlHelper.GetOptionalAttr(XmlNames.ProjectName, deployerXmlDoc) ??
                           ExtractProjectName(_projectRoot);


            /*
             * _selectedProfileName
             * 1. priority: command line argument
             * 2. priority: attribute "defaultProfile" in <deployer> in profile.xml
             * 3. priority: if only one <profile> inside <deployer> than choose that
             * else fail
             */
            var profileList = XmlHelper.GetOneOrMoreNodes(XmlNames.Profile, deployerNode);

            var requestedProfileName = argumentHandler.GetArgument(ProfileName)?.Values[0] ??
                                       XmlHelper.GetOptionalAttr(XmlNames.DefaultProfile, deployerNode);

            if (requestedProfileName == null)
            {
                if (profileList.Count == 1)
                {
                    requestedProfileName = XmlHelper.GetAttr(XmlNames.ProfileName, profileList[0]);
                }
                else
                {
                    throw new Exception("No profile selected");
                }
            }

            XmlNode selectedProfileNode = null;

            foreach (XmlNode profileNode in profileList)
            {
                if (!XmlHelper.GetAttr(XmlNames.ProfileName, profileNode).Equals(requestedProfileName))
                {
                    continue;
                }
                selectedProfileNode = profileNode;
                break;
            }

            if (selectedProfileNode == null)
            {
                throw new RequestedProfileNodeNotFoundException(requestedProfileName);
            }
        }
Exemple #5
0
        /// <summary>
        /// Generira članove žiria
        /// </summary>
        /// <returns>Lista članova žiria</returns>
        List <Jury> GenerateJury()
        {
            ArgumentHandler arguments  = ArgumentHandler.GetInstance();
            int             juryNumber = (int)arguments.GetArgument("JuryNumber");

            #region Pronalazak direktorija s imenima i prezimenima
            string namesLocation    = DirectoryLocator.GetDirectory("Person Names", Directory.GetCurrentDirectory(), 0, 3);
            string surnamesLocation = DirectoryLocator.GetDirectory("Person Surnames", Directory.GetCurrentDirectory(), 0, 3);
            #endregion

            #region Učitavanje listi imena i perzimena
            List <string> listOfNames = new List <string>();
            string[]      files1      = Directory.GetFiles(namesLocation);
            foreach (string file in files1)
            {
                string[] lines = System.IO.File.ReadAllLines(file);

                foreach (string line in lines)
                {
                    string name = line;
                    if (listOfNames.Contains(name) || string.Equals(name, ""))
                    {
                        continue;
                    }
                    listOfNames.Add(name);
                }
            }

            List <string> listOfSurnames = new List <string>();
            string[]      files2         = Directory.GetFiles(surnamesLocation);
            foreach (string file in files2)
            {
                Console.WriteLine("Učitavam prezimena iz " + file);
                string[] lines = System.IO.File.ReadAllLines(file);

                foreach (string line in lines)
                {
                    string surname = line;
                    if (listOfSurnames.Contains(surname) || string.Equals(surname, ""))
                    {
                        continue;
                    }
                    listOfSurnames.Add(surname);
                }
            }
            #endregion

            #region Generiranje članova žiria
            List <Jury>   jury            = new List <Jury>();
            List <string> listOfJuryNames = new List <string>();
            Randomizer    rnd             = Randomizer.GetInstance();

            while (jury.Count < juryNumber)
            {
                int    nameIndex = rnd.GetNumber(0, listOfNames.Count);
                string name      = listOfNames[nameIndex];

                int    surnameIndex = rnd.GetNumber(0, listOfSurnames.Count);
                string surname      = listOfSurnames[surnameIndex];

                string juryMemberName = name + " " + surname;
                if (rnd.GetNumber(0, 7) == 4)
                {
                    int    secondSurnameIndex = rnd.GetNumber(0, listOfSurnames.Count);
                    string secondSurname      = listOfSurnames[secondSurnameIndex];
                    if (!string.Equals(surname, secondSurname))
                    {
                        juryMemberName = juryMemberName + "-" + secondSurname;
                    }
                }

                if (!listOfJuryNames.Contains(juryMemberName))
                {
                    listOfJuryNames.Add(juryMemberName);
                    Jury juryMember = new Jury(juryMemberName);
                    jury.Add(juryMember);
                }
            }
            #endregion

            #region Ispis članova žiria
            Console.WriteLine("\nČlanovi žiria:");
            foreach (Jury juryMember in jury)
            {
                Console.WriteLine(juryMember.Name);
            }
            #endregion
            return(jury);
        }
Exemple #6
0
        /// <summary>
        /// Funkcija koja proglašava pobjednike i stvara datoteku rezultata
        /// </summary>
        /// <param name="competition">Singleton natječaja iz kojeg se vuku podaci</param>
        void VictoryProclamation(Competition competition)
        {
            ArgumentHandler arguments         = ArgumentHandler.GetInstance();
            string          resultFileName    = (string)arguments.GetArgument("ResultFile");
            string          directoryLocation = DirectoryLocator.GetDirectory("Results", Directory.GetCurrentDirectory(), 0, 3);
            string          resultFile        = directoryLocation + "\\" + resultFileName;

            List <string>       listOfCategories    = competition.DownloadCategories();
            List <Theme>        listOfThemes        = competition.DownloadThemess();
            List <Registration> listOfRegistrations = competition.DownloadRegistrations();
            List <Competitor>   listOfCompetitors   = competition.DownloadCompetitors();

            using (StreamWriter sw = new StreamWriter(resultFile))
            {
                #region Pobjednici po temama unutar kategorija
                sw.WriteLine("Pobjednici po temama unutar kategorija".ToUpper());
                foreach (string category in listOfCategories)
                {
                    sw.WriteLine(Indent(0) + "KATEGORIJA " + category + ":");
                    foreach (Theme theme in listOfThemes)
                    {
                        sw.WriteLine(Indent(1) + "TEMA " + theme.Name + ":");
                        List <Registration>        disqualifiedRegistrations = new List <Registration>();
                        Dictionary <string, float> victoryCandidatesPerTheme = new Dictionary <string, float>();
                        foreach (Registration registration in listOfRegistrations)
                        {
                            if (!string.Equals(registration.Category, category) || !string.Equals(registration.Theme.Name, theme.Name))
                            {
                                continue;
                            }

                            if (registration.IsDisqualified())
                            {
                                disqualifiedRegistrations.Add(registration);
                                continue;
                            }

                            sw.Write(Indent(2) + "NATJECATELJ " + registration.Competitor.Name);
                            sw.Write(Indent(1) + registration.ID);
                            foreach (KeyValuePair <string, int> score in registration.GetAllScores())
                            {
                                sw.Write(Indent(1) + score.Key + ": " + score.Value.ToString());
                            }
                            sw.WriteLine(Indent(1) + "UKUPNO: " + registration.FinalScore.ToString());

                            victoryCandidatesPerTheme.Add(registration.Competitor.Name, registration.FinalScore);
                        }
                        Dictionary <string, float> victorsPerTheme = VictoryHandler.GetVictors(victoryCandidatesPerTheme);
                        Console.WriteLine("\nPobjednici u temi " + theme.Name + ", kategorija " + category + ": ");
                        foreach (KeyValuePair <string, float> score in victorsPerTheme)
                        {
                            Console.WriteLine(score.Key + ": " + score.Value.ToString());
                        }

                        sw.WriteLine(Indent(3) + "DISKVALIFICIRANE PRIJAVE");
                        foreach (Registration disqualifiedRegistration in disqualifiedRegistrations)
                        {
                            sw.Write(Indent(4) + disqualifiedRegistration.Competitor.Name);
                            sw.WriteLine(Indent(1) + disqualifiedRegistration.ID);
                        }
                    }
                }
                #endregion

                #region Pobjednici po kategorijama
                sw.WriteLine();
                sw.WriteLine("Pobjednici po kategorijama".ToUpper());
                foreach (string category in listOfCategories)
                {
                    sw.WriteLine(Indent(0) + "KATEGORIJA " + category + ":");
                    Dictionary <string, float> victoryCandidatesPerCategory = new Dictionary <string, float>();
                    foreach (Competitor competitor in listOfCompetitors)
                    {
                        sw.WriteLine();
                        sw.WriteLine(Indent(1) + "NATJECATELJ " + competitor.Name + ":");
                        float totalScore = 0;
                        foreach (Registration registration in listOfRegistrations)
                        {
                            if (registration.IsDisqualified() || !string.Equals(registration.Category, category) || !string.Equals(registration.Competitor.Name, competitor.Name))
                            {
                                continue;
                            }

                            sw.Write(Indent(2) + "TEMA " + registration.Theme.Name);
                            sw.Write(Indent(2) + "PRIJAVA " + registration.ID);
                            sw.WriteLine(Indent(2) + "UKUPNI BODOVI " + registration.GetFinalScore().ToString());
                            totalScore += registration.GetFinalScore();
                        }
                        sw.WriteLine(Indent(1) + "UKUPNI BODOVI SVIH PRIJAVA: " + totalScore.ToString());
                        victoryCandidatesPerCategory.Add(competitor.Name, totalScore);
                    }

                    Dictionary <string, float> victorsPerCategory = VictoryHandler.GetVictors(victoryCandidatesPerCategory);
                    Console.WriteLine("\nPobjednici u kategoriji " + category + ": ");
                    foreach (KeyValuePair <string, float> score in victorsPerCategory)
                    {
                        Console.WriteLine(score.Key + ": " + score.Value.ToString());
                    }
                }
                #endregion

                #region Ukupni pobjednik
                sw.WriteLine();
                sw.WriteLine("Ukupno".ToUpper());
                Dictionary <string, float> victoryCandidates = new Dictionary <string, float>();
                foreach (Competitor competitor in listOfCompetitors)
                {
                    sw.WriteLine();
                    sw.WriteLine(Indent(0) + "NATJECATELJ " + competitor.Name + ":");
                    float globalScore = 0;
                    foreach (string category in listOfCategories)
                    {
                        float totalScore = 0;
                        foreach (Registration registration in listOfRegistrations)
                        {
                            if (!registration.IsDisqualified() && string.Equals(registration.Category, category) && string.Equals(registration.Competitor.Name, competitor.Name))
                            {
                                totalScore += registration.GetFinalScore();
                            }
                        }

                        sw.Write(Indent(2) + category);
                        sw.WriteLine(Indent(2) + "UKUPNI BODOVI: " + totalScore.ToString());
                        globalScore += totalScore;
                    }
                    sw.WriteLine(Indent(1) + "UKUPNI BODOVI NATJECATELJA: " + globalScore.ToString());
                    victoryCandidates.Add(competitor.Name, globalScore);
                }

                Dictionary <string, float> victors = VictoryHandler.GetVictors(victoryCandidates);
                Console.WriteLine("\nUkupni pobjednici: ");
                foreach (KeyValuePair <string, float> score in victors)
                {
                    Console.WriteLine(score.Key + ": " + score.Value.ToString());
                }
                #endregion
            }
        }