From: Alex Sadleir Date: Sat, 19 Jan 2013 13:11:26 +0000 Subject: group by category X-Git-Url: http://maxious.lambdacomplex.org/git/?p=scannr.git&a=commitdiff&h=7f656084c6c96fca04e8576ae1f88afcee20a5d0 --- group by category --- --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -37,7 +37,7 @@ - + @@ -133,7 +133,7 @@ - + @@ -238,8 +238,8 @@ + - - + - + - + - + @@ -486,7 +486,7 @@ - + --- a/generateHourlys.php +++ b/generateHourlys.php @@ -1,7 +1,7 @@ prepare("select tgid, extract(hour from call_timestamp) ahour, date_trunc('day', call_timestamp) aday, count(filename), array_to_string(array_agg(filename order by call_timestamp), ',') filenames from recordings group by tgid, ahour, aday order by aday DESC, ahour, tgid;"); +/*$sth = $conn->prepare("select tgid, extract(hour from call_timestamp) ahour, date_trunc('day', call_timestamp) aday, +count(filename), array_to_string(array_agg(filename order by call_timestamp), ',') filenames from recordings group by tgid, ahour, aday order by aday DESC, ahour, tgid;"); $sth->execute(); $hourlies = $sth->fetchAll(PDO::FETCH_ASSOC); foreach($hourlies as $hourly) { processHourly($hourly); } -$sth = $conn->prepare("select 'hour' as tgid, extract(hour from call_timestamp) ahour, date_trunc('day', call_timestamp) aday, count(filename), array_to_string(array_agg(filename order by call_timestamp), ',') filenames from recordings group by ahour, aday order by aday DESC, ahour;"); +$sth = $conn->prepare("select 'hour' as tgid, extract(hour from call_timestamp) ahour, date_trunc('day', call_timestamp) aday, +count(filename), array_to_string(array_agg(filename order by call_timestamp), ',') filenames from recordings group by ahour, aday order by aday DESC, ahour;"); + +$sth->execute(); +$hourlies = $sth->fetchAll(PDO::FETCH_ASSOC); +foreach($hourlies as $hourly) { + processHourly($hourly); +} +*/ +$sth = $conn->prepare("select coalesce(category,'unknown') as tgid, extract(hour from call_timestamp) ahour, date_trunc('day', call_timestamp) aday, +count(filename), array_to_string(array_agg(filename order by call_timestamp), ',') filenames +from recordings inner join tgids on recordings.tgid = tgids.tgid group by category, ahour, aday order by aday DESC, ahour, category;"); $sth->execute(); $hourlies = $sth->fetchAll(PDO::FETCH_ASSOC); @@ -31,3 +43,4 @@ processHourly($hourly); } + --- /dev/null +++ b/inserttgid.txt @@ -1,1 +1,2 @@ +insert into tgids (tgid,alpha_tag) (SELECT distinct tgid, tgname as alpha_tag FROM recordings WHERE NOT EXISTS (SELECT tgid FROM tgids WHERE tgid=recordings.tgid));