fix viewcalls
fix viewcalls

--- /dev/null
+++ b/.idea/dictionaries/Madoka.xml
@@ -1,1 +1,10 @@
-
+<component name="ProjectDictionaryState">
+  <dictionary name="Madoka">
+    <words>
+      <w>tgid</w>
+      <w>timefrom</w>
+      <w>timeto</w>
+      <w>tzoffset</w>
+    </words>
+  </dictionary>
+</component>

--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,10 +2,11 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="f90ee5b5-97e4-47ec-9b14-d4f4e896f100" name="Default" comment="">
+      <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/dictionaries/Madoka.xml" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/calls.json.php" afterPath="$PROJECT_DIR$/calls.json.php" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/common.inc.php" afterPath="$PROJECT_DIR$/common.inc.php" />
-      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/db.sql" afterPath="$PROJECT_DIR$/db.sql" />
+      <change type="MODIFICATION" beforePath="$PROJECT_DIR$/output.txt" afterPath="$PROJECT_DIR$/output.txt" />
       <change type="MODIFICATION" beforePath="$PROJECT_DIR$/viewcalls.php" afterPath="$PROJECT_DIR$/viewcalls.php" />
     </list>
     <ignored path="scannr.iws" />
@@ -29,11 +30,8 @@
       <file leaf-file-name="viewcalls.php" pinned="false" current="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/viewcalls.php">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="2" column="13" selection-start="46" selection-end="46" vertical-scroll-proportion="36.153847">
-              <folding>
-                <element signature="e#255#287#0" expanded="true" />
-                <element signature="e#341#363#0" expanded="true" />
-              </folding>
+            <state line="63" column="25" selection-start="2268" selection-end="2268" vertical-scroll-proportion="-3.7307692">
+              <folding />
             </state>
           </provider>
         </entry>
@@ -41,7 +39,7 @@
       <file leaf-file-name="common.inc.php" pinned="false" current="false" current-in-tab="false">
         <entry file="file://$PROJECT_DIR$/common.inc.php">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="34" column="0" selection-start="1179" selection-end="1179" vertical-scroll-proportion="-22.23077">
+            <state line="60" column="117" selection-start="2262" selection-end="2262" vertical-scroll-proportion="-1.1153846">
               <folding />
             </state>
           </provider>
@@ -50,7 +48,7 @@
       <file leaf-file-name="calls.json.php" pinned="false" current="true" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/calls.json.php">
           <provider selected="true" editor-type-id="text-editor">
-            <state line="2" column="9" selection-start="42" selection-end="42" vertical-scroll-proportion="-1.2507788">
+            <state line="69" column="33" selection-start="2628" selection-end="2628" vertical-scroll-proportion="1.6950867">
               <folding />
             </state>
           </provider>
@@ -70,8 +68,8 @@
     <option name="changedFiles">
       <list>
         <option value="$PROJECT_DIR$/scannr.py" />
+        <option value="$PROJECT_DIR$/calls.json.php" />
         <option value="$PROJECT_DIR$/common.inc.php" />
-        <option value="$PROJECT_DIR$/calls.json.php" />
         <option value="$PROJECT_DIR$/viewcalls.php" />
       </list>
     </option>
@@ -109,7 +107,6 @@
       <sortByType />
     </navigator>
     <panes>
-      <pane id="Scope" />
       <pane id="ProjectPane">
         <subPane>
           <PATH>
@@ -130,6 +127,7 @@
           </PATH>
         </subPane>
       </pane>
+      <pane id="Scope" />
     </panes>
   </component>
   <component name="PropertiesComponent">
@@ -137,8 +135,8 @@
     <property name="WebServerToolWindowFactoryState" value="false" />
     <property name="options.lastSelected" value="project.propVCSSupport.Mappings" />
     <property name="last_opened_file_path" value="$PROJECT_DIR$/../busui/myway/myway_timeliness.php" />
+    <property name="options.splitter.details.proportions" value="0.2" />
     <property name="options.searchVisible" value="true" />
-    <property name="options.splitter.details.proportions" value="0.2" />
   </component>
   <component name="RunManager">
     <configuration default="true" type="PHPUnitRunConfigurationType" factoryName="PHPUnit">
@@ -150,7 +148,7 @@
     </configuration>
     <configuration default="true" type="JavascriptDebugSession" factoryName="Local">
       <JSDebuggerConfigurationSettings>
-        <option name="engineId" />
+        <option name="engineId" value="embedded" />
         <option name="fileUrl" />
       </JSDebuggerConfigurationSettings>
       <method />
@@ -178,6 +176,7 @@
   </component>
   <component name="TaskManager">
     <task active="true" id="Default" summary="Default task">
+      <changelist id="f90ee5b5-97e4-47ec-9b14-d4f4e896f100" name="Default" comment="" />
       <created>1350026709905</created>
       <updated>1350026709905</updated>
     </task>
