From: Alex Sadleir Date: Wed, 02 Jan 2013 00:05:15 +0000 Subject: select input X-Git-Url: https://maxious.lambdacomplex.org/git/?p=scannr.git&a=commitdiff&h=d45092073c216d17f214015064451a7ea949b2ba --- select input --- --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,18 @@ *.pyc /nbproject/private/ /output.txt + +bin +gen +target +.settings +.classpath +.project +*.keystore +*.swp +*.orig +*.log +*.properties +seed.txt +map.txt + --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,10 +2,6 @@ - - - - @@ -13,55 +9,42 @@ - - - - - + - - - - - - - - - - - - + + + - + @@ -123,16 +106,43 @@ - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -158,10 +168,11 @@ @@ -169,7 +180,7 @@ @@ -197,6 +208,7 @@ + @@ -218,17 +230,16 @@ - - + + - + + + + + + + + + + + + @@ -280,21 +317,21 @@ - + - + - + @@ -364,92 +401,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + + --- a/calls.json.php +++ b/calls.json.php @@ -8,7 +8,7 @@ group by tgid, date_trunc(\'hour\', call_timestamp) order by time'); $sth->execute(Array($timeFrom, $timeTo)); - return $sth->fetchAll(); + return $sth->fetchAll(PDO::FETCH_ASSOC); } @@ -20,7 +20,7 @@ group by sensor_id, date_trunc(\'day\', time) order by time'); $sth->execute(Array($TGID)); - return $sth->fetchAll(); + return $sth->fetchAll(PDO::FETCH_ASSOC); } function getTGIDDataYears($TGID, $timeFrom, $timeTo) { @@ -28,7 +28,7 @@ $sth = $conn->prepare("select distinct extract('year' from call_timestamp) as year from recordings where tgid = ? order by year"); $sth->execute(Array($TGID)); - return $sth->fetchAll(); + return $sth->fetchAll(PDO::FETCH_ASSOC); } function getTGIDDataMonths($TGID, $timeFrom, $timeTo) @@ -37,7 +37,7 @@ $sth = $conn->prepare("select distinct extract('month' from call_timestamp) as month, extract('year' from call_timestamp) as year from recordings where tgid = ? order by year, month"); $sth->execute(Array($TGID)); - return $sth->fetchAll(); + return $sth->fetchAll(PDO::FETCH_ASSOC); } function getTGIDDataDays($TGID, $timeFrom, $timeTo) @@ -47,13 +47,21 @@ $sth->execute(Array($TGID)); - return $sth->fetchAll(); + return $sth->fetchAll(PDO::FETCH_ASSOC); } $action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : ''); $TGID = (isset($_REQUEST['tgid']) ? $_REQUEST['tgid'] : ''); $timefrom = (isset($_REQUEST['from']) ? $_REQUEST['from'] : ''); $timeto = (isset($_REQUEST['to']) ? $_REQUEST['to'] : ''); +if ($action == "data") { +$sth = $conn->prepare('select * from recordings + order by call_timestamp desc limit 100'); + +$sth->execute(Array()); + +echo json_encode ($sth->fetchAll(PDO::FETCH_ASSOC)); +} if ($action == "data_description") { $timefrom = strtotime($timefrom); $timeto = strtotime($timeto); --- a/generateConvos.php +++ b/generateConvos.php @@ -1,4 +1,5 @@ prepare('select * from recordings limit 100;'); --- /dev/null +++ b/generateHourlys.php @@ -1,1 +1,33 @@ +&1'; + //print_r($hourly); + exec ( $cmd,$output,$returncode ); + echo $cmd."
\n"; + if ($returncode != 10) { + //print_r($output); + //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->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->execute(); +$hourlies = $sth->fetchAll(PDO::FETCH_ASSOC); +foreach($hourlies as $hourly) { + processHourly($hourly); +} + --- /dev/null +++ b/scannrmobile/.gitignore @@ -1,1 +1,14 @@ +bin +gen +target +.settings +.classpath +.project +*.keystore +*.swp +*.orig +*.log +*.properties +seed.txt +map.txt --- /dev/null +++ b/scannrmobile/.idea/.name @@ -1,1 +1,1 @@ - +scannrmobile --- /dev/null +++ b/scannrmobile/.idea/ant.xml @@ -1,1 +1,8 @@ + + + + + + + --- /dev/null +++ b/scannrmobile/.idea/compiler.xml @@ -1,1 +1,27 @@ + + + + + + --- /dev/null +++ b/scannrmobile/.idea/copyright/profiles_settings.xml @@ -1,1 +1,5 @@ - + + + + + --- /dev/null +++ b/scannrmobile/.idea/encodings.xml @@ -1,1 +1,6 @@ + + + + + --- /dev/null +++ b/scannrmobile/.idea/misc.xml @@ -1,1 +1,11 @@ + + + + + + + + + + --- /dev/null +++ b/scannrmobile/.idea/modules.xml @@ -1,1 +1,10 @@ + + + + + + + + + --- /dev/null +++ b/scannrmobile/.idea/scopes/scope_settings.xml @@ -1,1 +1,5 @@ - + + + + --- /dev/null +++ b/scannrmobile/.idea/uiDesigner.xml @@ -1,1 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null +++ b/scannrmobile/.idea/vcs.xml @@ -1,1 +1,8 @@ + + + + + + + --- /dev/null +++ b/scannrmobile/.idea/workspace.xml @@ -1,1 +1,778 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + + + 1356156646856 + 1356156646856 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Android + + + + + + + + + + + + + + + Android 4.2 Platform + + + + + + + + Android|scannrmobile + + + + + + + + + + + + + + + + --- /dev/null +++ b/scannrmobile/AndroidManifest.xml @@ -1,1 +1,18 @@ + + + + + + + + + + + + + --- /dev/null +++ b/scannrmobile/build.xml @@ -1,1 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null +++ b/scannrmobile/proguard-project.txt @@ -1,1 +1,21 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + --- /dev/null +++ b/scannrmobile/res/layout/main.xml @@ -1,1 +1,13 @@ + + + + + + + --- /dev/null +++ b/scannrmobile/res/layout/simplerow.xml @@ -1,1 +1,8 @@ + + --- /dev/null +++ b/scannrmobile/res/values/strings.xml @@ -1,1 +1,5 @@ + + + scannrmobile + --- /dev/null +++ b/scannrmobile/scannrmobile.iml @@ -1,1 +1,44 @@ + + + + + + + + + + + + + + + + + + + --- /dev/null +++ b/scannrmobile/src/com/example/scannrmobile/HttpTask.java @@ -1,1 +1,73 @@ +package com.example.scannrmobile; +import android.os.AsyncTask; + +import org.apache.http.client.methods.*; +import java.io.BufferedReader; +import java.io.InputStreamReader; + +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.DefaultHttpClient; + +import org.json.*; +import android.util.Log; + + +//http://www.accella.net/android-http-get-json/ +public class HttpTask extends AsyncTask { + private static final String TAG = "Scannr_HTTP_TASK"; + + @Override + protected JSONArray doInBackground(HttpUriRequest...params) { + + // Performed on Background Thread + + HttpUriRequest request = params[0]; + HttpClient client = new DefaultHttpClient(); + + try { + // The UI Thread shouldn't be blocked long enough to do the reading in of the stream. + HttpResponse response = client.execute(request); + +// TODO handle bad response codes (such as 404, etc) + + BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); + StringBuilder builder = new StringBuilder(); + for (String line = null; (line = reader.readLine()) != null; ) { + builder.append(line).append("\n"); + } + JSONTokener tokener = new JSONTokener(builder.toString()); + JSONArray json = new JSONArray(tokener); + return json; + + } catch (Exception e) { + // TODO handle different exception cases + Log.e(TAG,e.toString()); + e.printStackTrace(); + return null; + } + } + + @Override + protected void onPostExecute(JSONArray json) { + // Done on UI Thread + if(json != null) { + taskHandler.taskSuccessful(json); + } else { + taskHandler.taskFailed(); + } + } + + public static interface HttpTaskHandler { + void taskSuccessful(JSONArray json); + void taskFailed(); + } + + HttpTaskHandler taskHandler; + + public void setTaskHandler(HttpTaskHandler taskHandler) { + this.taskHandler = taskHandler; + } + +} --- /dev/null +++ b/scannrmobile/src/com/example/scannrmobile/ScannrMobile.java @@ -1,1 +1,66 @@ +package com.example.scannrmobile; +import android.app.Activity; +import android.os.Bundle; +import android.util.Log; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import com.example.scannrmobile.HttpTask.HttpTaskHandler; +import org.apache.http.client.methods.HttpGet; +import org.json.JSONArray; +import org.json.JSONException; + +import java.util.ArrayList; + +public class ScannrMobile extends Activity { + private ListView mainListView ; + private ArrayAdapter listAdapter ; + private ScannrMobile view; + /** + * Called when the activity is first created. + */ + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.main); + mainListView = (ListView) findViewById( R.id.mainListView ); + view = this; + //DownloadWebPageTask task = new DownloadWebPageTask(); + //task.execute(new String[] { "http://www.vogella.com" }); + HttpTask task = new HttpTask(); + + task.setTaskHandler(new HttpTaskHandler() + { + public void taskSuccessful(JSONArray nodes) { + // Just put the JSONObjects into an array list so we can use a ListAdapter + ArrayList data = new ArrayList(); + // Ingest Data + try { + + Log.d(this.getClass().getName(), "Total Nodes: "+nodes.length()); + for (int i = 0; i < nodes.length(); i++ ) { + data.add(nodes.getJSONObject(i).toString() ); + } + // TODO update the list + } catch (JSONException j){ + Log.e(this.getClass().getName(), j.getMessage()); + } + // Create ArrayAdapter using the planet list. + listAdapter = new ArrayAdapter(view, R.layout.simplerow, R.id.rowTextView, data); + + // Set the ArrayAdapter as the ListView's adapter. + mainListView.setAdapter( listAdapter ); + } + + public void taskFailed() { + // handler failure (e.g network not available etc.) + Log.e(this.getClass().getName(),"Task Failed"); + } + }); + task.execute(new HttpGet("http://192.168.1.113/~maxious/scannr/calls.json.php?action=data")); + } + + +} + + --- a/test.py +++ b/test.py @@ -11,11 +11,17 @@ WAVE_OUTPUT_FILENAME = "output.wav" p = pyaudio.PyAudio() - +device_idx = 0; +for i in range (0, p.get_device_count()): + print(p.get_device_info_by_index(i)) + if p.get_device_info_by_index(i)['name'] == 'Built-in Input': + device_idx = i + print i stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, + input_device_index=device_idx, frames_per_buffer=CHUNK) print("* recording")