Beispiel #1
0
        public Form1()
        {
            InitializeComponent();
            UserIdList = new List <int>();
            List <KeyValuePair <SqlParameter, string> > UserParameters = new List <KeyValuePair <SqlParameter, string> >();

            //UserParameters.Add(GetUserIDKVP());

            DataTable UserDt = SQL.GetData("SELECT * FROM [dbo].[User] ", UserParameters);

            foreach (DataRow dr in UserDt.Rows)
            {
                int x = 0;
                if (Int32.TryParse(dr["UserId"].ToString(), out x))
                {
                    UserIdList.Add(x);
                }
            }

            double ContentTotal = 0; double PopularityTotal = 0; double HybridTotal = 0; int UserTotal = 0;

            foreach (int user in UserIdList)
            {
                DataTable dt        = SQL.GetData(String.Concat("SELECT uv.VideoId, v.VideoName FROM UserVideo AS uv JOIN Video AS v ON uv.VideoId = v.VideoId Where UserId = ", user, "AND ViewDate <= Convert(date, '", this.HalfDate, "')"), new List <KeyValuePair <SqlParameter, string> >());
                DataTable unwatched = SQL.GetData(String.Concat("SELECT VideoId, VideoName, AverageWatchTime, PercentageLiked FROM Video WHERE VideoId Not In ( SELECT VideoId FROM UserVideo Where UserId =  ", user, ")"), new List <KeyValuePair <SqlParameter, string> >());
                if (dt.Rows.Count > 0)
                {
                    content          = new Content(user, HalfDate, dt, unwatched);
                    ContentTotal    += TestAccuracy(this.AccStartDate, user, content.GetRecommendedVideos(10));
                    pop              = new Popularity(unwatched);
                    PopularityTotal += TestAccuracy(this.AccStartDate, user, pop.GetRecommendedVideos(10));
                    hybrid           = new Hybrid(content.GetRecommendedVideos());
                    HybridTotal     += TestAccuracy(this.AccStartDate, user, hybrid.GetRecommendedVideos(10));
                    UserTotal       += 1;
                }
            }

            ContentTotal           = ContentTotal / UserTotal;
            PopularityTotal        = PopularityTotal / UserTotal;
            HybridTotal            = HybridTotal / UserTotal;
            lblContentValue.Text   = String.Concat(ContentTotal, "%");
            lblPoplarityValue.Text = String.Concat(PopularityTotal, "%");
            lblHybridValue.Text    = String.Concat(HybridTotal, "%");
        }
Beispiel #2
0
        public Form1()
        {
            InitializeComponent();
            UserIdList   = new List <int>();
            PreRecVideos = new List <int>();

            List <KeyValuePair <SqlParameter, string> > UserParameters = new List <KeyValuePair <SqlParameter, string> >();

            //UserParameters.Add(GetUserIDKVP());

            DataTable UserDt = SQL.GetData("SELECT * FROM [dbo].[User] ", UserParameters);

            foreach (DataRow dr in UserDt.Rows)
            {
                int x = 0;
                if (Int32.TryParse(dr["UserId"].ToString(), out x))
                {
                    UserIdList.Add(x);
                }
            }

            double ContentTotal = 0; double PopularityTotal = 0; double HybridTotal = 0; int UserTotal = 0;

            foreach (int user in UserIdList)
            {
                DataTable dt = SQL.GetData(String.Concat("SELECT TOP 25 uv.VideoId, v.VideoName, uv.ViewDate FROM UserVideo AS uv JOIN Video AS v ON uv.VideoId = v.VideoId Where UserId = ", user, "Order By ViewDate ASC"), new List <KeyValuePair <SqlParameter, string> >());

                if (dt.Rows.Count > 0 && user == 2)
                {
                    StringBuilder sb = new StringBuilder("VideoId NOT IN (");
                    foreach (DataRow dr in dt.Rows)
                    {
                        int vid = 0;
                        Int32.TryParse(dr["VideoId"].ToString(), out vid);
                        PreRecVideos.Add(vid);
                        sb.Append(vid);
                        sb.Append(",");
                    }
                    sb.Length--;
                    sb.Append(")");

                    int    recNumber = 10;
                    object md        = dt.Compute("MAX(ViewDate)", null);


                    DataTable unwatched = SQL.GetData(String.Concat("SELECT VideoId, VideoName, AverageWatchTime, PercentageLiked FROM Video WHERE ", sb.ToString()), new List <KeyValuePair <SqlParameter, string> >());
                    if (dt.Rows.Count > 0 && user == 2)
                    {
                        content = new Content(user, HalfDate, dt, unwatched);
                        UpdateLabelRec(lblContentRec, content.GetRecommendedVideos(recNumber));
                        ContentTotal += TestAccuracy(this.AccStartDate, user, content.GetRecommendedVideos(recNumber), sb.ToString(), md);
                        pop           = new Popularity(unwatched);
                        UpdateLabelRec(lblPopularityRec, pop.GetRecommendedVideos(recNumber));

                        PopularityTotal += TestAccuracy(this.AccStartDate, user, pop.GetRecommendedVideos(recNumber), sb.ToString(), md);
                        hybrid           = new Hybrid(content.GetRecommendedVideos());
                        UpdateLabelRec(lblHybridRec, hybrid.GetRecommendedVideos(recNumber));

                        HybridTotal += TestAccuracy(this.AccStartDate, user, hybrid.GetRecommendedVideos(recNumber), sb.ToString(), md);
                        UserTotal   += 1;
                    }
                }
            }

            //ContentTotal = ContentTotal / UserTotal;
            //PopularityTotal = PopularityTotal / UserTotal;
            //HybridTotal = HybridTotal / UserTotal;
            lblContentValue.Text   = String.Concat(ContentTotal, "%");
            lblPoplarityValue.Text = String.Concat(PopularityTotal, "%");
            lblHybridValue.Text    = String.Concat(HybridTotal, "%");
        }