group by category
[scannr.git] / generateHourlys.php
blob:a/generateHourlys.php -> blob:b/generateHourlys.php
--- a/generateHourlys.php
+++ b/generateHourlys.php
@@ -1,7 +1,7 @@
 <?php
 include('common.inc.php');
 function processHourly($hourly) {
-    $filename = $hourly['tgid'].'-'.str_replace(' 00:00:00+1','',$hourly['aday']).'-'.$hourly['ahour'].'.3gp';
+    $filename = str_replace(' ',"_",$hourly['tgid']).'-'.str_replace(' 00:00:00+1','',$hourly['aday']).'-'.$hourly['ahour'].'.3gp';
 
     if(!file_exists("hourly/".$filename)) {
 
@@ -16,14 +16,26 @@
         }
     }
 }
-$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 = $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);
 }
 
+