Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public List <GraphStats> trafficGraph([FromBody] trafficInput input)
        {
            ArticleController    use = new ArticleController();
            get_admin_gid_Result res;
            List <GraphStats>    stats = new List <GraphStats>();

            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(input.fromDate), use.convertDate(input.toDate), "ga:sessions");
            var           result1 = auth.service.Data.Ga.Get(("ga:" + res.ga_id), use.convertDate(input.fromDate), use.convertDate(input.toDate), "ga:sessions");

            if (input.extra == "month" || input.extra == "week")
            {
                result.Dimensions  = "ga:month,ga:day";
                result1.Dimensions = "ga:month,ga:day";
            }
            else if (input.extra == "year")
            {
                result.Dimensions  = "ga:year,ga:month";
                result1.Dimensions = "ga:year,ga:month";
            }

            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 final  = result.Execute();
                var final1 = result1.Execute();
                int count  = (int)final.TotalResults;
                int count1 = (int)final1.TotalResults;
                if (count != 0 && (count == count1))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var        item1 = final.Rows[i];
                        var        item2 = final1.Rows[i];
                        GraphStats temp2 = new GraphStats()
                        {
                            dateTime = item2[1] + "/" + item2[0], sessions = item2[2], earned = GetEarned(item2[2], "premium")
                        };
                        GraphStats temp = new GraphStats()
                        {
                            dateTime = item1[1] + "/" + item1[0], sessions = (Int32.Parse(item1[2]) - Int32.Parse(temp2.sessions)).ToString(), earned = GetEarned((Int32.Parse(item1[2]) - Int32.Parse(temp2.sessions)).ToString(), "non-premium")
                        };
                        stats.Add(new GraphStats()
                        {
                            dateTime = temp.dateTime, sessions = (Int32.Parse(temp.sessions) + Int32.Parse(temp2.sessions)).ToString(), earned = temp.earned + temp2.earned
                        });
                    }
                }
            }catch (Exception e)
            {
            }
            return(stats);
        }
        public List <KeyValuePair <string, long> > TopUsers()
        {
            ArticleController a = new ArticleController();

            var to   = System.DateTime.Now;
            var from = new DateTime(to.Year, to.Month, 1);
            //List < List < UserStats >> total_stats = new List<List<UserStats>>();
            Dictionary <string, long> allUsers = new Dictionary <string, long>();
            List <Procedure_Result>   res      = new List <Procedure_Result>();

            using (var data = db.Procedure())
            {
                res = data.ToList <Procedure_Result>();
            }
            foreach (var item in res)
            {
                Authorization auth = new Authorization(item.email);

                var result = auth.service.Data.Ga.Get("ga:" + item.ga_id, a.convertDate(from), a.convertDate(to), "ga:Sessions");
                result.Dimensions = "ga:campaign";
                result.Filters    = "ga:medium=@digitalmarket";
                try
                {
                    var response = result.Execute();
                    if (response.TotalResults != 0)
                    {
                        foreach (var row in response.Rows)
                        {
                            if (allUsers.ContainsKey(row[0]))
                            {
                                allUsers[row[0]] = allUsers[row[0]] + long.Parse(row[1]);
                            }
                            else
                            {
                                allUsers.Add(row[0], long.Parse(row[1]));
                            }
                        }
                    }
                }
                catch (Exception e)
                { }
                // total_stats.Add(user_stats);
            }
            // allUsers.Remove("(not set)");
            return(new List <KeyValuePair <string, long> >(allUsers));
        }
