Permalink
Browse files

Intitial commit of the tools folder

  • Loading branch information...
1 parent 5458464 commit b8dffe9a06626c64dac5c2b01136c76e14b9c599 @csev committed Aug 23, 2016
Showing with 69,698 additions and 0 deletions.
  1. +6 −0 mod/config.php
  2. +6 −0 tools/config.php
  3. +170 −0 tools/python-data/comment_html.php
  4. +126 −0 tools/python-data/comment_json.php
  5. +127 −0 tools/python-data/comment_xml.php
  6. +14 −0 tools/python-data/data/.htaccess
  7. +46 −0 tools/python-data/data/README.txt
  8. +106 −0 tools/python-data/data/data_util.php
  9. BIN tools/python-data/data/favicon.ico
  10. +33 −0 tools/python-data/data/geojson.php
  11. +311 −0 tools/python-data/data/index.php
  12. +29 −0 tools/python-data/data/locations.php
  13. +1 −0 tools/python-data/data/locations.txt
  14. +5,995 −0 tools/python-data/data/names.php
  15. +2 −0 tools/python-data/data/robots.txt
  16. +165 −0 tools/python-data/geo_json.php
  17. +44 −0 tools/python-data/geo_pull.php
  18. +52 −0 tools/python-data/geo_test.php
  19. +30 −0 tools/python-data/grade-detail.php
  20. +10 −0 tools/python-data/grades.php
  21. +122 −0 tools/python-data/http_headers.php
  22. +79 −0 tools/python-data/index.php
  23. +192 −0 tools/python-data/knows.php
  24. +345 −0 tools/python-data/locations.inp
  25. +47 −0 tools/python-data/pull.py
  26. +148 −0 tools/python-data/regex_sum.php
  27. +10 −0 tools/python-data/register.php
  28. +8 −0 tools/python-data/static/.htaccess
  29. +10 −0 tools/python-data/static/intro-short.txt
  30. +590 −0 tools/python-data/static/intro.txt
  31. +2 −0 tools/pythonauto/auto.php
  32. +553 −0 tools/pythonauto/exercises.php
  33. +553 −0 tools/pythonauto/exercises3.php
  34. +30 −0 tools/pythonauto/grade-detail.php
  35. +10 −0 tools/pythonauto/grades.php
  36. +755 −0 tools/pythonauto/index.php
  37. +10 −0 tools/pythonauto/register.php
  38. +22 −0 tools/pythonauto/sendcode.php
  39. +25 −0 tools/pythonauto/sendgrade.php
  40. +9 −0 tools/pythonauto/static/.htaccess
  41. +264 −0 tools/pythonauto/static/codemirror/codemirror.css
  42. +6,093 −0 tools/pythonauto/static/codemirror/codemirror.js
  43. +378 −0 tools/pythonauto/static/codemirror/python.js
  44. +8 −0 tools/pythonauto/static/codemirrorepl/README.md
  45. +178 −0 tools/pythonauto/static/codemirrorepl/codemirror.css
  46. +7,468 −0 tools/pythonauto/static/codemirrorepl/codemirror.js
  47. +3,276 −0 tools/pythonauto/static/codemirrorepl/codemirrorepl.js
  48. +358 −0 tools/pythonauto/static/codemirrorepl/python.js
  49. +128 −0 tools/pythonauto/static/codemirrorepl/repl.js
  50. +6 −0 tools/pythonauto/static/files/.htaccess
  51. +1,910 −0 tools/pythonauto/static/files/mbox-short.txt
  52. +4 −0 tools/pythonauto/static/files/romeo.txt
  53. +24 −0 tools/pythonauto/static/files/words.txt
  54. +1 −0 tools/pythonauto/static/skulpt-004/skulpt-stdlib.js
  55. +32,365 −0 tools/pythonauto/static/skulpt-004/skulpt.js
  56. +999 −0 tools/pythonauto/static/skulpt-004/skulpt.min.js
  57. BIN tools/pythonauto/static/spinner.gif
  58. +280 −0 tools/pythonauto/static/splitter/jquery.splitter-0.14.0.js
  59. +57 −0 tools/pythonauto/static/splitter/jquery.splitter.css
  60. +7 −0 tools/sql-intro/.htaccess
  61. +20 −0 tools/sql-intro/README.txt
  62. +20 −0 tools/sql-intro/convert.php
  63. +178 −0 tools/sql-intro/count_lite.php
  64. +15 −0 tools/sql-intro/courses.php
  65. +29 −0 tools/sql-intro/grade-detail.php
  66. +9 −0 tools/sql-intro/grades.php
  67. +75 −0 tools/sql-intro/index.php
  68. +117 −0 tools/sql-intro/many_many_lite.php
  69. +303 −0 tools/sql-intro/many_many_mysql.php
  70. +227 −0 tools/sql-intro/many_one_lite.php
  71. +2 −0 tools/sql-intro/names.php
  72. +3,740 −0 tools/sql-intro/pop-names-07-t4.csv
  73. +10 −0 tools/sql-intro/register.php
  74. +18 −0 tools/sql-intro/roster_data.php
  75. +137 −0 tools/sql-intro/single_lite.php
  76. +123 −0 tools/sql-intro/single_mysql.php
  77. +78 −0 tools/sql-intro/sql_util.php
