public void RunMainProcess()
        {
            LanguageDomainReport firstReport  = new LanguageDomainReport();
            LanguagePageReport   secondReport = new LanguagePageReport();
            string targetFile;

            DateTime endPeriod   = StartPeriod.AddDays(this.DaysNumber * Config.OperatorBackDays);
            DateTime startPeriod = StartPeriod;

            string directoryPath = FileData.GetDataPath(startPeriod);

            PageViewsRawData pageViewData = new PageViewsRawData(GZip, FileData, this.DaysNumber);

            pageViewData.DownloadAllPeriodsData(startPeriod, endPeriod, directoryPath);
            pageViewData.DecompressData(directoryPath);

            CollectionsData processData = new CollectionsData(domainData);

            startPeriod = StartPeriod;
            //Process each file (period) and get the ressults
            do
            {
                FileData.SetConfigurationByPeriod(startPeriod, directoryPath);
                targetFile = FileData.GetTargetFileNoExt();

                //for free memory related to last analysis
                using (FileReader fr = new FileReader(targetFile))
                {
                    Console.WriteLine(string.Concat("Processing data in file ", targetFile, "..."));

                    //container of data to analyze
                    PageViewCollection periodCollection = fr.GetDataToCollection();

                    //First report
                    Console.WriteLine("\tProcessing language and domain data for period " + startPeriod.ToShortDateString());
                    LanguageDomain languageDomain = processData.GetLanguageAndDomainCount(periodCollection);
                    languageDomain.Period = startPeriod;
                    firstReport.AddLanguageDomain(languageDomain);

                    //Second report
                    LanguagePage languagePage = processData.GetLanguagePageCount(periodCollection);
                    Console.WriteLine("\tProcessing language page data for period " + startPeriod.ToShortDateString());
                    languagePage.Period = startPeriod;
                    secondReport.AddLanguagePage(languagePage);
                }

                startPeriod = startPeriod.AddDays(Config.OperatorBackDays);
            }while (startPeriod.CompareTo(endPeriod) != 0);


            //Report the results
            Console.Clear();

            ConsoleReport.DisplayLanguageDomainCount(firstReport);
            ConsoleReport.DisplayLanguagePageMaxCount(secondReport);
        }
        public LanguagePage GetLanguagePageCount(PageViewCollection periodCollection)
        {
            LanguagePage report = new LanguagePage();

            var entry = periodCollection.Data.Where(e => e.ViewCount > 0)
                        .GroupBy(x => x.PageTitle)
                        .Select(y => new PageViewEntry
            {
                PageTitle = y.Key,
                ViewCount = Convert.ToUInt32(y.Sum(s => s.ViewCount)),
            })
                        .OrderByDescending(x => x.ViewCount)
                        .FirstOrDefault();

            report.Page      = entry.PageTitle; //page tittle
            report.ViewCount = entry.ViewCount;

            return(report);
        }
Esempio n. 3
0
        public PageViewCollection GetDataToCollection()
        {
            this.fileData = new PageViewCollection();
            Console.WriteLine(string.Concat("Reading file ", targetFileNoExt, "..."));

            using (FileStream fs = File.Open(targetFileNoExt, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (BufferedStream bs = new BufferedStream(fs))
                    using (StreamReader sr = new StreamReader(bs))
                    {
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            //TODO: can optimize memory usage, by injecting the logix line by line
                            fileData.AddPageView(GetEntry(line));
                        }
                    }

            return(fileData);
        }
        public LanguageDomain GetLanguageAndDomainCount(PageViewCollection periodCollection)
        {
            LanguageDomain report = new LanguageDomain();

            var entry = periodCollection.Data.Where(e => e.ViewCount > 0)
                        .GroupBy(x => x.DomainCode)
                        .Select(y => new PageViewEntry
            {
                DomainCode = y.Key,
                ViewCount  = Convert.ToUInt32(y.Sum(s => s.ViewCount)),
            })
                        .OrderByDescending(x => x.ViewCount)
                        .FirstOrDefault();

            report.Domain       = domainData.GetDomainNameByCode(entry.DomainCode); //domain
            report.LanguageCode = domainData.GetLanguage(entry.DomainCode);         //language from domain
            report.ViewCount    = entry.ViewCount;

            return(report);
        }