Ejemplo n.º 1
0
 static string Format(CountryStats x)
 {
     return
         ($"{x.TotalCases:n0} :: +{x.NewCases:n0} - " +
          $"{x.Name} - " +
          $"{x.TotalDeaths:n0} :: +{x.NewDeaths:n0}");
 }
        public IHttpActionResult CountryForecast([FromUri] string country, [FromUri] int year, [FromUri] int month)
        {
            var inputExample = new CountryStats
            {
                Country = country,
                Year    = year,
                Month   = month
            };

            var client  = new RestClient(_mlServerUrl);
            var request = new RestRequest(_countryForecastUrl, Method.POST);

            request.AddJsonBody(inputExample);
            var response = client.Execute <float>(request);

            return(Ok(response.Data));
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public List <UserStats> statistics([FromBody] User_Analytic_Input analytics_Input)
        {
            //List < List < UserStats >> total_stats = new List<List<UserStats>>();
            GraphController  use               = new GraphController();
            List <UserStats> user_stats        = new List <UserStats>();
            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 + ",ga:newUsers");
                result.Dimensions = "ga:date, " + analytics_Input.country;
                result.Filters    = "ga:campaign=@" + analytics_Input.extra;
                try {
                    var response = result.Execute();
                    if (response.TotalResults != 0)
                    {
                        foreach (var row in response.Rows)
                        {
                            UserStats temp = new UserStats()
                            {
                                date = new DateTime(), day = "", premium = 0, non_premium = 0, total_traffic = 0, total_earning = 0, country_stats = new List <CountryStats>()
                            };
                            // UserStats temp = user_stats.Last<UserStats>();


                            temp = user_stats.FirstOrDefault(x => x.day == row[0]);

                            if (temp == null)
                            {
                                temp = new UserStats()
                                {
                                    date = new DateTime(), day = "", premium = 0, non_premium = 0, total_traffic = 0, total_earning = 0, country_stats = new List <CountryStats>()
                                };
                            }
                            if (!(temp.day.Equals(row[0])))
                            {
                                UserStats stats = new UserStats()
                                {
                                    date = new DateTime(), day = "", premium = 0, non_premium = 0, total_traffic = 0, total_earning = 0, country_stats = new List <CountryStats>()
                                };

                                stats.day  = row[0];
                                stats.date = dateConverter(stats.day);

                                if (row[1].Equals("Canada"))
                                {
                                    stats.premium       += long.Parse(row[2]);
                                    stats.total_earning += use.GetEarned(row[2], "premium");

                                    stats.total_traffic += long.Parse(row[2]);
                                }
                                else
                                {
                                    stats.non_premium   += long.Parse(row[2]);
                                    stats.total_earning += use.GetEarned(row[2], "non-premium");
                                    stats.total_traffic += long.Parse(row[2]);
                                }

                                var cFind = stats.country_stats.FirstOrDefault(x => x.country == row[1]);
                                if (cFind == null)
                                {
                                    cFind = new CountryStats()
                                    {
                                        country = row[1], sessions = "0", newSessions = "0"
                                    };
                                }
                                else
                                {
                                    stats.country_stats.Remove(cFind);
                                }
                                cFind.sessions    = (Int64.Parse(cFind.sessions) + Int64.Parse(row[2])).ToString();
                                cFind.newSessions = (Int64.Parse(cFind.newSessions) + Int64.Parse(row[3])).ToString();
                                stats.country_stats.Add(cFind);
                                user_stats.Add(stats);
                            }
                            else
                            {
                                user_stats.Remove(temp);
                                CountryStats cTemp = new CountryStats();
                                if (row[1].Equals("Canada"))
                                {
                                    temp.premium       += long.Parse(row[2]);
                                    temp.total_earning += use.GetEarned(row[2], "premium");

                                    temp.total_traffic += long.Parse(row[2]);
                                }
                                else
                                {
                                    temp.non_premium   += long.Parse(row[2]);
                                    temp.total_earning += use.GetEarned(row[2], "non-premium");
                                    temp.total_traffic += long.Parse(row[2]);
                                }
                                var cFind = temp.country_stats.FirstOrDefault(x => x.country == row[1]);
                                if (cFind == null)
                                {
                                    cFind = new CountryStats()
                                    {
                                        country = row[1], sessions = "0", newSessions = "0"
                                    };
                                }
                                else
                                {
                                    temp.country_stats.Remove(cFind);
                                }
                                cFind.sessions    = (Int64.Parse(cFind.sessions) + Int64.Parse(row[2])).ToString();
                                cFind.newSessions = (Int64.Parse(cFind.newSessions) + Int64.Parse(row[3])).ToString();
                                temp.country_stats.Add(cFind);
                                user_stats.Add(temp);
                            }
                        }
                    }
                    // total_stats.Add(user_stats);
                }
                catch (Exception e)
                { }
            }

            return(user_stats);
        }
