public AlertMeasure GetMainMeasure() { AlertMeasures measures = null; AlertMeasure ret = null; if (!ParentWorkflow.InternalParameters.Contains("AlertMeasures")) { measures = new AlertMeasures(); ParentWorkflow.InternalParameters.Add("AlertMeasures", measures); } else { measures = (AlertMeasures)ParentWorkflow.InternalParameters["AlertMeasures"]; } if (ParentWorkflow.Parameters.Contains("MainMeasure")) { //Return the main measure. string main = ParentWorkflow.Parameters["MainMeasure"].ToString(); ret = measures.Get(main); } else { //Default to clicks. ret = measures.Get("Clicks"); } return(ret); }
public AlertMeasure GetMeasure(string name) { if (name == null || name == String.Empty) { throw new ArgumentException("Invalid measure name. Cannot be null or empty!"); } AlertMeasures measures = null; AlertMeasure ret = null; if (!ParentWorkflow.InternalParameters.Contains("AlertMeasures")) { measures = new AlertMeasures(); ParentWorkflow.InternalParameters.Add("AlertMeasures", measures); } else { measures = (AlertMeasures)ParentWorkflow.InternalParameters["AlertMeasures"]; } ret = measures.Get(name); return(ret); }
private void GenerateHeaders(ref ExcelWorksheet ew, int row, AlertMeasure main) { string[] arr = _columns.Split(','); ArrayList a = new ArrayList(arr); int count = 0; for (int i = 0; i < a.Count; i++) { ew.Cell(row, i + 1).Value = a[i].ToString(); if (a[i].ToString().IndexOf(main.AlertMeasureName) != -1) { ew.Cell(row, i + 1).Style = "Heading 4"; count++; } else { //If we're here, and we already "colored" two cells, it means that we're in the //third cell - the "Difference (%)" which we also need to color. if (count == 2) { ew.Cell(row, i + 1).Style = "Heading 4"; count = 0; } } } }
public bool CheckEntity(float value, AlertMeasure measure, MeasureDiff diff) { if (value < 0) { return(false); } if (measure == null) { return(false); } try { MeasuredParameters ret = new MeasuredParameters(); bool bRet = false; ret = CheckMeasure(measure, value, diff); if (ret != null && ret.Count > 0) { AllocateReport(ret, measure.AlertMeasureName, diff); //If we have something to report about - also flush it into the database. Flush(ret); bRet = true; } return(bRet); } catch (Exception ex) { Log.Write("Exception in CheckEntity", ex); return(false); } }
public bool IncludeMeasure(AlertMeasure am, MeasuredParameter mp) { if (am == null) { throw new ArgumentNullException("Invalid alert measure parameter. Cannot be null."); } if (mp == null) { throw new ArgumentNullException("Invalid measured parameter argument. Cannot be null."); } IDictionaryEnumerator ide = GetEnumerator(); while (ide.MoveNext()) { AccountAlertFilter aaf = (AccountAlertFilter)ide.Value; if (aaf.MeasureID == am.AlertMeasureID) { //This is the measure we want to check the filter of. if (aaf.MatchesFilter(am, mp)) { return(true); } } } return(false); }
public bool GenerateExcel(ref ExcelWorksheet ew, ref int row, AlertMeasure main, string additionalMeasures) { //Add rows into the excel worksheet. if (_measuredParameters.Count <= 0) { return(false); } ew.Cell(row, 3).Value = _accountName; //First put the direction (falling/rising). row++; ew.InsertRow(row); ew.Cell(row, 1).Value = _heading; row++; ew.InsertRow(row); row++; //Now the headers (columns) ew.InsertRow(row); GenerateHeaders(ref ew, row, main); row++; _measuredParameters.ToExcel(ref ew, ref row, main, additionalMeasures); _criticalFound = _measuredParameters.CriticalThreshold; _processed = true; return(true); }
public bool MatchesFilter(AlertMeasure am, MeasuredParameter mp) { if (am == null) { throw new ArgumentNullException("Invalid alert measure parameter. Cannot be null."); } if (mp == null) { throw new ArgumentNullException("Invalid measured parameter argument. Cannot be null."); } if (_minValue > 0) { if (Convert.ToDouble(mp.CurrentValueFromMeasure(am.AlertMeasureName)) < _minValue || Convert.ToDouble(mp.CompareValueFromMeasure(am.AlertMeasureName)) < _minValue) { return(false); } } if (_maxValue > 0) { if (Convert.ToDouble(mp.CompareValueFromMeasure(am.AlertMeasureName)) > _maxValue || Convert.ToDouble(mp.CurrentValueFromMeasure(am.AlertMeasureName)) > _maxValue) { return(false); } } return(true); }
public async Task WriteMeasure(AlertMeasure measure) { await _influxDBClient .GetWriteApiAsync() .WriteMeasurementAsync( _options.Bucket, _options.Organization, WritePrecision.Ms, measure); }
/* Writing the results to the database */ protected virtual void WriteResult(MeasuredParameter mp) { AlertMeasures measures = (AlertMeasures)ParentWorkflow.InternalParameters["AlertMeasures"]; //Loop on each of the measures we have - and for each, write the results. IDictionaryEnumerator ide = measures.GetEnumerator(); while (ide.MoveNext()) { AlertMeasure am = (AlertMeasure)ide.Value; WriteResult(mp, am); } }
public AccountAlertFilter GetFilter(AlertMeasure am) { IDictionaryEnumerator ide = GetEnumerator(); while (ide.MoveNext()) { AccountAlertFilter aaf = (AccountAlertFilter)ide.Value; if (aaf.MeasureID == am.AlertMeasureID) { return(aaf); } } return(null); }
/* Rules */ protected virtual MeasuredParameters CheckMeasure(AlertMeasure measure, float value, MeasureDiff diff) { AlertMeasures measures = null; if (!ParentWorkflow.InternalParameters.Contains("AlertMeasures")) { measures = new AlertMeasures(); ParentWorkflow.InternalParameters.Add("AlertMeasures", measures); } else { measures = (AlertMeasures)ParentWorkflow.InternalParameters["AlertMeasures"]; } MeasuredParameters ret = new MeasuredParameters(); for (int i = 0; i < _results.Count; i++) { try { MeasuredParameter mp = (MeasuredParameter)_results[i]; if (measure.CompositeMeasure) { if (measure.Evaluate(mp, value, diff, measures)) { ret.Add(mp.GK, mp); } } else { if (Evaluate(mp.ValueFromMeasure(measure.AlertMeasureName), value, diff)) { ret.Add(mp.GK, mp); } } } catch (Exception ex) { Log.Write("Exception occured while adding measured parameters", ex); continue;; } } return(ret); }
protected virtual void WriteResult(MeasuredParameter mp, AlertMeasure am) { DataManager.ConnectionString = AppSettings.GetAbsolute("Easynet.Edge.Core.Workflow.AlertConnectionString"); //Create the command. using (DataManager.Current.OpenConnection()) { AlertMeasures measures = (AlertMeasures)ParentWorkflow.InternalParameters["AlertMeasures"]; string sql = "INSERT INTO AlertResults "; string columns = "(wf_id,wf_date,wf_parameters,wf_conditionValues,entity_type,Account_id,Channel_id,Account_name,Current_Day,Compare_Day,measure_id,measure_current_value,measure_compare_value,measure_change_ratio"; columns += GetColumns(mp); sql += columns + " VALUES("; int wfID = ParentWorkflow.WorkflowID; if (wfID <= 0) { if (ParentWorkflow.Parameters.ContainsKey("WorkflowID")) { wfID = Convert.ToInt32(ParentWorkflow.Parameters["WorkflowID"]); } } string values = String.Empty; values = wfID.ToString() + ",'" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "','" + ParentWorkflow.GetParametersAsString() + "','" + ParentWorkflow.GetConditionValuesAsString() + "'," + Convert.ToInt32(_entityType).ToString() + ","; values += mp.AccountID.ToString() + "," + mp.ChannelID.ToString() + ",'" + mp.AccountName + "'," + DayCode.ToDayCode(mp.CurrentDay).ToString() + "," + DayCode.ToDayCode(mp.CompareDate).ToString() + ","; values += mp.GetMeasureParameterSQL(am, measures) + ")"; sql += values; SqlCommand alertResults = DataManager.CreateCommand(sql); try { alertResults.ExecuteNonQuery(); } catch (Exception ex) { Log.Write("Failed to write alert result to database.", ex); throw ex; } } }
public bool ContainsMeasure(AlertMeasure am) { if (am == null) { throw new ArgumentNullException("Invalid alert measure parameter. Cannot be null."); } IDictionaryEnumerator ide = GetEnumerator(); while (ide.MoveNext()) { AccountAlertFilter aaf = (AccountAlertFilter)ide.Value; if (aaf.MeasureID == am.AlertMeasureID) { return(true); } } return(false); }
public void Generate(ref ExcelWorkbook wb, EntityTypes type, AlertMeasure main, string additionalMeasures) { //Loop on the reports we have, get the worksheet based on the entity type. ExcelWorksheet ew = null; switch (type) { case EntityTypes.Account: { ew = wb.Worksheets["Accounts"]; break; } case EntityTypes.Campaign: { ew = wb.Worksheets["Campaigns"]; break; } case EntityTypes.Adgroup: { ew = wb.Worksheets["AdGroups"]; break; } case EntityTypes.Keyword: { ew = wb.Worksheets["Keywords"]; break; } case EntityTypes.Gateway: { ew = wb.Worksheets["Gateways"]; break; } case EntityTypes.Adtext: { ew = wb.Worksheets["AdTexts"]; break; } } int row = START_ROW; IDictionaryEnumerator ide = GetEnumerator(); while (ide.MoveNext()) { Report r = (Report)ide.Value; r.AccountName = _accountName; r.GenerateExcel(ref ew, ref row, main, additionalMeasures); if (r.CriticalThreshold) { _criticalFound = r.CriticalThreshold; } row++; ew.InsertRow(row); row++; ew.InsertRow(row); row++; } }
private string GetAdditionalColumns() { //Add the date columns string dates = String.Empty; if (_alertType == AlertType.Period) { dates = "Base_Start_Date,Base_End_Date,Current_Start_Date,Current_End_Date"; } else { dates = "Base_Date,Current_Date"; } //Get the columns based on the measures we have. AlertMeasure main = GetMainMeasure(); string mainColumns = main.AlertMeasureColumns; if (mainColumns == String.Empty || mainColumns == null) { return(dates); } mainColumns = dates + "," + mainColumns; string additionalMeasures = String.Empty; if (ParentWorkflow.Parameters.ContainsKey("AdditionalMeasures")) { additionalMeasures = ParentWorkflow.Parameters["AdditionalMeasures"].ToString(); } if (additionalMeasures == String.Empty || additionalMeasures == null) { return(mainColumns); } AlertMeasures measures = null; if (!ParentWorkflow.InternalParameters.Contains("AlertMeasures")) { measures = new AlertMeasures(); ParentWorkflow.InternalParameters.Add("AlertMeasures", measures); } else { measures = (AlertMeasures)ParentWorkflow.InternalParameters["AlertMeasures"]; } if (measures == null) { Log.Write("Invalid Measures collection - could not find in parameters, and could not generate.", LogMessageType.Error); return(mainColumns); } string ret = String.Empty; string[] arr = additionalMeasures.Split(','); for (int i = 0; i < arr.Length; i++) { string name = arr[i]; AlertMeasure am = measures.Get(name); if (am != null) { //FUTURE - Remove double entries. if (am.CompositeMeasure) { //If we're a composite measure, check if one of our measures was //already displayed. } if (ret == String.Empty) { ret += am.AlertMeasureColumns; } else { ret += "," + am.AlertMeasureColumns; } } else { Log.Write("Could not find measure with name: " + name + ". In the measures collection.", LogMessageType.Warning); } } mainColumns += "," + ret; return(mainColumns); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { try { HasReport = false; bool critical = false; if (ParentWorkflow.InternalParameters.ContainsKey("Reports")) { //Get the reports and generate the file. string accountName = "Unknown"; if (ParentWorkflow.InternalParameters.ContainsKey("AccountName")) { accountName = ParentWorkflow.InternalParameters["AccountName"].ToString(); } string outputDir = String.Empty; if (!ParentWorkflow.Parameters.ContainsKey("DefaultReportDirectory")) { outputDir = @"c:\temp"; } else { outputDir = ParentWorkflow.Parameters["DefaultReportDirectory"].ToString(); } TimeDeltaType type = TimeDeltaType.General; if (ParentWorkflow.InternalParameters.ContainsKey("TimeDeltaType")) { type = (TimeDeltaType)ParentWorkflow.InternalParameters["TimeDeltaType"]; } string repType = GetReportTypeString(type); string alertType = GetAlertTypeString(); string mainMeasure = String.Empty; if (ParentWorkflow.Parameters.Contains("MainMeasure")) { mainMeasure = ParentWorkflow.Parameters["MainMeasure"].ToString(); } string fileName = alertType + "_" + repType + "_" + accountName + "_" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx"; string dir = String.Empty; if (mainMeasure != String.Empty) { fileName = mainMeasure + "_" + fileName; } if (!outputDir.EndsWith(@"\")) { outputDir += @"\"; } dir = outputDir; outputDir += fileName; string additionalMeasures = String.Empty; if (ParentWorkflow.Parameters.ContainsKey("AdditionalMeasures")) { additionalMeasures = ParentWorkflow.Parameters["AdditionalMeasures"].ToString(); } //First create the excel workbook string wbFileName = @"c:\temp\ReportTemplate.xlsx"; wbFileName = AppSettings.GetAbsolute("Easynet.Edge.Alerts.TemplateFileName"); if (ParentWorkflow.Parameters.ContainsKey("TemplateFileName")) { wbFileName = dir + ParentWorkflow.Parameters["TemplateFileName"].ToString(); } FileInfo newFile = new FileInfo(outputDir); FileInfo template = new FileInfo(wbFileName); using (ExcelPackage ep = new ExcelPackage(newFile, template)) { ExcelWorkbook ew = ep.Workbook; Hashtable reps = (Hashtable)ParentWorkflow.InternalParameters["Reports"]; IDictionaryEnumerator ereps = reps.GetEnumerator(); AlertMeasure main = GetMainMeasure(); StringBuilder sb = new StringBuilder(); while (ereps.MoveNext()) { HasReport = true; Reports reports = (Reports)ereps.Value; reports.AccountName = accountName; reports.Generate(ref ew, (EntityTypes)ereps.Key, main, additionalMeasures); } //Do another loop - to update one cell in each tab. ereps.Reset(); while (ereps.MoveNext()) { Reports reports = (Reports)ereps.Value; reports.Finalize(ref ew); if (reports.CriticalThreshold) { critical = reports.CriticalThreshold; } } ep.Save(); ParentWorkflow.InternalParameters.Add("MessageFileName", outputDir); } } PrepareMessage(critical); if (!HasReport) { Console.WriteLine("AlertEngine Says: Nothing to report."); } } catch (Exception ex) { Console.WriteLine("Exception at Master Report: " + ex.ToString()); } return(ActivityExecutionStatus.Closed); }