Exemplo n.º 1
0
 public Song(string Title, string Artist, double Length, SongGenre Genre)
 {
     this.Title  = Title;
     this.Artist = Artist;
     this.Length = Length;
     this.Genre  = Genre;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates new instance of gaussian mixture specified for one music genre
 /// </summary>
 /// <param name="_genre">Genre which this object will be representing</param>
 /// <param name="_d">Number of distributions inside this object</param>
 /// <param name="count">Count of elements in this object</param>
 public multivariateGaussian(double _threshold, SongGenre _genre, int _d, int count)
 {
     threshold     = _threshold;
     genre         = _genre;
     d             = _d;
     ElementsCount = count;
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            //Console.WriteLine(new Song("Baby", "Justin Bebier", 3.35, SongGenre.Pop));

            Library.LoadSongs(@"D:\songs4.txt");
            Console.WriteLine("\n\nAll songs");
            Console.WriteLine("{0, -20}{1, -40}{2, -10}{3, -10}", "Artist", "Title", "Duration", "Genre");
            Console.WriteLine("======              =====                                   ========  =====");
            Library.DisplaySongs();

            SongGenre genre = SongGenre.Rock;

            Console.WriteLine("\n\n{0} songs", genre);
            Console.WriteLine("{0, -20}{1, -40}{2, -10}{3, -10}", "Artist", "Title", "Duration", "Genre");
            Console.WriteLine("======              =====                                   ========  =====");
            Library.DisplaySongs(genre);

            string artist = "Bob Dylan";

            Console.WriteLine("\n\nSongs by {0}", artist);
            Console.WriteLine("{0, -20}{1, -40}{2, -10}{3, -10}", "Artist", "Title", "Duration", "Genre");
            Console.WriteLine("======              =====                                   ========  =====");
            Library.DisplaySongs(artist);

            double length = 5.0;

            Console.WriteLine("\n\nSongs more than {0}mins", length);
            Console.WriteLine("{0, -20}{1, -40}{2, -10}{3, -10}", "Artist", "Title", "Duration", "Genre");
            Console.WriteLine("======              =====                                   ========  =====");
            Library.DisplaySongs(length);
        }
        private void genreInfoCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            SongGenre song = (SongGenre)genreInfoCombobox.SelectedIndex;

            UpdateGenreInfo(song);
            UpdateROCCurve(song);
        }
Exemplo n.º 5
0
 public Song(string title, string artist, double length, SongGenre genre)
 {
     Artist = artist;
     Title  = title;
     Lenght = length;
     Genre  = genre;
 }