@@ -187,23 +186,23 @@
     <frame x="57" y="-8" width="1391" height="916" extended-state="6" />
     <editor active="true" />
     <layout>
-      <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
       <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
-      <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
       <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="true" content_ui="tabs" />
-      <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.24981189" sideWeight="0.6706349" order="0" side_tool="false" content_ui="combo" />
+      <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.2535741" sideWeight="0.6706349" order="0" side_tool="false" content_ui="combo" />
       <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
-      <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
-      <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32936507" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
+      <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
+      <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32936507" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
       <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
-      <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+      <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
       <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
       <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
+      <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
       <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
-      <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
       <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
+      <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
       <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
-      <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
     </layout>
   </component>
   <component name="VcsContentAnnotationSettings">
@@ -259,75 +258,79 @@
     <breakpoint-manager />
   </component>
   <component name="editorHistoryManager">
+    <entry file="file://$PROJECT_DIR$/viewcalls.php">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="2" column="13" selection-start="46" selection-end="46" vertical-scroll-proportion="0.0">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/common.inc.php">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="34" column="0" selection-start="1179" selection-end="1179" vertical-scroll-proportion="0.0">
+          <folding />
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/calls.json.php">
+      <provider selected="true" editor-type-id="text-editor">
+        <state line="2" column="9" selection-start="42" selection-end="42" vertical-scroll-proportion="0.0">
+          <folding />
+        </state>
+      </provider>
+    </entry>
     <entry file="file://$PROJECT_DIR$/trunklog.php">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
-          <folding />
-        </state>
+        <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/../disclosr/include/template.inc.php">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="72" column="93" selection-start="2545" selection-end="2635" vertical-scroll-proportion="0.43404254">
-          <folding />
-        </state>
+        <state line="72" column="93" selection-start="2545" selection-end="2635" vertical-scroll-proportion="0.43404254" />
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/../disclosr/include/common.inc.php">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
-          <folding />
-        </state>
+        <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
       </provider>
     </entry>
     <entry file="file://C:/tmp/h5bp-html5-boilerplate-2279296/index.html">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="38" column="11" selection-start="1245" selection-end="1982" vertical-scroll-proportion="0.93352604">
-          <folding />
-        </state>
+        <state line="38" column="11" selection-start="1245" selection-end="1982" vertical-scroll-proportion="0.93352604" />
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/../busui/myway/myway_timeliness.php">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="27" column="5" selection-start="1003" selection-end="1018" vertical-scroll-proportion="26.346153">
-          <folding />
-        </state>
+        <state line="27" column="5" selection-start="1003" selection-end="1018" vertical-scroll-proportion="26.346153" />
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/scannr.py">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="66" column="23" selection-start="2084" selection-end="2084" vertical-scroll-proportion="0.0">
-          <folding />
-        </state>
+        <state line="66" column="23" selection-start="2084" selection-end="2084" vertical-scroll-proportion="0.0" />
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/snd.py">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0">
-          <folding />
-        </state>
+        <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/viewcalls.php">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="2" column="13" selection-start="46" selection-end="46" vertical-scroll-proportion="36.153847">
-          <folding>
-            <element signature="e#255#287#0" expanded="true" />
-            <element signature="e#341#363#0" expanded="true" />
-          </folding>
+        <state line="63" column="25" selection-start="2268" selection-end="2268" vertical-scroll-proportion="-3.7307692">
+          <folding />
         </state>
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/common.inc.php">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="34" column="0" selection-start="1179" selection-end="1179" vertical-scroll-proportion="-22.23077">
+        <state line="60" column="117" selection-start="2262" selection-end="2262" vertical-scroll-proportion="-1.1153846">
           <folding />
         </state>
       </provider>
     </entry>
     <entry file="file://$PROJECT_DIR$/calls.json.php">
       <provider selected="true" editor-type-id="text-editor">
-        <state line="2" column="9" selection-start="42" selection-end="42" vertical-scroll-proportion="-1.2507788">
+        <state line="69" column="33" selection-start="2628" selection-end="2628" vertical-scroll-proportion="1.6950867">
           <folding />
         </state>
       </provider>

--- a/calls.json.php
+++ b/calls.json.php
@@ -1,66 +1,70 @@
 <?php
 include('common.inc.php');