View
@@ -0,0 +1,6 @@
+<?php
+
+// Make this require relative to the parent of the current folder
+// http://stackoverflow.com/questions/24753758
+
+require_once dirname(__DIR__)."/tsugi/config.php";
View
@@ -0,0 +1,6 @@
+<?php
+
+// Make this require relative to the parent of the current folder
+// http://stackoverflow.com/questions/24753758
+
+require_once dirname(__DIR__)."/tsugi/config.php";
@@ -0,0 +1,170 @@
+<?php
+
+use \Tsugi\Core\LTIX;
+use \Tsugi\Util\LTI;
+
+$sanity = array(
+ 'urllib' => 'You should use urllib to retrieve the data from the URL',
+ 'BeautifulSoup' => 'You should use the BeautifulSoup library to parse the HTML'
+);
+
+// A random code
+if ( isset($_SESSION['code_override']) ) {
+ $code = $_SESSION['code_override'];
+ $override = true;
+} else {
+ $code = $USER->id+$LINK->id+$CONTEXT->id;
+ $override = false;
+}
+
+// Set the data URLs
+$sample_url = dataUrl('comments_42.html');
+$actual_url = dataUrl('comments_'.$code.'.html');
+
+// Compute the sum data
+$json = getJsonOrDie(dataUrl('comments_42.json'));
+$sum_sample = sumCommentJson($json);
+
+$json = getJsonOrDie(dataUrl('comments_'.$code.'.json'));
+$sum = sumCommentJson($json);
+
+$oldgrade = $RESULT->grade;
+if ( isset($_POST['sum']) && isset($_POST['code']) ) {
+
+ if ( $USER->instructor && strpos($_POST['sum'],'code:') === 0 ) {
+ $pieces = explode(':',$_POST['sum']);
+ if ( count($pieces) == 2 && is_numeric($pieces[1]) ) {
+ if ( $pieces[1] == 0 ) {
+ unset($_SESSION['code_override']);
+ } else {
+ $_SESSION['code_override'] = $pieces[1]+0;
+ }
+ header('Location: '.addSession('index.php'));
+ }
+ }
+
+ $RESULT->setJsonKey('code', $_POST['code']);
+
+ if ( $_POST['sum'] != $sum ) {
+ $_SESSION['error'] = "Your sum did not match";
+ header('Location: '.addSession('index.php'));
+ return;
+ }
+
+ $val = validate($sanity, $_POST['code']);
+ if ( is_string($val) ) {
+ $_SESSION['error'] = $val;
+ header('Location: '.addSession('index.php'));
+ return;
+ }
+
+ LTIX::gradeSendDueDate(1.0, $oldgrade, $dueDate);
+ // Redirect to ourself
+ header('Location: '.addSession('index.php'));
+ return;
+}
+
+// echo($goodsha);
+if ( $RESULT->grade > 0 ) {
+ echo('<p class="alert alert-info">Your current grade on this assignment is: '.($RESULT->grade*100.0).'%</p>'."\n");
+}
+
+if ( $dueDate->message ) {
+ echo('<p style="color:red;">'.$dueDate->message.'</p>'."\n");
+}
+$sample_url = dataUrl('comments_42.html');
+$actual_url = dataUrl('comments_'.$code.'.html');
+?>
+<p>
+<!--
+
+If you are having problems with this assignment, give this code to the
+instructor: <?= $code ?>
+
+
+-->
+<b>Scraping Numbers from HTML using BeautifulSoup</b>
+In this assignment you will write a Python program similar to
+<a href="http://www.pythonlearn.com/code/urllink2.py" target="_blank">http://www.pythonlearn.com/code/urllink2.py</a>.
+The program will use <b>urllib</b> to read the HTML from the data files below, and parse the data,
+extracting numbers and compute the sum of the numbers in the file.
+</p>
+<p>
+We provide two files for this assignment. One is a sample file where we give you the sum for your
+testing and the other is the actual data you need to process for the assignment.
+<?php
+if ( $override ) {
+ echo('<p style="color:red">You are running emulating a student with a code of '.$code);
+ echo(' and an expected sum of '.$sum.".</p>\n");
+}
+?>
+<ul>
+<li> Sample data: <a href="<?= deHttps($sample_url) ?>" target="_blank"><?= deHttps($sample_url) ?></a>
+(Sum=<?= $sum_sample ?>) </li>
+<li> Actual data: <a href="<?= deHttps($actual_url) ?>" target="_blank"><?= deHttps($actual_url) ?></a>
+(Sum ends with <?= $sum%100 ?>)<br/> </li>
+</ul>
+You do not need to save these files to your folder since your
+program will read the data directly from the URL.
+<b>Note:</b> Each student will have a distinct data url for the assignment - so only use your
+own data url for analysis.
+</p>
+<b>Data Format</b>
+<p>
+The file is a table of names and comment counts. You can ignore most of the data in the
+file except for lines like the following:
+<pre>
+&lt;tr>&lt;td>Modu&lt;/td>&lt;td>&lt;span class="comments">90&lt;/span>&lt;/td>&lt;/tr>
+&lt;tr>&lt;td>Kenzie&lt;/td>&lt;td>&lt;span class="comments">88&lt;/span>&lt;/td>&lt;/tr>
+&lt;tr>&lt;td>Hubert&lt;/td>&lt;td>&lt;span class="comments">87&lt;/span>&lt;/td>&lt;/tr>
+</pre>
+You are to find all the &lt;span&gt; tags in the file and pull out the numbers from the
+tag and sum the numbers.
+<p>
+Look at the
+<a href="http://www.pythonlearn.com/code/urllink2.py" target="_blank">sample code</a>
+provided. It shows how to find all of a certain kind of tag, loop through the tags and
+extract the various aspects of the tags.
+<pre>
+...
+# Retrieve all of the anchor tags
+tags = soup('a')
+for tag in tags:
+ # Look at the parts of a tag
+ print 'TAG:',tag
+ print 'URL:',tag.get('href', None)
+ print 'Contents:',tag.contents[0]
+ print 'Attrs:',tag.attrs
+</pre>
+You need to adjust this code to look for <b>span</b> tags and pull out
+the text content of the span tag, convert them to integers and
+add them up to complete the assignment.
+</p>
+<p><b>Sample Execution</b>
+<p>
+<pre>
+$ python solution.py
+Enter - http://python-data.dr-chuck.net/comments_42.html
+Count 50
+Sum 2...
+</pre>
+</p>
+
+<p><b>Turning in the Assignment</b>
+<form method="post">
+Enter the sum from the actual data and your Python code below:<br/>
+Sum: <input type="text" size="20" name="sum">
+(ends with <?= $sum%100 ?>)
+<?php if ( $USER->instructor ) { ?>
+<p style="color:green">If you want to emulate a student, ask them to view source on
+their page and find their "code" value in the comments. Then enter 'code:' and their code
+in the sum area (above) and you can switch to their code and see what they are seeing.
+</p>
+<p>
+Enter 'code:0' to go back to your own view of the assignment.
+</p>
+<?php } ?>
+<input type="submit" value="Submit Assignment"><br/>
+Python code:<br/>
+<textarea rows="20" style="width: 90%" name="code"></textarea><br/>
+</form>
@@ -0,0 +1,126 @@
+<?php
+
+require_once('data/data_util.php');
+
+use \Tsugi\Core\LTIX;
+use \Tsugi\Util\LTI;
+
+$sanity = array(
+ 'urllib' => 'You should use urllib to retrieve the data from the URL',
+ 'json' => 'You should use json to parse the data retrieved from the URL'
+);
+
+// A random code
+$code = $USER->id+$LINK->id+$CONTEXT->id;
+
+// Set the data URLs
+$sample_url = dataUrl('comments_42.json');
+$actual_url = dataUrl('comments_'.$code.'.json');
+
+// Compute the sum data
+$json = getJsonOrDie(dataUrl('comments_42.json'));
+$sum_sample = sumCommentJson($json);
+
+$json = getJsonOrDie(dataUrl('comments_'.$code.'.json'));
+$sum = sumCommentJson($json);
+
+$oldgrade = $RESULT->grade;
+if ( isset($_POST['sum']) && isset($_POST['code']) ) {
+ $RESULT->setJsonKey('code', $_POST['code']);
+
+ if ( $_POST['sum'] != $sum ) {
+ $_SESSION['error'] = "Your sum did not match";
+ header('Location: '.addSession('index.php'));
+ return;
+ }
+
+ $val = validate($sanity, $_POST['code']);
+ if ( is_string($val) ) {
+ $_SESSION['error'] = $val;
+ header('Location: '.addSession('index.php'));
+ return;
+ }
+
+ LTIX::gradeSendDueDate(1.0, $oldgrade, $dueDate);
+ // Redirect to ourself
+ header('Location: '.addSession('index.php'));
+ return;
+}
+
+// echo($goodsha);
+if ( $RESULT->grade > 0 ) {
+ echo('<p class="alert alert-info">Your current grade on this assignment is: '.($RESULT->grade*100.0).'%</p>'."\n");
+}
+
+if ( $dueDate->message ) {
+ echo('<p style="color:red;">'.$dueDate->message.'</p>'."\n");
+}
+?>
+<p>
+<b>Extracting Data from JSON</b>
+<p>
+In this assignment you will write a Python program somewhat similar to
+<a href="http://www.pythonlearn.com/code/json2.py" target="_blank">http://www.pythonlearn.com/code/json2.py</a>.
+The program will prompt for a URL, read the JSON data from that URL using
+<b>urllib</b> and then parse and extract the comment counts from the JSON data,
+compute the sum of the numbers in the file and enter the sum below:<br/>
+</p>
+<p>
+We provide two files for this assignment. One is a sample file where we give you the sum for your
+testing and the other is the actual data you need to process for the assignment.
+<ul>
+<li> Sample data: <a href="<?= deHttps($sample_url) ?>" target="_blank"><?= deHttps($sample_url) ?></a>
+(Sum=<?= $sum_sample ?>) </li>
+<li> Actual data: <a href="<?= deHttps($actual_url) ?>" target="_blank"><?= deHttps($actual_url) ?></a>
+(Sum ends with <?= $sum%100 ?>)<br/> </li>
+</ul>
+You do not need to save these files to your folder since your
+program will read the data directly from the URL.
+<b>Note:</b> Each student will have a distinct data url for the assignment - so only use your
+own data url for analysis.
+</p>
+<b>Data Format</b>
+<p>
+The data consists of a number of names and comment counts in JSON as follows:
+<pre>
+{
+ comments: [
+ {
+ name: "Matthias"
+ count: 97
+ },
+ {
+ name: "Geomer"
+ count: 97
+ }
+ ...
+ ]
+}
+</pre>
+<p>
+The closest sample code that shows how to parse JSON and extract a list is
+<a href="http://www.pythonlearn.com/code/json2.py" target="_blank">json2.py</a>. You might also want
+to look at
+<a href="http://www.pythonlearn.com/code/geoxml.py" target="_blank">geoxml.py</a>
+to see how to prompt for a URL and retrieve data from a URL.
+</p>
+<p><b>Sample Execution</b></p>
+<pre>
+$ python solution.py
+Enter location: http://python-data.dr-chuck.net/comments_42.json
+Retrieving http://python-data.dr-chuck.net/comments_42.json
+Retrieved 2733 characters
+Count: 50
+Sum: 2...
+</pre>
+<?php httpsWarning($sample_url); ?>
+<p><b>Turning in the Assignment</b>
+<form method="post">
+Enter the sum from the actual data and your Python code below:<br/>
+Sum: <input type="text" size="20" name="sum">
+(ends with <?= $sum%100 ?>)
+<input type="submit" value="Submit Assignment"><br/>
+Python code:<br/>
+<textarea rows="20" style="width: 90%" name="code"></textarea><br/>
+</form>
+
Oops, something went wrong.

0 comments on commit b8dffe9

Please sign in to comment.