Hierarchies
If you need to summarize your data by time, most of the time you will want to use one of the pre-made time dimension hierarchies. It allows you to break down your data by year, month, day, hour, and other time units.
Example
use Doctrine\Common\Collections\Order;
use Doctrine\ORM\Mapping as ORM;
use Rekalogika\Analytics\Core\Metadata as Analytics;
use Rekalogika\Analytics\Core\Entity\Summary;
use Rekalogika\Analytics\Core\ValueResolver\PropertyValue;
use Rekalogika\Analytics\Time\Hierarchy\TimeDimensionHierarchy;
use Symfony\Component\Translation\TranslatableMessage;
class OrderSummary extends Summary
{
#[ORM\Embedded()]
#[Analytics\Dimension(
source: new PropertyValue('time'),
label: new TranslatableMessage('Placed Time'),
orderBy: Order::Ascending,
)]
#[TimeProperties(
sourceTimeZone: new \DateTimeZone('UTC'),
summaryTimeZone: new \DateTimeZone('Asia/Jakarta'),
)]
private TimeDimensionHierarchy $time;
}
In this example, the property $time
in the OrderSummary
class will be
summarized into the TimeDimensionHierarchy
hierarchy. You will be able to
select the time using the notation time.year
, time.month
, time.day
, etc.
Available Hierarchies
These are the available time dimension hierarchies and their corresponding properties:
Field | TimeDimensionHierarchy | TimeWithoutWeekDimensionHierarchy | DateDimensionHierarchy | DateWithoutWeekDimensionHierarchy | Trait |
---|---|---|---|---|---|
year | ✔️ | ✔️ | ✔️ | ✔️ | YearTrait |
weekYear | ✔️ | ❌ | ✔️ | ❌ | WeekYearTrait |
quarter | ✔️ | ✔️ | ✔️ | ✔️ | QuarterTrait |
quarterOfYear | ✔️ | ✔️ | ✔️ | ✔️ | |
month | ✔️ | ✔️ | ✔️ | ✔️ | MonthTrait |
monthOfYear | ✔️ | ✔️ | ✔️ | ✔️ | |
week | ✔️ | ❌ | ✔️ | ❌ | WeekTrait |
weekOfYear | ✔️ | ❌ | ✔️ | ❌ | |
weekOfMonth | ✔️ | ❌ | ✔️ | ❌ | |
date | ✔️ | ✔️ | ✔️ | ✔️ | DayTrait |
weekdate | ✔️ | ✔️ | ✔️ | ✔️ | |
dayOfWeek | ✔️ | ✔️ | ✔️ | ✔️ | |
dayOfMonth | ✔️ | ✔️ | ✔️ | ✔️ | |
dayOfYear | ✔️ | ✔️ | ✔️ | ✔️ | |
hour | ✔️ | ✔️ | ❌ | ❌ | HourTrait |
hourOfDay | ✔️ | ✔️ | ❌ | ❌ |
Traits
The traits listed in the last column of the table above are useful if you want to create a custom time dimension hierarchy. Read the existing hierarchies to see how they are used.