public static CampaignMonitoringVm FromCampaignTracking(Campaign campaign, CampaignTracking campaignTracking) { long Needed = campaignTracking.Quantity <= 100 ? campaignTracking.Quantity : (long)(campaignTracking.Quantity * 3 / 100.0); long Total = campaignTracking.Day1Clicks + campaignTracking.Day2Clicks + campaignTracking.Day3Clicks + campaignTracking.Day4Clicks + campaignTracking.Day5Clicks + campaignTracking.Day6Clicks + campaignTracking.Day7Clicks; double CampaignFill = (double)Total / Needed; var model = new CampaignMonitoringVm { CampaignId = campaign.Id.ToString(), TrackingId = campaignTracking.Id.ToString(), OrderNumber = string.IsNullOrEmpty(campaignTracking.SegmentNumber) ? campaignTracking.OrderNumber : campaignTracking.SegmentNumber, CampaignName = campaign.Approved.CampaignName, Quantity = string.Format("{0:n0}", campaignTracking.Quantity), ClicksNeeded = string.Format("{0:n0}", Needed), StartDate = campaignTracking.StartDate?.ToString(StringConstants.DateFormatSlashes), AMPM = campaignTracking.StartDate?.ToString(StringConstants.TimeFormatAMPM), ClickMeterLink = campaign.Testing.ClickMeterRotatorLink, Day1 = campaignTracking.StartDate?.ToString(StringConstants.DateFormatSlashes), Day2 = campaignTracking.StartDate?.AddDays(1).ToString(StringConstants.DateFormatSlashes), Day3 = campaignTracking.StartDate?.AddDays(2).ToString(StringConstants.DateFormatSlashes), Day4 = campaignTracking.StartDate?.AddDays(3).ToString(StringConstants.DateFormatSlashes), Day5 = campaignTracking.StartDate?.AddDays(4).ToString(StringConstants.DateFormatSlashes), Day6 = campaignTracking.StartDate?.AddDays(5).ToString(StringConstants.DateFormatSlashes), Day7 = campaignTracking.StartDate?.AddDays(6).ToString(StringConstants.DateFormatSlashes), Day1Clicks = string.Format("{0:n0}", campaignTracking.Day1Clicks), Day2Clicks = string.Format("{0:n0}", campaignTracking.Day2Clicks), Day3Clicks = string.Format("{0:n0}", campaignTracking.Day3Clicks), Day4Clicks = string.Format("{0:n0}", campaignTracking.Day4Clicks), Day5Clicks = string.Format("{0:n0}", campaignTracking.Day5Clicks), Day6Clicks = string.Format("{0:n0}", campaignTracking.Day6Clicks), Day7Clicks = string.Format("{0:n0}", campaignTracking.Day7Clicks), Day7PlusClicks = string.Format("{0:n0}", campaignTracking.Day7PlusClicks), Total = string.Format("{0:n0}", Total), CampaignFill = CampaignFill.ToString("0.00%") }; model.Day1Rule = string.Join("<br/>", campaign.Notifications .Where(x => x.QcRule <= (int)QcRule.NotHitClickRateIn1Day).Select(x => x.Message)); model.Day2Rule = string.Join("<br/>", campaign.Notifications .Where(x => x.QcRule == (int)QcRule.NotHitClickRateIn2Days || x.QcRule == (int)QcRule.NotHitOpenRateIn2Days).Select(x => x.Message)); model.Day3Rule = string.Join("<br/>", campaign.Notifications .Where(x => x.QcRule == (int)QcRule.NotHitClickRateIn3Days || x.QcRule == (int)QcRule.NotHitOpenRateIn3Days).Select(x => x.Message)); return(model); }
public ActionResult SendToTracking(Guid?id, string segmentNumber, string ioNumber) { Campaign campaign = Db.Campaigns.FirstOrDefault(x => x.Id == id); if (campaign == null) { throw new HttpException(404, "Not found"); } try { CampaignTracking campaignTracking = null; if (string.IsNullOrEmpty(segmentNumber)) { campaignTracking = Db.CampaignTrackings.FirstOrDefault(x => x.CampaignId == id); } else { campaignTracking = Db.CampaignTrackings.FirstOrDefault(x => x.CampaignId == id && x.SegmentNumber == segmentNumber); } if (campaignTracking != null) { campaignTracking.IoNumber = ioNumber; } campaign.Status = (int)CampaignStatus.Monitoring; Db.SaveChanges(); return(Json(new JsonResponse() { IsSucess = true }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new JsonResponse() { IsSucess = false, ErrorMessage = ex.Message }, JsonRequestBehavior.AllowGet)); } }
private CampaignTrackingModel CreateAutomailerTrackingModels(CampaignSetting campaignSetting) { EmailTemplate emailTemplate = _automailerContext.EmailTemplates.FirstOrDefault(x => x.EmailTemplateId == campaignSetting.EmailTemplateId); List <Contact> contacts = GetCampaignContacts(campaignSetting); List <AutomailerModel> automailerModels = new List <AutomailerModel>(); List <CampaignTracking> campaignTrackings = new List <CampaignTracking>(); foreach (Contact contact in contacts) { CampaignTracking campaignTracking = CampaignTracking.Create(campaignSetting.CampaignSettingId, emailTemplate.EmailTemplateId, contact.ContactId); campaignTrackings.Add(campaignTracking); AutomailerModel automailerModel = AutomailerModel.Create(ServerPath, campaignTracking.CampaignTrackingId, contact.ContactId, contact.Email, emailTemplate.EmailSubject, emailTemplate.EmailContent, contact.Name); automailerModels.Add(automailerModel); } return(new CampaignTrackingModel { AutomailerModels = automailerModels, CampaignTrackings = campaignTrackings }); }
private static void SendToVendorMulti(OrderVia orderVia, WfpictContext db, Campaign campaign, Vendor vendor, string[] segmentsSelected, string whiteLabelDomain) { var segments = db.CampaignSegments .Where(c => c.CampaignId == campaign.Id && segmentsSelected.Contains(c.SegmentNumber)) .ToList(); foreach (var segment in segments) { string sentOrder, queuedCampaignId = null; switch (orderVia) { case OrderVia.Email: sentOrder = EmailHelper.SendApprovedToVendor(vendor, campaign, segment); break; case OrderVia.Api: var response = ProDataApiManager.Create(campaign, segment, whiteLabelDomain); if (response.status != ProDataApiManager.Success) { throw new AdsException(response.ErrorMessage); } sentOrder = response.RequestMessage; queuedCampaignId = response.queued_pending_campaign_id.ToString(); break; default: throw new AdsException("Invalid orderVia while sending to vendor multiple"); } segment.SegmentStatus = (int)SegmentStatus.Monitoring; var campaignTracking = db.CampaignTrackings.FirstOrDefault(x => x.CampaignId == campaign.Id && x.SegmentNumber == segment.SegmentNumber); if (campaignTracking == null) { var trackingId = Guid.NewGuid(); var tracking = new CampaignTracking() { Id = trackingId, CreatedAt = DateTime.Now, CampaignId = campaign.Id, OrderNumber = campaign.OrderNumber, SegmentNumber = segment.SegmentNumber, Quantity = segment.Quantity, DateSent = DateTime.Now, SentOrder = sentOrder, IsCreatedThroughApi = orderVia == OrderVia.Api, QueuedCampaignId = queuedCampaignId }; db.CampaignTrackings.Add(tracking); db.SaveChanges(); } else { campaignTracking.Quantity = segment.Quantity; campaignTracking.DateSent = DateTime.Now; campaignTracking.SentOrder = sentOrder; campaignTracking.IsCreatedThroughApi = orderVia == OrderVia.Api; campaignTracking.QueuedCampaignId = queuedCampaignId; } LogHelper.AddLog(db, LogType.Vendor, campaign.OrderNumber, $"Multi {segment.SegmentNumber} has been sent to vendor successfully."); } }
private static void SendToVendorSingle(OrderVia orderVia, WfpictContext db, Campaign campaign, Vendor vendor, string whiteLabelDomain) { string sentOrder, queuedCampaignId = null; switch (orderVia) { case OrderVia.Email: sentOrder = EmailHelper.SendApprovedToVendor(vendor, campaign, null); break; case OrderVia.Api: var response = ProDataApiManager.Create(campaign, null, whiteLabelDomain); if (response.status != ProDataApiManager.Success) { throw new AdsException(response.ErrorMessage); } sentOrder = response.RequestMessage; queuedCampaignId = response.queued_pending_campaign_id.ToString(); break; default: throw new AdsException("Invalid orderVia while sending to vendor single"); } string orderNumberRdp = campaign.ReBroadcasted ? campaign.ReBroadcastedOrderNumber : campaign.OrderNumber; long quantity = campaign.ReBroadcasted ? campaign.ReBroadcastedQuantity : campaign.Approved.Quantity; var campaignTracking = db.CampaignTrackings.FirstOrDefault(x => x.CampaignId == campaign.Id && x.OrderNumber == orderNumberRdp && string.IsNullOrEmpty(x.SegmentNumber)); if (campaignTracking == null) { var trackingId = Guid.NewGuid(); var tracking = new CampaignTracking() { Id = trackingId, CreatedAt = DateTime.Now, CampaignId = campaign.Id, OrderNumber = orderNumberRdp, SegmentNumber = string.Empty, Quantity = quantity, DateSent = DateTime.Now, SentOrder = sentOrder, IsCreatedThroughApi = orderVia == OrderVia.Api, QueuedCampaignId = queuedCampaignId }; db.CampaignTrackings.Add(tracking); } else { campaignTracking.Quantity = quantity; campaignTracking.DateSent = DateTime.Now; campaignTracking.SentOrder = sentOrder; campaignTracking.IsCreatedThroughApi = orderVia == OrderVia.Api; campaignTracking.QueuedCampaignId = queuedCampaignId; } db.SaveChanges(); LogHelper.AddLog(db, LogType.Vendor, campaign.OrderNumber, !campaign.ReBroadcasted ? "Order has been sent to vendor successfully." : "Order Rebroad has been sent to vendor sucessfully."); }
public static TemplateReportVm FromCampaignTracking(Campaign campaign, CampaignTracking campaignTracking) { var model = new TemplateReportVm { CampaignId = campaign.Id.ToString(), TrackingId = campaignTracking.Id.ToString(), OrderNumber = string.IsNullOrEmpty(campaignTracking.SegmentNumber) ? campaignTracking.OrderNumber : campaignTracking.SegmentNumber, CampaignName = campaign.Approved.CampaignName, WhiteLabel = campaign.Approved.WhiteLabel, SubjectLine = campaign.Approved.SubjectLine, FromLine = campaign.Approved.FromLine, Quantity = campaignTracking.Quantity.ToString(), Status = ((CampaignStatus)campaign.Status).ToString(), OrderDate = campaign.CreatedAt.ToString(StringConstants.DateFormatSlashes), DateSent = campaignTracking.CreatedAt.ToString(StringConstants.DateFormatSlashes), SentOrder = campaignTracking.SentOrder, IsCreatedThroughApi = campaignTracking.IsCreatedThroughApi, QueuedCampaignId = campaignTracking.QueuedCampaignId, IoNumber = campaignTracking.IoNumber, StartDate = campaignTracking.StartDate?.ToString(StringConstants.DateFormatSlashes), Deployed = campaignTracking.Deployed.ToString(), Opened = campaignTracking.Opened.ToString(), Clicked = campaignTracking.Clicked.ToString(), Unsub = campaignTracking.Unsub.ToString(), Forwards = campaignTracking.Forwards.ToString(), Bounce = campaignTracking.Bounce.ToString(), Opt = campaignTracking.Opt.ToString(), Desktop = campaignTracking.Desktop.ToString(), Mobile = campaignTracking.Mobile.ToString(), IsRetargeting = campaign.Approved.ReBroadCast, RetargetingImpressions = campaignTracking.RetargetingImpressions.ToString(), RetargetingClicks = campaignTracking.RetargetingClicks.ToString(), DeliveryPercentage = campaignTracking.DeliveryPercentage.ToString("0.0000"), OpenedPercentage = campaignTracking.OpenedPercentage.ToString("0.0000"), ClickedPercentage = campaignTracking.ClickedPercentage.ToString("0.0000"), UnsubPercentage = campaignTracking.UnsubPercentage.ToString("0.0000"), ClickToOpenPercentage = campaignTracking.ClickToOpenPercentage.ToString("0.0000"), UnsubToOpenPercentage = campaignTracking.UnsubToOpenPercentage.ToString("0.0000"), Segments = new List <CampaignSegmentVm>(), PerLink = new List <TemplateReportDetailVm>() }; model.Segments = campaign.Segments.Where(x => !string.IsNullOrEmpty(x.SegmentDataFileUrl)) .Select(x => new CampaignSegmentVm() { SegmentNumber = x.SegmentNumber, SegmentDataFileUrl = x.SegmentDataFileUrl }).OrderBy(x => x.SegmentNumber).ToList(); var proDatas = campaign.ProDatas .Where(x => x.OrderNumber == campaignTracking.OrderNumber && x.SegmentNumber == campaignTracking.SegmentNumber) .OrderByDescending(x => x.ClickCount); //if (proDatas.Count() == 0) throw new AdsException("Tracking links not found."); foreach (var proData in proDatas) { model.PerLink.Add(new TemplateReportDetailVm() { Link = proData.Destination_URL, ClickCount = proData.ClickCount, UniqueCount = proData.UniqueCnt, MobileCount = proData.MobileCnt }); } return(model); }
private static void SaveNotification(WfpictContext db, SettingsVm settings, Guid?campaignId, string orderNumber, string segmentNumber, DateTime?deployDate, string responseStatus, CampaignTracking campaignTracking) { if (!deployDate.HasValue) { return; } string message; int hoursPassed = DateTime.Now.Subtract(deployDate.Value).Hours; // QC Rule 1 if (responseStatus == ProDataResponseStatus.NotFound.ToString() && hoursPassed >= settings.NotStartedInXHoursValue) { //message = $"{hoursPassed}Hrs passed and not yet started. Max allowed time {settings.NotStartedInXHoursValue}Hrs"; message = $"Campaign started {deployDate.Value} as of {DateTime.Now}, Campaign has no traffic."; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotStartedInFirstXHours, message); } else // If Started { // QC Rule 10 if (campaignTracking.OpenedPercentage < 0.01 && hoursPassed > 0) // less than 1% and deploy date time passed { message = $"Number of Opens in last 24hrs, No Open Traffic in 24hrs."; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.OpenTrafficInLast1Day, message); } // QC Rule 10 if (campaignTracking.ClickedPercentage < 0.01 && hoursPassed > 0) // less than 1% and deploy date time passed { message = $"Number of Clicks in last 24hrs, No Click Traffic in 24hrs."; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.ClickTrafficInLast1Day, message); } } if (hoursPassed >= 24) { // QC Rule 2 if (campaignTracking.OpenedPercentage < (settings.NotHitOpenRateIn24HoursValue / 100.0)) { message = $"{campaignTracking.Opened} / {campaignTracking.Quantity} is Less than required value {settings.NotHitOpenRateIn24HoursValue}% in first 24hrs"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotHitOpenRateIn1Day, message); } // QC Rule 4 if (campaignTracking.ClickedPercentage < (settings.NotHitClickRateIn24HoursValue / 100.0)) { message = $"{campaignTracking.Clicked} / {campaignTracking.Quantity} is Less than required value {settings.NotHitClickRateIn24HoursValue}% in first 24hrs"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotHitClickRateIn1Day, message); } // QC Rule 6 if (campaignTracking.OpenedPercentage > (settings.ExceededOpenRateIn24HoursValue / 100.0)) { message = $"{campaignTracking.Opened} / {campaignTracking.Quantity} is Greater than required value {settings.ExceededOpenRateIn24HoursValue}% in first 24hrs"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.ExceededOpenRateIn24Hours, message); } // QC Rule 8 if (campaignTracking.ClickedPercentage > (settings.ExceededClickRateIn24HoursValue / 100.0)) { message = $"{campaignTracking.Clicked} / {campaignTracking.Quantity} is Greater than required value {settings.ExceededClickRateIn24HoursValue}% in first 24hrs"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.ExceededClickRateIn24Hours, message); } } else if (hoursPassed >= 72) { // QC Rule 3 if (campaignTracking.OpenedPercentage < (settings.NotHitOpenRateIn72HoursValue / 100.0)) { message = $"{campaignTracking.Opened} / {campaignTracking.Quantity} is Less than required value {settings.NotHitOpenRateIn72HoursValue}% in first 72hrs"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotHitOpenRateIn3Days, message); } // QC Rule 5 if (campaignTracking.ClickedPercentage < (settings.NotHitClickRateIn72HoursValue / 100.0)) { message = $"{campaignTracking.Clicked} / {campaignTracking.Quantity} is Less than required value {settings.NotHitClickRateIn72HoursValue}% in first 72hrs"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotHitClickRateIn3Days, message); } // QC Rule 7 if (campaignTracking.OpenedPercentage > (settings.ExceededOpenRateIn72HoursValue / 100.0)) { message = $"{campaignTracking.Opened} / {campaignTracking.Quantity} is Greater than required value {settings.ExceededOpenRateIn72HoursValue}% in first 72hrs"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.ExceededOpenRateIn72Hours, message); } // QC Rule 9 if (campaignTracking.ClickedPercentage > (settings.ExceededClickRateIn72HoursValue / 100.0)) { message = $"{campaignTracking.Clicked} / {campaignTracking.Quantity} is Greater than required value {settings.ExceededClickRateIn72HoursValue}% in first 72hrs"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.ExceededClickRateIn72Hours, message); } } }
private static CampaignTracking UpdateTracking(WfpictContext db, Campaign campaign, string orderNumber, string segmentNumber, ProDataResponse data) { var campaignTracking = campaign.Trackings.FirstOrDefault(x => x.OrderNumber == orderNumber && x.SegmentNumber == segmentNumber); // Save tracking for Old orders if (campaignTracking == null) { string orderNumberRdp; long quantity; if (campaign.ReBroadcasted) { orderNumberRdp = campaign.ReBroadcastedOrderNumber; quantity = campaign.ReBroadcastedQuantity; } else { orderNumberRdp = campaign.OrderNumber; quantity = campaign.Approved.Quantity; } var trackingId = Guid.NewGuid(); campaignTracking = new CampaignTracking() { Id = trackingId, CreatedAt = DateTime.Now, CampaignId = campaign.Id, OrderNumber = orderNumberRdp, SegmentNumber = string.Empty, Quantity = quantity, DateSent = DateTime.Now, IsCreatedThroughApi = false }; db.CampaignTrackings.Add(campaignTracking); db.SaveChanges(); } if (campaignTracking?.DateSent == null || data.reports?.report == null || data.reports.report.Length == 0) { return(campaignTracking); } var reports = data.reports.report; var report = reports[0]; DateTime startDateTime; DateTime.TryParse(report.CampaignStartDate, out startDateTime); campaignTracking.IoNumber = report.IO; campaignTracking.StartDate = startDateTime; campaignTracking.Deployed = (long)(campaignTracking.Quantity * (1 + Random.Next(2, 30) / 10000.0)); campaignTracking.Opened = campaign.Approved.IsUseApiDataForOpen ? report.ImpressionCnt : OpenModelerProData.GetOpens(campaignTracking.Quantity, startDateTime); if (campaign.Approved.WhiteLabel == StringConstants.CustomerStrategus) { campaignTracking.Opened = (long)(((campaignTracking.Quantity * Random.Next(160000, 190000)) / 10000.0) / 100.0); } campaignTracking.Clicked = reports.Sum(x => long.Parse(x.ClickCount)); campaignTracking.Mobile = reports.Sum(x => x.MobileCnt); campaignTracking.Desktop = report.UniqueCnt; campaignTracking.Unsub = Random.Next(1, 100); campaignTracking.Forwards = Random.Next(1, 100); campaignTracking.Bounce = campaignTracking.Deployed - campaignTracking.Quantity; campaignTracking.Opt = Random.Next(1, 30); campaignTracking.DeliveryPercentage = campaignTracking.Quantity == 0 ? 0 : (double)campaignTracking.Quantity / campaignTracking.Deployed; campaignTracking.OpenedPercentage = campaignTracking.Quantity == 0 ? 0 : (double)campaignTracking.Opened / campaignTracking.Quantity; campaignTracking.ClickedPercentage = campaignTracking.Quantity == 0 ? 0 : (double)campaignTracking.Clicked / campaignTracking.Quantity; campaignTracking.UnsubPercentage = campaignTracking.Quantity == 0 ? 0 : (double)campaignTracking.Unsub / campaignTracking.Quantity; campaignTracking.ClickToOpenPercentage = campaignTracking.Opened == 0 ? 0 : (double)campaignTracking.Clicked / campaignTracking.Opened; campaignTracking.UnsubToOpenPercentage = campaignTracking.Opened == 0 ? 0 : (double)campaignTracking.Unsub / campaignTracking.Opened; db.SaveChanges(); return(campaignTracking); }
private static void SaveNotificationNXS(WfpictContext db, SettingsVm settings, Guid?campaignId, string orderNumber, string segmentNumber, DateTime?deployDate, string responseStatus, CampaignTracking campaignTracking) { if (!deployDate.HasValue) { return; } string message; int hoursPassed = (int)DateTime.Now.Subtract(deployDate.Value).TotalHours; // If Started if (hoursPassed < 96 && hoursPassed >= 72) // < 4 days { // QC Rule 3 if (campaignTracking.OpenedPercentage < (settings.NotHitOpenRateIn72HoursValue / 100.0)) { message = $"{campaignTracking.Opened} / {campaignTracking.Quantity} is Less than required value {settings.NotHitOpenRateIn72HoursValue}% in 3 days"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotHitOpenRateIn3Days, message); } // QC Rule 5 if (campaignTracking.ClickedPercentage < (settings.NotHitClickRateIn72HoursValue / 100.0)) { message = $"{campaignTracking.Clicked} / {campaignTracking.Quantity} is Less than required value {settings.NotHitClickRateIn72HoursValue}% in 3 days"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotHitClickRateIn3Days, message); } return; } if (hoursPassed < 72 && hoursPassed >= 48) { // QC Rule 3 if (campaignTracking.OpenedPercentage < (settings.NotHitOpenRateIn48HoursValue / 100.0)) { message = $"{campaignTracking.Opened} / {campaignTracking.Quantity} is Less than required value {settings.NotHitOpenRateIn48HoursValue}% in 2 days"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotHitOpenRateIn2Days, message); } // QC Rule 5 if (campaignTracking.ClickedPercentage < (settings.NotHitClickRateIn48HoursValue / 100.0)) { message = $"{campaignTracking.Clicked} / {campaignTracking.Quantity} is Less than required value {settings.NotHitClickRateIn48HoursValue}% in 2 days"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotHitClickRateIn2Days, message); } return; } if (hoursPassed < 48 && hoursPassed >= 24) { // QC Rule 2 if (campaignTracking.OpenedPercentage < (settings.NotHitOpenRateIn24HoursValue / 100.0)) { message = $"{campaignTracking.Opened} / {campaignTracking.Quantity} is Less than required value {settings.NotHitOpenRateIn24HoursValue}% in 1 day"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotHitOpenRateIn1Day, message); } // QC Rule 4 if (campaignTracking.ClickedPercentage < (settings.NotHitClickRateIn24HoursValue / 100.0)) { message = $"{campaignTracking.Clicked} / {campaignTracking.Quantity} is Less than required value {settings.NotHitClickRateIn24HoursValue}% in 1 day"; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotHitClickRateIn1Day, message); } } //if (hoursPassed < 24 && hoursPassed >= settings.NotStartedInXHoursValue) //{ // if (campaignTracking.OpenedPercentage < 0.001 && hoursPassed > 0) // less than 0.1% and deploy date time passed // { // message = $"Number of Opens in last 24hrs, No Open Traffic in 24hrs."; // SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.OpenTrafficInLast24Hours, message); // } // // QC Rule 10 // if (campaignTracking.ClickedPercentage < 0.001 && hoursPassed > 0) // less than 0.1% and deploy date time passed // { // message = $"Number of Click in last 24hrs, No Click Traffic in 24hrs."; // SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.ClickTrafficInLast24Hours, message); // } // return; //} // QC Rule 1, Not Started if (responseStatus == ProDataResponseStatus.NotFound.ToString() && hoursPassed >= settings.NotStartedInXHoursValue) { message = $"Campaign to be started {deployDate.Value} as of {DateTime.Now}, Campaign has not started within {settings.NotStartedInXHoursValue} hours."; SaveNotificationRecord(db, campaignId, orderNumber, segmentNumber, QcRule.NotStartedInFirstXHours, message); } }
public static CampaignTrackingMetricDetailVm[] FromCampaignTracking(Campaign campaign, CampaignTracking campaignTracking) { var urls = new List <CampaignTrackingMetricDetailVm>(); var proDatas = campaign.ProDatas .Where(x => x.OrderNumber == campaignTracking.OrderNumber && x.SegmentNumber == campaignTracking.SegmentNumber) .OrderByDescending(x => x.ClickCount); int index = 1; foreach (var proData in proDatas) { var model = new CampaignTrackingMetricDetailVm { SFD_ID = campaign.Assets.SFDClientId, Client_ID = SfidLookup.GetCampaignName(campaign.Assets.SFDClientId), Campaign_Name = campaign.Approved.CampaignName, From_Line = campaign.Approved.FromLine, Subject_Line = campaign.Approved.SubjectLine, Deployment_Date = campaign.Approved.DeployDate?.ToString(StringConstants.DateFormatSlashes), URLS = proData.Destination_URL, Total_Clicks = proData.ClickCount, //string.Format("{0:n0}", proData.ClickCount), Unique_Clicks = proData.UniqueCnt, Mobile_Clicks = proData.MobileCnt, ID = index++ }; urls.Add(model); } return(urls.ToArray()); }
protected static CampaignTracking UpdateTrackingNXS(WfpictContext db, Campaign campaign, string orderNumber, string segmentNumber, ProDataResponse data, Customer customer, List <long> dayWise = null) { var campaignTracking = campaign.Trackings.FirstOrDefault(x => x.OrderNumber == orderNumber && x.SegmentNumber == segmentNumber); long quantity = orderNumber.EndsWith("RDP") ? campaign.ReBroadcastedQuantity : campaign.Approved.Quantity; DateTime?startDateTime = orderNumber.EndsWith("RDP") ? campaign.ReBroadcastedDate : campaign.Approved.DeployDate; // Save tracking for Old orders if (campaignTracking == null) { var trackingId = Guid.NewGuid(); campaignTracking = new CampaignTracking() { Id = trackingId, CreatedAt = DateTime.Now, CampaignId = campaign.Id, OrderNumber = orderNumber, SegmentNumber = string.Empty, Quantity = quantity, DateSent = DateTime.Now, IsCreatedThroughApi = false }; db.CampaignTrackings.Add(campaignTracking); db.SaveChanges(); } if (campaignTracking?.DateSent == null || data.reports?.report == null || data.reports.report.Length == 0) { return(campaignTracking); } var reports = data.reports.report; var report = reports[0]; campaignTracking.IoNumber = report.IO; campaignTracking.StartDate = startDateTime; campaignTracking.Deployed = (long)(campaignTracking.Quantity * (1 + Random.Next(2, 30) / 10000.0)); // Prodata & ProData fake Open Modeler int openRandom = Random.Next((int)customer.OpenInitial, (int)customer.OpenEnd); long openCountTotal = (long)((openRandom * campaignTracking.Quantity / 100000.0) / 100.0); campaignTracking.Opened = openCountTotal; // Open by mobile, desktop campaignTracking.Desktop = (long)(((campaignTracking.Opened * Random.Next(50000, 60000)) / 1000.0) / 100.0); campaignTracking.Mobile = campaignTracking.Opened - campaignTracking.Desktop; campaignTracking.Clicked = reports.Sum(x => long.Parse(x.ClickCount)); campaignTracking.Unsub = Random.Next(1, 100); campaignTracking.Forwards = Random.Next(1, 100); campaignTracking.Bounce = Random.Next(1, 25); //campaignTracking.Deployed - campaignTracking.Quantity; campaignTracking.Opt = Random.Next(1, 5); //var retargetingClicks = (long)(((campaignTracking.Quantity * Random.Next(160000, 190000)) / 100000.0) / 100.0); //campaignTracking.RetargetingClicks = retargetingClicks; //campaignTracking.RetargetingImpressions = (long)(retargetingClicks / (Random.Next(90, 130) / 10000.0)); // 100-120% of qty campaignTracking.RetargetingImpressions = (long)((campaignTracking.Quantity * Random.Next(100000, 120000)) / 100000.0); // .8 to 1.0% of qty campaignTracking.RetargetingClicks = (long)((campaignTracking.Quantity * Random.Next(800, 1000)) / 100000.0); campaignTracking.DeliveryPercentage = campaignTracking.Quantity == 0 ? 0 : (double)campaignTracking.Quantity / campaignTracking.Deployed; campaignTracking.OpenedPercentage = campaignTracking.Quantity == 0 ? 0 : (double)campaignTracking.Opened / campaignTracking.Quantity; campaignTracking.ClickedPercentage = campaignTracking.Quantity == 0 ? 0 : (double)campaignTracking.Clicked / campaignTracking.Quantity; campaignTracking.UnsubPercentage = campaignTracking.Quantity == 0 ? 0 : (double)campaignTracking.Unsub / campaignTracking.Quantity; campaignTracking.ClickToOpenPercentage = campaignTracking.Opened == 0 ? 0 : (double)campaignTracking.Clicked / campaignTracking.Opened; campaignTracking.UnsubToOpenPercentage = campaignTracking.Opened == 0 ? 0 : (double)campaignTracking.Unsub / campaignTracking.Opened; if (dayWise != null) { campaignTracking.Day1Clicks = GetCount(dayWise, 0); campaignTracking.Day2Clicks = GetCount(dayWise, 1); campaignTracking.Day3Clicks = GetCount(dayWise, 2); campaignTracking.Day4Clicks = GetCount(dayWise, 3); campaignTracking.Day5Clicks = GetCount(dayWise, 4); campaignTracking.Day6Clicks = GetCount(dayWise, 5); campaignTracking.Day7Clicks = GetCount(dayWise, 6); campaignTracking.Day7PlusClicks = dayWise.Sum(); } db.SaveChanges(); return(campaignTracking); }
public static CampaignTrackingOpenModelVm FromCampaignTracking(Campaign campaign, CampaignTracking campaignTracking) { var model = new CampaignTrackingOpenModelVm { CampaignId = campaign.Id.ToString(), TrackingId = campaignTracking.Id.ToString(), OrderNumber = string.IsNullOrEmpty(campaignTracking.SegmentNumber) ? campaignTracking.OrderNumber : campaignTracking.SegmentNumber, CampaignName = campaign.Approved.CampaignName, WhiteLabel = campaign.Approved.WhiteLabel, SubjectLine = campaign.Approved.SubjectLine, FromLine = campaign.Approved.FromLine, Quantity = string.Format("{0:n0}", campaignTracking.Quantity), Status = ((CampaignStatus)campaign.Status).ToString(), OrderDate = campaign.CreatedAt.ToString(StringConstants.DateFormatSlashes), DateSent = campaignTracking.CreatedAt.ToString(StringConstants.DateFormatSlashes), SentOrder = campaignTracking.SentOrder, IsCreatedThroughApi = campaignTracking.IsCreatedThroughApi, QueuedCampaignId = campaignTracking.QueuedCampaignId, IoNumber = campaignTracking.IoNumber, StartDate = campaignTracking.StartDate?.ToString(StringConstants.DateFormatSlashes), Deployed = campaignTracking.Deployed == 0 ? "NA" : string.Format("{0:n0}", campaignTracking.Deployed), Opened = campaignTracking.Opened == 0 ? "NA" : string.Format("{0:n0}", campaignTracking.Opened), Clicked = campaignTracking.Clicked == 0 ? "NA" : string.Format("{0:n0}", campaignTracking.Clicked), Unsub = campaignTracking.Unsub == 0 ? "NA" : string.Format("{0:n0}", campaignTracking.Unsub), Forwards = campaignTracking.Forwards == 0 ? "NA" : string.Format("{0:n0}", campaignTracking.Forwards), Mobile = string.Format("{0:n0}", campaignTracking.Mobile), Desktop = string.Format("{0:n0}", campaignTracking.Desktop), Bounce = string.Format("{0:n0}", campaignTracking.Bounce), Opt = string.Format("{0:n0}", campaignTracking.Opt), DeliveryPercentage = campaignTracking.DeliveryPercentage.ToString("0.00%"), OpenedPercentage = campaignTracking.OpenedPercentage.ToString("0.00%"), ClickedPercentage = campaignTracking.ClickedPercentage.ToString("0.00%"), UnsubPercentage = campaignTracking.UnsubPercentage.ToString("0.00%"), ClickToOpenPercentage = campaignTracking.ClickToOpenPercentage.ToString("0.00%"), UnsubToOpenPercentage = campaignTracking.UnsubToOpenPercentage.ToString("0.00%"), OpenModelLinksCount = string.Format("{0:n0}", campaign.Assets.OpenModelLinksCount), OpenModelImgUploaded = string.IsNullOrEmpty(campaign.Assets.OpenModelImageFile) ? "No" : "Yes", Segments = new List <CampaignSegmentVm>(), PerLink = new List <CampaignTrackingDetailVm>() }; model.Segments = campaign.Segments.Where(x => !string.IsNullOrEmpty(x.SegmentDataFileUrl)) .Select(x => new CampaignSegmentVm() { SegmentNumber = x.SegmentNumber, SegmentDataFileUrl = x.SegmentDataFileUrl }).OrderBy(x => x.SegmentNumber).ToList(); var proDatas = campaign.ProDatas .Where(x => x.OrderNumber == campaignTracking.OrderNumber && x.SegmentNumber == campaignTracking.SegmentNumber) //.OrderBy(x => ProDataHelper.GetIndex(x.Reportsite_URL)); .OrderByDescending(x => x.ClickCount); foreach (var proData in proDatas) { model.PerLink.Add(new CampaignTrackingDetailVm { IoNumber = proData.IO, OrderNumber = proData.Reportsite_URL, Link = proData.Destination_URL, ClickCount = string.Format("{0:n0}", proData.ClickCount), UniqueCount = string.Format("{0:n0}", proData.UniqueCnt), MobileCount = string.Format("{0:n0}", proData.MobileCnt) }); } return(model); }
public static CampaignTrackingMetricVm[] FromCampaignTracking(Campaign campaign, CampaignTracking campaignTracking) { string filePathLive = $"{S3FileManager.ServerPrefix}{campaign.Assets.OpenModelImageFile}"; var metrics = new CampaignTrackingMetricVm[1] { new CampaignTrackingMetricVm { SFD_ID = campaign.Assets.SFDClientId, Client_ID = SfidLookup.GetCampaignName(campaign.Assets.SFDClientId), Campaign_Name = campaign.Approved.CampaignName, From_Line = campaign.Approved.FromLine, Subject_Line = campaign.Approved.SubjectLine, Deployment_Date = campaign.Approved.DeployDate?.ToString(StringConstants.DateFormatSlashes), Delivered = campaignTracking.Quantity, Open_Rate = campaignTracking.OpenedPercentage, Total_Opens = campaignTracking.Opened, Total_Clicks = campaignTracking.Clicked, Click_Percentage = campaignTracking.ClickedPercentage, HTML_CTR = campaignTracking.ClickToOpenPercentage, Mobile = campaignTracking.Mobile, Desktop = campaignTracking.Desktop, Image_URL = filePathLive } }; return(metrics); }
public static void Generate(System.Web.HttpResponseBase Response, Campaign campaign, CampaignTracking campaignTracking) { var metric = CampaignTrackingMetricVm.FromCampaignTracking(campaign, campaignTracking); var urls = CampaignTrackingMetricDetailVm.FromCampaignTracking(campaign, campaignTracking); ExcelPackage excel = new ExcelPackage(); var workSheet = excel.Workbook.Worksheets.Add("Strat Metrics"); workSheet.Cells[1, 1].LoadFromCollection(metric, true); workSheet.Cells[2, 8].Style.Numberformat.Format = "0.00%"; workSheet.Cells[2, 11].Style.Numberformat.Format = "0.00%"; workSheet.Cells[2, 12].Style.Numberformat.Format = "0.00%"; var workSheet2 = excel.Workbook.Worksheets.Add("Strat URLs"); workSheet2.Cells[1, 1].LoadFromCollection(urls, true); using (var memoryStream = new MemoryStream()) { string orderNumber = campaign.ReBroadcasted ? $"{campaign.ReBroadcastedOrderNumber}" : $"{campaign.OrderNumber}"; string fileName = $"{orderNumber}report.xlsx"; Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader($"content-disposition", $"attachment; filename={fileName}"); excel.SaveAs(memoryStream); memoryStream.WriteTo(Response.OutputStream); Response.Flush(); Response.End(); } }