public JsonResult GetFlurryConversionNotifCount(string metric) { FlurryResponse response = new FlurryResponse(); LineGraph graph = new LineGraph(); LineGraph Chart = new LineGraph(); //LineGraph chart = new LineGraph(); try { DateTime dt = DateTime.Now.AddSeconds(10); while (DateTime.Now > dt) { } string url = "http://api.flurry.com/eventMetrics/Event?apiAccessCode=" + apiAccessCode + "&apiKey=" + apiKey + "&startDate=" + fromDate + "&endDate=" + endDate + "&eventName=" + metric; HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(url); var httpResponse = (HttpWebResponse)httpWReq.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); result = result.Replace("@generatedDate", "generatedDate").Replace("@day", "day").Replace("@date", "date").Replace("@value", "value").Replace("@totalCount", "totalCount") .Replace("@name", "name").Replace("@type", "type").Replace("@metric", "metric").Replace("@eventName", "eventName").Replace("@version", "version"); response = JsonHelper.JsonDeserializer <FlurryResponse>(result); } long count = 0; foreach (Day day in response.day) { count += day.totalCount; } if (metric == "NearNotificationReceived") { ViewBag.NearNotificationR = count; } else if (metric == "CloseNotificationReceived") { ViewBag.closeNotificationR = count; } else if (metric == "FarNotificationReceived") { ViewBag.FarNotificationR = count; } else { ViewBag.totalConversion = count; } if (metric == "Conversion") { } else { List <decimal[, ]> graphData = new List <decimal[, ]>(); response.day = response.day.Count > 10 ? response.day.OrderByDescending(d => d.date).Take(10).ToList() : response.day; foreach (Day day in response.day.OrderByDescending(d => d.date).Take(10)) { graphData.Add(new decimal[1, 2] { { ConvertToTimestamp(DateTime.ParseExact(day.date, "yyyy-M-d", CultureInfo.InvariantCulture)), day.totalCount } }); } graph.data = graphData; List <decimal[, ]> ChartData = new List <decimal[, ]>(); response.day = response.day.Count > 10 ? response.day.OrderByDescending(d => d.date).Take(10).ToList() : response.day; foreach (Day day in response.day.OrderByDescending(d => d.date).Take(10)) { ChartData.Add(new decimal[1, 2] { { ConvertToTimestamp(DateTime.ParseExact(day.date, "yyyy-M-d", CultureInfo.InvariantCulture)), day.totalCount } }); } Chart.data = ChartData; if (metric == "CloseNotificationReceived") { graph.label = "Notified"; ViewBag.LineCloseNotification = graph; Chart.label = "Close"; ViewBag.LineCloseNotificationS = Chart; } else if (metric == "NearNotificationReceived") { graph.label = "Engaged"; ViewBag.LineNearNotification = graph; Chart.label = "Near"; ViewBag.LineNearNotificationS = Chart; } else // if (metric == "FarNotificationRecieved") { graph.label = "Engaged"; ViewBag.LineFarNotification = graph; Chart.label = "Near"; ViewBag.LineFarNotificationS = Chart; } } Thread.Sleep(2000); } catch { // GetActiveUsers("week"); } return(Json(graph, JsonRequestBehavior.AllowGet)); }
public JsonResult GetFlurryCount(string metric) { FlurryResponse response = new FlurryResponse(); LineGraph graph = new LineGraph(); try { DateTime dt = DateTime.Now.AddSeconds(10); while (DateTime.Now > dt) { } string url = "http://api.flurry.com/appMetrics/" + metric + "?apiAccessCode=" + apiAccessCode + "&apiKey=" + apiKey + "&startDate=" + fromDate + "&endDate=" + endDate; HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(url); var httpResponse = (HttpWebResponse)httpWReq.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); result = result.Replace("@generatedDate", "generatedDate").Replace("@day", "day").Replace("@date", "date").Replace("@value", "value").Replace("@totalCount", "totalCount") .Replace("@name", "name").Replace("@type", "type").Replace("@metric", "metric").Replace("@eventName", "eventName").Replace("@version", "version"); response = JsonHelper.JsonDeserializer <FlurryResponse>(result); } long count = 0; long max = 0; DateTime maxFootfallDate = DateTime.Now; foreach (Day day in response.day) { count += day.value; if (max < day.value) { max = day.value; maxFootfallDate = Convert.ToDateTime(day.date); } } if (metric == "NewUsers") { ViewBag.NewUser = count; ViewBag.MaxFootfallDate = maxFootfallDate; } else if (metric == "ActiveUsers") { ViewBag.UniqueUser = count; } else { ViewBag.Session = count; } List <decimal[, ]> graphData = new List <decimal[, ]>(); response.day = response.day.Count > 10 ? response.day.OrderByDescending(d => d.date).Take(10).ToList() : response.day; if (metric == "NewUsers") { graphData.Add(new decimal[1, 2] { { count, 2 } }); graph.data = graphData; graph.label = "Annonymous Users"; ViewBag.LineNewUser = graph; } else if (metric == "ActiveUsers") { graphData.Add(new decimal[1, 2] { { count, 1 } }); graph.data = graphData; graph.label = "Registered User"; ViewBag.LineUniqueUser = graph; } else { graph.label = "Session"; } Thread.Sleep(2000); } catch { //////// GetActiveUsers("week"); } return(Json(graph, JsonRequestBehavior.AllowGet)); }
public JsonResult GetFlurryOfferViewRated(string metric) { FlurryResponse response = new FlurryResponse(); LineGraph graph = new LineGraph(); LineGraph Chart = new LineGraph(); try { DateTime dt = DateTime.Now.AddSeconds(10); while (DateTime.Now > dt) { } string url = "http://api.flurry.com/eventMetrics/Event?apiAccessCode=" + apiAccessCode + "&apiKey=" + apiKey + "&startDate=" + fromDate + "&endDate=" + endDate + "&eventName=" + metric; HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(url); var httpResponse = (HttpWebResponse)httpWReq.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); result = result.Replace("@generatedDate", "generatedDate").Replace("@day", "day").Replace("@date", "date").Replace("@value", "value").Replace("@totalCount", "totalCount") .Replace("@name", "name").Replace("@type", "type").Replace("@metric", "metric").Replace("@eventName", "eventName").Replace("@version", "version"); response = JsonHelper.JsonDeserializer <FlurryResponse>(result); } long count = 0; foreach (Day day in response.day) { count += day.totalCount; } if (metric == "OfferViewed") { ViewBag.OfferViewed = count; } else if (metric == "OfferSaved") { ViewBag.OfferSaved = count; } else { ViewBag.OfferRated = count; } List <decimal[, ]> graphData = new List <decimal[, ]>(); response.day = response.day.Count > 10 ? response.day.OrderByDescending(d => d.date).Take(10).ToList() : response.day; foreach (Day day in response.day.OrderByDescending(d => d.date).Take(10)) { graphData.Add(new decimal[1, 2] { { day.totalCount, ConvertToTimestamp(DateTime.ParseExact(day.date, "yyyy-M-d", CultureInfo.InvariantCulture)) } }); } graph.data = graphData; if (metric == "OfferViewed") { Key actions = (from result in response.parameters.key where result.name == "campaignId" select result).FirstOrDefault(); foreach (Value k in actions.value) { if (max01 < Convert.ToDecimal(k.totalCount)) { max01 = k.totalCount; max1 = k.name; } } var notification = _unitOfWorkAsync.Repository <Entities.Notification>().Find(Convert.ToInt32(max1)); ViewBag.topOffer = notification.NotificationTitle; string NotiImg = notification.NotificationImage; ViewBag.NotificationImg = NotiImg; graph.label = "Viewed"; ViewBag.LineOfferViewed = graph; } else if (metric == "OfferSaved") { graph.label = "Saved"; ViewBag.LineOfferSaved = graph; } else { graph.label = "Rated"; ViewBag.LineOfferRated = graph; } Thread.Sleep(2000); } catch { // GetActiveUsers("week"); } return(Json(graph, JsonRequestBehavior.AllowGet)); }