예제 #1
0
        public void Run()
        {
            ArgumentHandler arguments  = ArgumentHandler.GetInstance();
            string          resultFile = (string)arguments.GetArgument("ResultFile");

            Console.WriteLine(resultFile);
        }
예제 #2
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;
            }
        }
예제 #3
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");
        }
예제 #4
0
        /// <summary>
        /// Ova funkcija učitava argumente iz komandne linije
        /// </summary>
        /// <param name="args">Polje argumenata</param>
        /// <returns>True ako je sve dobro učitano, inače False</returns>
        public static bool ReadArgs(string[] args)
        {
            ArgumentHandler arguments = ArgumentHandler.GetInstance();

            try
            {
                if (args.Length < 8)
                {
                    Console.WriteLine("Nisu upisani svi argumenti!");
                    return(false);
                }

                #region  Učitaj generator slučajnog broja
                int randomSeed = Int32.Parse(args[0]);
                if (randomSeed < 100)
                {
                    Console.WriteLine("Generator slučajnog broja mora imati bar 3 znamenke!");
                    return(false);
                }
                arguments.AddArgument("RandomSeed", "int", randomSeed, true);
                #endregion

                #region  Učitaj maksimalni broj tema
                int maxThemeNumber = Int32.Parse(args[1]);
                if (maxThemeNumber <= 0 || maxThemeNumber > 10)
                {
                    Console.WriteLine("Maksimalni broj tema mora biti u rangu 1-10!");
                    return(false);
                }
                arguments.AddArgument("MaxThemeNumber", "int", maxThemeNumber, true);
                #endregion

                #region Učitaj maksimalni broj tema po natjecatelju
                int maxThemeNumberPerCompetitor = Int32.Parse(args[2]);
                if (maxThemeNumberPerCompetitor <= 0 || maxThemeNumberPerCompetitor > maxThemeNumber)
                {
                    Console.WriteLine("Maksimalni broj tema po natjecatelju mora biti veći od 0 i manji ili jedna maksimalnom broju tema!");
                    return(false);
                }
                arguments.AddArgument("MaxThemeNumberPerCompetitor", "int", maxThemeNumberPerCompetitor, true);
                #endregion

                #region  Učitaj maksimalni broj kategorija po natjecatelju
                int maxCategoryNumberPerCompetitor = Int32.Parse(args[3]);
                if (maxCategoryNumberPerCompetitor <= 0 || maxCategoryNumberPerCompetitor > 3)
                {
                    Console.WriteLine("Maksimalni broj kategorija po natjecatelju mora biti u rangu 1-3!");
                    return(false);
                }
                arguments.AddArgument("MaxCategoryNumberPerCompetitor", "int", maxCategoryNumberPerCompetitor, true);
                #endregion

                #region  Učitaj maksimalni broj natjecatelja
                int maxCompetitorNumber = Int32.Parse(args[4]);
                if (maxCompetitorNumber < 0)
                {
                    Console.WriteLine("Maksimalni broj natjecatelja ne smije biti manji od 0");
                    return(false);
                }
                arguments.AddArgument("MaxCompetitorNumber", "int", maxCompetitorNumber, true);
                #endregion

                #region  Učitaj broj članova žiria
                int juryNumber = Int32.Parse(args[5]);
                if (maxCompetitorNumber <= 0)
                {
                    Console.WriteLine("Maksimalni broj kategorija po natjecatelju mora biti veći od 0!");
                    return(false);
                }
                arguments.AddArgument("JuryNumber", "int", juryNumber, true);
                #endregion

                #region  Učitaj naziv klase bodovanja
                string scoringClass = args[6];
                arguments.AddArgument("ScoringClass", "string", scoringClass, true);
                #endregion

                #region učitaj naziv datoteke u koju se spremaju svi rezultati i tablice bodova
                string resultFile = args[7];
                arguments.AddArgument("ResultFile", "string", resultFile, true);
                #endregion
            }
            catch
            {
                Console.WriteLine("Došlo je do nepoznate pogreške");
                return(false);
            }

            return(true);
        }
예제 #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);
        }
예제 #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
            }
        }