Exemple #1
0
        public GraphStats articleTraffic([FromBody] trafficInput input)
        {
            ArticleController use     = new ArticleController();
            user_traffic      traffic = new user_traffic();
            GraphStats        total   = new GraphStats()
            {
                dateTime = "", sessions = "", earned = 0
            };

            traffic.non_premium = 0;
            traffic.premium     = 0;

            get_admin_gid_Result res;
            DateTime             join;

            using (var data = db.get_joining_date(input.id))
            {
                join = data.FirstOrDefault <get_joining_date_Result>().date;
            }
            using (var data = db.get_admin_gid(input.site_url))
            {
                res = data.FirstOrDefault <get_admin_gid_Result>();
            }

            Authorization auth = new Authorization(res.Email);

            var result  = auth.service.Data.Ga.Get("ga:" + res.ga_id, use.convertDate(join), use.convertDate(System.DateTime.Now), input.session);
            var result1 = auth.service.Data.Ga.Get("ga:" + res.ga_id, use.convertDate(join), use.convertDate(System.DateTime.Now), input.session);

            result.Filters  = "ga:landingPagePath=@" + use.convertUrl(input.url, input.site_url) + ";ga:campaign=@" + input.uid + ";ga:medium=@referral";
            result1.Filters = "ga:landingPagePath=@" + use.convertUrl(input.url, input.site_url) + ";ga:campaign=@" + input.uid + ";ga:medium=@referral;ga:country=@Canada";
            try
            {
                var session_result  = result.Execute();
                var session_result1 = result1.Execute();
                int count           = (int)session_result.TotalResults;
                if (count != 0)
                {
                    IList <string> l = session_result.Rows[0];
                    traffic.non_premium = traffic.non_premium + long.Parse(l[0]);
                }
                traffic.non_premium = traffic.non_premium + 0;
                int count2 = (int)session_result1.TotalResults;
                if (count2 != 0)
                {
                    IList <string> lp = session_result1.Rows[0];
                    traffic.premium = traffic.premium + long.Parse(lp[0]);
                }
                traffic.premium = traffic.premium + 0;

                traffic.non_premium = traffic.non_premium - traffic.premium;

                total.earned   = total.earned + GetEarned(traffic.premium.ToString(), "premium") + GetEarned(traffic.non_premium.ToString(), "non-premium");
                total.sessions = (traffic.premium + traffic.non_premium).ToString();
            }catch (Exception e)
            {
            }
            return(total);
        }
        public GraphStats admin_gid(string url, DateTime publishDate, string a_url, string username)
        {
            RateController rate   = new RateController();
            user_earned    earned = new user_earned()
            {
                premium = 0, non_premium = 0
            };
            get_admin_gid_Result res;
            user_traffic         traffic = new user_traffic()
            {
                premium = 0, non_premium = 0
            };

            using (var data = db.get_admin_gid(url))
            {
                res = data.FirstOrDefault <get_admin_gid_Result>();
            }
            Authorization auth   = new Authorization(res.Email);
            var           result = auth.service.Data.Ga.Get(("ga:" + res.ga_id), convertDate(publishDate), convertDate(System.DateTime.Now), "ga:sessions");

            result.Filters = "ga:landingPagePath=@" + convertUrl(a_url, url) + ";ga:campaign=@" + username;
            var result1 = auth.service.Data.Ga.Get(("ga:" + res.ga_id), convertDate(publishDate), convertDate(System.DateTime.Now), "ga:sessions");

            result1.Filters = "ga:landingPagePath=@" + convertUrl(a_url, url) + ";ga:campaign=@" + username + ";ga:country=@Canada";
            try
            {
                var final1 = result1.Execute();
                var final  = result.Execute();
                int count  = (int)final.TotalResults;
                int count1 = (int)final1.TotalResults;
                if (count1 != 0)
                {
                    IList <string> l = final1.Rows[0];
                    traffic.premium += long.Parse(l[0]);
                }
                if (count != 0)
                {
                    IList <string> l = final.Rows[0];
                    traffic.non_premium += long.Parse(l[0]);
                }
                traffic.non_premium = traffic.non_premium - traffic.premium;

                earned.premium     = (Decimal.ToDouble(rate.GetRate("premium").FirstOrDefault <get_rate_Result>().rate) * traffic.premium) / 1000;
                earned.non_premium = (Decimal.ToDouble(rate.GetRate("non-premium").FirstOrDefault <get_rate_Result>().rate) * traffic.non_premium) / 1000;
            }catch (Exception E)
            {
            }
            return(new GraphStats()
            {
                dateTime = "", sessions = (traffic.premium + traffic.non_premium).ToString(), earned = earned.premium + earned.non_premium
            });
        }
        public user_traffic UserSession([FromBody] User_Analytic_Input analytics_Input)
        {
            user_traffic traffic = new user_traffic();

            traffic.non_premium = 0;
            traffic.premium     = 0;
            List <get_user_traffic_Result> res = get_all_sites(analytics_Input.uid);


            foreach (var item in res)
            {
                Authorization auth = new Authorization(item.email);

                var result  = auth.service.Data.Ga.Get("ga:" + item.ga_id, analytics_Input.from_date, analytics_Input.to_date, analytics_Input.session);
                var result1 = auth.service.Data.Ga.Get("ga:" + item.ga_id, analytics_Input.from_date, analytics_Input.to_date, analytics_Input.session);
                if ((analytics_Input.extra != null))
                {
                    if (!analytics_Input.extra.Equals(""))
                    {
                        result.Filters  = "ga:campaign=@" + analytics_Input.extra;
                        result1.Filters = "ga:campaign=@" + analytics_Input.extra + ";ga:country=@Canada";
                    }
                }
                try {
                    var session_result  = result.Execute();
                    var session_result1 = result1.Execute();
                    int count           = (int)session_result.TotalResults;
                    if (count != 0)
                    {
                        IList <string> l = session_result.Rows[0];
                        traffic.non_premium = traffic.non_premium + long.Parse(l[0]);
                    }
                    traffic.non_premium = traffic.non_premium + 0;
                    int count2 = (int)session_result1.TotalResults;
                    if (count2 != 0)
                    {
                        IList <string> lp = session_result1.Rows[0];
                        traffic.premium = traffic.premium + long.Parse(lp[0]);
                    }
                    traffic.premium = traffic.premium + 0;
                }
                catch (Exception e)
                { }
            }

            traffic.non_premium = traffic.non_premium - traffic.premium;
            return(traffic);
        }
        public user_traffic_earning UserSessions([FromBody] User_Analytic_Input analytics_Input)
        {
            user_traffic_earning traffic = new user_traffic_earning()
            {
                todayEarned = 0, monthlyTraffic = 0, todayTraffic = 0, monthlyEarned = 0
            };
            ArticleController a             = new ArticleController();
            GraphController   use           = new GraphController();
            user_traffic      month_traffic = new user_traffic()
            {
                premium = 0, non_premium = 0
            };
            user_traffic today_traffic = new user_traffic()
            {
                premium = 0, non_premium = 0
            };
            List <get_user_traffic_Result> res = get_all_sites(analytics_Input.uid);
            var to     = System.DateTime.Now;
            var t_from = System.DateTime.Now;
            var m_from = System.DateTime.Now;

            if (to.Month == 1)
            {
                m_from = new DateTime(to.Year - 1, 12, to.Day);
            }
            else
            {
                m_from = new DateTime(to.Year, to.Month - 1, to.Day);
            }

            foreach (var item in res)
            {
                Authorization auth = new Authorization(item.email);

                var result  = auth.service.Data.Ga.Get("ga:" + item.ga_id, a.convertDate(m_from), a.convertDate(to), analytics_Input.session);
                var result1 = auth.service.Data.Ga.Get("ga:" + item.ga_id, a.convertDate(m_from), a.convertDate(to), analytics_Input.session);
                var result3 = auth.service.Data.Ga.Get("ga:" + item.ga_id, a.convertDate(t_from), a.convertDate(to), analytics_Input.session);
                var result4 = auth.service.Data.Ga.Get("ga:" + item.ga_id, a.convertDate(t_from), a.convertDate(to), analytics_Input.session);
                if ((analytics_Input.extra != null))
                {
                    if (!analytics_Input.extra.Equals(""))
                    {
                        result.Filters  = "ga:campaign=@" + analytics_Input.extra;
                        result1.Filters = "ga:campaign=@" + analytics_Input.extra + ";ga:country=@Canada";
                        result3.Filters = "ga:campaign=@" + analytics_Input.extra;
                        result4.Filters = "ga:campaign=@" + analytics_Input.extra + ";ga:country=@Canada";
                    }
                }
                try {
                    var today_result    = result3.Execute();
                    var today_result1   = result4.Execute();
                    var session_result  = result.Execute();
                    var session_result1 = result1.Execute();
                    int count           = (int)session_result.TotalResults;
                    if (count != 0)
                    {
                        month_traffic.non_premium += long.Parse(session_result.Rows[0].FirstOrDefault <string>());
                    }
                    //     month_traffic.non_premium = month_traffic.non_premium + 0;
                    int count2 = (int)session_result1.TotalResults;
                    if (count2 != 0)
                    {
                        month_traffic.premium += long.Parse(session_result1.Rows[0].FirstOrDefault <string>());
                    }

                    int count3 = (int)today_result.TotalResults;
                    if (count3 != 0)
                    {
                        today_traffic.non_premium += long.Parse(today_result.Rows[0].FirstOrDefault <string>());
                    }
                    //     month_traffic.non_premium = month_traffic.non_premium + 0;
                    int count4 = (int)today_result1.TotalResults;
                    if (count4 != 0)
                    {
                        today_traffic.premium += long.Parse(today_result1.Rows[0].FirstOrDefault <string>());
                    }
                    //     month_traffic.premium = month_traffic.premium + 0;
                }
                catch (Exception e)
                { }
            }


            month_traffic.non_premium = month_traffic.non_premium - month_traffic.premium;
            today_traffic.non_premium = today_traffic.non_premium - today_traffic.premium;
            traffic.monthlyTraffic    = month_traffic.premium + month_traffic.non_premium;
            traffic.todayTraffic      = today_traffic.premium + today_traffic.non_premium;
            traffic.monthlyEarned     = use.GetEarned((month_traffic.premium).ToString(), "premium") + use.GetEarned((month_traffic.non_premium).ToString(), "non-premium");
            traffic.todayEarned       = use.GetEarned((today_traffic.premium).ToString(), "premium") + use.GetEarned((today_traffic.non_premium).ToString(), "non-premium");

            return(traffic);
        }