Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Look up counties from the tiger/line database by zipcode. On disconne…

…cts and errors, attempt to upload whatever data we have to a remote server.
  • Loading branch information...
commit f9466f42c15311093b897384fea2bdd43af5814d 1 parent 07f81b3
@aaronpk aaronpk authored
View
90 include/include.php
@@ -29,6 +29,12 @@ function askQuestion($question, $secondTry=FALSE)
'next' => $question['key'] . '.json'
)
);
+ $tropo[] = array(
+ 'on' => array(
+ 'event' => 'hangup',
+ 'next' => 'hangup.json'
+ )
+ );
if($question['choices'] == '[RECORD]')
{
@@ -48,8 +54,7 @@ function askQuestion($question, $secondTry=FALSE)
}
else
{
- $tropo[] = array(
- 'record' => array(
+ $ask = array(
'say' => array(
'value' => $question[($secondTry && array_key_exists('prompt2', $question) ? 'prompt2' : 'prompt')],
),
@@ -63,7 +68,12 @@ function askQuestion($question, $secondTry=FALSE)
'beep' => FALSE,
'format' => 'audio/mp3',
'url' => 'http://' . $_SERVER['SERVER_NAME'] . WEB_ROOT . $question['key'] . '.json?record=1&session_id=' . session_id()
- )
+ );
+ if(array_key_exists('minConfidence', $question))
+ $ask['minConfidence'] = $question['minConfidence'];
+
+ $tropo[] = array(
+ 'record' => $ask
);
}
}
@@ -92,19 +102,20 @@ function storeSurveyResponse($key, $value)
function getCountiesForZipcode($zip)
{
- switch($zip)
- {
- case 98683:
- return array(53011=>'Clark');
- case 98112:
- return array(53033=>'King');
- case 98111:
- return array(53033=>'King', 53053=>'Pierce');
- default:
- return array(53033=>'King');
- }
+ $query = db()->prepare('
+ SELECT cz.fips, countyName
+ FROM countyZipcodes cz
+ JOIN counties c ON cz.fips = c.fips
+ WHERE zip = :zip');
+ $query->bindParam(':zip', $zip);
+ $query->execute();
+ $results = array();
+ while($row = $query->fetch(PDO::FETCH_ASSOC))
+ $results[$row['fips']] = $row['countyName'];
+ return $results;
}
+// TODO: Find and import cities/zip data from Tiger/Line Census data
function getCitiesForZipcode($zip)
{
switch($zip)
@@ -120,7 +131,58 @@ function getCitiesForZipcode($zip)
}
}
+function getStateForFips($fips)
+{
+ $query = db()->prepare('
+ SELECT state
+ FROM counties
+ WHERE fips = :fips');
+ $query->bindParam(':fips', $fips);
+ $query->execute();
+ $result = $query->fetch();
+ return $result['state'];
+}
+
+function sendCallToServer($id, $url)
+{
+ // Gather up all the responses and send them off to the server
+ $responses = db()->prepare('SELECT * FROM responses WHERE callID = :id');
+ $responses->bindParam($id);
+ $responses->execute();
+
+ $data = array();
+ while($row = $responses->fetch(PDO::FETCH_ASSOC))
+ $data[$row['key']] = $row;
+
+ $params = array();
+ $params['first_name'] = @'http://' . $_SERVER['SERVER_NAME'] . WEB_ROOT . 'recordings/' . $data['name']['recording'];
+ $params['street1'] = @'http://' . $_SERVER['SERVER_NAME'] . WEB_ROOT . 'recordings/' . $data['street1']['recording'];
+ $params['county'] = @$data['county']['value'];
+ $params['postcode'] = @$data['postcode']['value'];
+ $params['is_owner'] = @$data['owner']['value'];
+ $params['damage_date'] = @$data['date']['value'];
+ $params['eststructloss'] = @str_replace('USD', '', $data['eststructloss']['value']);
+ $params['estperproploss'] = @str_replace('USD', '', $data['estperproploss']['value']);
+ $params['cause'] = @$data['cause']['value'];
+ $params['is_habitable'] = @$data['habitable']['value'];
+ $params['is_accessible'] = @$data['accessible']['value'];
+ $params['damage'] = @$data['damage_type']['value'];
+ $params['description'] = @'http://' . $_SERVER['SERVER_NAME'] . WEB_ROOT . 'recordings/' . @$data['description']['recording'];
+ $params['insurance'] = @$data['insurance']['value'];
+ $params['provider'] = @$data['provider']['value'];
+ $params['source'] = 'voice';
+
+ ircdebug('Sending form data');
+
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_URL, $url);
+ curl_setopt($ch, CURLOPT_POST, TRUE);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
+ $response = curl_exec($ch);
+ filedebug($response);
+}
function tropoInput()
{
View
1  include/question.php
@@ -74,6 +74,7 @@
'say' => array('value'=>'Sorry, there was an error. Goodbye.'),
'voice' => $voice
);
+ sendCurrentCall();
}
View
8 index.php
@@ -56,6 +56,11 @@
askQuestion(array_shift($questions));
break;
+ case 'hangup':
+ if(defined('REMOTE_UPLOAD_SERVER') && REMOTE_UPLOAD_SERVER)
+ sendCallToServer($_SESSION['callID'], REMOTE_UPLOAD_SERVER);
+ ircdebug('Call completed');
+ break;
default:
define('SURVEY_MODE', TRUE);
include('include/question.php');
@@ -74,12 +79,13 @@
{
echo $json;
}
-
+/*
if(isset($_SESSION))
{
filedebug("\n\nSession:\n");
filedebug($_SESSION);
}
+*/
filedebug($json);
View
105 survey.php
@@ -1,7 +1,7 @@
<?php
$firstPrompt = 'Thanks for calling the Mobile Assessment of Damage hotline.';
-/*
+
$questions[] = array(
'key' => 'name',
'name' => 'Name',
@@ -9,7 +9,7 @@
'prompt2' => didntUnderstand() . 'What is your name?',
'choices' => '[RECORD]'
);
-*/
+
$questions[] = array(
'key' => 'postcode',
@@ -19,7 +19,7 @@
'choices' => '[5 DIGITS]'
);
-if(defined('SURVEY_MODE') && ($zip = surveyVal('postcode')) !== FALSE)
+if(defined('SURVEY_MODE') && ($zip = surveyVal('postcode')) !== FALSE && surveyVal('county') == FALSE)
{
// Look up the counties for this zip code
$counties = getCountiesForZipcode($zip);
@@ -40,7 +40,9 @@
}
else
{
- storeSurveyResponse('county', array_pop($counties));
+ $fips = array_pop(array_flip($counties));
+ storeSurveyResponse('county', $fips);
+ storeSurveyResponse('state', getStateForFIPS($fips));
}
}
else
@@ -54,6 +56,92 @@
}
$questions[] = array(
+ 'key' => 'street1',
+ 'name' => 'Address',
+ 'prompt' => 'What is the address of the property?',
+ 'prompt2' => didntUnderstand() . 'What is the address?',
+ 'choices' => '[RECORD]'
+);
+
+
+$questions[] = array(
+ 'key' => 'habitable',
+ 'name' => 'Is Habitable?',
+ 'prompt' => 'Is the property currently habitable?',
+ 'prompt2' => didntUnderstand() . 'Please say yes or no.',
+ 'choices' => '[BOOLEAN]'
+);
+
+$questions[] = array(
+ 'key' => 'accessible',
+ 'name' => 'Accessible?',
+ 'prompt' => 'Is the property currently accessible?',
+ 'prompt2' => didntUnderstand() . 'Please say yes or no.',
+ 'choices' => '[BOOLEAN]'
+);
+
+
+
+$questions[] = array(
+ 'key' => 'damagetoday',
+ 'name' => 'Date of Damage',
+ 'prompt' => 'Did the damage happen today?',
+ 'prompt2' => didntUnderstand() . 'Was today the day the damage happened?',
+ 'choices' => '[BOOLEAN]'
+);
+
+if(defined('SURVEY_MODE') && ($today = surveyVal('damagetoday')) !== FALSE)
+{
+ if($today)
+ {
+ storeSurveyResponse('date', date('Y-m-d'));
+ }
+ else
+ {
+ $questions[] = array(
+ 'key' => 'date',
+ 'name' => 'Date of Damage',
+ 'prompt' => 'What day did the damage happen?',
+ 'prompt2' => 'Please tell me the full date.',
+ 'choices' => '[DATE]'
+ );
+ }
+}
+
+$questions[] = array(
+ 'key' => 'damage_type',
+ 'name' => 'Type of Damage',
+ 'prompt' => 'What type of damage happened? You can say structural, roadway, or land.',
+ 'prompt2' => didntUnderstand() . 'Please say structural, road, or land.',
+ 'choices' => 'structural(structural, structure, building), roadway(roadway, road), land(land)'
+);
+
+$questions[] = array(
+ 'key' => 'cause',
+ 'name' => 'Primary Cause',
+ 'prompt' => 'What was the primary cause of the damage? You can say things like fire, flood, earthquake, and others.',
+ 'prompt2' => didntUnderstand() . 'The options are fire, flood, earthquake, wind, volcano, snow, ice, vandalism, other.',
+ 'choices' => 'fire(fire), flood(flood), earthquake(earthquake), wind(wind), volcano(volcano), snow(snow), ice(ice), vandalism(vandalism), other(other)'
+);
+
+$questions[] = array(
+ 'key' => 'description',
+ 'name' => 'Description',
+ 'prompt' => 'Please provide a brief description of the damages.',
+ 'prompt2' => didntUnderstand(),
+ 'choices' => '[RECORD]'
+);
+
+
+$questions[] = array(
+ 'key' => 'owner',
+ 'name' => 'Owner?',
+ 'prompt' => 'Are you an owner or a renter?',
+ 'prompt2' => didntUnderstand() . 'Do you own or rent?',
+ 'choices' => '1(owner, own, 1, yes), 0(renter, rent, 2)'
+);
+
+$questions[] = array(
'key' => 'insurance',
'name' => 'Has Insurance',
'prompt' => 'Do you have insurance?',
@@ -72,14 +160,6 @@
);
}
-
-$questions[] = array(
- 'key' => 'owner',
- 'name' => 'Owner?',
- 'prompt' => 'Are you an owner or a renter?',
- 'prompt2' => didntUnderstand() . 'Do you own or rent?',
- 'choices' => '1(owner, own, 1, yes), 0(renter, rent, 2)'
-);
$questions[] = array(
'key' => 'eststructloss',
'name' => 'Est. Structural Damage',
@@ -87,6 +167,7 @@
'prompt2' => didntUnderstand() . 'Say the dollar amount slowly',
'choices' => '[CURRENCY]'
);
+
$questions[] = array(
'key' => 'estperproploss',
'name' => 'Est. Personal Loss',
View
8 view.php
@@ -47,7 +47,7 @@
echo '<table>';
foreach($responses as $r)
{
- if(array_key_exists('lookup', $data[$r['key']]))
+ if(array_key_exists($r['key'], $data) && array_key_exists('lookup', $data[$r['key']]))
{
$lookup = $data[$r['key']]['lookup'];
$query = db()->prepare('SELECT ' . $lookup['value'] . ' AS val FROM ' . $lookup['table'] . ' WHERE ' . $lookup['key'] . ' = :key');
@@ -60,7 +60,7 @@
$value = $r['value'];
echo '<tr>';
- echo '<td>' . (array_key_exists('name', $data[$r['key']]) ? $data[$r['key']]['name'] : $r['key']) . '</td>';
+ echo '<td>' . (array_key_exists($r['key'], $data) && array_key_exists('name', $data[$r['key']]) ? $data[$r['key']]['name'] : $r['key']) . '</td>';
echo '<td>' . $value . '</td>';
echo '<td>' . ($r['recording'] ? '<a href="recordings/' . $r['recording'] . '" id="recording_' . $r['id'] . '" class="recording">listen</a>' : '') . '</td>';
echo '</tr>';
@@ -76,8 +76,8 @@
echo '<tr>';
echo '<td><a href="?id=' . $call['id'] . '">' . $call['date'] . '</a></td>';
echo '<td>' . $call['callerID'] . '</td>';
- echo '<td>' . $call['dateFinished'] . '</td>';
- echo '<td>' . ((strtotime($call['dateFinished']) - strtotime($call['date'])) / 60) . '</td>';
+ #echo '<td>' . $call['dateFinished'] . '</td>';
+ #echo '<td>' . ((strtotime($call['dateFinished']) - strtotime($call['date'])) / 60) . '</td>';
echo '</tr>';
}
echo '</table>';
Please sign in to comment.
Something went wrong with that request. Please try again.