Ejemplo n.º 5
0
        public List <AdminStats> AdminStatistics([FromBody] Analytics_Input analytics_Input)
        {
            //List < List < UserStats >> total_stats = new List<List<UserStats>>();

            List <AdminStats> admin_stats = new List <AdminStats>();

            GraphController use = new GraphController();

            Authorization auth = new Authorization(analytics_Input.extra);

            var result = auth.service.Data.Ga.Get("ga:" + analytics_Input.ga_id, analytics_Input.from_date, analytics_Input.to_date, analytics_Input.session + ",ga:newUsers");

            result.Dimensions = "ga:date, " + analytics_Input.country;
            result.Filters    = "ga:medium=@referral";
            try {
                var response = result.Execute();
                if (response.TotalResults != 0)
                {
                    foreach (var row in response.Rows)
                    {
                        AdminStats temp = new AdminStats()
                        {
                            date = new DateTime(), earning = 0.0, day = "", premium = 0, non_premium = 0, total_traffic = 0, total_earning = 0, country_stats = new List <CountryStats>()
                        };
                        // UserStats temp = user_stats.Last<UserStats>();


                        temp = admin_stats.FirstOrDefault(x => x.day == row[0]);

                        if (temp == null)
                        {
                            temp = new AdminStats()
                            {
                                date = new DateTime(), earning = 0.0, day = "", premium = 0, non_premium = 0, total_traffic = 0, total_earning = 0, country_stats = new List <CountryStats>()
                            };
                        }
                        if (!(temp.day.Equals(row[0])))
                        {
                            AdminStats stats = new AdminStats()
                            {
                                date = new DateTime(), earning = 0.0, day = "", premium = 0, non_premium = 0, total_traffic = 0, total_earning = 0, country_stats = new List <CountryStats>()
                            };

                            stats.day  = row[0];
                            stats.date = dateConverter(row[0]);
                            if (row[1].Equals("Canada"))
                            {
                                stats.premium += long.Parse(row[2]);
                                stats.earning += use.GetEarned(row[2], "premium");

                                stats.total_traffic += long.Parse(row[2]);
                            }
                            else
                            {
                                stats.non_premium   += long.Parse(row[2]);
                                stats.earning       += use.GetEarned(row[2], "non-premium");
                                stats.total_traffic += long.Parse(row[2]);
                            }

                            CountryStats cFind = new CountryStats()
                            {
                                country = row[1], sessions = "0", newSessions = "0"
                            };


                            cFind.sessions    = (Int64.Parse(cFind.sessions) + Int64.Parse(row[2])).ToString();
                            cFind.newSessions = (Int64.Parse(cFind.newSessions) + Int64.Parse(row[3])).ToString();
                            stats.country_stats.Add(cFind);
                            admin_stats.Add(stats);
                        }
                        else
                        {
                            admin_stats.Remove(temp);
                            CountryStats cTemp = new CountryStats();
                            if (row[1].Equals("Canada"))
                            {
                                temp.premium       += long.Parse(row[2]);
                                temp.earning       += use.GetEarned(row[2], "premium");
                                temp.total_traffic += long.Parse(row[2]);
                            }
                            else
                            {
                                temp.non_premium   += long.Parse(row[2]);
                                temp.earning       += use.GetEarned(row[2], "non-premium");
                                temp.total_traffic += long.Parse(row[2]);
                            }

                            CountryStats cFind = new CountryStats()
                            {
                                country = row[1], sessions = "0", newSessions = "0"
                            };

                            cFind.sessions    = (Int64.Parse(row[2])).ToString();
                            cFind.newSessions = (Int64.Parse(row[3])).ToString();
                            temp.country_stats.Add(cFind);
                            admin_stats.Add(temp);
                        }
                    }
                }
            }
            catch (Exception e)
            { }
            return(admin_stats);
        }
 public float CountryForecast(CountryStats data)
 {
     return(ForecastEngine.CountryForecast(data));
 }
        public void ImportScrape(cvScrapeData data)
        {
            if (data.heading.Contains("XX,XXX"))
            {
                return;
            }
            var existScrape = ctx.ScrapeRuns.FirstOrDefault(r => r.Heading.Trim() == data.heading.Trim());

            if (existScrape != null)
            {
                return;
            }
            Console.WriteLine("updating...");
            cvDataUtils.createGeolocationsFromScrapeFile(data);
            cvDataUtils.createCountriesFromScrapeFile(data);

            ScrapeRun scrape = new ScrapeRun()
            {
                CreateDate = DateTime.Now,
                Heading    = data.heading,
                ScrapeDate = data.scrapeDate
            };

            ctx.ScrapeRuns.Add(scrape);
            ctx.SaveChanges();

            foreach (var geo in data.geoLocations)
            {
                foreach (var detail in geo.details)
                {
                    var country = ctx.Countries.FirstOrDefault(r => r.Name == detail.country);
                    if (country == null && detail.country != "TOTAL")
                    {
                        throw new Exception("country not found: " + detail.country);
                    }
                    if (detail.country == "TOTAL")
                    {
                        continue;
                    }

                    CountryStats stats = new CountryStats()
                    {
                        ScrapeRunId = scrape.Id,
                        CountryId   = country.Id,
                        CreateDate  = DateTime.Now,
                        CaseCount   = int.Parse(detail.cases.Trim().Replace(",", "").Replace("*", "")),
                        DeathCount  = int.Parse(detail.deaths.Trim().Replace(",", "").Replace("*", "")),
                        Notes       = detail.notes
                    };
                    ctx.CountryStats.Add(stats);
                }
            }
            try
            {
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }