QPR ProcessAnalyzer Expression Query Examples: Difference between revisions

From QPR ProcessAnalyzer Wiki
Jump to navigation Jump to search
Line 226: Line 226:
== Dynamic ValueType Examples ==
== Dynamic ValueType Examples ==


=== Count of occurred event types by time (Event type trends analysis) ===
=== Count of occurred event types by time (Event Type Trends Analysis) ===
The following analysis shows how many different types of events occurred divided to time ranges (works like the [[Event_Types#Event_Type_Analysis_in_the_Trends_Mode|Event Type Trend Analysis]]).
The following analysis shows how many different types of events occurred divided to time ranges (works like the [[Event Types#Event Type Analysis in the Trends Mode|Event Type Trends Analysis]]).
<pre>
<pre>
{
{
Line 243: Line 243:
     },
     },
     {
     {
       "ValueDimensionExpression": "For(\"i\", 1, i < 7, i + 1, DateTime(2017, i, 1))",
       "ValueDimensionExpression": "For(\"i\", 1, i < 12, i + 1, DateTime(2017, i, 1))",
       "NameExpression": "\"\" + _.Year + \"-\" + If(_.Month < 10, \"0\", \"\") + _.Month",
       "NameExpression": "\"\" + _.Year + \"-\" + If(_.Month < 10, \"0\", \"\") + _.Month",
       "Expression": "GetAt(0, Count(
       "Expression": "GetAt(0, Count(
Line 255: Line 255:
     {
     {
       "Name": "Event Name",
       "Name": "Event Name",
      "Direction": "Ascending"
    }
  ]
}
</pre>
=== Case counts for each case attributes values by time (Profiling Trends Analysis) ===
The following analysis shows case counts for each case attribute values ("Region" in this example) and for each months (works like the [[Profiling Analysis#Trends|Profiging Trends Analysis]]).
<pre>
{
  "Root": "Cases",
  "Dimensions": [
    {
      "Name": "Region",
      "Expression": "Region"
    }
  ],
  "Values": [
    {
      "ValueDimensionExpression": "For(\"i\", 1, i < 12, i + 1, DateTime(2017, i, 1))",
      "NameExpression": "\"\" + _.Year + \"-\" + If(_.Month < 10, \"0\", \"\") + _.Month",
      "Expression": "GetAt(0, Count(
        _.Events.Where(TimeStamp.Year == ValueDimension.Year &&
        TimeStamp.Month == ValueDimension.Month)
      ))",
      "Type": "Dynamic"
    }
  ],
  "Ordering": [
    {
      "Name": "Region",
       "Direction": "Ascending"
       "Direction": "Ascending"
     }
     }

Revision as of 15:15, 19 December 2017

This page contains example KPI Analyses.

Single ValueType Examples

Events grouped by event attributes

The following analysis calculates:

  1. Number of cases
  2. List of case names
  3. List of distinct case names (single case appears only once in the list)

for each event attribute Color and Category.

{
  "Root": "Events",
  "Dimensions": [
    {
      "Name": "Color",
      "Expression": "Color"
    },
    {
      "Name": "Category",
      "Expression": "Category"
    }
  ],
  "Values": [
    {
      "Name": "Count",
      "Expression": "Count(_)" 
    },
    {
      "Name": "Cases",
      "Expression": "StringJoin(\",\", _.Case.Name)" 
    },
    {
      "Name": "DistinctCases",
      "Expression": "StringJoin(\",\", Distinct(_.Case.Name))" 
    }
  ],
  "Ordering": [ 
    {
      "Name": "Color",
      "Direction": "Ascending"
    },
    {
      "Name": "Category",
      "Direction": "Descending"
    }
  ]
}

Cases grouped by case attributes

Same analysis for for case attributes:

{
  "Root": "Cases",
  "Dimensions": [
    {
      "Name": "Color",
      "Expression": "Color"
    },
    {
      "Name": "Category",
      "Expression": "Category"
    }
  ],
  "Values": [
    {
      "Name": "Count",
      "Expression": "Count(_)" 
    },
    {
      "Name": "Cases",
      "Expression": "StringJoin(\",\", _.Name)" 
    }
    ],
  "Ordering": [ 
    {
      "Name": "Color",
      "Direction": "Ascending"
    },
    {
      "Name": "Category",
      "Direction": "Ascending"
    }
  ]
}

Return only dimension values

The following analysis returns a list of all dimensions but doesn't calculate any KPI's:

{
  "Root": "Cases",
  "Dimensions": [
    {
      "Name": "Region",
      "Expression": "Region"
    }
  ],
  "Values": []
}

Return only single KPI value without dimensioning

The following analysis calculates a KPI for all filtered data but doesn't slice it to any dimensions:

{
  "Root": "Cases",
  "Dimensions": [],
  "Values": [
    {
      "Name": "Case count",
      "Expression": "Count(_)" 
    }
  ]
}

3 Grams

{
  "Root": "Cases",
  "Dimensions": [
    {
      "Name": "CaseId",
      "Expression": "Name"
    }
  ],
  "Values": [
    {
      "Expression": "
        Flatten(
          _
          .Array(
            StringJoin(\"->\", 
            Array(\"0\", 
              GetAt(0, Events).Type.Name, 
              If(
                Count(Events) > 1, 
                GetAt(1, Events).Type.Name, 
                \"0\"
                )
              )
            ),
            StringJoin(\"->\", 
              Events.Where(!IsNull(NextInCase))
              .Array(Type.Name, 
                NextInCase.Type.Name, 
                If(
                  !IsNull(NextInCase.NextInCase), 
                  NextInCase.NextInCase.Type.Name, 
                  \"0\"
                )
              )
            )
          )
        ).Where(_ != \"\")
      ",
      "DimensionOrderExpression": "OrderByValue(_)",
      "Type": "Pivot"
    }
  ],
  "Ordering": [ 
    {
      "Name": "CaseId",
      "Direction": "Ascending"
    }
  ]
}

Case duration distribution by hours

Following analysis shows case duration distribution by hours (works like the Duration Analysis)

{
  "Root": "Cases",
    "Dimensions": [
      {
        "Name": "Case Duration in Hours",
        "Expression": "Duration.TotalHours.Round(0)"
      }
    ],
    "Values": [
      {
        "Name": "Case Count",
        "Expression": "Count(_)" 
      }
    ],
    "Ordering": [ 
      {
        "Name": "Case Duration in Hours",
        "Direction": "Ascending"
    }
  ]
}

Monthly average case duration

The following analysis calculates monthly average case duration. Case start month needs to be a dimension and KPI is the average case duration (also rounding is used).

{
  "Root": "Cases",
  "Dimensions": [
    {
      "Name": "Start Month",
      "Expression": "StartTime.Month"
    }
  ],
  "Values": [
    {
      "Name": "Average Case Duration in Days",
      "Expression": "Round(Average(_.Duration.TotalSeconds) / 3600, 0)"
    }
  ],
  "Ordering": [
    {
      "Name": "Start Month",
      "Direction": "Ascending"
    }
  ]
}

Dynamic ValueType Examples

Count of occurred event types by time (Event Type Trends Analysis)

The following analysis shows how many different types of events occurred divided to time ranges (works like the Event Type Trends Analysis).

{
  "Root": "EventTypes",
  "Dimensions": [
    {
      "Name": "Event Name",
      "Expression": "Name"
    }
  ],
  "Values": [
    {
      "Name": "Event Count",
      "Expression": "GetAt(0, _.Count)" 
    },
    {
      "ValueDimensionExpression": "For(\"i\", 1, i < 12, i + 1, DateTime(2017, i, 1))",
      "NameExpression": "\"\" + _.Year + \"-\" + If(_.Month < 10, \"0\", \"\") + _.Month",
      "Expression": "GetAt(0, Count(
        _.Events.Where(TimeStamp.Year == ValueDimension.Year &&
        TimeStamp.Month == ValueDimension.Month)
      ))",
      "Type": "Dynamic"
    }
  ],
  "Ordering": [ 
    {
      "Name": "Event Name",
      "Direction": "Ascending"
    }
  ]
}

Case counts for each case attributes values by time (Profiling Trends Analysis)

The following analysis shows case counts for each case attribute values ("Region" in this example) and for each months (works like the Profiging Trends Analysis).

{
  "Root": "Cases",
  "Dimensions": [
    {
      "Name": "Region",
      "Expression": "Region"
    }
  ],
  "Values": [
    {
      "ValueDimensionExpression": "For(\"i\", 1, i < 12, i + 1, DateTime(2017, i, 1))",
      "NameExpression": "\"\" + _.Year + \"-\" + If(_.Month < 10, \"0\", \"\") + _.Month",
      "Expression": "GetAt(0, Count(
        _.Events.Where(TimeStamp.Year == ValueDimension.Year &&
        TimeStamp.Month == ValueDimension.Month)
      ))",
      "Type": "Dynamic"
    }
  ],
  "Ordering": [ 
    {
      "Name": "Region",
      "Direction": "Ascending"
    }
  ]
}

Pivot ValueType Examples

Event type ordering

{
  "Root": "Cases",
  "Dimensions": [
    {
      "Name": "CaseId",
      "Expression": "Name"
    }
  ],
  "Values": [
    {
      "Expression": "
        Flatten(
          _
          .Events
          .For(\"i\", IndexInCase + 1, i < Count(Case.Events), i + 1, 
            StringJoin(\">\", 
              Array(
                Type.Name, 
                GetAt(i, Case.Events).Type.Name
              )
            )
          )
        )
      ",
      "DimensionOrderExpression": "OrderByValue(_)",
      "Type": "Pivot"
    }
  ],
  "Ordering": [ 
    {
      "Name": "CaseId",
      "Direction": "Ascending"
    }
  ]
}

Repeats

{
  "Root": "Cases",
  "Dimensions": [
    {
      "Name": "CaseId",
      "Expression": "Name"
    }
  ],
  "Values": [
    {
      "Expression": "
        Flatten(
          _
          .FindRepeats(Events.Type.Name)
          .Repeat(
            Count(GetAt(1, _)) - 1, 
            StringJoin(\"->\", GetAt(0, _))
          )
        )
      ",
      "DimensionOrderExpression": "OrderByValue(_)",
      "Type": "Pivot"
    }
  ],
  "Ordering": [ 
    {
      "Name": "CaseId",
      "Direction": "Ascending"
    }
  ]
}

Workload per resource

{
  "Root": "
TimeRange(DateTime(2012,1,1,12,0), DateTime(2012,1,1,13,0), TimeSpan(0, 0, 5))
", 
  "Dimensions": [
    { 
      "Name": "Time",
      "Expression": "_"
    }
  ], 
  "Values": [
    {
      "Type": "Pivot",
      "Expression": "
Def(\"ActiveEventUnitsAt\", \"at\", 
  Cases:GetAt(0, Events)
    .RecursiveFind(
      NextInCase,
      TimeStamp <= at 
      && (IsNull(NextInCase) || (NextInCase.TimeStamp > at))
    )
  .Unit
);
Let(\"CurrentTime\", 
  GetAt(
    0, 
    _
  ), 
  Flatten(
    EventLog
    .ActiveEventUnitsAt(
      CurrentTime
    )
  )
)
"
    }
  ]
}