From: Alex Sadleir Date: Mon, 11 Mar 2013 05:03:10 +0000 Subject: better hourly X-Git-Url: http://maxious.lambdacomplex.org/git/?p=scannr.git&a=commitdiff&h=1f2cec837a1056643fdf763c734546ec91e90660 --- better hourly --- --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,7 +2,6 @@ - --- a/.idea/workspace.xml +++ /dev/null @@ -1,457 +1,1 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1350026709905 - 1350026709905 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --- a/db.sql +++ b/db.sql @@ -92,13 +92,13 @@ -- PostgreSQL database dump complete -- -CREATE TABLE "compilation" ( +CREATE TABLE "compilations" ( "filename" text NOT NULL, "files" text ARRAY NOT NULL, "datetime" timestamp NOT NULL ); -CREATE TABLE "trunk_log" ( +CREATE TABLE "trunk_logs" ( "id" text NOT NULL, "datetime" integer NOT NULL, "site" integer NOT NULL, --- a/generateHourlys.php +++ b/generateHourlys.php @@ -1,37 +1,64 @@ -&1'; + $filenames = explode(",", $hourly['filenames']); + $cmd = "/usr/local/bin/ffmpeg"; + if (count($filenames) > 1) { + $cmd .=" -filter_complex concat=n=" . count($filenames) . ":v=0:a=1"; // only concat when more than 1 file + } + $cmd .=" -i data/" . implode(" -i data/", $filenames) . " -ar 8000 -ab 4.75k -ac 1 hourly/" . $hfilename . ' 2>&1'; //print_r($hourly); - exec ( $cmd,$output,$returncode ); - echo $cmd."
\n"; - if ($returncode != 10) { - //print_r($output); - //die(); + exec($cmd, $output, $returncode); + echo $cmd . "
\n"; + if ($returncode != 0) { + echo $returncode; + print_r($output); + unlink("hourly/" . $hfilename); // delete incomplete file +// die(); } else { - /* insert - "filename" text NOT NULL, - "files" text ARRAY NOT NULL, - "datetime" timestamp NOT NULL - */ - // delete wav files? can we link to times in a compilation? + +$time = strtotime($hourly['aday'] . ' +' . $hourly['ahour'] . " hours"); + $q = " insert into compilations (filename,files,datetime) VALUES ('" . $hfilename . "', ARRAY['" . implode("', '", $filenames) . "'], to_timestamp('" . $time . "') );"; +$conn->query($q); +//echo $q."\n"; + foreach ($filenames as $filename) { + $q = "UPDATE recordings SET archived = '$hfilename' WHERE filename = '$filename' ;"; +$conn->query($q); +//echo $q."\n"; + } +//die(); } } } -$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;"); + // TODO use tgid categories instead, tgid too specific $sth->execute(); $hourlies = $sth->fetchAll(PDO::FETCH_ASSOC); -foreach($hourlies as $hourly) { +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 +having count(archived) != count(filename) +order by aday DESC, ahour, category;"); $sth->execute(); $hourlies = $sth->fetchAll(PDO::FETCH_ASSOC); @@ -40,5 +67,3 @@ } -// delete uninteresting compilations - --- /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)); --- /dev/null +++ b/purgeArchived.php @@ -1,1 +1,13 @@ +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;"); +// TODO use tgid categories instead, tgid too specific +$sth->execute(); +$hourlies = $sth->fetchAll(PDO::FETCH_ASSOC); +foreach($hourlies as $hourly) { + processHourly($hourly); +} +// delete uninteresting compilations + --- a/snd.py +++ b/snd.py @@ -94,7 +94,11 @@ while 1: try: - data = stream.read(CHUNK_SIZE) + data = stream.read(CHUNK_SIZE) # Fewer than n bytes may be returned if the operating system call returns fewer than n bytes. + #if len(data) < 4096: + #print "cropped packet detected! " + len(data) + #data.extend('\x00' * CHUNK_SIZE - len(data)) + #print "fixed to " + len(data) except IOError as ex: if ex[1] != pyaudio.paInputOverflowed: raise