protected override void ParseLine(string line) { var values = line.Split('\t'); if (values.Length == 2) { if (values[1].ToLower().Contains("level")) { int.TryParse(values[1].Substring(values[1].Length - 1), out this.level); } values[1] = values[1].Replace(".", string.Empty); DateTime date; int eventCount; if (DateTime.TryParse(values[0], new CultureInfo("es-AR"), DateTimeStyles.None, out date) && int.TryParse(values[1], out eventCount)) { string levelName = string.Concat(new string[] { "Level", level.ToString() }); var levelProperty = typeof(Analytics).GetProperty(levelName); var analytics = repository.Get<Analytics, DateTime>(date); if (analytics == null) { analytics = new Analytics { Date = date }; levelProperty.SetValue(analytics, eventCount, null); repository.Save<Analytics>(analytics); } else { levelProperty.SetValue(analytics, eventCount, null); repository.Update<Analytics>(analytics); } } } }
private void AddFacebookInsight(IXLWorksheet performanceSheet, int n, FacebookInsights insight) { performanceSheet.Cell(n, 1).Value = insight.Date; //Date performanceSheet.Cell(n, 3).Value = insight.DailyActiveUsers; //DAU performanceSheet.Cell(n, 4).FormulaA1 = string.Format("C{0}-C{1}", n, n + 1); //Q Users performanceSheet.Cell(n, 5).FormulaA1 = string.Format("IF(C{0}=0,0, D{1}/C{2})", n + 1, n, n + 1); //% Users performanceSheet.Cell(n, 6).Value = insight.MonthlyActiveUsers; //MAU performanceSheet.Cell(n, 7).FormulaA1 = string.Format("F{0}-F{1}", n, n + 1); //Q users performanceSheet.Cell(n, 8).FormulaA1 = string.Format("IF(F{0}=0,0,G{1}/F{2})", n + 1, n, n + 1); //% Users performanceSheet.Cell(n, 9).FormulaA1 = string.Format("IF(F{0}=0,0,C{1}/F{2})", n, n, n); //DAU/MAU performanceSheet.Cell(n, 10).FormulaA1 = string.Format("IF(G{0}=0,0,D{1}/G{2})", n, n, n); //DAU INDEX performanceSheet.Cell(n, 11).Value = insight.DailyAppInstalls; //Instalaciones var virality = repository.Get<Virality, DateTime>(insight.Date); if (virality == null) virality = new Virality(); performanceSheet.Cell(n, 12).Value = virality.Total; //K Factor (overall) performanceSheet.Cell(n, 13).Value = virality.Invite; //K Factor invite performanceSheet.Cell(n, 14).Value = virality.Notification; //K Notification performanceSheet.Cell(n, 15).Value = virality.TotalInstallations; //Viral Installs performanceSheet.Cell(n, 16).FormulaA1 = string.Format("K{0}-O{0}", n, n); //MKT Installs var analytics = repository.Get<Analytics, DateTime>(insight.Date); if (analytics == null) analytics = new Analytics(); performanceSheet.Cell(n, 17).Value = analytics.Visits; //Visits performanceSheet.Cell(n, 18).FormulaA1 = string.Format("IF(C{0}=0,0,Q{1}/C{2})", n, n, n); //Daily Sessions TimeSpan timeOnSite = new TimeSpan(0, 0, analytics.TimeOnSite); performanceSheet.Cell(n, 19).Value = timeOnSite.ToString(); //Time on site var revenue = repository.Get<Revenue, DateTime>(insight.Date); if (revenue == null) revenue = new Revenue(); performanceSheet.Cell(n, 20).Value = revenue.TotalRevenue; //Daily Revenue performanceSheet.Cell(n, 21).FormulaA1 = string.Format("IF(C{0}=0,0,T{1}/C{2})", n, n, n); //ARP DAU performanceSheet.Cell(n, 22).FormulaA1 = string.Format("IF(F{0}=0,0,T{1}/F{2})", n, n, n); //ARP MAU performanceSheet.Cell(n, 23).FormulaA1 = string.Format("IF(X{0}=0,0, T{1}/X{2})", n, n, n); //ARP PU performanceSheet.Cell(n, 24).Value = revenue.TransactionCount; ///Pay Users performanceSheet.Cell(n, 25).FormulaA1 = string.Format("X{0}/C{0}", n, n); //% Pay. Users performanceSheet.Cell(n, 26).FormulaA1 = string.Format("L{0}*T{0}*I{0}", n, n); //LTV performanceSheet.Cell(n, 27).Value = string.Empty; //CPA performanceSheet.Cell(n, 28).FormulaA1 = "K" + n.ToString(); // Level 1 performanceSheet.Cell(n, 29).FormulaA1 = string.Format("IF(C{0}=0,0,AB{1}/C{2})", n, n, n); //%DAU performanceSheet.Cell(n, 30).Value = analytics.Level2; //Level 2 performanceSheet.Cell(n, 31).FormulaA1 = string.Format("IF(C{0}=0,0,AD{1}/C{2})", n, n, n); //%DAU performanceSheet.Cell(n, 32).FormulaA1 = string.Format("IF(AB{0}=0,0,AD{1}/AB{2})", n, n, n); //% Pasaje performanceSheet.Cell(n, 33).Value = analytics.Level3; //Level 3 performanceSheet.Cell(n, 34).FormulaA1 = string.Format("IF(C{0}=0,0,AG{1}/C{2})", n, n, n); //%DAU performanceSheet.Cell(n, 35).FormulaA1 = string.Format("IF(AD{0}=0,0,AG{1}/AD{2})", n, n, n); //% Pasaje performanceSheet.Cell(n, 36).Value = analytics.Level4; //Level 4 performanceSheet.Cell(n, 37).FormulaA1 = string.Format("IF(C{0}=0,0,AJ{1}/C{2})", n, n, n); //%DAU performanceSheet.Cell(n, 38).FormulaA1 = string.Format("IF(AG{0}=0,0,AJ{1}/AG{2})", n, n, n); //% Pasaje performanceSheet.Cell(n, 39).Value = analytics.Level5; //Level 5 performanceSheet.Cell(n, 40).FormulaA1 = string.Format("IF(C{0}=0,0,AM{1}/C{2})", n, n, n); //%DAU performanceSheet.Cell(n, 41).FormulaA1 = string.Format("IF(AJ{0}=0,0,AM{1}/AJ{2})", n, n, n); //% Pasaje performanceSheet.Cell(n, 42).Value = string.Empty; //Weekly Average performanceSheet.Cell(n, 43).Value = string.Empty; //Monthly Average if (insight.Date.DayOfWeek == DayOfWeek.Saturday || insight.Date.DayOfWeek == DayOfWeek.Sunday) { performanceSheet.Row(n).Style.Fill.BackgroundColor = XLColor.Yellow; } }