Beispiel #1
0
        public static double HistogramConv(SongProfile sp1, SongProfile sp2, double step)
        {
            var ans    = new List <double>();
            var interm = new List <double>();

            List <double> avg1_smoothed = new List <double>(), avg2_smoothed = new List <double>();

            for (int i = 0; i < sp1.fft_smoothed_snaps.Count; i++)
            {
                avg1_smoothed.Add(sp1.fft_smoothed_snaps[i].Average());
                avg2_smoothed.Add(sp2.fft_smoothed_snaps[i].Average());
            }

            for (int i = 0; i < sp1.fft_smoothed_snaps.Count; i++)
            {
                for (int j = 0; j < sp2.fft_smoothed_snaps.Count; j++)
                {
                    interm.Add(Utility.Correl(sp1.fft_smoothed_snaps[i], sp2.fft_smoothed_snaps[j], avg1_smoothed[i], avg2_smoothed[j]));
                }
            }

            for (double k = -1; k <= 1; k += step)
            {
                ans.Add((double)interm.Count(t => (t > k - step) && (t <= k)) / (double)interm.Count);
            }

            double s = 0;

            for (int i = 0; i < ans.Count; i++)
            {
                s += ans[i] * ((double)(i) - 1 / step);
            }

            return(s * step);
        }
Beispiel #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(
                    this,
                    "Are you sure want to (re)create the database?",
                    "HOLO",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }

            listBox1.Items.Clear();

            var fll = MakeFilesList(textBox1.Text);
            var fl  = fll.OrderBy(t => Path.GetFileName(t).Length.ToString()).ToList();

            listBox1.Items.Add("Found files: " + fl.Count);
            using (var db = new SQLiteConnection())
            {
                try
                {
                    db.ConnectionString = GetConnectionString(tbDBName.Text);
                    db.Open();
                    Database.Create(db);
                }
                catch
                {
                    MessageBox.Show("Something has gone wrong with the database");
                    return;
                }

                int s_count = 0;

                PB1.Maximum = fl.Count;
                PB1.Minimum = 0;

                foreach (var f in fl)
                {
                    try
                    {
                        if (s_count % 50 == 0)
                        {
                            listBox1.Items.Clear();
                            listBox1.Items.Add("Items done: " + s_count + " of " + fl.Count);
                        }

                        var songProfile = new SongProfile(Path.GetFileName(f), f);
                        if (!songProfile.MakeSnaps((int)nUD2.Value, (int)nUD.Value, f))
                        {
                            listBox1.Items.Add("![" + s_count + "]! Cannot make snapshots for " + songProfile.Path);
                            s_count++;
                            continue;
                        }

                        songProfile.MakeDownscaledSnaps((int)nUD4.Value);

                        listBox1.Items.Add("[" + s_count + "] " + songProfile.Name);

                        Database.SaveSongProfile(db, s_count, songProfile);

                        PB1.Value = s_count;
                        Application.DoEvents();
                        s_count++;
                    }
                    catch
                    {
                        continue;
                    }
                }
            }

            DBPostProcess(tbDBName.Text);
        }
Beispiel #3
0
        public static void SaveSongProfile(SQLiteConnection db, int id, SongProfile songProfile)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }
            if (songProfile == null)
            {
                throw new ArgumentNullException("songProfile");
            }

            var d = songProfile.CalcAllStats();

            var myparam1 = new SQLiteParameter("@id");
            var myparam2 = new SQLiteParameter("@name");
            var myparam3 = new SQLiteParameter("@path");

            var myparam2_1 = new SQLiteParameter("@id");
            var myparam2_2 = new SQLiteParameter("@statname");
            var myparam2_3 = new SQLiteParameter("@statparam1");
            var myparam2_4 = new SQLiteParameter("@statparam2");
            var myparam2_5 = new SQLiteParameter("@statvalue");

            using (var cmd = db.CreateCommand())
            {
                cmd.CommandText = "BEGIN TRANSACTION;";
                cmd.ExecuteNonQuery();

                foreach (var di in d)
                {
                    cmd.CommandText = "INSERT INTO STATS VALUES (@id, @statname, @statparam1, @statparam2, @statvalue);";

                    myparam2_1.Value = id;
                    myparam2_2.Value = di.Key;
                    myparam2_3.Value = 0;
                    myparam2_4.Value = 0;
                    myparam2_5.Value = di.Value;

                    cmd.Parameters.Clear();
                    cmd.Parameters.Add(myparam2_1);
                    cmd.Parameters.Add(myparam2_2);
                    cmd.Parameters.Add(myparam2_3);
                    cmd.Parameters.Add(myparam2_4);
                    cmd.Parameters.Add(myparam2_5);
                    cmd.ExecuteNonQuery();
                }

                cmd.CommandText = "INSERT INTO MAIN VALUES (@id, @name, @path);";

                myparam1.Value = id;
                myparam2.Value = songProfile.Name;
                myparam3.Value = songProfile.Path;

                cmd.Parameters.Clear();
                cmd.Parameters.Add(myparam1);
                cmd.Parameters.Add(myparam2);
                cmd.Parameters.Add(myparam3);
                cmd.ExecuteNonQuery();

                cmd.CommandText = "COMMIT;";
                cmd.ExecuteNonQuery();
            }
        }