Exemplo n.º 6
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(string[] selectedGenres)
        {
            var newSong = new Song();

            if (selectedGenres != null)
            {
                newSong.SongGenres = new List <SongGenre>();
                foreach (var gen in selectedGenres)
                {
                    var genToAdd = new SongGenre
                    {
                        GenreID = int.Parse(gen)
                    };
                    newSong.SongGenres.Add(genToAdd);
                }
            }
            if (await TryUpdateModelAsync <Song>(
                    newSong,
                    "Song",
                    i => i.Title, i => i.Album,
                    i => i.WeeksInTop40, i => i.FirstRelease, i => i.RecordLabelID, i => i.ArtistID))
            {
                _context.Song.Add(newSong);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            PopulateAssignedGenreData(_context, newSong);
            return(Page());
        }
        public async Task <ActionResult> QuestionsSubmit(Questions questions)
        {
            ClassMateFood classMateFood = new ClassMateFood();

            classMateFood.ClassMateId = questions.classmateid;
            classMateFood.FoodId      = questions.foodid;
            ClassMateVacation classMateVacation = new ClassMateVacation();

            classMateVacation.ClassMateId = questions.classmateid;
            classMateVacation.VacationId  = questions.vactionid;
            IdealSaturdayClassMate idealSaturdayClassMate = new IdealSaturdayClassMate();

            idealSaturdayClassMate.ClassMateId     = questions.classmateid;
            idealSaturdayClassMate.IdealSaturdayId = questions.idealsaturdayid;
            List <String> songGenres = await GetSpotifyGenreData(questions.songorartist);

            foreach (string genre in songGenres)
            {
                SongGenre songGenre = AddSongGenre(genre, questions.classmateid);
            }
            db.IdealSaturdayClassMates.Add(idealSaturdayClassMate);
            db.ClassMateVacations.Add(classMateVacation);
            db.ClassMateFoods.Add(classMateFood);
            db.SaveChanges();
            return(View("ThankYou"));
        }
        public async Task<IActionResult> PutSongGenre(int id, SongGenre songGenre)
        {
            if (id != songGenre.Id)
            {
                return BadRequest();
            }

            _context.Entry(songGenre).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SongGenreExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return NoContent();
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.WriteLine("[Sample Test]");
            Console.WriteLine(new Song("Baby", "Justin Bebier", 3.35, SongGenre.Pop));

            Console.WriteLine("\n-----------------------------------------------------------------------------------\n");

            // Read File
            Library.LoadSongs("songs4.txt");

            Console.WriteLine("[All songs]");
            Library.DisplaySongs();

            Console.WriteLine("\n-----------------------------------------------------------------------------------\n");

            Console.WriteLine("[List of Rocks]");
            SongGenre genre = SongGenre.Rock;

            Library.DisplaySongs(genre);

            Console.WriteLine("\n-----------------------------------------------------------------------------------\n");

            Console.WriteLine("[List of Bob Dylan's songs]");
            Library.DisplaySongs("Bob Dylan");

            Console.WriteLine("\n-----------------------------------------------------------------------------------\n");

            Console.WriteLine("[List of songs which has length longer than 5 mins length]");
            Library.DisplaySongs(5);
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            //To test the constructor and the ToString method
            Console.WriteLine(new Song("Baby", "Justin Bebier", 3.35, SongGenre.Pop));
            Console.WriteLine(new Song("The Promise", "Chris Cornell", 4.26, SongGenre.Country | SongGenre.Rock));

            Library.LoadSongs("Week_03_lab_09_songs4.txt");     //Class methods are invoke with the class name
            Console.WriteLine("\n\nAll songs");
            Library.DisplaySongs();

            SongGenre genre = SongGenre.Rock;

            Console.WriteLine($"\n\n{genre} songs");
            Library.DisplaySongs(genre);

            string artist = "Bob Dylan";

            Console.WriteLine($"\n\nSongs by {artist}");
            Library.DisplaySongs(artist);

            double length = 5.0;

            Console.WriteLine($"\n\nSongs more than {length}mins");
            Library.DisplaySongs(length);
        }
Exemplo n.º 11
0
 // CONSTRUCTOR
 public Song(string title, string artist, double length, SongGenre genre)
 {
     this.Title     = title;
     this.Artist    = artist;
     this.Length    = length;
     this.SongGenre = genre;
 }
Exemplo n.º 12
0
        public static void LoadSongs(string fileName)
        {
            using (TextReader reader = new StreamReader(fileName))
            {
                string    line = "", title = "", artist = "";
                double    length = 0;
                SongGenre genre  = SongGenre.Unclassified;
                while (line != null)
                {
                    title = reader.ReadLine();
                    if (title == null)
                    {
                        break;
                    }                           //reach end of txt.file gives "null" w dont convert to double/Enum & give err. So "break" before reaching conversion expression.
                    artist = reader.ReadLine();
                    length = Convert.ToDouble(reader.ReadLine());
                    //(SongGenre) casts "object" instance of Enum into a "SongGenre" type.!!! Enum.Parse converts string into an obj.
                    //we need to pass string representation of an Enum enumerated ABOVE under namespace>> reader returns string from txt file that is EXACTLY one of enumerated list.
                    genre = (SongGenre)Enum.Parse(typeof(SongGenre), reader.ReadLine());

                    songs.Add(new Song(title, artist, length, genre));
                }
                //int counter = 0;
                ////title = reader.ReadLine();
                ////artist = reader.ReadLine();
                ////length = reader.ReadLine();
                ////genre = reader.ReadLine();
                //while (line != null)
                //{

                //    for (int i = 0; i < 4; i++)
                //    {
                //        line = reader.ReadLine();
                //        counter++;
                //        if (line == null)
                //        { break; }
                //            switch (counter % 4)
                //            {
                //                case 1:
                //                    title = line;
                //                    break;
                //                case 2:
                //                    artist = line;
                //                    break;
                //                case 3:
                //                    length = Convert.ToDouble(line);
                //                    break;
                //                case 0:
                //                    genre = (SongGenre)Enum.Parse(typeof(SongGenre), line);
                //                    break;
                //                    //while() on top(NOT do-while) bcoz "null" cannot be converted into Enum in Case 0; & hence err.
                //            }

                //    }
                //    if (line == null)
                //    { break; }
                //    songs.Add(new Song(title, artist, length, genre));
                //}
            }
        }
Exemplo n.º 13
0
 public Song(string title, string artist, double length, SongGenre genre)
 {
     this.Title = title;
     this.Artist = artist;
     this.Length = length;
     this.Genre = genre;
 }
Exemplo n.º 14
0
        private void UpdateSongGenres(string[] selectedGenres, Song songToUpdate)
        {
            if (selectedGenres == null)
            {
                songToUpdate.SongGenres = new List <SongGenre>();
                return;
            }

            var selectedGenresHS = new HashSet <string>(selectedGenres);
            var songGenres       = new HashSet <int>
                                       (songToUpdate.SongGenres.Select(c => c.Genre.GenreID));

            foreach (var genre in repository.Genres())
            {
                if (selectedGenresHS.Contains(genre.GenreID.ToString()))
                {
                    if (!songGenres.Contains(genre.GenreID))
                    {
                        songToUpdate.SongGenres.Add(new SongGenre {
                            SongID = songToUpdate.SongID, GenreID = genre.GenreID
                        });
                    }
                }
                else
                {
                    if (songGenres.Contains(genre.GenreID))
                    {
                        SongGenre SongGenreToRemove = songToUpdate.SongGenres.FirstOrDefault(i => i.GenreID == genre.GenreID);
                        repository.DeleteSongGenre(SongGenreToRemove);
                    }
                }
            }
        }
Exemplo n.º 15
0
        private static ConfusionMatrixValidation TestClassificator(AbstractClassification classificator, bool printToStdout = false)
        {
            List <DataElement> dataSet = new List <DataElement>();

            using (Database db = new Database())
            {
                dataSet = db.GetElements();
            }

            classificator.Learn(dataSet);
            ConfusionMatrixValidation validator = new ConfusionMatrixValidation(classificator, dataSet, crossValidationSets);

            if (printToStdout)
            {
                Console.WriteLine($"Accuracy rate: {validator.AccuracyRate}");
                Console.WriteLine($"Correct: {validator.CorrectCount}");
                Console.WriteLine($"Errors: {validator.ErrorCount}");

                for (int i = 0; i < Enum.GetNames(typeof(SongGenre)).Length; i++)
                {
                    SongGenre genre = (SongGenre)i;
                    Console.WriteLine("------------");
                    Console.WriteLine(genre.ToString().ToUpper());
                    Console.WriteLine("------------");
                    Console.WriteLine($"ROC > True Positive rate: {validator.TPRate(genre)}");
                    Console.WriteLine($"ROC > False Positive rate: {validator.FPRate(genre)}");
                    Console.WriteLine($"True positive: {validator.TP(genre)}");
                    Console.WriteLine($"True negative: {validator.TN(genre)}");
                    Console.WriteLine($"False positive: {validator.FP(genre)}");
                    Console.WriteLine($"False negative: {validator.FN(genre)}");
                }
            }
            return(validator);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Creates new song instance
 /// </summary>
 /// <param name="filePath">Genre of the song</param>
 /// <param name="label">Genre of the song</param>
 /// <param name="meanVector">Mean vector of song features</param>
 /// <param name="mfccCoefficients">MFCC coefficients of song</param>
 /// <param name="covarianceMatrix">Covariancematrix of song features</param>
 public DataElement(string filePath, SongGenre label, double[] meanVector, double[][] mfccCoefficients, double[,] covarianceMatrix)
 {
     FilePath         = filePath;
     _label           = label;
     MeanVector       = meanVector;
     MfccCoefficients = mfccCoefficients;
     CovarianceMatrix = covarianceMatrix;
 }
Exemplo n.º 17
0
 public static void DisplaySongs(SongGenre genre)
 {
     for (int i = 0; i < songs.Count; i++){
         if (songs[i].Genre == genre){
             Console.WriteLine(songs[i]);
         }
     }
 }
Exemplo n.º 18
0
        public ViewResult RemoveSongGenre(int?id)
        {
            SongGenre sg = repository.SongGenres().Single(a => a.SongGenreID == id);

            repository.DeleteSongGenre(sg);
            repository.SaveContext();

            return(View());
        }
Exemplo n.º 19
0
 public static void DisplaySongs(SongGenre genre)
 {
     foreach (Song x in songs)
     {
         if (x.Genre == genre)
         {
             Console.WriteLine(x);
         }
     }
 }
Exemplo n.º 20
0
 public static void DisplaySongs(SongGenre genre)
 {
     for (int i = 0; i < songs.Count; i++)
     {
         if (songs[i].Genre == genre)
         {
             Console.WriteLine(songs[i]);
         }
     }
 }
Exemplo n.º 21
0
 public static void DisplaySongs(SongGenre genre)
 {
     foreach (Song song in songs)
     {
         if (song.Genre == genre)
         {
             Console.WriteLine($"{song.Title} by {song.Artist} ({song.Genre}) {song.Length}min");
         }
     }
 }
Exemplo n.º 22
0
 public static void DisplaySongs(SongGenre Genre)
 {
     foreach (Song s in songs)
     {
         if (s.Genre == Genre)
         {
             Console.WriteLine(s);
         }
     }
 }
Exemplo n.º 23
0
        /// <summary>
        /// Counts sum of fun(SongGenre song, int cvTets) results for each cvTest
        /// </summary>
        /// <returns>Sum of fun for each cvTest: [0, cvCount]</returns>
        private int CountSumForEachCvTest(Func <SongGenre, int, int> fun, SongGenre song)
        {
            int sum = 0;

            for (int i = 0; i < cvCount; i++)
            {
                sum += fun(song, i);
            }
            return(sum);
        }
Exemplo n.º 24
0
        public void UpdateSongGenre(int id, SongGenre updatedSongGenre)
        {
            var songGenre = SongGenres.SingleOrDefault(x => x.Id == id);

            if (songGenre != null)
            {
                songGenre.Name = updatedSongGenre.Name;
            }
            this.SaveChanges();
        }
Exemplo n.º 25
0
        public IActionResult Edit(int id)
        {
            SongGenre genreFromDb = _context.GetSongGenre(id);

            SongGenreEditViewModel vm = new SongGenreEditViewModel()
            {
                Name = genreFromDb.Name
            };

            return(View(vm));
        }
        // GET: SongGenres/Details/{id}
        public ActionResult Details(int id)
        {
            SongGenre songGenre = null;

            using (var context = new ApplicationDbContext())
            {
                songGenre = context.SongGenres.Find(id);
            }

            return(View(songGenre));
        }
Exemplo n.º 27
0
 /// <summary>
 /// Gets count of songs of all crossvalidation tests
 /// </summary>
 /// <param name="source">Real genre of song</param>
 /// <param name="dest">Computed genre of song</param>
 /// <returns></returns>
 public int this[SongGenre source, SongGenre dest]
 {
     get
     {
         int sum = 0;
         for (int i = 0; i < cvCount; i++)
         {
             sum += this[i, source, dest].Count;
         }
         return(sum);
     }
 }
Exemplo n.º 28
0
 private List <DataElement> this[int cvTest, SongGenre source, SongGenre dest]
 {
     get
     {
         int src = (int)source;
         int dst = (int)dest;
         if (_confusionMatrix[cvTest, src, dst] == null)
         {
             _confusionMatrix[cvTest, src, dst] = new List <DataElement>();
         }
         return(_confusionMatrix[cvTest, src, dst]);
     }
 }
Exemplo n.º 29
0
        public IActionResult Delete(int id)
        {
            SongGenre genreFromDb = _context.GetSongGenre(id);


            SongGenreDeleteViewModel genreToDelete = new SongGenreDeleteViewModel()
            {
                Id   = id,
                Name = genreFromDb.Name
            };

            return(View(genreToDelete));
        }
Exemplo n.º 30
0
 private void ComputeMatrix()
 {
     for (int test = 0; test < cvCount; test++)
     {
         var dataSet = crossValidator[test];
         _classificator.Learn(dataSet.TrainingSet);
         for (int i = 0; i < dataSet.TestingSet.Count; i++)
         {
             var       data     = dataSet.TestingSet[i];
             SongGenre outGenre = _classificator.GetClass(data);
             this[test, data.Label, outGenre].Add(data);
         }
     }
 }
        public ActionResult Create([Bind(Include = "Id,Name")] SongGenre songGenre)
        {
            using (var context = new ApplicationDbContext()) {
                context.SongGenres.Add(songGenre);

                // Commit to database
                context.SaveChanges();
            }

            // Add id to ViewBag in order to display it into the view
            //ViewBag.InsertedId = songGenre.Id;

            return(RedirectToAction("Index"));
        }
Exemplo n.º 32
0
        private int FN(SongGenre song, int cvTest)
        {
            int songInd = (int)song;
            int sum     = 0;

            for (int i = 0; i < SongsCount; i++)
            {
                if (i != songInd)
                {
                    sum += this[cvTest, song, (SongGenre)i].Count;
                }
            }
            return(sum);
        }