-function getSensorValuesByHour($sensorID, $timeFrom, $timeTo) {
+function getTGIDValuesByHour($TGID, $timeFrom, $timeTo) {
     global $conn;
     $sth = $conn->prepare( 'select min(call_timestamp) as time, count(*), min(length), max(length), avg(length), stddev(length) from recordings
             group by tgid, date_trunc(\'hour\', call_timestamp) order by time');
 
-    $sth->execute( Array($sensorID, $timeFrom, $timeTo));
-    return  $sth->fetchAll();
+    $sth->execute( );
+    //Array($TGID, $timeFrom, $timeTo)
+        return  $sth->fetchAll();
+
+
 }
 
-function getSensorValuesByDay($sensorID, $dayFrom, $dayTo) {
+function getTGIDValuesByDay($TGID, $dayFrom, $dayTo) {
     global $conn;
     $sth = $conn->prepare('select min(time) as time, min(value), max(value), avg(value), stddev(value) from sensor_values where sensor_id = ?
             group by sensor_id, date_trunc(\'day\', time) order by time');
 
-    $sth->execute( Array($sensorID));
+    $sth->execute( Array($TGID));
     return  $sth->fetchAll();
 }
-function getSensorDataYears($sensorID, $timeFrom, $timeTo) {
+function getTGIDDataYears($TGID, $timeFrom, $timeTo) {
     global $conn;
     $sth = $conn->prepare("select distinct extract('year' from call_timestamp) as year from recordings where tgid = ? order by year");
 
-    $sth->execute(Array($sensorID));
+    $sth->execute(Array($TGID));
     return  $sth->fetchAll();
 }
 
-function getSensorDataMonths($sensorID, $timeFrom, $timeTo) {
+function getTGIDDataMonths($TGID, $timeFrom, $timeTo) {
     global $conn;
     $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($sensorID));
+    $sth->execute(Array($TGID));
     return  $sth->fetchAll();
 }
 
-function getSensorDataDays($sensorID, $timeFrom, $timeTo) {
+function getTGIDDataDays($TGID, $timeFrom, $timeTo) {
     global $conn;
     $sth = $conn->prepare("select distinct extract('day' from call_timestamp) as day, extract('month' from call_timestamp) as month, extract('year' from call_timestamp) as year from recordings where tgid = ?  order by year,month,day");
 
 
-    $sth->execute(Array($sensorID));
+    $sth->execute(Array($TGID));
     return  $sth->fetchAll();
 }
-$action = $_REQUEST['action'];
-    $sensorID = $_REQUEST['tgid'];
-$timefrom = $_REQUEST['from'];
-$timeto = $_REQUEST['to'];
-if ($action = "data_description") {
+$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_description") {
     $timefrom = strtotime($timefrom);
     $timeto = strtotime($timeto);
-    $years = getSensorDataYears($sensorID, $timefrom, $timeto);
+    $years = getTGIDDataYears($TGID, $timefrom, $timeto);
 
-    $months = getSensorDataMonths($sensorID, $timefrom, $timeto);
-    $days = getSensorDataDays($sensorID, $timefrom, $timeto);
+    $months = getTGIDDataMonths($TGID, $timefrom, $timeto);
+    $days = getTGIDDataDays($TGID, $timefrom, $timeto);
 
     echo json_encode(Array("years" => $years, "months" => $months, "days" => $days
                     ));
 }
 
 
-if ($action = "graph") {
-    $values = getSensorValuesByHour($sensorID, $timefrom, $timeto);
-    $label = $sensorID;
+if ($action == "graph") {
+    $values = getTGIDValuesByHour($TGID, $timefrom, $timeto);
+    $label = $TGID;
     $data = Array();
     $tzoffset = get_timezone_offset("UTC");
     foreach ($values as $value) {

--- a/common.inc.php
+++ b/common.inc.php
@@ -10,6 +10,7 @@
 catch(Exception $e) {
     die('Unknown error in ' . __FILE__ . '.');
 }
+$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
 $basePath = "";
 $DATA_DIR = "./data";
 
@@ -57,7 +58,7 @@
     <link rel="stylesheet" href="css/main.css">
     <script src="js/vendor/modernizr-2.6.1.min.js"></script>
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
-    <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.0.min.js"><\/script>')</script>
+    <!--<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.0.min.js"><\/script>')</script>-->
     <script type="text/javascript" src="<?php echo $basePath ?>js/flotr2/flotr2.js"></script>
     <script src="js/plugins.js"></script>
     <script src="js/main.js"></script>

--- a/viewcalls.php
+++ b/viewcalls.php
@@ -53,7 +53,7 @@
         
         });
                
-        getData('<?php echo $tgid; ?>','<?php echo strtotime("10/10/2012") ?>','<?php echo strtotime("12/10/2012") ?>');
+        getData('<?php echo $tgid; ?>','<?php echo strtotime("10/10/2012") ?>','<?php echo strtotime("10/21/2012") ?>');
         
     });
     
@@ -61,7 +61,7 @@
         data =[]
         data[data.length] = series;
         
-        plot = $.plot($("#placeholder"), data, options);
+        plot =Flotr.draw(placeholder, data, options);
     }
     function getData(sensorID,from,to) {
         $.ajax({