Skip to content
Snippets Groups Projects
Verified Commit e15cf498 authored by Andrej Ramašeuski's avatar Andrej Ramašeuski
Browse files

Datovy model pro statistiku

parent 85b49151
No related branches found
No related tags found
No related merge requests found
......@@ -41,5 +41,16 @@ __PACKAGE__->has_many(
log_items => 'PZ::Schema::Result::Log',
{ 'foreign.shortcut_id' => 'self.id', },
);
__PACKAGE__->has_many(
stat_hourly_items => 'PZ::Schema::Result::StatHourly',
{ 'foreign.shortcut_id' => 'self.id', },
);
__PACKAGE__->has_many(
stat_dayly_items => 'PZ::Schema::Result::StatDayly',
{ 'foreign.shortcut_id' => 'self.id', },
);
1;
package PZ::Schema::Result::StatDaily;
use strict;
use warnings;
use base 'DBIx::Class::Core';
our $VERSION = 1;
__PACKAGE__->table('stat_daily');
__PACKAGE__->add_columns(
qw(
shortcut_id
period
count
),
);
__PACKAGE__->set_primary_key('shortcut_id', 'period');
1;
package PZ::Schema::Result::StatHourly;
use strict;
use warnings;
use base 'DBIx::Class::Core';
our $VERSION = 1;
__PACKAGE__->table('stat_hourly');
__PACKAGE__->add_columns(
qw(
shortcut_id
period
count
),
);
__PACKAGE__->set_primary_key('shortcut_id', 'period');
1;
......@@ -50,3 +50,24 @@ alter table "log" add column "ua" text;
-- 4 up
alter table "log" add column "referrer" text;
-- 5 up
create view "stat_hourly" as
select
"shortcut_id",
date_trunc('hour', "time") as "period",
count(*)
from "log"
group by "shortcut_id", date_trunc('hour', "time")
order by date_trunc('hour', "time")
;
create view "stat_daily" as
select
"shortcut_id",
date_trunc('day', "time") as "period",
count(*)
from "log"
group by "shortcut_id", date_trunc('day', "time")
order by date_trunc('day', "time")
;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment