/// <summary> /// 生成所有曲线的JSON /// </summary> protected void GetAllLineJson() { LineChart chart = new LineChart(BeginTime, EndTime); bool isNewUserReport = reporttype.Value == "0"; chart.Period = net91com.Stat.Core.PeriodOptions.Daily; for (int i = 0; i < ListAll.Count; i++) { LineChartLine line = new LineChartLine { Name = DataNames[i], Show = true, XIntervalDays = 0, Points = ListAll[i].Select(a => new LineChartPoint { XValue = a.StatDate, YValue = isNewUserReport ? a.NewUserCount : a.ActiveUserCount, DataContext = a }).ToList() }; chart.Y.Add(line); } AxisJsonStr = string.Format("{{{0},labels:{{align:'left',tickLength:80,tickPixelInterval:140,rotation:-45,x:-30,y:45,step:{1}}}}}" , chart.GetXJson() , chart.Step); SeriesJsonStr = chart.GetYJson( delegate(LineChartPoint point) { return(string.Format(",\"growth\":\"{0}\",\"Denominator\":{1},\"Other\":null", "", "0")); }); }
/// <summary> /// 获取分版本曲线数据 /// </summary> /// <param name="softId"></param> /// <param name="platform"></param> /// <param name="period"></param> /// <param name="startDate"></param> /// <param name="endDate"></param> /// <param name="channelId"></param> /// <param name="channelType"></param> public void GetStatUsersByVersionLine(int softId, int platform, int period, DateTime startDate, DateTime endDate, int channelId, ChannelTypeOptions channelType) { //权限验证 CheckHasRight(softId, "Reports/StatUsersByVersionTransverse.aspx"); //版本ID string[] versionIds = string.IsNullOrEmpty(ThisRequest["VersionIds"]) ? new string[0] : ThisRequest["VersionIds"].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToArray(); if (versionIds.Length > 0) { StatUsersService suService = new StatUsersService(); List <Sjqd_StatUsers> statUsersList = suService.GetStatUsersByVersion(softId, platform, channelType, channelId, versionIds[0], period, startDate, endDate); LineChart chart = new LineChart(startDate, endDate); chart.Period = (net91com.Stat.Core.PeriodOptions)period; LineChartLine newUserLine = new LineChartLine { Name = "新增", Show = true, XIntervalDays = 0, Points = statUsersList.Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.NewUserCount, DataContext = a }).ToList() }; chart.Y.Add(newUserLine); LineChartLine activeUserLine = new LineChartLine { Name = "活跃", Show = true, XIntervalDays = 0, Points = statUsersList.Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.ActiveUserCount, DataContext = a }).ToList() }; chart.Y.Add(activeUserLine); string axisJsonStr = string.Format("{{{0},labels:{{align:'left',tickLength:80,tickPixelInterval:140,rotation:-45,x:-30,y:45,step:{1}}}}}" , chart.GetXJson() , chart.Step); string seriesJsonStr = chart.GetYJson( delegate(LineChartPoint point) { return(string.Format(",\"growth\":\"{0}\",\"Denominator\":{1},\"Other\":null", "", "0")); }); string result = "{ x:" + axisJsonStr + "," + "y:" + seriesJsonStr + "}"; HttpContext.Current.Response.Write(result); } }
/// <summary> /// 设置曲线 /// </summary> /// <param name="chart"></param> /// <param name="list"></param> /// <param name="iscompare"></param> protected void SetChart(LineChart chart, List <List <LinkTagCount> > list, bool iscompare = false) { for (int i = 0; i < list.Count; i++) { string softName = GetSoft(list[i][0].SoftId).Name; string platform = "_" + ((MobileOption)list[i][0].Platform).GetDescription(); if (platform == "_None") { platform = "_不区分平台"; } string tagName = list[i][0].TagName; List <LineChartPoint> MyPoints = null; MyPoints = list[i].Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.StatCount, DataContext = a }).ToList(); LineChartLine line = new LineChartLine { Name = softName + platform + tagName, Show = true, Points = MyPoints }; chart.Y.Add(line); } }
/// <summary> /// 生成所有曲线的JSON /// </summary> protected void GetAllLineJson() { LineChart chart = new LineChart(BeginTime, EndTime); chart.Period = Period; int lineType = HeadControl1.isChecked ? 1 : 2; for (int i = 0; i < ListAll.Count; i++) { string softName = GetSoft(ListAll[i][0].SoftId).Name; string platform = "_" + ((MobileOption)ListAll[i][0].Platform).GetDescription(); if (platform == "_None") { platform = "_不区分平台"; } string channelName = QuDao ? "_" + ListAll[i][0].ChannelName : string.Empty; //1 是ActiveNum-ActivityPercent-TotalNum 2 是UseNum-UsePercent-TotalNum,3 是LostNum-LostPercent-UseNum List <LineChartPoint> MyPoints = null; List <LineChartPoint> MyPoints2 = null; if (lineType == 1) { MyPoints = ListAll[i].Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.ActiveNum, DataContext = a, Denominator = a.TotalNum, Percent = a.ActivityPercent }).ToList(); MyPoints2 = ListAll[i].Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.FirstActiveUserCount + a.ActiveUserCount_Shanzhai, DataContext = a, Denominator = a.TotalNum }).ToList(); } else { MyPoints = ListAll[i].Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.UseNum, DataContext = a, Denominator = a.TotalNum, Percent = a.UsePercent }).ToList(); MyPoints2 = ListAll[i].Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.FirstUseUserCount + a.ActiveUserCount_Shanzhai + a.NewUserCount_Shanzhai, DataContext = a, Denominator = a.TotalNum }).ToList(); } LineChartLine line = new LineChartLine { Name = softName + platform + channelName, Show = true, XIntervalDays = 0, Points = MyPoints }; chart.Y.Add(line); //增加新增用户未修正的线 if (!QuDao && checkForNotUpdated.Checked && Period != net91com.Stat.Core.PeriodOptions.TimeOfDay && Period != net91com.Stat.Core.PeriodOptions.Hours && !QuDao) { LineChartLine line2 = new LineChartLine { Name = softName + platform + channelName + "_未修正数据", Show = true, XIntervalDays = 0, Points = MyPoints2 }; chart.Y.Add(line2); } } //增加对比线 //对比线前后时间差值 int intervalDays = 0; if (ListAll[0].Count != 0 && ListAllForCompare.Count != 0 && ListAllForCompare[0].Count != 0) { intervalDays = ListAll[0][0].StatDate.Subtract(ListAllForCompare[0][0].StatDate).Days; } foreach (var item in ListAllForCompare) { string softName = GetSoft(item[0].SoftId).Name; string platform = "_" + ((MobileOption)item[0].Platform).GetDescription(); if (platform == "_None") { platform = "_不区分平台"; } string channelName = QuDao ? "_" + item[0].ChannelName : string.Empty; List <LineChartPoint> ComparePoints = null; if (lineType == 1) { ComparePoints = item.Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.ActiveNum, DataContext = a, Denominator = a.TotalNum, Percent = a.ActivityPercent }).ToList(); } else { ComparePoints = item.Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.UseNum, DataContext = a, Denominator = a.TotalNum, Percent = a.UsePercent }).ToList(); } chart.Y.Add( new LineChartLine { Name = softName + platform + channelName + "_对比线", Show = true, XIntervalDays = intervalDays, Points = ComparePoints }); } AxisJsonStr = string.Format("{{{0},labels:{{align:'left',tickLength:80,tickPixelInterval:140{1},step:{2}}}}}" , chart.GetXJson() , Period == net91com.Stat.Core.PeriodOptions.Hours ? ",rotation:-45,x:-40,y:60" : (Period == net91com.Stat.Core.PeriodOptions.TimeOfDay ? ",x:-5" : ",rotation:-45,x:-30,y:45") , chart.Step); SeriesJsonStr = chart.GetYJson( delegate(LineChartPoint point) { SoftUser user = (SoftUser)point.DataContext; return(string.Format(",\"growth\":\"{0}\",\"Denominator\":{1},\"Other\":null", point.Percent, point.Denominator)); }); }
/// <summary> /// 设置曲线 /// </summary> /// <param name="chart"></param> /// <param name="list"></param> /// <param name="iscompare"></param> protected void SetChart(LineChart chart, List <List <SoftUser> > list, bool iscompare = false) { //对比线前后时间差值 int intervalDays = 0; if (iscompare && ListAll[0].Count != 0 && ListAllForCompare.Count != 0 && ListAllForCompare[0].Count != 0) { intervalDays = ListAll[0][0].StatDate.Subtract(ListAllForCompare[0][0].StatDate).Days; } for (int i = 0; i < list.Count; i++) { string softName = GetSoft(list[i][0].SoftId).Name; string platform = "_" + ((MobileOption)list[i][0].Platform).GetDescription(); if (platform == "_None") { platform = "_不区分平台"; } string channelName = QuDao ? "_" + list[i][0].ChannelName : string.Empty; List <LineChartPoint> MyPoints = null; if (reporttype.Value == "0") { MyPoints = list[i].Select( a => new LineChartPoint { XValue = a.StatDate, YValue = a.NewNum, DataContext = a }).ToList(); } else { MyPoints = list[i].Select( a => new LineChartPoint { XValue = a.StatDate, YValue = a.ActiveNum, DataContext = a, Denominator = a.TotalNum, Percent = a.ActivityPercent }).ToList(); } LineChartLine line = new LineChartLine { Name = softName + platform + channelName + (iscompare?"_对比线":""), Show = true, XIntervalDays = intervalDays, Points = MyPoints }; if (ForeCastUserDatas.Count > 0 && reporttype.Value == "0" && !iscompare) { List <ForecastSoftUser> tempMyForecastUser = ForeCastUserDatas.Where(p => p.Period == (int)Period).Where(p => p.SoftId == ListAll[i][0].SoftId && p.Platform == ListAll[i][0].Platform && ListAll[i][0].ChannelID == p.ChannelID).OrderByDescending(p => p.StatDate).ToList(); SoftUser user = GetForeCastSoftUser(tempMyForecastUser); if (user != null) { line.ForecastPoint = new LineChartPoint { YValue = user.NewNum, DataContext = user } } ; } //mileStoneDate[i].ForEach(a => line.AddMarker(a.MileStoneDate, Period, a.Remarks)); chart.Y.Add(line); } }
public SchoolYearTargetAttendanceChartGenerator(string InternalConnectionString, ChartJob Options) { this.Title = "% Students with at least " + ((decimal)Options.TargetAttendanceRate * 100).ToString("0") + "% Attendance Rate"; this.SubTitle = Options.StartDate.ToShortDateString() + " to " + Options.EndDate.ToShortDateString(); this.ShowValuesInChart = true; // Labels / Data points will be one for each month this.Lines = new List <LineChartLine>(); // DATA NEEDED FOR THIS REPORT // - Load all enrolled students // - For each month within the specified date range, calculate every student's attendance rate // - Find the final values for each month // This chart is done by the School Year, not arbitrary dates InternalStudentRepository studentRepo = new InternalStudentRepository(InternalConnectionString); InternalStudentSchoolEnrolmentRepository schoolEnrolmentRepo = new InternalStudentSchoolEnrolmentRepository(InternalConnectionString); InternalStudentAttendanceRateRepository attendanceRateRepo = new InternalStudentAttendanceRateRepository(InternalConnectionString, Options.StartDate, Options.EndDate); InternalSchoolRepository schoolRepo = new InternalSchoolRepository(InternalConnectionString); // Determine limiting schools (if any) List <int> limitediSchoolIDs = new List <int>(); if (Options.LimitSchools.Count > 0) { limitediSchoolIDs = Options.LimitSchools; List <string> schoolNames = schoolRepo.Get(limitediSchoolIDs).Select(x => x.Name).ToList <string>(); this.SubSubTitle = this.SubTitle; this.SubTitle = schoolNames.ToCommaSeparatedString(); } else { limitediSchoolIDs = schoolRepo.GetAllKnownSchoolIDs(); } LineChartLine fnmStudentsLine = new LineChartLine() { Label = "FNM Students" }; LineChartLine nonFNMStudentsLine = new LineChartLine() { Label = "Non-FNM Students" }; // Find the school year that the specified dates fit into // If the dates span into two or more school years, use the first one detected // The chart will always start at the beginning of the school year and end at the end of the school year int schoolYear = ReturnLower(Parsers.FindSchoolYear(Options.StartDate), Parsers.FindSchoolYear(Options.EndDate)); List <ChartMonth> schoolYears = new List <ChartMonth>() { new ChartMonth { Label = "AUG", Starts = new DateTime(schoolYear, 8, 1), Ends = new DateTime(schoolYear, 8, DateTime.DaysInMonth(schoolYear, 8)) }, new ChartMonth { Label = "SEP", Starts = new DateTime(schoolYear, 9, 1), Ends = new DateTime(schoolYear, 9, DateTime.DaysInMonth(schoolYear, 9)) }, new ChartMonth { Label = "OCT", Starts = new DateTime(schoolYear, 10, 1), Ends = new DateTime(schoolYear, 10, DateTime.DaysInMonth(schoolYear, 10)) }, new ChartMonth { Label = "NOV", Starts = new DateTime(schoolYear, 11, 1), Ends = new DateTime(schoolYear, 11, DateTime.DaysInMonth(schoolYear, 11)) }, new ChartMonth { Label = "DEC", Starts = new DateTime(schoolYear, 12, 1), Ends = new DateTime(schoolYear, 12, DateTime.DaysInMonth(schoolYear, 12)) }, new ChartMonth { Label = "JAN", Starts = new DateTime(schoolYear + 1, 1, 1), Ends = new DateTime(schoolYear + 1, 1, DateTime.DaysInMonth(schoolYear + 1, 1)) }, new ChartMonth { Label = "FEB", Starts = new DateTime(schoolYear + 1, 2, 1), Ends = new DateTime(schoolYear + 1, 2, DateTime.DaysInMonth(schoolYear + 1, 2)) }, new ChartMonth { Label = "MAR", Starts = new DateTime(schoolYear + 1, 3, 1), Ends = new DateTime(schoolYear + 1, 3, DateTime.DaysInMonth(schoolYear + 1, 3)) }, new ChartMonth { Label = "APR", Starts = new DateTime(schoolYear + 1, 4, 1), Ends = new DateTime(schoolYear + 1, 4, DateTime.DaysInMonth(schoolYear + 1, 4)) }, new ChartMonth { Label = "MAY", Starts = new DateTime(schoolYear + 1, 5, 1), Ends = new DateTime(schoolYear + 1, 5, DateTime.DaysInMonth(schoolYear + 1, 5)) }, new ChartMonth { Label = "JUN", Starts = new DateTime(schoolYear + 1, 6, 1), Ends = new DateTime(schoolYear + 1, 6, DateTime.DaysInMonth(schoolYear + 1, 6)) }, new ChartMonth { Label = "JUL", Starts = new DateTime(schoolYear + 1, 7, 1), Ends = new DateTime(schoolYear + 1, 7, DateTime.DaysInMonth(schoolYear + 1, 7)) }, }; this.Labels = schoolYears.Select(x => x.Label).ToList(); foreach (ChartMonth month in schoolYears) { // Check to see if this month falls within the specified time period // If it doesn't, skip it if (month.Starts > Options.EndDate) { continue; } if (month.Ends < Options.StartDate) { continue; } // Clamp the start and end dates to the start and end dates specified if (month.Starts < Options.StartDate) { month.Starts = Options.StartDate; } if (month.Ends > Options.EndDate) { month.Ends = Options.EndDate; } // If the month is the current month, cap the end date at today, because future data won't exist yet if ((month.Starts.Month == DateTime.Today.Month) && (month.Starts.Year == DateTime.Today.Year)) { if (month.Ends > DateTime.Today) { month.Ends = DateTime.Today; } } decimal dataPointThisMonth_NonFNM = (decimal) - 1.0; decimal dataPointThisMonth_FNM = (decimal) - 1.0; // Now, load all the enrolled students during the start and end of the month // and calculate their average attendances List <Student> enrolledStudentsThisMonth = studentRepo.Get(schoolEnrolmentRepo.GetStudentIDsEnrolledOn(month.Starts, month.Ends, limitediSchoolIDs, true)); if (enrolledStudentsThisMonth.Count == 0) { continue; } List <decimal> attendanceRatesNonFNM = new List <decimal>(); List <decimal> attendanceRatesFNM = new List <decimal>(); foreach (Student s in enrolledStudentsThisMonth) { StudentAttendanceRate sar = attendanceRateRepo.GetForStudent(s.iStudentID, month.Starts, month.Ends); decimal attendanceRate = sar.GetAttendanceRate(month.Starts, month.Ends); if (attendanceRate != -1) { if (s.IsFirstNations) { attendanceRatesFNM.Add(attendanceRate); } else { attendanceRatesNonFNM.Add(attendanceRate); } } } // Now, find the number of the rates that are greater than or equal to the target try { dataPointThisMonth_NonFNM = (decimal)((decimal)attendanceRatesNonFNM.Count(x => x > Options.TargetAttendanceRate) / (decimal)attendanceRatesNonFNM.Count()); } catch { } try { dataPointThisMonth_FNM = (decimal)((decimal)attendanceRatesFNM.Count(x => x > Options.TargetAttendanceRate) / (decimal)attendanceRatesFNM.Count()); } catch { } // Add the data point to the line if (dataPointThisMonth_NonFNM > -1) { nonFNMStudentsLine.LineDataPoints.Add(month.Label, dataPointThisMonth_NonFNM); } if (dataPointThisMonth_FNM > -1) { fnmStudentsLine.LineDataPoints.Add(month.Label, dataPointThisMonth_FNM); } } // Finally, add the lines to the chart this.Lines.Add(nonFNMStudentsLine); this.Lines.Add(fnmStudentsLine); }
/// <summary> /// 生成所有曲线的JSON /// </summary> protected void GetAllLineJson() { LineChart chart = new LineChart(BeginTime, EndTime); chart.Period = Period; chart.NeedForecastPoint = (Period == net91com.Stat.Core.PeriodOptions.Daily || Period == net91com.Stat.Core.PeriodOptions.Weekly || Period == net91com.Stat.Core.PeriodOptions.Monthly); for (int i = 0; i < ListAll.Count; i++) { string softName = GetSoft(ListAll[i][0].SoftId).Name; string platform = "_" + ((MobileOption)ListAll[i][0].Platform).GetDescription(); if (platform == "_None") { platform = "_不区分平台"; } string channelName = QuDao ? "_" + ListAll[i][0].ChannelName : string.Empty; LineChartLine line = new LineChartLine { Name = softName + platform + channelName, Show = true, XIntervalDays = 0, Points = ListAll[i].Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.NewNum, DataContext = a }).ToList() }; if (ForeCastUserDatas.Count > 0) { List <ForecastSoftUser> tempMyForecastUser = ForeCastUserDatas.Where(p => p.Period == (int)Period) .Where( p => p.SoftId == ListAll[i][0].SoftId && p.Platform == ListAll[i][0].Platform && ListAll[i][0].ChannelID == p.ChannelID) .OrderByDescending(p => p.StatDate) .ToList(); SoftUser user = GetForeCastSoftUser(tempMyForecastUser); if (user != null) { line.ForecastPoint = new LineChartPoint { YValue = user.NewNum, DataContext = user } } ; } //mileStoneDate[i].ForEach(a => line.AddMarker(a.MileStoneDate, Period, a.Remarks)); chart.Y.Add(line); ////增加新增用户未修正的线 //if (!QuDao && checkForNotUpdated.Checked && Period != PeriodOptions.TimeOfDay && Period != PeriodOptions.Hours) //{ // LineChartLine line2 = new LineChartLine // { // Name = softName + platform + channelName + "_未修正数据", // Show = true, // XIntervalDays = 0, // Points = ListAll[i].Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.FirstNewUserCount + a.NewUserCount_Shanzhai, DataContext = a, Type = -1 }).ToList() // }; // chart.Y.Add(line2); //} } //对比线前后时间差值 int intervalDays = 0; if (ListAll[0].Count != 0 && ListAllForCompare.Count != 0 && ListAllForCompare[0].Count != 0) { intervalDays = ListAll[0][0].StatDate.Subtract(ListAllForCompare[0][0].StatDate).Days; } foreach (var item in ListAllForCompare) { string softName = GetSoft(item[0].SoftId).Name; string platform = "_" + ((MobileOption)item[0].Platform).GetDescription(); if (platform == "_None") { platform = "_不区分平台"; } string channelName = QuDao ? "_" + item[0].ChannelName : string.Empty; chart.Y.Add( new LineChartLine { Name = softName + platform + channelName + "_对比线", Show = true, XIntervalDays = intervalDays, Points = item.Select(a => new LineChartPoint { XValue = a.StatDate, YValue = a.NewNum, DataContext = a }).ToList() }); } AxisJsonStr = string.Format("{{{0},labels:{{align:'left',tickLength:80,tickPixelInterval:140{1},step:{2}}}}}" , chart.GetXJson() , Period == net91com.Stat.Core.PeriodOptions.Hours ? ",rotation:-45,x:-40,y:60" : (Period == net91com.Stat.Core.PeriodOptions.TimeOfDay ? ",x:-5" : ",rotation:-45,x:-30,y:45") , chart.Step); SeriesJsonStr = chart.GetYJson( delegate(LineChartPoint point) { SoftUser user = (SoftUser)point.DataContext; if (point.Type != -1) { return(string.Format(",\"growth\":\"{0}\",\"Denominator\":{1},\"Other\":null", user.Growth, user.TotalNum - user.NewNum)); } else { return(string.Format(",\"growth\":\"{0}\",\"Denominator\":{1},\"Other\":null", "", "0")); } }); }