Exemplo n.º 4
0
        public List <CountryStats> countryGraph([FromBody] trafficInput input)
        {
            ArticleController    use = new ArticleController();
            get_admin_gid_Result res;
            List <CountryStats>  stats = new List <CountryStats>();

            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(input.fromDate), use.convertDate(input.toDate), "ga:sessions");

            result.Dimensions = "ga:country";
            result.MaxResults = 5;
            result.Sort       = "-ga:sessions";
            result.Filters    = "ga:landingPagePath=@" + use.convertUrl(input.url, input.site_url) + ";ga:campaign=@" + input.uid + ";ga:medium=@referral";
            try
            {
                var final = result.Execute();
                int count = (int)final.TotalResults;
                if (count != 0)
                {
                    foreach (var item in final.Rows)
                    {
                        CountryStats temp = new CountryStats()
                        {
                            country = item[0], sessions = item[1]
                        };
                        stats.Add(temp);
                    }
                }
            }catch (Exception e)
            {
            }
            return(stats);
        }
        public Map getMapData([FromBody] Analytics_Input input)
        {
            Map res = new Map()
            {
                max = 0, min = 0, avg = 0, mapData = new List <MapData>()
            };
            Dictionary <string, countrieees> countries = CountriesList();

            ArticleController a = new ArticleController();

            var to   = System.DateTime.Now;
            var from = System.DateTime.Now;

            if (to.Month == 1)
            {
                from = new DateTime(to.Year - 1, 12, to.Day);
            }
            else
            {
                from = new DateTime(to.Year, to.Month - 1, to.Day);
            }
            //List < List < UserStats >> total_stats = new List<List<UserStats>>();

            List <MapData> map = new List <MapData>();


            Authorization auth   = new Authorization(input.extra);
            var           result = auth.service.Data.Ga.Get("ga:" + input.ga_id, a.convertDate(from), a.convertDate(to), input.session);

            result.Dimensions = "ga:countryIsoCode";
            try {
                var session_result = result.Execute();


                int count = (int)session_result.TotalResults;
                int total = 0;
                if (count != 0)
                {
                    foreach (var item in session_result.Rows)
                    {
                        total++;
                        if (countries.ContainsKey(item[0]))
                        {
                            map.Add(new MapData()
                            {
                                id = countries[item[0]].id, value = item[1]
                            });
                        }
                        if (res.max == 0)
                        {
                            res.min = Int32.Parse(item[1]);
                        }
                        if (res.max == 0)
                        {
                            res.max = Int32.Parse(item[1]);
                        }
                        if (res.avg == 0)
                        {
                            res.max = Int32.Parse(item[1]);
                        }
                        if (Int32.Parse(item[1]) <= res.min)
                        {
                            res.min = Int32.Parse(item[1]);
                        }
                        if (Int32.Parse(item[1]) >= res.max)
                        {
                            res.max = Int32.Parse(item[1]);
                        }
                        res.avg = res.avg + Int32.Parse(item[1]);
                    }
                }
                res.avg     = total == 0 ? res.avg : res.avg / total;
                res.mapData = map;
            }
            catch (Exception e)
            { }
            return(res);
        }
        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);
        }
Exemplo n.º 7
0
        public AdminGraph statAdminGraph([FromBody] Analytics_Input input)
        {
            ArticleController a     = new ArticleController();
            List <GraphStats> stats = new List <GraphStats>();
            AdminGraph        data  = new AdminGraph()
            {
                amount = 0.0, graph = stats
            };
            var to   = System.DateTime.Now;
            var from = System.DateTime.Now;

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

            //List < List < UserStats >> total_stats = new List<List<UserStats>>();

            List <GraphStats> list = new List <GraphStats>();


            Authorization auth   = new Authorization(input.extra);
            var           result = auth.service.Data.Ga.Get("ga:" + input.ga_id, a.convertDate(from), a.convertDate(to), input.session);


            var result1 = auth.service.Data.Ga.Get("ga:" + input.ga_id, a.convertDate(from), a.convertDate(to), input.session);

            result.Dimensions  = "ga:year,ga:month,ga:day";
            result1.Dimensions = "ga:year,ga:month,ga:day";

            result.Filters  = "ga:medium=@referral";
            result1.Filters = "ga:medium=@referral;ga:country=@Canada";
            try
            {
                var final  = result.Execute();
                var final1 = result1.Execute();
                int count  = (int)final.TotalResults;
                int count1 = (int)final1.TotalResults;
                if (count != 0 && (count == count1))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var    item1   = final.Rows[i];
                        var    item2   = final1.Rows[i];
                        double pEarned = GetEarned(item2[3], "premium");
                        double nEarned = GetEarned((Int32.Parse(item1[3]) - Int32.Parse(item2[3])).ToString(), "non-premium");
                        data.amount += pEarned + nEarned;


                        GraphStats temp = new GraphStats()
                        {
                            dateTime = item2[2] + "/" + item1[1] + "/" + item1[0], sessions = (Int32.Parse(item1[3])).ToString(), earned = GetEarned((Int32.Parse(item1[3]) - Int32.Parse(item2[3])).ToString(), "non-premium") + GetEarned(item2[3], "premium")
                        };
                        stats.Add(new GraphStats()
                        {
                            dateTime = temp.dateTime, sessions = temp.sessions, earned = temp.earned
                        });
                    }
                    data.graph = stats;
                }
            }catch (Exception e)
            {
            }

            return(data);
        }