Browse Source

Add portal page

Closes #3
tags/SensorLogger/0.1.3
Chris Smith 14 years ago
parent
commit
3a3080fb08
3 changed files with 119 additions and 1 deletions
  1. 15
    0
      website/common.php
  2. 1
    1
      website/data.php
  3. 103
    0
      website/portal.php

+ 15
- 0
website/common.php View File

@@ -21,4 +21,19 @@
21 21
         }
22 22
  }
23 23
 
24
+ function getStatusCodeReason($code) {
25
+ 	switch ((int) $code) {
26
+		case 2: return 'no IMEI code was specified';
27
+		case 3: return 'no activity was specified';
28
+		case 4: return 'no application version was specified';
29
+		case 5: return 'no sensor data was included';
30
+		case 6: return 'an invalid date was specified';
31
+		case 7: return 'insufficient sensor data was included';
32
+		case 8: return 'the sensor data was already submitted (duplicate)';
33
+		case 9: return 'the sensor data contained long periods of identical values';
34
+	}
35
+
36
+	return 'unknown reason';
37
+ }
38
+
24 39
 ?>

+ 1
- 1
website/data.php View File

@@ -64,7 +64,7 @@
64 64
   return;
65 65
  }
66 66
 
67
- $sql = 'SELECT log_id, log_version, log_time, log_activity, log_data FROM sensorlogger WHERE log_statuscode = 1';
67
+ $sql = 'SELECT log_id, log_imei, log_version, log_time, log_activity, log_data FROM sensorlogger WHERE log_statuscode = 1';
68 68
  $res = mysql_query($sql);
69 69
 
70 70
  echo '<table border="1">';

+ 103
- 0
website/portal.php View File

@@ -0,0 +1,103 @@
1
+<?PHP
2
+
3
+ if (!isset($_GET['imei']) || !ctype_digit($_GET['imei'])) {
4
+  // TODO: Better error
5
+  die('Invalid IMEI');
6
+ }
7
+
8
+ define('IMEI', $_GET['imei']);
9
+
10
+ require_once('common.php');
11
+
12
+ $sql = 'SELECT log_activity, log_id, log_statuscode FROM sensorlogger WHERE log_imei = \'' . m(IMEI) . '\'';
13
+ $res = mysql_query($sql);
14
+
15
+ echo '<?xml version="1.0"?>';
16
+?>
17
+<html xmlns="http://www.w3.org/1999/xhtml">
18
+  <head>
19
+    <title>SensorLogger Results</title>
20
+    <link rel="stylesheet" type="text/css" href="/style.css"/>
21
+    <style type="text/css">
22
+     .qr { float: left; clear: left; margin-right: 15px; }
23
+     .qr img { width: 128px; }
24
+    </style>
25
+  </head>
26
+  <body style="margin-top: 0; padding-top: 0;">
27
+    <h1 style="background: url('android.png') no-repeat right; padding-top: 50px; margin-top: 0;">SensorLogger results for <span><?PHP echo IMEI; ?></span></h1>
28
+    <div>
29
+<?PHP if (($num = mysql_num_rows($res)) == 0) { ?>
30
+     <h2>Welcome</h2>
31
+     <p>
32
+      You do not appear to have submitted any data from the sensor logger application, yet.
33
+     </p>
34
+     <p>
35
+      Why not <a href="/android/">download it</a> and give it a try, then check back soon!
36
+     </p> 
37
+<?PHP } else { ?>
38
+     <h2>Thank you</h2>
39
+     <p>
40
+      You've submitted <strong><?PHP echo number_format($num); ?></strong>
41
+      record<?PHP echo $num == 1 ? '' : 's'; ?> from the sensor logger application.
42
+     </p>
43
+<?PHP
44
+ $data = array();
45
+ $codes = array();
46
+ $rejects = 0;
47
+ 
48
+ while ($row = mysql_fetch_assoc($res)) {
49
+  if ($row['log_statuscode'] == '1') {
50
+   $data[] = $row;
51
+  } else {
52
+   $codes[(int) $row['log_statuscode']]++;
53
+   $rejects++;
54
+  }
55
+ }
56
+
57
+ if ($rejects > 0) {
58
+?>
59
+   <p>
60
+    Unfortunately, some of these traces have been rejected as they are not suitable for analysis:
61
+   </p>
62
+   <ul>
63
+<?PHP
64
+ foreach ($codes as $code => $count) {
65
+  echo '<li>', number_format($count), ' rejected because ' . getStatusCodeReason($code) . '</li>';
66
+ }
67
+?>
68
+   </ul>
69
+<?PHP if ($num > $rejects) { ?>
70
+  <p>The remaining <strong><?PHP echo $num - $rejects; ?></strong> record<?PHP echo $num > $rejects + 1 ? 's look' : ' looks'; ?>
71
+     good, and <?PHP echo $num > $rejects + 1 ? 'are' : 'is'; ?> shown below:</p>
72
+<?PHP } else { ?>
73
+  <p>Oh dear, that's all of your records. Make sure you're using the <a href="/android/">latest version</a>
74
+     to ensure you get the best results. Record some more and check back soon!</p>
75
+<?PHP }
76
+ } else {
77
+?>
78
+ <p>Our system didn't find any problems with your records, so all of them are shown below:</p>
79
+<?PHP
80
+ }
81
+
82
+ if ($rejects < $num) {
83
+?>
84
+  <h2>Your records</h2>
85
+<?PHP
86
+
87
+ foreach ($data as $datum) {
88
+  echo '<h3>', htmlentities($datum['log_activity']), '</h3>';
89
+  echo '<div style="height: 700px; overflow: auto;">';
90
+  echo '<img src="data.php?graph=' . $datum['log_id'] . '&amp;ds=1" height="330" alt="Graph of accelerometer data"/><br/>';
91
+  echo '<img src="data.php?graph=' . $datum['log_id'] . '&amp;ds=2" height="330" alt="Graph of magnetic fielddata"/>';
92
+  echo '</div>';
93
+ }
94
+?>
95
+ <h2>Check back soon...</h2>
96
+ <p>for information on how your records are being used, explanations of the data, and information on the application
97
+    which will be created as a result</p>
98
+<?PHP } ?>
99
+<?PHP } ?>
100
+    </div>
101
+    <div id="footer"/>
102
+  </body>
103
+</html>

Loading…
Cancel
Save