Created
February 17, 2018 12:10
-
-
Save joshi-kumar/ec458968458c177cef1840eb6f84d417 to your computer and use it in GitHub Desktop.
Chart js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Controller | |
using DotNet.Highcharts.Options; | |
using Nop.Core.Domain.Customers; | |
using Nop.Plugin.OneRead.AnalyticsAndReports.Domain; | |
using Nop.Plugin.OneRead.AnalyticsAndReports.Models; | |
using Nop.Plugin.OneRead.AnalyticsAndReports.Services; | |
using Nop.Services.Common; | |
using Nop.Services.Customers; | |
using Nop.Web.Framework.Controllers; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Web.Mvc; | |
namespace Nop.Plugin.OneRead.AnalyticsAndReports.Controllers | |
{ | |
public class AnalyticsAndReportsController : BasePluginController | |
{ | |
#region Global Obj | |
private readonly IAnalyticsAndReportService _analyticsAndReportService; | |
private readonly ICustomerService _customerService; | |
private readonly IGenericAttributeService _genericAttributeService; | |
#endregion | |
#region Cons | |
public AnalyticsAndReportsController(IAnalyticsAndReportService analyticsAndReportService, ICustomerService customerService, IGenericAttributeService genericAttributeService) | |
{ | |
this._analyticsAndReportService = analyticsAndReportService; | |
this._customerService = customerService; | |
this._genericAttributeService = genericAttributeService; | |
} | |
public ActionResult InsertAnalytic(int productId = 0, int typeId = 0, int categoryId = 0) | |
{ | |
if (productId > 0) | |
_analyticsAndReportService.InsretProductAnalytics(productId, typeId); | |
if (categoryId > 0) | |
_analyticsAndReportService.InsretCategoryAnalytics(categoryId, typeId); | |
return null; | |
} | |
public ActionResult InsertAnalytics(int productId = 0, int typeId = 0, int categoryId = 0) | |
{ | |
if (productId > 0) | |
_analyticsAndReportService.InsretProductAnalytics(productId, typeId); | |
if (categoryId > 0) | |
_analyticsAndReportService.InsretCategoryAnalytics(categoryId, typeId); | |
return Json("", JsonRequestBehavior.AllowGet); | |
} | |
#endregion | |
#region High-charts | |
public ActionResult HighCharts() | |
{ | |
DateTimeModel model = new DateTimeModel(); | |
return View(model); | |
} | |
[HttpGet] | |
public JsonResult DisplayChart(int viewtypeid, DateTime startDate, DateTime endDate, int actionType = 0) | |
{ | |
List<HighChartModel> list = new List<HighChartModel>(); | |
List<HighChartModel> list_d = new List<HighChartModel>(); | |
List<int> existing = new List<int>(); | |
List<int> existing_d = new List<int>(); | |
var record = new List<AnalyticsAndReportsProduct>(); | |
var record_d = new List<AnalyticsAndReportsProduct>(); | |
if (actionType == 10 || actionType==40 || actionType == 50) //10 for Browse and download,40 for age group, 50 for downloaded by country | |
{ | |
record = _analyticsAndReportService.GetBrowesProduct(); | |
record_d = _analyticsAndReportService.GetDownloadProduct(); | |
} | |
else if (actionType == 30)//30 for publish | |
{ | |
record = _analyticsAndReportService.GetPublishProduct(); | |
} | |
#region downloaded by country | |
if (actionType == 50) | |
{ | |
// list = AgeGroupBrowsedProduct(record, list); | |
list_d = ProductDownloadedByCountry(record_d, list_d); | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
#endregion | |
#region age group | |
if (actionType==40) | |
{ | |
list = AgeGroupBrowsedProduct(record, list); | |
list_d = AgeGroupDownloadedProduct(record_d,list_d); | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
#endregion | |
#region year view | |
if (viewtypeid == 10) | |
{ | |
list = ProductBrowseOrPublishYearView(list, record, existing); | |
if (actionType == 10) | |
{ | |
list_d = ProductDownloadedYearView(list_d, record_d, existing_d); | |
} | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
#endregion year | |
#region month view | |
else if (viewtypeid == 20) | |
{ | |
list = ProductBrowseOrPublishMonthView(list, record, existing); | |
if (actionType == 10) | |
{ | |
list_d = ProductDownloadedMonthView(list_d, record_d, existing_d); | |
} | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
#endregion year | |
#region week view | |
else if (viewtypeid == 30) | |
{ | |
list = ProductBrowseOrPublishWeekView(list, record); | |
if(actionType==10) | |
{ | |
list_d = ProductDownloadedWeekView(list_d, record_d); | |
} | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
#endregion year | |
#region Date range | |
else if (viewtypeid == 0) | |
{ | |
int startYear = startDate.Year; | |
int endYear = endDate.Year; | |
int startMonth = startDate.Month; | |
int endMonth = endDate.Month; | |
var dateRangeRecord = (from m in record | |
where m.CreatedOnUtc >= startDate && m.CreatedOnUtc <= endDate | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
var dateRangeRecord_d = (from m in record_d | |
where m.CreatedOnUtc >= startDate && m.CreatedOnUtc <= endDate | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
if (startMonth == endMonth && startYear == endYear) //Display weekly or day bases | |
{ | |
double days = (endDate - startDate).TotalDays; | |
if (days < 10) | |
{ | |
list = ProductBrowseOrPublishDateRangeDaysView(list, existing, dateRangeRecord); | |
if(actionType==10) | |
{ | |
list_d = ProductDownloadedDaysView(list_d, existing_d, dateRangeRecord_d); | |
} | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
else | |
{ | |
int diff = Convert.ToInt32(days / 7); | |
double mod = Convert.ToInt32(days % 7); | |
if (mod != 0 && mod < 4) | |
{ | |
diff = diff + 1; | |
} | |
list = ProductBrowseOrPublishDateRangeWeekView(startDate, list, ref dateRangeRecord, days, diff); | |
if(actionType==10) | |
{ | |
list_d = ProductDownloadedDateRangeWeekView(startDate, list_d, dateRangeRecord_d, diff); | |
} | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
} | |
else if (startYear == endYear) //Display monthly | |
{ | |
list = ProductBrowseOrPublishDateRangeMonthView(list, existing, dateRangeRecord); | |
if(actionType==10) | |
{ | |
list_d = ProductDownloadedDateRangeMonthView(list_d, existing_d, dateRangeRecord_d); | |
} | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
else if (startYear < endYear) // Display yearly | |
{ | |
list = ProductBrowseOrPublishDateRangeYearView(list, record, existing, dateRangeRecord); | |
if (actionType == 10) | |
{ | |
list_d = ProductDownloadedDateRangeYearView(list_d, record_d, existing_d, dateRangeRecord_d); | |
} | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
} | |
#endregion Date range | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
[HttpGet] | |
public JsonResult DisplayCategoryChart(int viewtypeid, DateTime startDate, DateTime endDate) | |
{ | |
List<HighChartModel> list = new List<HighChartModel>(); | |
//var record = new List<AnalyticsAndReportsCategory>(); | |
var record = _analyticsAndReportService.GetBrowesCategory(); | |
List<int> existing = new List<int>(); | |
#region year view | |
if (viewtypeid == 10) | |
{ | |
list = CategoryBrowseYearView(list, record, existing); | |
return Json(list, JsonRequestBehavior.AllowGet); | |
} | |
#endregion year | |
#region month view | |
else if (viewtypeid == 20) | |
{ | |
list = CategorytBrowseMonthView(list, record, existing); | |
return Json(list, JsonRequestBehavior.AllowGet); | |
} | |
#endregion year | |
#region week view | |
else if (viewtypeid == 30) | |
{ | |
list = CategorytBrowseWeekView(list, record); | |
return Json(list, JsonRequestBehavior.AllowGet); | |
} | |
#endregion year | |
#region Date range | |
else if (viewtypeid == 0) | |
{ | |
int startYear = startDate.Year; | |
int endYear = endDate.Year; | |
int startMonth = startDate.Month; | |
int endMonth = endDate.Month; | |
var dateRangeRecord = (from m in record | |
where m.CreatedOnUtc.Date >= startDate && m.CreatedOnUtc.Date <= endDate | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
if (startMonth == endMonth && startYear == endYear) //Display weekly or dayly bases | |
{ | |
double days = (endDate - startDate).TotalDays; | |
if (days < 10) | |
{ | |
list = CategorytBrowseDateRangeDaysView(list, existing, dateRangeRecord); | |
return Json(list, JsonRequestBehavior.AllowGet); | |
} | |
else | |
{ | |
list = CategorytBrowseDateRangeWeekView(startDate, list, dateRangeRecord, days); | |
return Json(list, JsonRequestBehavior.AllowGet); | |
} | |
} | |
else if (startYear == endYear) //Display monthly | |
{ | |
list = CategorytBrowseDateRangeMonthView(list, existing, dateRangeRecord); | |
return Json(list, JsonRequestBehavior.AllowGet); | |
} | |
else if (startYear < endYear) // Display yearly | |
{ | |
list = CategorytBrowseDateRangeYearView(list, record, existing, dateRangeRecord); | |
return Json(list, JsonRequestBehavior.AllowGet); | |
} | |
} | |
#endregion Date range | |
return Json(list, JsonRequestBehavior.AllowGet); | |
} | |
[HttpGet] | |
public JsonResult DisplayCustomerChart(int viewtypeid, DateTime startDate, DateTime endDate, int actionType = 0) | |
{ | |
List<HighChartModel> list = new List<HighChartModel>(); | |
List<HighChartModel> list_d = new List<HighChartModel>(); | |
List<int> existing = new List<int>(); | |
List<int> existing_d = new List<int>(); | |
var record = new List<AnalyticsAndReportsProduct>(); | |
var record_d = new List<AnalyticsAndReportsProduct>(); | |
var allCustomers = _customerService.getAllCustomer(); | |
#region user Demographics | |
if (actionType == 60) | |
{ | |
list = UserDemographicsView(allCustomers, list); | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
#endregion | |
#region User Timeline | |
else if (actionType == 70) | |
{ | |
#region year view | |
if (viewtypeid == 10) | |
{ | |
list = ActiveUserYearView(allCustomers ,list); | |
list_d = NewUserYearView(allCustomers, list_d); | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
#endregion year | |
#region month view | |
else if (viewtypeid == 20) | |
{ | |
list = ActiveUserMonthView(allCustomers, list); | |
list_d = NewUserMonthView(allCustomers, list_d); | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
#endregion year | |
#region week view | |
else if (viewtypeid == 30) | |
{ | |
list = ActiveUserWeekView(allCustomers, list); | |
list_d = NewUserWeekView(allCustomers, list_d); | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
#endregion year | |
#region Date range | |
else if (viewtypeid == 0) | |
{ | |
int startYear = startDate.Year; | |
int endYear = endDate.Year; | |
int startMonth = startDate.Month; | |
int endMonth = endDate.Month; | |
var customers = (from m in allCustomers | |
where m.CreatedOnUtc >= startDate && m.CreatedOnUtc <= endDate | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
//var allCustumer_ = (from m in allCustomers | |
// where m.CreatedOnUtc >= startDate && m.CreatedOnUtc <= endDate | |
// orderby m.CreatedOnUtc.Month ascending | |
// select m).ToList(); | |
if (startMonth == endMonth && startYear == endYear) //Display weekly or day bases | |
{ | |
double days = (endDate - startDate).TotalDays; | |
if (days < 10) | |
{ | |
list = ActiveUserDateRangeDaysView(customers, list); | |
list_d = NewUserDateRangeDaysView(customers, list_d); | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
else | |
{ | |
int diff = Convert.ToInt32(days / 7); | |
double mod = Convert.ToInt32(days % 7); | |
if (mod != 0 && mod < 4) | |
{ | |
diff = diff + 1; | |
} | |
list = ActiveUserDateRangeWeekView(startDate, list, ref customers, days, diff); | |
list_d = NewUserDateRangeWeekView(startDate, list_d, ref customers, days, diff); | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
} | |
else if (startYear == endYear) //Display monthly | |
{ | |
list = ActiveUserDateRangeMonthView(list, existing, customers); | |
list_d = NewUserDateRangeMonthView(list_d, existing_d, customers); | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
else if (startYear < endYear) // Display yearly | |
{ | |
list = ActiveUserDateRangeYearView(list, allCustomers, existing, customers); | |
list_d = NewUserDateRangeYearView(list_d, allCustomers, existing_d, customers); | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
} | |
#endregion Date range | |
} | |
#endregion | |
return Json(new { list = list, list_d = list_d }, JsonRequestBehavior.AllowGet); | |
} | |
#endregion | |
#region Utilities | |
private static List<HighChartModel> ProductDownloadedDateRangeWeekView(DateTime startDate, List<HighChartModel> list_d, List<AnalyticsAndReportsProduct> dateRangeRecord_d, int diff) | |
{ | |
DateTime preWeeks_d = startDate; | |
DateTime EndDate_d = preWeeks_d.AddDays(7).AddSeconds(-1); | |
for (int i = 0; i < diff; i++) | |
{ | |
int c = (from q in dateRangeRecord_d | |
where q.CreatedOnUtc <= EndDate_d | |
select q).Count(); | |
DateTime preEndDate = DateTime.Today; | |
preEndDate = EndDate_d; | |
EndDate_d = EndDate_d.AddDays(7); | |
dateRangeRecord_d = (from w in dateRangeRecord_d | |
where w.CreatedOnUtc > preEndDate | |
select w).ToList(); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate_d.Date.AddDays(-7).ToString("ddMMM")); | |
list_d.Add(r); | |
} | |
return list_d; | |
} | |
private static List<HighChartModel> ProductBrowseOrPublishDateRangeWeekView(DateTime startDate, List<HighChartModel> list, ref List<AnalyticsAndReportsProduct> dateRangeRecord, double days,int diff) | |
{ | |
DateTime preWeeks = startDate; | |
DateTime Today = DateTime.Today; | |
DateTime StartDate = preWeeks; | |
DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1); | |
for (int i = 0; i < diff; i++) | |
{ | |
int c = (from q in dateRangeRecord | |
where q.CreatedOnUtc <= EndDate | |
select q).Count(); | |
DateTime preEndDate = DateTime.Today; | |
preEndDate = EndDate; | |
EndDate = EndDate.AddDays(7); | |
dateRangeRecord = (from w in dateRangeRecord | |
where w.CreatedOnUtc > preEndDate | |
select w).ToList(); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM")); | |
list.Add(r); | |
} | |
return list; | |
} | |
private static List<HighChartModel> ProductDownloadedDaysView(List<HighChartModel> list_d, List<int> existing_d, List<AnalyticsAndReportsProduct> dateRangeRecord_d) | |
{ | |
foreach (var rc in dateRangeRecord_d) | |
{ | |
var day = rc.CreatedOnUtc.Day; | |
if (existing_d.Contains(day)) | |
continue; | |
int c = (from q in dateRangeRecord_d | |
where q.CreatedOnUtc.Date == rc.CreatedOnUtc.Date | |
select q).Count(); | |
existing_d.Add(day); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Date.ToString("ddMMM")); | |
list_d.Add(r); | |
} | |
list_d = list_d.OrderBy(i => i.Value).ToList(); | |
return list_d; | |
} | |
private static List<HighChartModel> ProductBrowseOrPublishDateRangeDaysView(List<HighChartModel> list, List<int> existing, List<AnalyticsAndReportsProduct> dateRangeRecord) | |
{ | |
foreach (var rc in dateRangeRecord) | |
{ | |
var day = rc.CreatedOnUtc.Day; | |
if (existing.Contains(day)) | |
continue; | |
int c = (from q in dateRangeRecord | |
where q.CreatedOnUtc.Date == rc.CreatedOnUtc.Date | |
select q).Count(); | |
existing.Add(day); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Date.ToString("ddMMM")); | |
list.Add(r); | |
} | |
list = list.OrderBy(i => i.Value).ToList(); | |
return list; | |
} | |
private static List<HighChartModel> ProductDownloadedDateRangeMonthView(List<HighChartModel> list_d, List<int> existing_d, List<AnalyticsAndReportsProduct> dateRangeRecord_d) | |
{ | |
var monthrecord_d = (from m in dateRangeRecord_d | |
where m.CreatedOnUtc.Year == DateTime.UtcNow.Year | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
foreach (var rc in monthrecord_d) | |
{ | |
var month = rc.CreatedOnUtc.Month; | |
if (existing_d.Contains(month)) | |
continue; | |
int c = (from q in monthrecord_d | |
where q.CreatedOnUtc.Month == month | |
select q.ProducId).Count(); | |
existing_d.Add(month); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
list_d.Add(r); | |
} | |
return list_d; | |
} | |
private static List<HighChartModel> ProductBrowseOrPublishDateRangeMonthView(List<HighChartModel> list, List<int> existing, List<AnalyticsAndReportsProduct> dateRangeRecord) | |
{ | |
var monthrecord = (from m in dateRangeRecord | |
where m.CreatedOnUtc.Year == DateTime.UtcNow.Year | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
foreach (var rc in monthrecord) | |
{ | |
var month = rc.CreatedOnUtc.Month; | |
if (existing.Contains(month)) | |
continue; | |
int c = (from q in monthrecord | |
where q.CreatedOnUtc.Month == month | |
select q.ProducId).Count(); | |
existing.Add(month); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
list.Add(r); | |
} | |
return list; | |
} | |
private static List<HighChartModel> ProductDownloadedDateRangeYearView(List<HighChartModel> list_d, List<AnalyticsAndReportsProduct> record_d, List<int> existing_d, List<AnalyticsAndReportsProduct> dateRangeRecord_d) | |
{ | |
foreach (var rc in dateRangeRecord_d) | |
{ | |
var year = rc.CreatedOnUtc.Year; | |
if (existing_d.Contains(year)) | |
continue; | |
int c = (from q in record_d | |
where q.CreatedOnUtc.Year == year | |
select q.ProducId).Count(); | |
existing_d.Add(year); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Year); | |
list_d.Add(r); | |
} | |
list_d = list_d.OrderBy(i => i.Value).ToList(); | |
return list_d; | |
} | |
private static List<HighChartModel> ProductBrowseOrPublishDateRangeYearView(List<HighChartModel> list, List<AnalyticsAndReportsProduct> record, List<int> existing, List<AnalyticsAndReportsProduct> dateRangeRecord) | |
{ | |
foreach (var rc in dateRangeRecord) | |
{ | |
var year = rc.CreatedOnUtc.Year; | |
if (existing.Contains(year)) | |
continue; | |
int c = (from q in record | |
where q.CreatedOnUtc.Year == year | |
select q.ProducId).Count(); | |
existing.Add(year); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Year); | |
list.Add(r); | |
} | |
list = list.OrderBy(i => i.Value).ToList(); | |
return list; | |
} | |
private static List<HighChartModel> ProductDownloadedWeekView(List<HighChartModel> list_d, List<AnalyticsAndReportsProduct> record_d) | |
{ | |
DateTime preWeeks_d = DateTime.Now.AddDays(-27); | |
var weekrecord_d = (from m in record_d | |
where m.CreatedOnUtc >= preWeeks_d && m.CreatedOnUtc <= DateTime.UtcNow | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
//DateTime EndDate_d = preWeeks_d.AddDays(7).AddSeconds(-1); | |
DateTime EndDate_d = preWeeks_d.AddDays(7).AddSeconds(-1); | |
//DateTime EndDate = preWeeks.AddDays(7); | |
int addDays_d = 0; | |
for (int i = 0; i < 4; i++) | |
{ | |
int c = (from q in weekrecord_d | |
where q.CreatedOnUtc <= EndDate_d | |
select q).Count(); | |
DateTime preEndDate = DateTime.Today; | |
preEndDate = EndDate_d; | |
EndDate_d = EndDate_d.AddDays(7); | |
weekrecord_d = (from w in weekrecord_d | |
where w.CreatedOnUtc >= preEndDate | |
select w).ToList(); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(preEndDate.Date.AddDays(-7).ToString("ddMMM") + " To " + EndDate_d.Date.AddDays(-8).ToString("ddMMM")); | |
list_d.Add(r); | |
} | |
return list_d; | |
} | |
private static List<HighChartModel> ProductBrowseOrPublishWeekView(List<HighChartModel> list, List<AnalyticsAndReportsProduct> record) | |
{ | |
DateTime preWeeks = DateTime.Now.AddDays(-27); | |
var weekrecord = (from m in record | |
where m.CreatedOnUtc >= preWeeks && m.CreatedOnUtc <= DateTime.UtcNow | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
DateTime Today = DateTime.Today; | |
DateTime StartDate = preWeeks; | |
//DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1); | |
DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1); | |
//DateTime EndDate = preWeeks.AddDays(7); | |
int addDays = 0; | |
for (int i = 0; i < 4; i++) | |
{ | |
int c = (from q in weekrecord | |
where q.CreatedOnUtc <= EndDate | |
select q).Count(); | |
DateTime preEndDate = DateTime.Today; | |
preEndDate = EndDate; | |
EndDate = EndDate.AddDays(7); | |
weekrecord = (from w in weekrecord | |
where w.CreatedOnUtc >= preEndDate | |
select w).ToList(); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM")); | |
list.Add(r); | |
} | |
return list; | |
} | |
private static List<HighChartModel> ProductDownloadedMonthView(List<HighChartModel> list_d, List<AnalyticsAndReportsProduct> record_d, List<int> existing_d) | |
{ | |
var monthrecord_d = (from m in record_d | |
where m.CreatedOnUtc.Year == DateTime.UtcNow.Year | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
foreach (var rc in monthrecord_d) | |
{ | |
var month = rc.CreatedOnUtc.Month; | |
if (existing_d.Contains(month)) | |
continue; | |
int c = (from q in monthrecord_d | |
where q.CreatedOnUtc.Month == month | |
select q.ProducId).Count(); | |
existing_d.Add(month); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
list_d.Add(r); | |
} | |
return list_d; | |
} | |
private static List<HighChartModel> ProductBrowseOrPublishMonthView(List<HighChartModel> list, List<AnalyticsAndReportsProduct> record, List<int> existing) | |
{ | |
var monthrecord = (from m in record | |
where m.CreatedOnUtc.Year == DateTime.UtcNow.Year | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
foreach (var rc in monthrecord) | |
{ | |
var month = rc.CreatedOnUtc.Month; | |
if (existing.Contains(month)) | |
continue; | |
int c = (from q in monthrecord | |
where q.CreatedOnUtc.Month == month | |
select q.ProducId).Count(); | |
existing.Add(month); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
list.Add(r); | |
} | |
return list; | |
} | |
private static List<HighChartModel> ProductDownloadedYearView(List<HighChartModel> list_d, List<AnalyticsAndReportsProduct> record_d, List<int> existing_d) | |
{ | |
foreach (var rc in record_d) | |
{ | |
var year = rc.CreatedOnUtc.Year; | |
if (existing_d.Contains(year)) | |
continue; | |
int c = (from q in record_d | |
where q.CreatedOnUtc.Year == year | |
select q.ProducId).Count(); | |
existing_d.Add(year); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Year); | |
list_d.Add(r); | |
} | |
list_d = list_d.OrderBy(i => i.Value).ToList(); | |
return list_d; | |
} | |
private static List<HighChartModel> ProductBrowseOrPublishYearView(List<HighChartModel> list, List<AnalyticsAndReportsProduct> record, List<int> existing) | |
{ | |
foreach (var rc in record) | |
{ | |
var year = rc.CreatedOnUtc.Year; | |
if (existing.Contains(year)) | |
continue; | |
int c = (from q in record | |
where q.CreatedOnUtc.Year == year | |
select q.ProducId).Count(); | |
existing.Add(year); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Year); | |
list.Add(r); | |
} | |
list = list.OrderBy(i => i.Value).ToList(); | |
return list; | |
} | |
private List<HighChartModel> AgeGroupBrowsedProduct(List<AnalyticsAndReportsProduct> record,List<HighChartModel> list) | |
{ | |
List<int> existing = new List<int>(); | |
//List<int> cusId = new List<int>(); | |
int age; | |
string ageGroup = null; | |
var cusId = from x in record | |
group x.CustomerId by x.CustomerId into g | |
let count = g.Count() | |
select new { Value = g.Key, Count = count }; | |
list = prepareListValue(list); | |
foreach (var rc in cusId) | |
{ | |
var custInfo = _customerService.GetCustomerById(rc.Value); | |
var dateOfBirth = custInfo.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth); | |
if (dateOfBirth.HasValue) | |
{ | |
age = DateTime.UtcNow.Year - dateOfBirth.Value.Year; | |
ageGroup = GetAgeGroup(age); | |
} | |
else | |
{ | |
ageGroup = "UnKnown"; | |
} | |
foreach (var item in list.Where(w => w.Value == ageGroup)) | |
{ | |
item.Item = Convert.ToInt32(rc.Count); | |
} | |
} | |
list = list.OrderBy(i => i.Value).ToList(); | |
return list; | |
} | |
private List<HighChartModel> AgeGroupDownloadedProduct(List<AnalyticsAndReportsProduct> record_d, List<HighChartModel> list_d) | |
{ | |
List<int> existing = new List<int>(); | |
//List<int> cusId = new List<int>(); | |
int age; | |
string ageGroup = null; | |
var cusId = from x in record_d | |
group x.CustomerId by x.CustomerId into g | |
let count = g.Count() | |
select new { Value = g.Key, Count = count }; | |
list_d = prepareListValue(list_d); | |
foreach (var rc in cusId) | |
{ | |
var custInfo = _customerService.GetCustomerById(rc.Value); | |
var dateOfBirth = custInfo.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth); | |
if (dateOfBirth.HasValue) | |
{ | |
age = DateTime.UtcNow.Year - dateOfBirth.Value.Year; | |
ageGroup = GetAgeGroup(age); | |
} | |
else | |
{ | |
ageGroup = "UnKnown"; | |
} | |
foreach (var item in list_d.Where(w => w.Value == ageGroup)) | |
{ | |
item.Item = Convert.ToInt32(rc.Count); | |
} | |
} | |
list_d = list_d.OrderBy(i => i.Value).ToList(); | |
return list_d; | |
} | |
private List<HighChartModel> prepareListValue(List<HighChartModel> list) | |
{ | |
HighChartModel model=new HighChartModel(); | |
list.Add(new HighChartModel { Item = 0.0, Value = "00-08" }); | |
list.Add(new HighChartModel { Item = 0.0, Value = "09-16" }); | |
list.Add(new HighChartModel { Item = 0.0, Value = "17-24" }); | |
list.Add(new HighChartModel { Item = 0.0, Value = "25-32" }); | |
list.Add(new HighChartModel { Item = 0.0, Value = "33-40" }); | |
list.Add(new HighChartModel { Item = 0.0, Value = "41-48" }); | |
list.Add(new HighChartModel { Item = 0.0, Value = "49-56" }); | |
list.Add(new HighChartModel { Item = 0.0, Value = "57-64" }); | |
list.Add(new HighChartModel { Item = 0.0, Value = "65-100" }); | |
list.Add(new HighChartModel { Item = 0.0, Value = "UnKnown" }); | |
return list; | |
} | |
private string GetAgeGroup(int p) | |
{ | |
if (p >= 0 && p <= 8) | |
{ | |
return "00-08"; | |
} | |
else if (p >= 9 && p <= 16) | |
{ | |
return "09-16"; | |
} | |
else if (p >= 17 && p <= 24) | |
{ | |
return "17-24"; | |
} | |
else if (p >= 25 && p <= 32) | |
{ | |
return "25-32"; | |
} | |
else if (p >= 33 && p <= 40) | |
{ | |
return "33-40"; | |
} | |
else if (p >= 41 && p <= 48) | |
{ | |
return "41-48"; | |
} | |
else if (p >= 49 && p <= 56) | |
{ | |
return "49-56"; | |
} | |
else if (p >= 56 && p <= 64) | |
{ | |
return "57-64"; | |
} | |
else | |
{ | |
return "65-100"; | |
} | |
// string ageGroup; | |
//switch (p) | |
//{ | |
// case 00-08: | |
// ageGroup = "00 - 08"; | |
// break; | |
// case 09-16: | |
// ageGroup = "09 - 16"; | |
// break; | |
// case 18-24: | |
// ageGroup = "17 - 24"; | |
// break; | |
// case 25 - 32: | |
// ageGroup = "25 - 32"; | |
// break; | |
// case 33 - 40: | |
// ageGroup = "33 - 40"; | |
// break; | |
// case 41 - 48: | |
// ageGroup = "41 - 48"; | |
// break; | |
// case 49 - 56: | |
// ageGroup = "49 - 56"; | |
// break; | |
// case 57 - 64: | |
// ageGroup = "57 - 64"; | |
// break; | |
// case 64 - 100: | |
// ageGroup = "64 - 100"; | |
// break; | |
//} | |
} | |
private static List<HighChartModel> CategorytBrowseDateRangeYearView(List<HighChartModel> list, List<AnalyticsAndReportsCategory> record, List<int> existing, List<AnalyticsAndReportsCategory> dateRangeRecord) | |
{ | |
foreach (var rc in dateRangeRecord) | |
{ | |
var year = rc.CreatedOnUtc.Year; | |
if (existing.Contains(year)) | |
continue; | |
int c = (from q in record | |
where q.CreatedOnUtc.Year == year | |
select q.CategoryId).Count(); | |
existing.Add(year); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Year); | |
list.Add(r); | |
} | |
list = list.OrderBy(i => i.Value).ToList(); | |
return list; | |
} | |
private static List<HighChartModel> CategorytBrowseDateRangeMonthView(List<HighChartModel> list, List<int> existing, List<AnalyticsAndReportsCategory> dateRangeRecord) | |
{ | |
var monthrecord = (from m in dateRangeRecord | |
where m.CreatedOnUtc.Year == DateTime.UtcNow.Year | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
foreach (var rc in monthrecord) | |
{ | |
var month = rc.CreatedOnUtc.Month; | |
if (existing.Contains(month)) | |
continue; | |
int c = (from q in monthrecord | |
where q.CreatedOnUtc.Month == month | |
select q.CategoryId).Count(); | |
existing.Add(month); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
list.Add(r); | |
} | |
return list; | |
} | |
private static List<HighChartModel> CategorytBrowseDateRangeWeekView(DateTime startDate, List<HighChartModel> list, List<AnalyticsAndReportsCategory> dateRangeRecord, double days) | |
{ | |
DateTime preWeeks = startDate; | |
DateTime Today = DateTime.Today; | |
DateTime StartDate = preWeeks; | |
DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1); | |
int diff = Convert.ToInt32(days / 7); | |
double mod = Convert.ToInt32(days % 7); | |
if (mod != 0 && mod < 4) | |
{ | |
diff = diff + 1; | |
} | |
for (int i = 0; i < diff; i++) | |
{ | |
int c = (from q in dateRangeRecord | |
where q.CreatedOnUtc.Date <= EndDate | |
select q).Count(); | |
DateTime preEndDate = DateTime.Today; | |
preEndDate = EndDate; | |
EndDate = EndDate.AddDays(7); | |
dateRangeRecord = (from w in dateRangeRecord | |
where w.CreatedOnUtc.Date > preEndDate.Date | |
select w).ToList(); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM")); | |
list.Add(r); | |
} | |
return list; | |
} | |
private static List<HighChartModel> CategorytBrowseDateRangeDaysView(List<HighChartModel> list, List<int> existing, List<AnalyticsAndReportsCategory> dateRangeRecord) | |
{ | |
foreach (var rc in dateRangeRecord) | |
{ | |
var day = rc.CreatedOnUtc.Day; | |
if (existing.Contains(day)) | |
continue; | |
int c = (from q in dateRangeRecord | |
// where q.CreatedOnUtc | |
where q.CreatedOnUtc.Date == rc.CreatedOnUtc.Date | |
select q).Count(); | |
existing.Add(day); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Date.ToString("ddMMM")); | |
list.Add(r); | |
} | |
list = list.OrderBy(i => i.Value).ToList(); | |
return list; | |
} | |
private static List<HighChartModel> CategorytBrowseWeekView(List<HighChartModel> list, List<AnalyticsAndReportsCategory> record) | |
{ | |
DateTime preWeeks = DateTime.Now.AddDays(-27); | |
var weekrecord = (from m in record | |
where m.CreatedOnUtc >= preWeeks && m.CreatedOnUtc <= DateTime.UtcNow | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
DateTime Today = DateTime.Today; | |
DateTime StartDate = preWeeks; | |
DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1); | |
for (int i = 0; i < 4; i++) | |
{ | |
int c = (from q in weekrecord | |
// where q.CreatedOnUtc | |
where q.CreatedOnUtc <= EndDate | |
select q).Count(); | |
DateTime preEndDate = DateTime.Today; | |
preEndDate = EndDate; | |
EndDate = EndDate.AddDays(7); | |
//addDays = addDays + 7; | |
weekrecord = (from w in weekrecord | |
where w.CreatedOnUtc >= preEndDate | |
select w).ToList(); | |
// existing.Add(month); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM")); | |
list.Add(r); | |
} | |
return list; | |
} | |
private static List<HighChartModel> CategorytBrowseMonthView(List<HighChartModel> list, List<AnalyticsAndReportsCategory> record, List<int> existing) | |
{ | |
var monthrecord = (from m in record | |
where m.CreatedOnUtc.Year == DateTime.UtcNow.Year | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
foreach (var rc in monthrecord) | |
{ | |
var month = rc.CreatedOnUtc.Month; | |
if (existing.Contains(month)) | |
continue; | |
int c = (from q in monthrecord | |
where q.CreatedOnUtc.Month == month | |
select q.CategoryId).Count(); | |
existing.Add(month); | |
//monthrecord = (from m in monthrecord where rc.CreatedOnUtc.Month != month select m).ToList(); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
list.Add(r); | |
} | |
return list; | |
} | |
private static List<HighChartModel> CategoryBrowseYearView(List<HighChartModel> list, List<AnalyticsAndReportsCategory> record, List<int> existing) | |
{ | |
foreach (var rc in record) | |
{ | |
var year = rc.CreatedOnUtc.Year; | |
if (existing.Contains(year)) | |
continue; | |
int c = (from q in record | |
where q.CreatedOnUtc.Year == year | |
select q.CategoryId).Count(); | |
existing.Add(year); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Year); | |
list.Add(r); | |
} | |
list = list.OrderBy(i => i.Value).ToList(); | |
return list; | |
} | |
private List<HighChartModel> ProductDownloadedByCountry(List<AnalyticsAndReportsProduct> record_d, List<HighChartModel> list_d) | |
{ | |
List<int> existing = new List<int>(); | |
var cusId = (from x in record_d | |
group x.CustomerId by x.CustomerId into g | |
let count = g.Count() | |
select new | |
{ Value = g.Key, | |
Count = count | |
}).OrderByDescending(c=>c.Count).Take(20); | |
foreach (var rc in cusId) | |
{ | |
HighChartModel model = new HighChartModel(); | |
string country =null; | |
var custInfo = _customerService.GetCustomerById(rc.Value); | |
if (custInfo != null && custInfo.BillingAddress != null && custInfo.BillingAddress.Country != null && custInfo.BillingAddress.Country.Name !=null) | |
country = custInfo.BillingAddress.Country.Name; | |
if (!string.IsNullOrEmpty(country)) | |
{ | |
var exist = list_d.Where(w => w.Value == country).FirstOrDefault(); | |
if (exist == null) | |
{ | |
model.Item = rc.Count; | |
model.Value = country; | |
list_d.Add(model); | |
} | |
else | |
{ | |
exist.Item += rc.Count; | |
} | |
} | |
else | |
{ | |
var exist = list_d.Where(w => w.Value == country).FirstOrDefault(); | |
if (exist == null) | |
{ | |
model.Item = rc.Count; | |
model.Value = "UnKnown"; | |
list_d.Add(model); | |
} | |
else | |
{ | |
exist.Item += rc.Count; | |
} | |
} | |
} | |
list_d = list_d.OrderBy(i => i.Value).ToList(); | |
return list_d; | |
} | |
private List<HighChartModel> UserDemographicsView(List<Customer> allCustomers, List<HighChartModel> list) | |
{ | |
List<int> existing = new List<int>(); | |
int age; | |
string ageGroup = null; | |
list = prepareListValue(list); | |
foreach (var rc in allCustomers) | |
{ | |
var custInfo = _customerService.GetCustomerById(rc.Id); | |
var dateOfBirth = custInfo.GetAttribute<DateTime?>(SystemCustomerAttributeNames.DateOfBirth); | |
if (dateOfBirth.HasValue) | |
{ | |
age = DateTime.UtcNow.Year - dateOfBirth.Value.Year; | |
ageGroup = GetAgeGroup(age); | |
} | |
else | |
{ | |
ageGroup = "UnKnown"; | |
} | |
foreach (var item in list.Where(w => w.Value == ageGroup)) | |
{ | |
item.Item =item.Item+1; | |
} | |
} | |
list = list.OrderBy(i => i.Value).ToList(); | |
return list; | |
} | |
private List<HighChartModel> ActiveUserYearView(List<Customer> allCustomers ,List<HighChartModel> list) | |
{ | |
List<int> existing = new List<int>(); | |
allCustomers = (from c in allCustomers | |
where c.Active | |
select c).ToList(); | |
foreach (var rc in allCustomers) | |
{ | |
var year = Convert.ToString(rc.CreatedOnUtc.Year); | |
var exist = list.Where(w => w.Value == year).FirstOrDefault(); | |
if (exist == null) | |
{ | |
HighChartModel r = new HighChartModel(); | |
r.Item = 1; | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Year); | |
list.Add(r); | |
} | |
else | |
{ | |
exist.Item++; | |
} | |
} | |
list = list.OrderBy(i => i.Value).ToList(); | |
list = ActivePrapareList(list); | |
return list; | |
} | |
private List<HighChartModel> NewUserYearView(List<Customer> allCustomers, List<HighChartModel> list_d) | |
{ | |
List<int> existing = new List<int>(); | |
foreach (var rc in allCustomers) | |
{ | |
var year = Convert.ToString(rc.CreatedOnUtc.Year); | |
var exist = list_d.Where(w => w.Value == year).FirstOrDefault(); | |
if (exist == null) | |
{ | |
HighChartModel r = new HighChartModel(); | |
r.Item = 1; | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Year); | |
list_d.Add(r); | |
} | |
else | |
{ | |
exist.Item++; | |
} | |
} | |
list_d = list_d.OrderBy(i => i.Value).ToList(); | |
return list_d; | |
} | |
private List<HighChartModel> ActiveUserMonthView(List<Customer> allCustomers, List<HighChartModel> list) | |
{ | |
List<int> existing = new List<int>(); | |
int currentYear = DateTime.UtcNow.Year; | |
allCustomers = (from c in allCustomers | |
where c.CreatedOnUtc.Year == currentYear && c.Active | |
orderby c.CreatedOnUtc.Month ascending | |
select c).ToList(); | |
foreach (var rc in allCustomers) | |
{ | |
var month = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
var exist = list.Where(w => w.Value == month).FirstOrDefault(); | |
if (exist == null) | |
{ | |
HighChartModel r = new HighChartModel(); | |
r.Item = 1; | |
r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
list.Add(r); | |
} | |
else | |
{ | |
exist.Item++; | |
} | |
} | |
list = ActivePrapareList(list); | |
return list; | |
} | |
private List<HighChartModel> NewUserMonthView(List<Customer> allCustomers, List<HighChartModel> list_d) | |
{ | |
List<int> existing = new List<int>(); | |
int currentYear = DateTime.UtcNow.Year; | |
allCustomers = (from c in allCustomers | |
where c.CreatedOnUtc.Year == currentYear && c.Active | |
orderby c.CreatedOnUtc.Month ascending | |
select c).ToList(); | |
foreach (var rc in allCustomers) | |
{ | |
var month = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
var exist = list_d.Where(w => w.Value == month).FirstOrDefault(); | |
if (exist == null) | |
{ | |
HighChartModel r = new HighChartModel(); | |
r.Item = 1; | |
r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
list_d.Add(r); | |
} | |
else | |
{ | |
exist.Item++; | |
} | |
} | |
return list_d; | |
} | |
private List<HighChartModel> ActiveUserWeekView(List<Customer> allCustomers, List<HighChartModel> list) | |
{ | |
DateTime preWeeks = DateTime.Now.AddDays(-27); | |
allCustomers = (from m in allCustomers | |
where m.CreatedOnUtc >= preWeeks && m.CreatedOnUtc <= DateTime.UtcNow | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
DateTime Today = DateTime.Today; | |
DateTime StartDate = preWeeks; | |
DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1); | |
for (int i = 0; i < 4; i++) | |
{ | |
int c = (from q in allCustomers | |
where q.CreatedOnUtc <= EndDate | |
select q).Count(); | |
DateTime preEndDate = DateTime.Today; | |
preEndDate = EndDate; | |
EndDate = EndDate.AddDays(7); | |
//addDays = addDays + 7; | |
allCustomers = (from w in allCustomers | |
where w.CreatedOnUtc >= preEndDate | |
select w).ToList(); | |
// existing.Add(month); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM")); | |
list.Add(r); | |
} | |
list = ActivePrapareList(list); | |
return list; | |
} | |
private static List<HighChartModel> ActivePrapareList(List<HighChartModel> list) | |
{ | |
string cValue = null; | |
int counter = 0; | |
foreach (var l in list) | |
{ | |
string pValue = cValue; | |
cValue = l.Value; | |
if (counter > 0) | |
{ | |
double prevItem = (from p in list | |
where p.Value == pValue | |
select p.Item).FirstOrDefault(); | |
l.Item = l.Item + prevItem; | |
} | |
counter++; | |
} | |
return list; | |
} | |
private List<HighChartModel> NewUserWeekView(List<Customer> allCustomers, List<HighChartModel> list_d) | |
{ | |
DateTime preWeeks = DateTime.Now.AddDays(-27); | |
allCustomers = (from m in allCustomers | |
where m.CreatedOnUtc >= preWeeks && m.CreatedOnUtc <= DateTime.UtcNow | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
DateTime Today = DateTime.Today; | |
DateTime StartDate = preWeeks; | |
DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1); | |
for (int i = 0; i < 4; i++) | |
{ | |
int c = (from q in allCustomers | |
where q.CreatedOnUtc <= EndDate | |
select q).Count(); | |
DateTime preEndDate = DateTime.Today; | |
preEndDate = EndDate; | |
EndDate = EndDate.AddDays(7); | |
//addDays = addDays + 7; | |
allCustomers = (from w in allCustomers | |
where w.CreatedOnUtc >= preEndDate | |
select w).ToList(); | |
// existing.Add(month); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM")); | |
list_d.Add(r); | |
} | |
string cValue = null; | |
int counter = 0; | |
return list_d; | |
} | |
private List<HighChartModel> ActiveUserDateRangeDaysView(List<Customer> allCustomers, List<HighChartModel> list) | |
{ | |
List<int> existing = new List<int>(); | |
foreach (var rc in allCustomers) | |
{ | |
var day = rc.CreatedOnUtc.Day; | |
if (existing.Contains(day)) | |
continue; | |
int c = (from q in allCustomers | |
// where q.CreatedOnUtc | |
where q.CreatedOnUtc.Date == rc.CreatedOnUtc.Date | |
select q).Count(); | |
existing.Add(day); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Date.ToString("ddMMM")); | |
list.Add(r); | |
} | |
list = list.OrderBy(i => i.Value).ToList(); | |
list = ActivePrapareList(list); | |
return list; | |
} | |
private List<HighChartModel> NewUserDateRangeDaysView(List<Customer> allCustomers, List<HighChartModel> list_d) | |
{ | |
List<int> existing = new List<int>(); | |
foreach (var rc in allCustomers) | |
{ | |
var day = rc.CreatedOnUtc.Day; | |
if (existing.Contains(day)) | |
continue; | |
int c = (from q in allCustomers | |
// where q.CreatedOnUtc | |
where q.CreatedOnUtc.Date == rc.CreatedOnUtc.Date | |
select q).Count(); | |
existing.Add(day); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Date.ToString("ddMMM")); | |
list_d.Add(r); | |
} | |
list_d = list_d.OrderBy(i => i.Value).ToList(); | |
return list_d; | |
} | |
private static List<HighChartModel> ActiveUserDateRangeWeekView(DateTime startDate, List<HighChartModel> list, ref List<Customer> allCustomer, double days, int diff) | |
{ | |
DateTime preWeeks = startDate; | |
DateTime Today = DateTime.Today; | |
DateTime StartDate = preWeeks; | |
DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1); | |
for (int i = 0; i < diff; i++) | |
{ | |
int c = (from q in allCustomer | |
where q.CreatedOnUtc <= EndDate | |
select q).Count(); | |
DateTime preEndDate = DateTime.Today; | |
preEndDate = EndDate; | |
EndDate = EndDate.AddDays(7); | |
allCustomer = (from w in allCustomer | |
where w.CreatedOnUtc > preEndDate | |
select w).ToList(); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM")); | |
list.Add(r); | |
} | |
list = ActivePrapareList(list); | |
return list; | |
} | |
private static List<HighChartModel> NewUserDateRangeWeekView(DateTime startDate, List<HighChartModel> list_d, ref List<Customer> allCustomer, double days, int diff) | |
{ | |
DateTime preWeeks = startDate; | |
DateTime Today = DateTime.Today; | |
DateTime StartDate = preWeeks; | |
DateTime EndDate = preWeeks.AddDays(7).AddSeconds(-1); | |
for (int i = 0; i < diff; i++) | |
{ | |
int c = (from q in allCustomer | |
where q.CreatedOnUtc <= EndDate | |
select q).Count(); | |
DateTime preEndDate = DateTime.Today; | |
preEndDate = EndDate; | |
EndDate = EndDate.AddDays(7); | |
allCustomer = (from w in allCustomer | |
where w.CreatedOnUtc > preEndDate | |
select w).ToList(); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(preEndDate.Date.AddDays(-6).ToString("ddMMM") + " To " + EndDate.Date.AddDays(-7).ToString("ddMMM")); | |
list_d.Add(r); | |
} | |
return list_d; | |
} | |
private List<HighChartModel> ActiveUserDateRangeMonthView(List<HighChartModel> list, List<int> existing, List<Customer> allCustomers) | |
{ | |
allCustomers = (from m in allCustomers | |
where m.CreatedOnUtc.Year == DateTime.UtcNow.Year | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
foreach (var rc in allCustomers) | |
{ | |
var month = rc.CreatedOnUtc.Month; | |
if (existing.Contains(month)) | |
continue; | |
int c = (from q in allCustomers | |
where q.CreatedOnUtc.Month == month | |
select q).Count(); | |
existing.Add(month); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
list.Add(r); | |
} | |
list = ActivePrapareList(list); | |
return list; | |
} | |
private List<HighChartModel> NewUserDateRangeMonthView(List<HighChartModel> list_d, List<int> existing_d, List<Customer> allCustomers) | |
{ | |
allCustomers = (from m in allCustomers | |
where m.CreatedOnUtc.Year == DateTime.UtcNow.Year | |
orderby m.CreatedOnUtc.Month ascending | |
select m).ToList(); | |
foreach (var rc in allCustomers) | |
{ | |
var month = rc.CreatedOnUtc.Month; | |
if (existing_d.Contains(month)) | |
continue; | |
int c = (from q in allCustomers | |
where q.CreatedOnUtc.Month == month | |
select q).Count(); | |
existing_d.Add(month); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.ToString("MMMM")); | |
list_d.Add(r); | |
} | |
return list_d; | |
} | |
private List<HighChartModel> ActiveUserDateRangeYearView(List<HighChartModel> list, List<Customer> allCustomers, List<int> existing, List<Customer> customers) | |
{ | |
foreach (var rc in customers) | |
{ | |
var year = rc.CreatedOnUtc.Year; | |
if (existing.Contains(year)) | |
continue; | |
int c = (from q in allCustomers | |
where q.CreatedOnUtc.Year == year | |
select q).Count(); | |
existing.Add(year); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Year); | |
list.Add(r); | |
} | |
list = list.OrderBy(i => i.Value).ToList(); | |
list = ActivePrapareList(list); | |
return list; | |
} | |
private List<HighChartModel> NewUserDateRangeYearView(List<HighChartModel> list_d, List<Customer> allCustomers, List<int> existing_d, List<Customer> customers) | |
{ | |
foreach (var rc in customers) | |
{ | |
var year = rc.CreatedOnUtc.Year; | |
if (existing_d.Contains(year)) | |
continue; | |
int c = (from q in allCustomers | |
where q.CreatedOnUtc.Year == year | |
select q).Count(); | |
existing_d.Add(year); | |
HighChartModel r = new HighChartModel(); | |
r.Item = Convert.ToDouble(c); | |
r.Value = Convert.ToString(rc.CreatedOnUtc.Year); | |
list_d.Add(r); | |
} | |
list_d = list_d.OrderBy(i => i.Value).ToList(); | |
return list_d; | |
} | |
#endregion | |
} | |
} | |
**************************************************************************************************************** | |
[HighChart.cshtml] | |
@model Nop.Plugin.OneRead.AnalyticsAndReports.Models.DateTimeModel | |
@Html.ValidationSummary(false) | |
@using Nop.Web.Framework.Events; | |
@using Nop.Core.Infrastructure; | |
@using Nop.Services.Events; | |
@using Nop.Web.Framework.ViewEngines.Razor; | |
@{ | |
Layout = "/Administration/Views/Shared/_AdminLayout.cshtml"; | |
Html.AppendCssFileParts("~/Content/kendo/2014.1.318/kendo.common.min.css"); | |
Html.AppendCssFileParts("~/Content/kendo/2014.1.318/kendo.default.min.css"); | |
Html.AppendScriptParts("~/Scripts/kendo/2014.1.318/kendo.web.min.js"); | |
Html.AppendScriptParts("~/Scripts/chart/Chart.bundle.js"); // chart library | |
<!--calender--> | |
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css"> | |
} | |
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "product-form" })) | |
{ | |
<script> | |
$(document).ready(function () { | |
$("#product-edit").kendoTabStrip({ | |
animation: { | |
open: { | |
effects: "fadeIn" | |
} | |
}, | |
select: tabstrip_on_tab_select | |
}); | |
}); | |
</script> | |
<div class="section-header"> | |
<div class="title"> | |
<img src="@Url.Content("~/Administration/Content/images/ico-catalog.png")" alt="" /> | |
Analytics and Reports | |
</div> | |
</div> | |
<div id="product-edit"> | |
<ul> | |
<li @Html.RenderSelectedTabIndex(0, GetSelectedTabIndex())> | |
Product | |
</li> | |
<li @Html.RenderSelectedTabIndex(1, GetSelectedTabIndex())> | |
Category | |
</li> | |
<li @Html.RenderSelectedTabIndex(2, GetSelectedTabIndex())> | |
Customer | |
</li> | |
</ul> | |
<div> | |
@TabProduct() | |
</div> | |
<div> | |
@TabCategory() | |
</div> | |
<div> | |
@TabCustomer() | |
</div> | |
</div> | |
@helper TabProduct() | |
{ | |
@Html.Partial("_ProductLineChart") | |
} | |
@helper TabCategory() | |
{ | |
@Html.Partial("_CategoryLineChart") | |
} | |
@helper TabCustomer() | |
{ | |
@Html.Partial("_CustomerLineChart") | |
} | |
} | |
*************************************************************************************************************************** | |
[_productChart.cshtml] | |
<style> | |
.timeButton { | |
background-color: #00c0ef; | |
border-color: #00acd6; | |
color: white; | |
} | |
.activecolor { | |
background-color: #3c8dbc !important; | |
} | |
.selectchart { | |
width: 20%; | |
float: right; | |
height: 30px; | |
background-color: #00c0ef; | |
color: white; | |
margin-top: -2%; | |
} | |
</style> | |
<input type="button" id="browsedview" value="Product Browsed by Time" class="timeButton" /> | |
<input type="button" id="publishedview" value="Product Published by Time" class="timeButton" /> | |
<input type="button" id="usergroupview" value="Product Uses By Age Group" class="timeButton" /> | |
<input type="button" id="downloadedbycountryview" value="Product download by Country" class="timeButton" /> | |
<div style="margin: 0 auto; width: 400px;"> | |
<input type="button" id="yearview" value="Year View" class="timeButton"> | |
<input type="button" id="monthview" value="Month View" class="timeButton" /> | |
<input type="button" id="weekview" value="Week View" class="timeButton" /> | |
<input type="button" id="dateview" value="View by date" class="timeButton" /> | |
<div id="datepicker" style="display:none"> | |
StartDate: <input type="text" id="sdatepicker"> | |
EndDate: <input type="text" id="edatepicker"> | |
</div> | |
<input id="datepickerbtn" style="display:none" type="button" value="View" class="timeButton" /> | |
</div> | |
<select name="selector" class="selectchart"> | |
<option value=" 1">Line Chart</option> | |
<option value="2">Bar Chart</option> | |
</select> | |
<div id="graph-container" style="width:500px;height:500px;margin: auto;"> | |
<canvas id="browsedDownloadedChart"></canvas> | |
</div> | |
@*<div id="container" style="min-width: 350px; height: 350px; max-width: 600px; margin: 0 auto"></div>*@ | |
<script type="text/javascript"> | |
$(document).ready(function () { | |
$("#datepicker").hide(); | |
$("#datepickerbtn").hide(); | |
var actiontypeId = 10; | |
var viewtypevalue = 10; | |
var startDate = '01-01-1980'; | |
var endDate = '01-01-1980'; | |
// On chart type change | |
$('select[name=selector]').change(function () { | |
addclass(viewtypevalue); | |
addclassOnAction(actiontypeId); | |
AjaxMethod(viewtypevalue, startDate, endDate, actiontypeId) | |
}); | |
//call function on load | |
addclass(viewtypevalue); | |
addclassOnAction(actiontypeId); | |
AjaxMethod(viewtypevalue, startDate, endDate, actiontypeId) | |
$('#yearview, #monthview, #weekview, #datepickerbtn, #browsedview , #publishedview, #usergroupview,#downloadedbycountryview').click(function () { | |
var viewtype = $(this).val(); | |
if (viewtype.trim().toUpperCase() == 'YEAR VIEW') { | |
viewtypevalue = 10; | |
addclass(viewtypevalue); | |
$("#datepicker,#datepickerbtn").hide(); | |
} | |
else if (viewtype.trim().toUpperCase() == 'MONTH VIEW') { | |
viewtypevalue = 20; | |
addclass(viewtypevalue); | |
$("#datepicker,#datepickerbtn").hide(); | |
} | |
else if (viewtype.trim().toUpperCase() == 'WEEK VIEW') { | |
viewtypevalue = 30; | |
addclass(viewtypevalue); | |
$("#datepicker,#datepickerbtn").hide(); | |
} | |
else { | |
viewtypevalue = 0; | |
} | |
if (viewtype.trim().toUpperCase() == 'PRODUCT BROWSED BY TIME') { | |
viewtypevalue = 10; | |
actiontypeId = 10; | |
addclass(viewtypevalue); | |
addclassOnAction(actiontypeId); | |
$("#datepicker,#datepickerbtn").hide(); | |
$("#yearview,#monthview,#weekview,#dateview").show(); | |
} | |
else if (viewtype.trim().toUpperCase() == 'PRODUCT PUBLISHED BY TIME') { | |
viewtypevalue = 10; | |
actiontypeId = 30; | |
addclass(viewtypevalue); | |
addclassOnAction(actiontypeId); | |
$("#datepicker,#datepickerbtn").hide(); | |
$("#yearview,#monthview,#weekview,#dateview").show(); | |
} | |
else if (viewtype.trim().toUpperCase() == 'VIEW') { | |
if ($("#sdatepicker").val()) { | |
startDate = $("#sdatepicker").val(); | |
} | |
if ($("#edatepicker").val()) { | |
endDate = $("#edatepicker").val(); | |
} | |
if (startDate == '01-01-1980' || endDate == '01-01-1980') { | |
if (startDate == '01-01-1980' && endDate == '01-01-1980') { | |
$("<div>" + "Select start date and end date." + "</div>").dialog({ | |
title: 'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
return false; | |
} | |
else if (startDate == '01-01-1980') { | |
$("<div>" + "Select start date." + "</div>").dialog({ | |
title: 'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
return false; | |
} | |
else if (endDate == '01-01-1980') { | |
$("<div>" + "Select end date." + "</div>").dialog({ | |
title: 'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
return false; | |
} | |
} | |
else if ((new Date(startDate).getTime() >= new Date(endDate).getTime())) { | |
$("<div class='dialogbox'>" + "Start date must be less than end date." + "</div>").dialog({ | |
title:'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
return false; | |
} | |
} | |
else if (viewtype.trim().toUpperCase() == 'PRODUCT USES BY AGE GROUP') { | |
viewtypevalue = 40; | |
actiontypeId = 40; | |
addclass(viewtypevalue); | |
addclassOnAction(actiontypeId); | |
$("#datepicker,#datepickerbtn,#yearview,#monthview,#weekview,#dateview").hide(); | |
} | |
else if (viewtype.trim().toUpperCase() == 'PRODUCT DOWNLOAD BY COUNTRY') { | |
viewtypevalue = 50; | |
actiontypeId = 50; | |
addclass(viewtypevalue); | |
addclassOnAction(actiontypeId); | |
$("#datepicker,#datepickerbtn,#yearview,#monthview,#weekview,#dateview").hide(); | |
} | |
AjaxMethod(viewtypevalue, startDate, endDate, actiontypeId); | |
}); | |
}); | |
function AjaxMethod(viewtypevalue, startDate, endDate, actiontypeId) | |
{ | |
$.ajax({ | |
url: '@Html.Raw(Url.Action("DisplayChart", "AnalyticsAndReports"))', | |
data: { "viewtypeid": viewtypevalue, "startDate": startDate, "endDate": endDate, "actionType": actiontypeId }, | |
dataType: "json", | |
type: "GET", | |
contentType: 'application/json; charset=utf-8', | |
async: false, | |
processData: true, | |
cache: false, | |
delay: 15, | |
success: function (responseData) { | |
var BrowseSeriesValue = new Array(); | |
var BrowseSeriesItem = new Array(); | |
for (var i in responseData.list) { | |
var serieItm = new Array((responseData.list[i].Item).toString()); | |
var serieValue = new Array(responseData.list[i].Value); | |
BrowseSeriesItem.push(parseInt(serieItm)); | |
BrowseSeriesValue.push(serieValue); | |
} | |
var DownloadedSeriesValue = new Array(); | |
var DownloadedSeriesItem = new Array(); | |
for (var i in responseData.list_d) { | |
var serieValue = new Array(responseData.list_d[i].Value); | |
var serieItem = new Array(responseData.list_d[i].Item.toString()); | |
DownloadedSeriesItem.push(parseInt(serieItem)); | |
DownloadedSeriesValue.push(serieValue); | |
} | |
DrawLineChart(BrowseSeriesValue, BrowseSeriesItem, DownloadedSeriesValue, DownloadedSeriesItem, viewtypevalue, actiontypeId); | |
}, | |
error: function (xhr) { | |
alert('error'); | |
} | |
}); | |
} | |
function DrawLineChart(BrowseSeriesValue, BrowseSeriesItem, DownloadedSeriesValue, DownloadedSeriesItem, viewtypevalue, actiontypeId) { | |
$('#browsedDownloadedChart').remove(); // this is <canvas> element | |
$('#graph-container').append('<canvas id="browsedDownloadedChart"><canvas>'); //remove canvas than add again becose of clear old chart issue. | |
var ctx = document.getElementById("browsedDownloadedChart"); | |
var chartTypeId = $('select[name=selector]').val(); | |
var CType = 'line'; | |
var label = BrowseSeriesValue; | |
if (BrowseSeriesValue == '') | |
{ | |
label = DownloadedSeriesValue; | |
} | |
if (chartTypeId == 1) | |
CType = 'line'; | |
else if (chartTypeId == 2) | |
CType = 'bar'; | |
var label1 = 'Browsed'; | |
var label2 = 'Downloaded'; | |
if (actiontypeId == 30) { | |
label1 = 'Published'; | |
label2 = ''; | |
} | |
if (actiontypeId == 50) { | |
label1 = ''; | |
var label2 = 'Downloaded'; | |
} | |
var browsedDownloadedChart = new Chart(ctx, { | |
type: CType, | |
data: { | |
labels: label, | |
datasets: [ | |
{ | |
fillColor: "rgba(60,141,188,0.9)", | |
strokeColor: "rgba(60,141,188,0.8)", | |
label: label1, | |
pointColor: "#3b8bba", | |
pointStrokeColor: "rgba(60,141,188,1)", | |
pointHighlightFill: "#fff", | |
pointHighlightStroke: "rgba(60,141,188,1)", | |
borderColor: 'rgba(60, 141, 188, 0.7)', | |
backgroundColor: 'rgba(44, 152, 214, 0.5)', | |
pointBorderColor: 'rgba(37, 103, 142, 0.9)', | |
pointBackgroundColor: 'rgba(60, 141, 188, 0.4)', | |
pointBorderWidth: 1, | |
data: BrowseSeriesItem, | |
}, | |
{ | |
label: label2, | |
fillColor: "rgba(60,141,188,0.9)", | |
strokeColor: "rgba(60,141,188,0.8)", | |
pointColor: "#00a65a", | |
pointStrokeColor: "rgba(0,166,90,1)", | |
pointHighlightFill: "#fff", | |
pointHighlightStroke: "rgba(0,166,90,1)", | |
borderColor: 'rgba(0,166,90, 1)', | |
backgroundColor: 'rgba(0,166,90,0.5)', | |
pointBorderColor: 'rgba(0,166,90,0.7)', | |
pointBackgroundColor: 'rgba(0,166,90,0.2)', | |
pointBorderWidth: 1, | |
data: DownloadedSeriesItem, | |
} | |
] | |
}, | |
responsive: true, | |
options: { | |
scales: { | |
yAxes: [{ | |
ticks: { | |
beginAtZero: true | |
} | |
}] | |
}, | |
scaleShowLabels: false | |
} | |
}); | |
} | |
$(function () { | |
$("#sdatepicker").datepicker({ | |
changeMonth: true, | |
changeYear: true | |
}); | |
$("#edatepicker").datepicker({ | |
changeMonth: true, | |
changeYear: true | |
}); | |
}); | |
$('#dateview').click(function () { | |
$("#datepicker,#datepickerbtn").show(); | |
addclass(0); | |
}); | |
function addclass(viewtypevalue) { | |
if (viewtypevalue == 10) { | |
$("#yearview").addClass("activecolor"); | |
$("#monthview").removeClass("activecolor"); | |
$("#weekview").removeClass("activecolor"); | |
$("#dateview").removeClass("activecolor"); | |
} | |
else if (viewtypevalue == 20) { | |
$("#monthview").addClass("activecolor"); | |
$("#yearview").removeClass("activecolor"); | |
$("#weekview").removeClass("activecolor"); | |
$("#dateview").removeClass("activecolor"); | |
} | |
else if (viewtypevalue == 30) { | |
$("#weekview").addClass("activecolor"); | |
$("#monthview").removeClass("activecolor"); | |
$("#yearview").removeClass("activecolor"); | |
$("#dateview").removeClass("activecolor"); | |
} | |
else if (viewtypevalue == 0) { | |
$("#dateview").addClass("activecolor"); | |
$("#monthview").removeClass("activecolor"); | |
$("#weekview").removeClass("activecolor"); | |
$("#yearview").removeClass("activecolor"); | |
} | |
} | |
function addclassOnAction(actiontypeId) { | |
if (actiontypeId == 10) { | |
$("#browsedview").addClass("activecolor"); | |
$("#publishedview").removeClass("activecolor"); | |
$("#usergroupview").removeClass("activecolor"); | |
$("#downloadedbycountryview").removeClass("activecolor"); | |
} | |
else if (actiontypeId == 30) { | |
$("#publishedview").addClass("activecolor"); | |
$("#browsedview").removeClass("activecolor"); | |
$("#usergroupview").removeClass("activecolor"); | |
$("#downloadedbycountryview").removeClass("activecolor"); | |
} | |
else if (actiontypeId == 40) { | |
$("#usergroupview").addClass("activecolor"); | |
$("#browsedview").removeClass("activecolor"); | |
$("#publishedview").removeClass("activecolor"); | |
$("#downloadedbycountryview").removeClass("activecolor"); | |
} | |
else if (actiontypeId == 50) { | |
$("#downloadedbycountryview").addClass("activecolor"); | |
$("#browsedview").removeClass("activecolor"); | |
$("#publishedview").removeClass("activecolor"); | |
$("#usergroupview").removeClass("activecolor"); | |
} | |
} | |
</script> | |
********************************************************************************************** | |
[_categoryChart.cshtml] | |
<style> | |
.timeButton { | |
background-color: #00c0ef; | |
border-color: #00acd6; | |
color: white; | |
} | |
</style> | |
<div style="margin: 0 auto; width: 400px;"> | |
<input type="button" id="cyearview" value="Year View" class="timeButton" /> | |
<input type="button" id="cmonthview" value="Month View" class="timeButton" /> | |
<input type="button" id="cweekview" value="Week View" class="timeButton" /> | |
<input type="button" id="cdateview" value="View by date" class="timeButton" /> | |
<div id="catdatepicker" style="display:none">StartDate: <input type="text" id="catsdatepicker"> EndDate: <input type="text" id="catedatepicker"></div> | |
<input id="catdatepickerbtn" style="display:none" type="button" value="View" class="timeButton" /> | |
</div> | |
<select name="selectorPublished" class="selectchart"> | |
<option value="1">Line Chart</option> | |
<option value="2">Bar Chart</option> | |
</select> | |
<div id="cat-graph-container" style="width:500px;height:500px;margin: auto;"> | |
<canvas id="catChart"></canvas> | |
</div> | |
<script type="text/javascript"> | |
$(document).ready(function () { | |
$("#catdatepicker").hide(); | |
var viewtypevalue = 10; | |
var startDate = '01-01-1980'; | |
var endDate = '01-01-1980'; | |
// On chart type change | |
$('select[name=selectorPublished]').change(function () { | |
addcatclass(viewtypevalue); | |
CatAjaxMethod(viewtypevalue, startDate, endDate) | |
}); | |
// call function on load | |
addcatclass(viewtypevalue); | |
CatAjaxMethod(viewtypevalue, startDate, endDate); | |
$('#cyearview, #cmonthview, #cweekview, #catdatepickerbtn').click(function () { | |
var viewtype = $(this).val(); | |
if (viewtype.trim().toUpperCase() == 'YEAR VIEW') { | |
viewtypevalue = 10; | |
addcatclass(viewtypevalue); | |
$("#catdatepicker ,#catdatepickerbtn").hide(); | |
} | |
else if (viewtype.trim().toUpperCase() == 'MONTH VIEW') { | |
viewtypevalue = 20; | |
addcatclass(viewtypevalue); | |
$("#catdatepicker ,#catdatepickerbtn").hide(); | |
} | |
else if (viewtype.trim().toUpperCase() == 'WEEK VIEW') { | |
viewtypevalue = 30; | |
addcatclass(viewtypevalue); | |
$("#catdatepicker ,#catdatepickerbtn").hide(); | |
} | |
else { | |
viewtypevalue = 0; | |
} | |
if (viewtype.trim().toUpperCase() == 'VIEW') { | |
if ($("#catsdatepicker").val()) { | |
startDate = $("#catsdatepicker").val(); | |
} | |
if ($("#catedatepicker").val()) { | |
endDate = $("#catedatepicker").val(); | |
} | |
if (startDate == '01-01-1980' || endDate == '01-01-1980') { | |
if (startDate == '01-01-1980' && endDate == '01-01-1980') { | |
$("<div>" + "Select start date and end date." + "</div>").dialog({ | |
title: 'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
//alert("Select start date and end date.") | |
return false; | |
} | |
else if (startDate == '01-01-1980') { | |
$("<div>" + "Select start date." + "</div>").dialog({ | |
title: 'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
return false; | |
} | |
else if (endDate == '01-01-1980') { | |
$("<div>" + "Select end date." + "</div>").dialog({ | |
title: 'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
return false; | |
} | |
} | |
else if ((new Date(startDate).getTime() >= new Date(endDate).getTime())) { | |
$("<div>" + "Start date must be less than end date." + "</div>").dialog({ | |
title: 'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
return false; | |
} | |
} | |
//if ($("#catsdatepicker").val()) { | |
// startDate = $("#catsdatepicker").val(); | |
//} | |
//if ($("#catedatepicker").val()) { | |
// endDate = $("#catedatepicker").val(); | |
//} | |
//var startDate = $("#sdatepicker").val(); | |
CatAjaxMethod(viewtypevalue, startDate, endDate); | |
}); | |
}); | |
function CatAjaxMethod(viewtypevalue, startDate, endDate) { | |
$.ajax({ | |
url: '@Html.Raw(Url.Action("DisplayCategoryChart", "AnalyticsAndReports"))', | |
data: { "viewtypeid": viewtypevalue, "startDate": startDate, "endDate": endDate }, | |
dataType: "json", | |
type: "GET", | |
contentType: 'application/json; charset=utf-8', | |
async: false, | |
processData: true, | |
cache: false, | |
delay: 15, | |
success: function (data) { | |
var series = new Array(); | |
var CatSeriesValue = new Array(); | |
var CatSeriesItem = new Array(); | |
for (var i in data) { | |
var serieItm = new Array((data[i].Item).toString()); | |
var serieValue = new Array(data[i].Value); | |
CatSeriesItem.push(parseInt(serieItm)); | |
CatSeriesValue.push(serieValue); | |
} | |
DrawCatLineChart(CatSeriesValue, CatSeriesItem); | |
}, | |
error: function (xhr) { | |
alert('error'); | |
} | |
}); | |
} | |
function DrawCatLineChart(CatSeriesValue, CatSeriesItem) { | |
$('#catChart').remove(); // this is <canvas> element | |
$('#cat-graph-container').append('<canvas id="catChart"><canvas>'); | |
var ctx = document.getElementById("catChart"); | |
var ChartType = 'line'; | |
var chartTypeId = $('select[name=selectorPublished]').val(); | |
if (chartTypeId == 1) | |
ChartType = 'line'; | |
else if (chartTypeId == 2) | |
ChartType = 'bar'; | |
var catChart = new Chart(ctx, { | |
type: ChartType, | |
data: { | |
labels: CatSeriesValue, | |
datasets: [ | |
{ | |
label: 'Category Browsed', | |
fillColor: "rgba(60,141,188,0.9)", | |
strokeColor: "rgba(60,141,188,0.8)", | |
pointColor: "#3b8bba", | |
pointStrokeColor: "rgba(60,141,188,1)", | |
pointHighlightFill: "#fff", | |
pointHighlightStroke: "rgba(60,141,188,1)", | |
borderColor: 'rgba(60, 141, 188, 0.7)', | |
backgroundColor: 'rgba(44, 152, 214, 0.5)', | |
pointBorderColor: 'rgba(37, 103, 142, 0.9)', | |
pointBackgroundColor: 'rgba(60, 141, 188, 0.4)', | |
pointBorderWidth: 1, | |
data: CatSeriesItem, | |
}, | |
] | |
}, | |
options: { | |
scales: { | |
yAxes: [{ | |
ticks: { | |
beginAtZero: true | |
} | |
}] | |
} | |
} | |
}); | |
} | |
$(function () { | |
$("#catsdatepicker").datepicker({ | |
changeMonth: true, | |
changeYear: true | |
}); | |
$("#catedatepicker").datepicker({ | |
changeMonth: true, | |
changeYear: true | |
}); | |
}); | |
$('#cdateview').click(function () { | |
$("#catdatepicker ,#catdatepickerbtn").show(); | |
addcatclass(0); | |
}); | |
function addcatclass(viewtypevalue) { | |
if (viewtypevalue == 10) { | |
$("#cyearview").addClass("activecolor"); | |
$("#cmonthview").removeClass("activecolor"); | |
$("#cweekview").removeClass("activecolor"); | |
$("#cdateview").removeClass("activecolor"); | |
} | |
else if (viewtypevalue == 20) { | |
$("#cmonthview").addClass("activecolor"); | |
$("#cyearview").removeClass("activecolor"); | |
$("#cweekview").removeClass("activecolor"); | |
$("#cdateview").removeClass("activecolor"); | |
} | |
else if (viewtypevalue == 30) { | |
$("#cweekview").addClass("activecolor"); | |
$("#cmonthview").removeClass("activecolor"); | |
$("#cyearview").removeClass("activecolor"); | |
$("#cdateview").removeClass("activecolor"); | |
} | |
else if (viewtypevalue == 0) { | |
$("#cdateview").addClass("activecolor"); | |
$("#cmonthview").removeClass("activecolor"); | |
$("#cweekview").removeClass("activecolor"); | |
$("#cyearview").removeClass("activecolor"); | |
} | |
} | |
</script> | |
*********************************************************************************************** | |
[_customerChart.cshtml] | |
<style> | |
.timeButton { | |
background-color: #00c0ef; | |
border-color: #00acd6; | |
color: white; | |
} | |
.activecolor { | |
background-color: #3c8dbc !important; | |
} | |
.selectchart { | |
width: 20%; | |
float: right; | |
height: 30px; | |
background-color: #00c0ef; | |
color: white; | |
margin-top: -2%; | |
} | |
</style> | |
<input type="button" id="userdemographicview" value="User Demographics" class="timeButton" /> | |
<input type="button" id="usertimelineview" value="User Timeline" class="timeButton" /> | |
<div style="margin: 0 auto; width: 400px;"> | |
<input type="button" id="custyearview" value="Year View" class="timeButton"> | |
<input type="button" id="custmonthview" value="Month View" class="timeButton" /> | |
<input type="button" id="custweekview" value="Week View" class="timeButton" /> | |
<input type="button" id="custdateview" value="View by date" class="timeButton" /> | |
<div id="custdatepicker" style="display:none"> | |
StartDate: <input type="text" id="custsdatepicker"> | |
EndDate: <input type="text" id="custedatepicker"> | |
</div> | |
<input id="custdatepickerbtn" style="display:none" type="button" value="View" class="timeButton" /> | |
</div> | |
<select name="selectorCustoemr" class="selectchart"> | |
<option value="1">Line Chart</option> | |
<option value="2">Bar Chart</option> | |
</select> | |
<div id="cust-graph-container" style="width:500px;height:500px;margin: auto;"> | |
<canvas id="Customerchart" ></canvas> | |
</div> | |
@*<div id="container" style="min-width: 350px; height: 350px; max-width: 600px; margin: 0 auto"></div>*@ | |
<script type="text/javascript"> | |
$(document).ready(function () { | |
$("#custdatepicker").hide(); | |
$("#custdatepickerbtn").hide(); | |
var actiontypeId = 60; | |
var viewtypevalue = 00; | |
var startDate = '01-01-1980'; | |
var endDate = '01-01-1980'; | |
// On chart type change | |
$('select[name=selectorCustoemr]').change(function () { | |
addCustclass(viewtypevalue); | |
AjaxCustMethod(viewtypevalue, startDate, endDate, actiontypeId); | |
}); | |
//call function on load | |
//addCustclass(viewtypevalue); | |
addclassOnCustAction(actiontypeId); | |
$("#custdatepicker,#custdatepickerbtn,#custyearview,#custmonthview,#custweekview,#custdateview").hide(); | |
AjaxCustMethod(viewtypevalue, startDate, endDate, actiontypeId) | |
$('#custyearview, #custmonthview, #custweekview, #custdatepickerbtn,#userdemographicview,#usertimelineview').click(function () { | |
var viewtype = $(this).val(); | |
if (viewtype.trim().toUpperCase() == 'YEAR VIEW') { | |
viewtypevalue = 10; | |
addCustclass(viewtypevalue); | |
$("#custdatepicker,#custdatepickerbtn").hide(); | |
} | |
else if (viewtype.trim().toUpperCase() == 'MONTH VIEW') { | |
viewtypevalue = 20; | |
addCustclass(viewtypevalue); | |
$("#custdatepicker,#custdatepickerbtn").hide(); | |
} | |
else if (viewtype.trim().toUpperCase() == 'WEEK VIEW') { | |
viewtypevalue = 30; | |
addCustclass(viewtypevalue); | |
$("#custdatepicker,#custdatepickerbtn").hide(); | |
} | |
else { | |
viewtypevalue = 0; | |
} | |
if (viewtype.trim().toUpperCase() == 'VIEW') { | |
if ($("#custsdatepicker").val()) { | |
startDate = $("#custsdatepicker").val(); | |
} | |
if ($("#custedatepicker").val()) { | |
endDate = $("#custedatepicker").val(); | |
} | |
if (startDate == '01-01-1980' || endDate == '01-01-1980') { | |
if (startDate == '01-01-1980' && endDate == '01-01-1980') { | |
$("<div>" + "Select start date and end date." + "</div>").dialog({ | |
title: 'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
return false; | |
} | |
else if (startDate == '01-01-1980') { | |
$("<div>" + "Select start date." + "</div>").dialog({ | |
title: 'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
return false; | |
} | |
else if (endDate == '01-01-1980') { | |
$("<div>" + "Select end date." + "</div>").dialog({ | |
title: 'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
return false; | |
} | |
} | |
else if ((new Date(startDate).getTime() >= new Date(endDate).getTime())) { | |
$("<div class='dialogbox'>" + "Start date must be less than end date." + "</div>").dialog({ | |
title: 'OneRead', | |
height: 70, | |
width: 350, | |
modal: true, | |
resizable: true | |
}); | |
return false; | |
} | |
} | |
else if (viewtype.trim().toUpperCase() == 'USER DEMOGRAPHICS') { | |
viewtypevalue = 60; | |
actiontypeId = 60; | |
addclassOnCustAction(actiontypeId); | |
$("#custdatepicker,#custdatepickerbtn,#custyearview,#custmonthview,#custweekview,#custdateview").hide(); | |
} | |
if (viewtype.trim().toUpperCase() == 'USER TIMELINE') { | |
viewtypevalue = 10; | |
actiontypeId = 70; | |
addCustclass(viewtypevalue); | |
addclassOnCustAction(actiontypeId); | |
$("#custdatepicker,#custdatepickerbtn").hide(); | |
$("#custyearview,#custmonthview,#custweekview,#custdateview").show(); | |
} | |
AjaxCustMethod(viewtypevalue, startDate, endDate, actiontypeId); | |
}); | |
}); | |
function AjaxCustMethod(viewtypevalue, startDate, endDate, actiontypeId) { | |
$.ajax({ | |
url: '@Html.Raw(Url.Action("DisplayCustomerChart", "AnalyticsAndReports"))', | |
data: { "viewtypeid": viewtypevalue, "startDate": startDate, "endDate": endDate, "actionType": actiontypeId }, | |
dataType: "json", | |
type: "GET", | |
contentType: 'application/json; charset=utf-8', | |
async: false, | |
processData: true, | |
cache: false, | |
delay: 15, | |
success: function (responseData) { | |
var CustSeriesValue = new Array(); | |
var CustSeriesItem = new Array(); | |
for (var i in responseData.list) { | |
var serieItm = new Array((responseData.list[i].Item).toString()); | |
var serieValue = new Array(responseData.list[i].Value); | |
CustSeriesItem.push(parseInt(serieItm)); | |
CustSeriesValue.push(serieValue); | |
} | |
var Cust_dSeriesValue = new Array(); | |
var Cust_dSeriesItem = new Array(); | |
for (var i in responseData.list_d) { | |
var serieValue = new Array(responseData.list_d[i].Value); | |
var serieItem = new Array(responseData.list_d[i].Item.toString()); | |
Cust_dSeriesItem.push(parseInt(serieItem)); | |
Cust_dSeriesValue.push(serieValue); | |
} | |
DrawCustLineChart(CustSeriesValue, CustSeriesItem, Cust_dSeriesValue, Cust_dSeriesItem, actiontypeId); | |
}, | |
error: function (xhr) { | |
alert('error'); | |
} | |
}); | |
} | |
function DrawCustLineChart(CustSeriesValue, CustSeriesItem, Cust_dSeriesValue, Cust_dSeriesItem, actiontypeId) { | |
$('#Customerchart').remove(); // this is <canvas> element | |
$('#cust-graph-container').append('<canvas id="Customerchart"><canvas>'); | |
var ctx = document.getElementById("Customerchart"); | |
var CustChartType = 'line'; | |
var label = CustSeriesValue; | |
if (CustSeriesValue == '') { | |
label = Cust_dSeriesValue; | |
} | |
var CustchartTypeId = $('select[name=selectorCustoemr]').val(); | |
if (CustchartTypeId == 1) | |
CustChartType = 'line'; | |
else if (CustchartTypeId == 2) | |
CustChartType = 'bar'; | |
var label1 = 'Active Cutomers'; | |
var label2 = 'New Customers'; | |
if (actiontypeId == 60) { | |
label1 = 'Customers Demographic'; | |
label2 = ''; | |
} | |
var Customerchart = new Chart(ctx, { | |
type: CustChartType, | |
data: { | |
labels: label, | |
datasets: [ | |
{ | |
fillColor: "rgba(60,141,188,0.9)", | |
strokeColor: "rgba(60,141,188,0.8)", | |
label: label1, | |
pointColor: "#3b8bba", | |
pointStrokeColor: "rgba(60,141,188,1)", | |
pointHighlightFill: "#fff", | |
pointHighlightStroke: "rgba(60,141,188,1)", | |
borderColor: 'rgba(60, 141, 188, 0.7)', | |
backgroundColor: 'rgba(44, 152, 214, 0.5)', | |
pointBorderColor: 'rgba(37, 103, 142, 0.9)', | |
pointBackgroundColor: 'rgba(60, 141, 188, 0.4)', | |
pointBorderWidth: 1, | |
data: CustSeriesItem, | |
}, | |
{ | |
label: label2, | |
fillColor: "rgba(60,141,188,0.9)", | |
strokeColor: "rgba(60,141,188,0.8)", | |
pointColor: "#00a65a", | |
pointStrokeColor: "rgba(0,166,90,1)", | |
pointHighlightFill: "#fff", | |
pointHighlightStroke: "rgba(0,166,90,1)", | |
borderColor: 'rgba(0,166,90, 1)', | |
backgroundColor: 'rgba(0,166,90,0.5)', | |
pointBorderColor: 'rgba(0,166,90,0.7)', | |
pointBackgroundColor: 'rgba(0,166,90,0.2)', | |
pointBorderWidth: 1, | |
data: Cust_dSeriesItem, | |
} | |
] | |
}, | |
responsive: true, | |
options: { | |
scales: { | |
yAxes: [{ | |
ticks: { | |
beginAtZero: true | |
} | |
}] | |
} | |
} | |
}); | |
} | |
$(function () { | |
$("#custsdatepicker").datepicker({ | |
changeMonth: true, | |
changeYear: true | |
}); | |
$("#custedatepicker").datepicker({ | |
changeMonth: true, | |
changeYear: true | |
}); | |
}); | |
$('#custdateview').click(function () { | |
$("#custdatepicker,#custdatepickerbtn").show(); | |
addCustclass(0); | |
}); | |
function addCustclass(viewtypevalue) { | |
if (viewtypevalue == 10) { | |
$("#custyearview").addClass("activecolor"); | |
$("#custmonthview").removeClass("activecolor"); | |
$("#custweekview").removeClass("activecolor"); | |
$("#custdateview").removeClass("activecolor"); | |
} | |
else if (viewtypevalue == 20) { | |
$("#custmonthview").addClass("activecolor"); | |
$("#custyearview").removeClass("activecolor"); | |
$("#custweekview").removeClass("activecolor"); | |
$("#custdateview").removeClass("activecolor"); | |
} | |
else if (viewtypevalue == 30) { | |
$("#custweekview").addClass("activecolor"); | |
$("#custmonthview").removeClass("activecolor"); | |
$("#custyearview").removeClass("activecolor"); | |
$("#custdateview").removeClass("activecolor"); | |
} | |
else if (viewtypevalue == 0) { | |
$("#custdateview").addClass("activecolor"); | |
$("#custmonthview").removeClass("activecolor"); | |
$("#custweekview").removeClass("activecolor"); | |
$("#custyearview").removeClass("activecolor"); | |
} | |
} | |
function addclassOnCustAction(actiontypeId) { | |
if (actiontypeId == 60) { | |
$("#userdemographicview").addClass("activecolor"); | |
$("#usertimelineview").removeClass("activecolor"); | |
} | |
else if (actiontypeId == 70) { | |
$("#usertimelineview").addClass("activecolor"); | |
$("#userdemographicview").removeClass("activecolor"); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment