public void LoadFile_ValidFile_Success()
        {
            IDataLoader dataLoader = new CSVDataLoader();
            var         result     = dataLoader.Load(".\\IntegrationTests\\Repository\\Test.csv");

            Assert.Equal(3, result.Length);
        }
        public BookDetails GetBookDetails()
        {
            IDataCacher dataCacher = new MemDataCacher();

            if (dataCacher.GetData() == null)
            {
                IDataLoader dataLoader  = new CSVDataLoader();
                BookDetails bookDetails = new BookDetails();
                bookDetails = dataLoader.Load();
                dataCacher.SetData(bookDetails);
                return(bookDetails);
            }
            else
            {
                return(dataCacher.GetData());
            }
        }
        public List <Book> Recommend(Preference preference, int limit)
        {
            BooksDataService            dataService = new BooksDataService();
            Dictionary <string, double> pairs       = new Dictionary <string, double>();
            List <Book> books       = new List <Book>();
            IDataLoader dataLoader  = new CSVDataLoader();
            BookDetails bookDetails = new BookDetails();

            bookDetails = dataService.GetBookDetails();
            Dictionary <string, List <long> > keyValuePairs = new Dictionary <string, List <long> >();
            IRatingAggregator aggregator = new RatingAggregatorClass();

            keyValuePairs = aggregator.Aggregate(bookDetails, preference);
            IRecommender recommender = new PearsonRecommender();
            List <long>  baseData    = new List <long>();

            foreach (BookUserRating rating in bookDetails.bookUserRatings)
            {
                if (string.Compare(rating.ISBN, preference.ISBN) == 0)
                {
                    baseData.Add(rating.BookRating);
                }
            }
            foreach (var keyValue in keyValuePairs)
            {
                double corValue = recommender.GetCorrelation(baseData, keyValue.Value);
                pairs.Add(keyValue.Key, corValue);
            }
            pairs = pairs.OrderByDescending(pair => pair.Value).ToDictionary(pair => pair.Key, pair => pair.Value);
            int count = 0;

            foreach (var item in pairs)
            {
                if (count == limit)
                {
                    break;
                }
                count++;
                books.Add(bookDetails.books.Find(b => b.ISBN == item.Key));
            }
            return(books);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            try
            {
                IDataLoader   dataLoader   = new CSVDataLoader(); //note, we dould implement different data loaders e.g. google sheets data loader.
                IStatsService statsService = new StatsService();

                //note for simplicity we are not using a service locator for example.
                IAssignmentService assignment = new AssignmentService(dataLoader, statsService);
                assignment.DoAssignment("SampleData.csv");
            }
            catch (ArgumentException argEx)
            {
                Console.WriteLine("Invalid argument");
                Console.WriteLine(argEx.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine("exceptions occured while running the program");
                Console.WriteLine(ex.ToString());
            }

            Console.ReadLine();
        }
        public void LoadFile_FileNotExists_ArgumentException()
        {
            IDataLoader dataLoader = new CSVDataLoader();

            Assert.Throws <ArgumentException>(() => dataLoader.Load(".\\IntegrationTests\\Repository\\DoesNotExists.csv"));
        }
        static void Main(string[] args)
        {
            CSVDataLoader load = new CSVDataLoader();

            load.Load();
        }