<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22112/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=WikiSysop</id>
	<title>22112 - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22112/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=WikiSysop"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php/Special:Contributions/WikiSysop"/>
	<updated>2026-05-02T09:09:57Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=156</id>
		<title>22112 High Performance Computing in Life Science</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=156"/>
		<updated>2025-12-04T06:56:33Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Course details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&#039;&#039;&#039;Teacher:&#039;&#039;&#039; [https://www.inside.dtu.dk/da/dtuinside/generelt/telefonbog/person?id=816&amp;amp;cpid=214027&amp;amp;tab=2&amp;amp;qt=dtupublicationquery Peter Wad Sackett], pwsa@dtu.dk &amp;lt;!--, [https://www.inside.dtu.dk/en/dtuinside/generelt/telefonbog/person?id=130596&amp;amp;tab=0 Gisle Alberg Vestergaard], gisves@dtu.dk --&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Language:&#039;&#039;&#039; The course is taught in English.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Tools:&#039;&#039;&#039; Various servers will be introduced.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Textbooks:&#039;&#039;&#039; There are no text books for the course. I will make do with powerpoints, videos and references to online resources. You can find the material under the individual lessons in the [[Programme]].&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Location:&#039;&#039;&#039; Building 208, room 001.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Time:&#039;&#039;&#039; Thursday 13:00 - 17:00, module E1-B.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Course details ==&lt;br /&gt;
The course is a practical introduction to working with supercomputers in Life Science. Using both &amp;quot;ordinary&amp;quot; laptops and computer clusters as a basis for lectures and exercises, we will cover subjects such as computer design, queueing systems, distributed computing, algorithms, parallel programming, performance and performance dependencies, database design and use, and practical organization of projects.&lt;br /&gt;
&lt;br /&gt;
{| &lt;br /&gt;
|-&lt;br /&gt;
| [[Aligning expectations]] || Mandatory read at course start&lt;br /&gt;
|-&lt;br /&gt;
| [[Programme]] || Fall 2024&lt;br /&gt;
|-&lt;br /&gt;
| [https://teaching.healthtech.dtu.dk/22112/progress/ Exercise progression] || How well are you doing?&lt;br /&gt;
|-&lt;br /&gt;
| [[Computerome]] || Some info on Computerome&lt;br /&gt;
|-&lt;br /&gt;
| [https://teaching.healthtech.dtu.dk/material/22112/StudentAssistantLundbeck.pdf Job] || Student job at Lundbeck&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Earlier programmes ==&lt;br /&gt;
[[Programme Fall 2023]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[Programme Fall 2024]]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Parallel_programming&amp;diff=155</id>
		<title>Parallel programming</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Parallel_programming&amp;diff=155"/>
		<updated>2025-11-06T13:29:37Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Algorithms]]&lt;br /&gt;
|Next: [[More parallelism]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=6d186b7e-f5a7-4e1f-b613-af270122f263 Parallel Programming - problems]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=bb4fc4d2-c0af-44bd-b181-af270122cf03 Libraries to use and how they work]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=5aa86527-f501-44b6-9ee4-af270122a685 Parent/Child relationships]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_09-Programming.ppt Programming]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=8ff003cd-f906-4d42-9f3d-af2701228c6d What is expected from exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
&#039;&#039;Read a fasta file, find the complement strand of each entry, save result in new fasta file.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Note: The python you should use on &#039;&#039;&#039;pupil1&#039;&#039;&#039; server is /home/ctools/anaconda3-2024.10-1/bin/python3 - there are 2 pythons, so it is possible to choose wrong.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
In lesson 6, Distributed computing, you created 2-3 programs and used the Queueing System to submit your sub tasks. You are going to repeat this exercise, but this time do not use the QS to do the sub tasks, but use&lt;br /&gt;
&#039;&#039;&#039;subprocess&#039;&#039;&#039; and &#039;&#039;&#039;joblib&#039;&#039;&#039; as shown in the powerpoint example. The code is the same as second exercise except for the part that do the sub tasks, and waits for them to finish.&amp;lt;br&amp;gt;&lt;br /&gt;
You must still use the QS to submit the initial main job.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
If you feel this was too easy, then the administrator should only index the fasta file and launch workers with the indexed info using &#039;&#039;&#039;joblib&#039;&#039;&#039; and an internal worker function.&lt;br /&gt;
The workers will create the complement strand entry as a file and the administrator will collect the pieces as in above. This is using techniques we have already covered. The result will be the same as above, but faster.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
For an extra challenge, then create a different worker function that writes the complement stand directly back into the file the right place as has been discussed earlier.&lt;br /&gt;
Here you need your own &amp;quot;private&amp;quot; fasta file, because you can not write in mine in /home/projects/pr_course.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Time everything to see the difference. Don&#039;t use more than 8 workers at a time - &#039;&#039;&#039;joblib&#039;&#039;&#039; helps with that.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Queueing_System&amp;diff=154</id>
		<title>Queueing System</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Queueing_System&amp;diff=154"/>
		<updated>2025-11-05T12:19:59Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Material for the lesson */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Computer design]]&lt;br /&gt;
|Next: [[Distributed computing]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_05-Queue.ppt Queueing System]&amp;lt;br&amp;gt;&lt;br /&gt;
IUPAC nucleotide codes: [http://www.dnabaser.com/articles/IUPAC%20ambiguity%20codes.html Read before doing exercise]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=d679e5c8-9372-4af7-9260-af270124ddf6 Introduction to the Queueing System]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=bca57da6-2c60-4218-96ac-af270124b673 Submitting jobs]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=e6e59e86-2928-4caf-b5c3-af2701248a3d Queue control and practical advice]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=c82ed125-4664-4c5b-b23b-af1700719969 Exercises]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
The exercises must work with the human genome in the fastafile human.fsa and you can develop/test your program against the small scale humantest.fsa file.&lt;br /&gt;
&#039;&#039;You must use the Queueing System and &#039;&#039;&#039;sbatch&#039;&#039;&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
# Make (or reuse) a program that reads a fasta file and finds the complement strand for each entry, and saves the result in a new file. Keep it simple. Make sure it works. Speed is not important in this step.&lt;br /&gt;
# Speed is still not important. Add this functionality to your program: Count the bases and unknowns in the entry and add the counts to the header line, like  &amp;gt;seq01 A:3450 T:45665 C:34576 G:142345 N:5462&lt;br /&gt;
# You need to increase the performance of your program. Experiment with various ideas of how to increase the speed. You got some ideas last lecture and you should also be using your Python knowledge. Document your experiments with a line or two as comments in your program. This exercise is likely the one that takes the most time to complete and the shortest to run.&lt;br /&gt;
&lt;br /&gt;
I solved this problem in 222 seconds on a server, however time vary, as I had also a run using 527 seconds with the same code - IO from other users can really affect your time. I had a &amp;quot;slow&amp;quot; version run on a server in over 1000 seconds. On my laptop with SSD I solved the problem in 100 seconds.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=153</id>
		<title>22112 High Performance Computing in Life Science</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=153"/>
		<updated>2025-10-29T06:23:07Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Course details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&#039;&#039;&#039;Teacher:&#039;&#039;&#039; [https://www.inside.dtu.dk/da/dtuinside/generelt/telefonbog/person?id=816&amp;amp;cpid=214027&amp;amp;tab=2&amp;amp;qt=dtupublicationquery Peter Wad Sackett], pwsa@dtu.dk &amp;lt;!--, [https://www.inside.dtu.dk/en/dtuinside/generelt/telefonbog/person?id=130596&amp;amp;tab=0 Gisle Alberg Vestergaard], gisves@dtu.dk --&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Language:&#039;&#039;&#039; The course is taught in English.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Tools:&#039;&#039;&#039; Various servers will be introduced.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Textbooks:&#039;&#039;&#039; There are no text books for the course. I will make do with powerpoints, videos and references to online resources. You can find the material under the individual lessons in the [[Programme]].&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Location:&#039;&#039;&#039; Building 208, room 001.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Time:&#039;&#039;&#039; Thursday 13:00 - 17:00, module E1-B.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Course details ==&lt;br /&gt;
The course is a practical introduction to working with supercomputers in Life Science. Using both &amp;quot;ordinary&amp;quot; laptops and computer clusters as a basis for lectures and exercises, we will cover subjects such as computer design, queueing systems, distributed computing, algorithms, parallel programming, performance and performance dependencies, database design and use, and practical organization of projects.&lt;br /&gt;
&lt;br /&gt;
{| &lt;br /&gt;
|-&lt;br /&gt;
| [[Aligning expectations]] || Mandatory read at course start&lt;br /&gt;
|-&lt;br /&gt;
| [[Programme]] || Fall 2024&lt;br /&gt;
|-&lt;br /&gt;
| [https://teaching.healthtech.dtu.dk/22112/progress/ Exercise progression] || How well are you doing?&lt;br /&gt;
|-&lt;br /&gt;
| [[Computerome]] || Some info on Computerome&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Earlier programmes ==&lt;br /&gt;
[[Programme Fall 2023]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[Programme Fall 2024]]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=152</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=152"/>
		<updated>2025-09-25T17:52:36Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
Note that the videos are no longer completely aligned with the powerpoints due to a shift in focus.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Motto: Less fear - more fun&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1) Measuring IO speed&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2) The Chat Board&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;&#039;chatboard&#039;&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;&#039;messages&#039;&#039;&#039; with the fields;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id      primary key auto_increment&lt;br /&gt;
mesg    varchar(500)&lt;br /&gt;
name    varchar(15) default NULL&lt;br /&gt;
channel varchar(12) default &#039;common&#039;&lt;br /&gt;
stamp   timestamp default CURRENT_TIMESTAMP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last field, stamp, is automatically updated to the current time when the message is inserted. You only have to insert mesg, name and channel when inserting a row. You can only read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality. You are to make a python program that runs in the terminal and interacts with you (your commands). If confused, start with making a program that simply pulls all messages from the database and show them. Build up with selecting a channel to show, then the ability to post a message.&amp;lt;br&amp;gt;&lt;br /&gt;
Something that I found to be a challenge was to figure out when to pull new messages from the database and which messages. If you are overwhelmed, then just auto pull the last 5-10 messages every time - but you get a lot redundant information that way. You could rely on the &#039;&#039;/last&#039;&#039; command - you command the pull yourself. I made a pull for only new messages when I pressed &amp;lt;enter&amp;gt; without any command/message.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt; This is minimum useful functionality/requirement.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;, &#039;&#039;/trueid&#039;&#039;, which sets your name to your login name, &#039;&#039;/activity&#039;&#039;, which shows when the channels had the latest messages.&amp;lt;br&amp;gt;&lt;br /&gt;
You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
Hint: Something I found useful is that you can get the &#039;&#039;id&#039;&#039;, i.e. the auto incremented primary key of you last inserted message like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cursor.execute(&amp;quot;&amp;quot;&amp;quot;INSERT INTO messages SET mesg=%s, name=%s, channel=%s&amp;quot;&amp;quot;&amp;quot;, (chat, nick, channel))&lt;br /&gt;
msgID = cursor.lastrowid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Extra optional fun:&#039;&#039;&#039; ChatBots&amp;lt;br&amp;gt;&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
* find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
* be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
* find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
* camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
* copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
* advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
* have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
* If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=151</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=151"/>
		<updated>2025-09-25T17:51:05Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Material for the lesson */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
Note that the videos are no longer completely aligned with the powerpoints due to a shift in focus.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Motto: Less fear - more fun&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1) Measuring IO speed&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2) The Chat Board&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;&#039;chatboard&#039;&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;&#039;messages&#039;&#039;&#039; with the fields;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id      primary key auto_increment&lt;br /&gt;
mesg    varchar(500)&lt;br /&gt;
name    varchar(15) default NULL&lt;br /&gt;
channel varchar(12) default &#039;common&#039;&lt;br /&gt;
stamp   timestamp default CURRENT_TIMESTAMP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last field, stamp, is automatically updated to the current time when the message is inserted. You only have to insert mesg, name and channel when inserting a row. You can only read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality. You are to make a python program that runs in the terminal and interacts with you (your commands). If confused, start with making a program that simply pulls all messages from the database and show them. Build up with selecting a channel to show, then the ability to post a message.&amp;lt;br&amp;gt;&lt;br /&gt;
Something that I found to be a challenge was to figure out when to pull new messages from the database and which messages. If you are overwhelmed, then just auto pull the last 5-10 messages every time - but you get a lot redundant information that way. You could rely on the &#039;&#039;/last&#039;&#039; command - you command the pull yourself. I made a pull for only new messages when I pressed &amp;lt;enter&amp;gt; without any command/message.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt; This is minimum useful functionality/requirement.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;, &#039;&#039;/trueid&#039;&#039;, which sets your name to your login name, &#039;&#039;/activity&#039;&#039;, which shows when the channels had the latest messages.&amp;lt;br&amp;gt;&lt;br /&gt;
You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
Hint: Something I found useful is that you can get the &#039;&#039;id&#039;&#039;, i.e. the auto incremented primary key of you last inserted message like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cursor.execute(&amp;quot;&amp;quot;&amp;quot;INSERT INTO messages SET mesg=%s, name=%s, channel=%s&amp;quot;&amp;quot;&amp;quot;, (chat, nick, channel))&lt;br /&gt;
msgID = cursor.lastrowid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Extra optional fun:&#039;&#039;&#039; ChatBots&amp;lt;br&amp;gt;&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
* find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
* be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
* find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
* camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
* copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
* advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
* have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
* If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=150</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=150"/>
		<updated>2025-09-25T17:50:30Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
Note that the videos are no longer completely aligned with the powerpoints due to a shift in focus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Motto: Less fear - more fun&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1) Measuring IO speed&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2) The Chat Board&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;&#039;chatboard&#039;&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;&#039;messages&#039;&#039;&#039; with the fields;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id      primary key auto_increment&lt;br /&gt;
mesg    varchar(500)&lt;br /&gt;
name    varchar(15) default NULL&lt;br /&gt;
channel varchar(12) default &#039;common&#039;&lt;br /&gt;
stamp   timestamp default CURRENT_TIMESTAMP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last field, stamp, is automatically updated to the current time when the message is inserted. You only have to insert mesg, name and channel when inserting a row. You can only read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality. You are to make a python program that runs in the terminal and interacts with you (your commands). If confused, start with making a program that simply pulls all messages from the database and show them. Build up with selecting a channel to show, then the ability to post a message.&amp;lt;br&amp;gt;&lt;br /&gt;
Something that I found to be a challenge was to figure out when to pull new messages from the database and which messages. If you are overwhelmed, then just auto pull the last 5-10 messages every time - but you get a lot redundant information that way. You could rely on the &#039;&#039;/last&#039;&#039; command - you command the pull yourself. I made a pull for only new messages when I pressed &amp;lt;enter&amp;gt; without any command/message.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt; This is minimum useful functionality/requirement.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;, &#039;&#039;/trueid&#039;&#039;, which sets your name to your login name, &#039;&#039;/activity&#039;&#039;, which shows when the channels had the latest messages.&amp;lt;br&amp;gt;&lt;br /&gt;
You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
Hint: Something I found useful is that you can get the &#039;&#039;id&#039;&#039;, i.e. the auto incremented primary key of you last inserted message like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cursor.execute(&amp;quot;&amp;quot;&amp;quot;INSERT INTO messages SET mesg=%s, name=%s, channel=%s&amp;quot;&amp;quot;&amp;quot;, (chat, nick, channel))&lt;br /&gt;
msgID = cursor.lastrowid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Extra optional fun:&#039;&#039;&#039; ChatBots&amp;lt;br&amp;gt;&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
* find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
* be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
* find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
* camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
* copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
* advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
* have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
* If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=149</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=149"/>
		<updated>2025-09-25T17:48:57Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
Note that the videos are no longer completely aligned with the powerpoints due to a shift in focus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
&#039;&#039;&#039;1) Measuring IO speed&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2) The Chat Board&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;&#039;chatboard&#039;&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;&#039;messages&#039;&#039;&#039; with the fields;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id      primary key auto_increment&lt;br /&gt;
mesg    varchar(500)&lt;br /&gt;
name    varchar(15) default NULL&lt;br /&gt;
channel varchar(12) default &#039;common&#039;&lt;br /&gt;
stamp   timestamp default CURRENT_TIMESTAMP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last field, stamp, is automatically updated to the current time when the message is inserted. You only have to insert mesg, name and channel when inserting a row. You can only read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality. You are to make a python program that runs in the terminal and interacts with you (your commands). If confused, start with making a program that simply pulls all messages from the database and show them. Build up with selecting a channel to show, then the ability to post a message.&amp;lt;br&amp;gt;&lt;br /&gt;
Something that I found to be a challenge was to figure out when to pull new messages from the database and which messages. If you are overwhelmed, then just auto pull the last 5-10 messages every time - but you get a lot redundant information that way. You could rely on the &#039;&#039;/last&#039;&#039; command - you command the pull yourself. I made a pull for only new messages when I pressed &amp;lt;enter&amp;gt; without any command/message.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt; This is minimum useful functionality/requirement.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;, &#039;&#039;/trueid&#039;&#039;, which sets your name to your login name, &#039;&#039;/activity&#039;&#039;, which shows when the channels had the latest messages.&amp;lt;br&amp;gt;&lt;br /&gt;
You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
Hint: Something I found useful is that you can get the &#039;&#039;id&#039;&#039;, i.e. the auto incremented primary key of you last inserted message like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cursor.execute(&amp;quot;&amp;quot;&amp;quot;INSERT INTO messages SET mesg=%s, name=%s, channel=%s&amp;quot;&amp;quot;&amp;quot;, (chat, nick, channel))&lt;br /&gt;
msgID = cursor.lastrowid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Extra optional fun:&#039;&#039;&#039; ChatBots&amp;lt;br&amp;gt;&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
* find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
* be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
* find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
* camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
* copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
* advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
* have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
* If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=148</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=148"/>
		<updated>2025-09-25T17:46:55Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
Note that the videos are no longer completely aligned with the powerpoints due to a shift in focus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
&#039;&#039;&#039;1) Measuring IO speed&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2) The Chat Board&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;&#039;chatboard&#039;&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;&#039;messages&#039;&#039;&#039; with the fields;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id      primary key auto_increment&lt;br /&gt;
mesg    varchar(500)&lt;br /&gt;
name    varchar(15) default NULL&lt;br /&gt;
channel varchar(12) default &#039;common&#039;&lt;br /&gt;
stamp   timestamp default CURRENT_TIMESTAMP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last field, stamp, is automatically updated to the current time when the message is inserted. You only have to insert mesg, name and channel when inserting a row. You can only read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality. You are to make a python program that runs in the terminal and interacts with you (your commands). If confused, start with making a program that simply pulls all messages from the database and show them. Build up with selecting a channel to show, then the ability to post a message.&amp;lt;br&amp;gt;&lt;br /&gt;
Something that I found to be a challenge was to figure out when to pull new messages from the database and which messages. If you are overwhelmed, then just auto pull the last 5-10 messages every time - but you get a lot redundant information that way. You could rely on the &#039;&#039;/last&#039;&#039; command - you command the pull yourself. I made a pull for only new messages when I pressed &amp;lt;enter&amp;gt; without any command/message.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt; This is minimum useful functionality/requirement.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;, &#039;&#039;/trueid&#039;&#039;, which sets your name to your login name, &#039;&#039;/activity&#039;&#039;, which shows when the channels had the latest messages.&amp;lt;br&amp;gt;&lt;br /&gt;
You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
Hint: Something I found useful is that you can get the &#039;&#039;id&#039;&#039;, i.e. the auto incremented primary key of you last inserted message like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cursor.execute(&amp;quot;&amp;quot;&amp;quot;INSERT INTO messages SET mesg=%s, name=%s, channel=%s&amp;quot;&amp;quot;&amp;quot;, (chat, nick, channel))&lt;br /&gt;
msgID = cursor.lastrowid&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Extra optional fun:&#039;&#039;&#039; ChatBots&amp;lt;br&amp;gt;&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=147</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=147"/>
		<updated>2025-09-25T17:39:24Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
Note that the videos are no longer completely aligned with the powerpoints due to a shift in focus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
&#039;&#039;&#039;1) Measuring IO speed&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2) The Chat Board&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;&#039;chatboard&#039;&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;&#039;messages&#039;&#039;&#039; with the fields;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id      primary key auto_increment&lt;br /&gt;
mesg    varchar(500)&lt;br /&gt;
name    varchar(15) default NULL&lt;br /&gt;
channel varchar(12) default &#039;common&#039;&lt;br /&gt;
stamp   timestamp default CURRENT_TIMESTAMP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last field, stamp, is automatically updated to the current time when the message is inserted. You only have to insert mesg, name and channel when inserting a row. You can only read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality. You are to make a python program that runs in the terminal and interacts with you (your commands). If confused, start with making a program that simply pulls all messages from the database and show them. Build up with selecting a channel to show, then the ability to post a message.&amp;lt;br&amp;gt;&lt;br /&gt;
Something that I found to be a challenge was to figure out when to pull new messages from the database and which messages. If you are overwhelmed, then just auto pull the last 5-10 messages every time - but you get a lot redundant information that way. You could rely on the &#039;&#039;/last&#039;&#039; command - you command the pull yourself. I made a pull for only new messages when I pressed &amp;lt;enter&amp;gt; without any command/message.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt; This is minimum useful functionality/requirement.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;, &#039;&#039;/trueid&#039;&#039;, which sets your name to your login name, &#039;&#039;/activity&#039;&#039;, which shows when the channels had the latest messages.&amp;lt;br&amp;gt;&lt;br /&gt;
You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Extra optional fun:&#039;&#039;&#039; ChatBots&amp;lt;br&amp;gt;&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=146</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=146"/>
		<updated>2025-09-25T17:21:10Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
Note that the videos are no longer completely aligned with the powerpoints due to a shift in focus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
&#039;&#039;&#039;1) Measuring IO speed&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2) The Chat Board&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;&#039;chatboard&#039;&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id      primary key auto_increment&lt;br /&gt;
mesg    varchar(500)&lt;br /&gt;
name    varchar(15) default NULL&lt;br /&gt;
channel varchar(12) default &#039;common&#039;&lt;br /&gt;
stamp   timestamp default CURRENT_TIMESTAMP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last field, stamp, is automatically updated to the current time when the message is inserted. You only have to insert mesg, name and channel when inserting a row. You can only read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;, &#039;&#039;/trueid&#039;&#039;, which sets your name to your login name, &#039;&#039;/activity&#039;&#039;, which shows when the channels had the latest messages.&amp;lt;br&amp;gt;&lt;br /&gt;
You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=145</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=145"/>
		<updated>2025-09-25T17:17:57Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
Note that the videos are no longer completely aligned with the powerpoints due to a shift in focus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
&#039;&#039;&#039;1) Measuring IO speed&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2) The Chat Board&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;&#039;chatboard&#039;&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
id      primary key auto_increment&lt;br /&gt;
mesg    varchar(500)&lt;br /&gt;
name    varchar(15) default NULL&lt;br /&gt;
channel varchar(12) default &#039;common&#039;&lt;br /&gt;
stamp   timestamp default CURRENT_TIMESTAMP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The last field, stamp, is automatically updated to the current time when the message is inserted. You only have to insert mesg, name and channel. You can only read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=144</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=144"/>
		<updated>2025-09-25T17:12:47Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
Note that the videos are no longer completely aligned with the powerpoints due to a shift in focus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039; Measuring IO speed&amp;lt;br&amp;gt;&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039; The Chat Board&amp;lt;br&amp;gt;&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;&#039;chatboard&#039;&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key auto_increment), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), stamp (timestamp) default CURRENT_TIMESTAMP, which means the timestamp is automatically created when the message is inserted. You only have the ability to read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=143</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=143"/>
		<updated>2025-09-25T17:12:03Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
Note that the videos are no longer completely aligned with the powerpoints due to a shift in focus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039; Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039; The Chat Board&amp;lt;br&amp;gt;&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key auto_increment), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), stamp (timestamp) default CURRENT_TIMESTAMP, which means the timestamp is automatically created when the message is inserted. You only have the ability to read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=142</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=142"/>
		<updated>2025-09-25T17:10:23Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&amp;lt;br&amp;gt;&lt;br /&gt;
According to my results: 262 people are born out of wedlock. That is amazing as it is out of 500 people.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional - really simple once it works&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
===Chatboard exercise moved to next lesson===&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Exercises_and_Organization&amp;diff=141</id>
		<title>Exercises and Organization</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Exercises_and_Organization&amp;diff=141"/>
		<updated>2025-09-25T06:38:15Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Material for the lesson */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Hash usage]]&lt;br /&gt;
|Next: [https://teaching.healthtech.dtu.dk/22112/index.php/22112_High_Performance_Computing_in_Life_Science Main page]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
&amp;lt;!--Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=0ccf3b1b-52b7-4d91-9314-af17007069b8 Organization and Exercises]&amp;lt;br&amp;gt;--&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_13-Project.ppt Projects - organize your work life]&amp;lt;br&amp;gt;&lt;br /&gt;
PDF: [https://teaching.healthtech.dtu.dk/material/22112/22112_13-Organization.pdf Organization of projects] Article by someone like you - just older and more experienced.&amp;lt;br&amp;gt;&lt;br /&gt;
PDF: [https://teaching.healthtech.dtu.dk/material/22112/guide-to-reproducible-code.pdf Guide to Reproducible Code]&amp;lt;br&amp;gt;&lt;br /&gt;
PDF: [https://teaching.healthtech.dtu.dk/material/22112/HPC_analysis_framework_Leon.pdf HPC Analysis Framework] by Leon Jessen&amp;lt;br&amp;gt;&lt;br /&gt;
Tweet: [https://twitter.com/jessenleon/status/964236119658418176 Use Twitter for academic networking. You needn’t tweet anything yourself, but it’s a great way to follow bioinformatics influencers and news], Leon Jessen&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://www.youtube.com/watch?v=8xnm_RKkycQ Alexander Schönhuth: &amp;quot;Snakemake: Reproducible and Scalable Data Analysis&amp;quot;] Optional, but good to know about. Just get the idea.&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&lt;br /&gt;
In this exercise we will work with an Illumina sequencing file: ngs1.fastq.gz. There is a test version, ngs1test.fastq.gz, and an even smaller version, ngs1small.fastq.gz, of this file, which you should use when developing your programs. You need to use the queueing system, or log in on an interactive node if you are just doing &amp;quot;small stuff&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
All NGS fastq files are horrendously big. This is why they are always compressed. When working with these kind of files, you always use (de)compression, simply to save disk space. If you can manage to (de)compress on the fly (this means decompressing while reading) you might even save time since the file is being read compressed (i.e. small) and unfolds directly in RAM on the computer. The (de)compression takes CPU time and the reading/writing takes IO time.&lt;br /&gt;
&lt;br /&gt;
The content of the file looks like these 4 lines repeated a lot:&lt;br /&gt;
&lt;br /&gt;
 @ST-K00127:16:H32JKBBXX:8:1101:1111:1246 1:N:0:&amp;lt;font color=&amp;quot;FF0000&amp;quot;&amp;gt;AGCCATGC&amp;lt;/font&amp;gt;&lt;br /&gt;
 NAAAAGGCTCGACGCCTGTTATTATCGGAGTAGAACCGGAAATATCCGGATTAAGTTTTTCAGATCGGAAGAGCACACGTCTGAACTCCAGTCACAGCCA&lt;br /&gt;
 +&lt;br /&gt;
 #AAFFKKKKKKKKKKFK&amp;lt;KFKKKKKKKKFKFFKKKKKKKKKKKKKKKKK7FKKKKKKKKK&amp;lt;FF&amp;lt;KKKKKKKFKKKKKKKKKKKKKKKKKKKKKKKKKKKK&lt;br /&gt;
This is called a read. The lines are in order: header line, sequence, comment line (usually empty, just a +) and quality score. There is a char on the quality score for each base in the sequence, i.e. sequence and quality lines have the same length.&lt;br /&gt;
&lt;br /&gt;
The file contains microbiome sequencing data from a number of persons. This is common practice. Each person has a unique barcode, which is the red DNA string in the header.&lt;br /&gt;
&lt;br /&gt;
The act of splitting the file up in several files - one for each person - is called demultiplexing. We will be doing this in next exercise.&lt;br /&gt;
&lt;br /&gt;
Any current sequencing technology creates sequencing errors. The barcode can actually be sequenced wrong, not just the dna in the read. This means that some of the reads in the file belongs to people we can not identify.&lt;br /&gt;
&lt;br /&gt;
Your job in this exercise is therefore to identify which barcodes are real, and which are due to sequencing errors. The erronous barcodes and their data are simply discarded. You can assume that ”right” barcodes occur much more frequently than ”wrong” barcodes, but it is also true that there can be a significant difference in the frequency of &amp;quot;right&amp;quot; barcodes.&amp;lt;br&amp;gt;&lt;br /&gt;
Another strong/useful observation is that barcodes are &amp;quot;spread&amp;quot; across the spectrum. The distance from a real barcode to another real barcode is big. The distance is counted as bases that do not match at the same position in the barcodes.&lt;br /&gt;
 Real: CACTTCGA&lt;br /&gt;
 Real: TGAAGAGA&lt;br /&gt;
 Distance: 6&lt;br /&gt;
The distance between a real barcode and one that is sequenced wrong in one base is obviously 1.&lt;br /&gt;
 Real:  CACTTCGA&lt;br /&gt;
 Error: TACTTCGA&lt;br /&gt;
 Distance: 1&lt;br /&gt;
This means that it is possible to assign some of the sequences to the right barcode even if the barcode is sequenced wrong. You are not required to do so in these exercises, but it is good to remember this in real life.&lt;br /&gt;
&lt;br /&gt;
Be careful in how much CPU time you are using to solve the task.&lt;br /&gt;
&lt;br /&gt;
You must report&lt;br /&gt;
 The program&lt;br /&gt;
 A list (file) of correct barcodes.&lt;br /&gt;
 Report the number of persons.&lt;br /&gt;
&lt;br /&gt;
For your benefit, I have made a function that opens a gzipped file, like the ngs file.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import gzip, sys&lt;br /&gt;
def openfile(filename):&lt;br /&gt;
    try:&lt;br /&gt;
        if filename.endswith(&#039;.gz&#039;):&lt;br /&gt;
            fh = gzip.open(filename, mode=&#039;rb&#039;)&lt;br /&gt;
        else:&lt;br /&gt;
            fh = open(filename, &#039;rb&#039;)&lt;br /&gt;
    except:&lt;br /&gt;
        print(&amp;quot;Can&#039;t open file:&amp;quot;, filename)&lt;br /&gt;
    return fh&lt;br /&gt;
&lt;br /&gt;
myfilehandle = openfile(&#039;mygzippedfile.gz&#039;)&lt;br /&gt;
for line in myfilehandle:&lt;br /&gt;
    print(line)&lt;br /&gt;
myfilehandle.close()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&lt;br /&gt;
Now that you have a list of correct barcodes, your task is to write a program that can demultiplex the ngs1.fastq.gz and save the resulting fastq files.&lt;br /&gt;
This could be combined with the previous exercise.&lt;br /&gt;
&lt;br /&gt;
You need to focus on performance and disk space. &lt;br /&gt;
This means that the solution to the problem contains a jobscript (for submission to the queueing system) and likely a program or two, which handles the various aspects of the job.&amp;lt;br&amp;gt;&lt;br /&gt;
Hint: you might look into the &#039;&#039;&#039;Popen&#039;&#039;&#039; call in &#039;&#039;&#039;subprocess&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
You need to report the following:&lt;br /&gt;
&lt;br /&gt;
 Your programs.&lt;br /&gt;
 How much disk space are you using to store your results?&lt;br /&gt;
 How long time did it take to complete the job?&lt;br /&gt;
&lt;br /&gt;
When you are done, delete your results to conserve disk space.&lt;br /&gt;
 My numbers are: 30 GB and 97 minutes.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=140</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=140"/>
		<updated>2025-09-23T11:45:00Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&amp;lt;br&amp;gt;&lt;br /&gt;
According to my results: 262 people are born out of wedlock. That is amazing as it is out of 500 people.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key auto_increment), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), stamp (timestamp) default CURRENT_TIMESTAMP, which means the timestamp is automatically created when the message is inserted. You only have the ability to read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=139</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=139"/>
		<updated>2025-09-21T11:40:42Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&amp;lt;br&amp;gt;&lt;br /&gt;
According to my results: 262 people are born out of wedlock. That is amazing as it is out of 500 people.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key auto_increment), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), stamp (timestamp). You only have the ability to read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=138</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=138"/>
		<updated>2025-09-21T11:35:49Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&amp;lt;br&amp;gt;&lt;br /&gt;
According to my results: 262 people are born out of wedlock.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key auto_increment), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), stamp (timestamp). You only have the ability to read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=137</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=137"/>
		<updated>2025-09-21T09:55:53Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key auto_increment), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), stamp (timestamp). You only have the ability to read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is something:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As you hopefully can see, this structure makes it easy to start small with simple things and build up with new expanded functionality.&lt;br /&gt;
&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
/last &amp;lt;X&amp;gt;               Pull last X messages from the chosen channel and display.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=136</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=136"/>
		<updated>2025-09-21T08:03:04Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key auto_increment), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), stamp (timestamp). You only have the ability to read the table and insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=135</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=135"/>
		<updated>2025-09-21T07:54:48Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key auto_increment), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), stamp (timestamp). You only have the ability to insert new rows in the table - that is - create new messages. Only the moderator can delete messages.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=134</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=134"/>
		<updated>2025-09-21T06:38:30Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key auto_increment), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), stamp (timestamp). You only have the ability to insert new rows in the table - that is - create new messages. Only the moderator can delete messages. &#039;&#039;&#039;This database and table is NOT CREATED YET.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;stamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=133</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=133"/>
		<updated>2025-09-21T06:26:58Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key autoincrement), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), timestamp (timestamp). You only have the ability to insert new rows in the table - that is - create new messages. Only the moderator can delete messages. &#039;&#039;&#039;This database and table is NOT CREATED YET.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;timestamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=132</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=132"/>
		<updated>2025-09-21T06:26:34Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key autoincrement), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), timestamp (timestamp). You only have the ability to insert new rows in the table - that is - create new messages. Only the moderator can delete messages. &#039;&#039;&#039;This database and table is NOT CREATED YET.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;timestamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&lt;br /&gt;
If anybody posted a calculation, it could compute the result and post it - just like google.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=131</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=131"/>
		<updated>2025-09-21T06:24:30Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key autoincrement), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), timestamp (timestamp). You only have the ability to insert new rows in the table - that is - create new messages. Only the moderator can delete messages. &#039;&#039;&#039;This database and table is NOT CREATED YET.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;timestamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course. Once you get the the SSH tunneling set up, you just run your client from home/your laptop. How can it get any better?&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=130</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=130"/>
		<updated>2025-09-21T06:22:52Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key autoincrement), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), timestamp (timestamp). You only have the ability to insert new rows in the table - that is - create new messages. Only the moderator can delete messages. &#039;&#039;&#039;This database and table is NOT CREATED YET.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;timestamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas for bots.&lt;br /&gt;
&lt;br /&gt;
The fun part of this exercise is you can use the Chat Board for the rest of the course, once you made the client. You can even develop your client and/or bot more in the progress of the course.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=129</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=129"/>
		<updated>2025-09-21T06:17:21Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key autoincrement), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), timestamp (timestamp). You only have the ability to insert new rows in the table - that is - create new messages. Only the moderator can delete messages. &#039;&#039;&#039;This database and table is NOT CREATED YET.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;timestamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;Your dream, pal, your vision.&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=128</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=128"/>
		<updated>2025-09-21T06:12:00Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key autoincrement), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), timestamp (timestamp). You only have the ability to insert new rows in the table - that is - create new messages. Only the moderator can delete messages. &#039;&#039;&#039;This database and table is NOT CREATED YET.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;timestamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
Your dream, pal, your vision.&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&amp;lt;br&amp;gt;&lt;br /&gt;
It could copy other posters - simply repeating their message.&amp;lt;br&amp;gt;&lt;br /&gt;
It could advertise an event across all channels.&amp;lt;br&amp;gt;&lt;br /&gt;
It could have a list of people&#039;s birthdays, and when the day came about, post &amp;quot;Today is X&#039;s birthday&amp;quot; on the common channel.&lt;br /&gt;
&lt;br /&gt;
I think that was enough ideas.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=127</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=127"/>
		<updated>2025-09-21T06:05:40Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key autoincrement), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), timestamp (timestamp). You only have the ability to insert new rows in the table - that is - create new messages. Only the moderator can delete messages. &#039;&#039;&#039;This database and table is NOT CREATED YET.&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;timestamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;br /&gt;
&lt;br /&gt;
When you have done your ChatClient you have accumulated enough experience to create a ChatBot. What should the bot do?&amp;lt;br&amp;gt;&lt;br /&gt;
Your dream, pal, your vision.&amp;lt;br&amp;gt;&lt;br /&gt;
It could behave like a dog; search for a random or specific user, and bark at them or pee on them.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the latest message and add &#039;That is what she said yesterday&#039;.&amp;lt;br&amp;gt;&lt;br /&gt;
It could be more clever and consult external AI and generate a one-line answer/comment.&amp;lt;br&amp;gt;&lt;br /&gt;
It could find the quote of the day and post on the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
It could camp on the &#039;Dreams&#039; channel and say to every new poster: &amp;quot;Tell me about your dreams!&amp;quot;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=126</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=126"/>
		<updated>2025-09-21T05:49:58Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key autoincrement), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), timestamp (timestamp). This database and table is NOT CREATED YET.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;timestamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit                   Quits the program, possibly leaving a message.&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;  Selects/creates the channel for your messages.&lt;br /&gt;
/showchannels           Shows possible channels.&lt;br /&gt;
/trueid                 Sets your name to your login name.&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;        Sets your name to &amp;lt;nickname&amp;gt;.&lt;br /&gt;
/activity               Which channels had the latest messages, and when.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search for messages by the person. &#039;&#039;/who&#039;&#039;, which would show who has messages. &#039;&#039;/dance&#039;&#039;, which displays a message &amp;quot;&amp;lt;yourname&amp;gt; is dancing for you&amp;quot;. You dream it up - it is your chat client and the more powerful and funny it is, the better chances of you being the next Mark Zuckerberg.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=125</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=125"/>
		<updated>2025-09-21T05:40:14Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board ===&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key autoincrement), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default &#039;common&#039;), timestamp (timestamp). This database and table is NOT CREATED YET.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. Ask google if you don&#039;t know what a chat channel is. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;timestamp&#039;&#039; is when the message is created. This is used for selecting the newest messages and deleting the old.&lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last messages and show&lt;br /&gt;
get a one-line input&lt;br /&gt;
while input is not quit:&lt;br /&gt;
    if input is command1:&lt;br /&gt;
        do commmand1 code&lt;br /&gt;
    elif input is command2:&lt;br /&gt;
        do command2 code&lt;br /&gt;
    elif input is nothing:&lt;br /&gt;
        pass&lt;br /&gt;
    else:&lt;br /&gt;
        input was a message, so post it to the chat board&lt;br /&gt;
    pull chat board for new messages and display them if any&lt;br /&gt;
    get next online input&lt;br /&gt;
close database connection&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
A command is an input where the first word starts with slash possibly followed by a parameter. Anything else is just a message to be posted on the selected channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;b&amp;gt;List of commands:&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/quit&lt;br /&gt;
/channel &amp;lt;channelname&amp;gt;&lt;br /&gt;
/showchannels&lt;br /&gt;
/trueid&lt;br /&gt;
/nick &amp;lt;nickname&amp;gt;&lt;br /&gt;
/activity&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can implement your own commands, like &#039;&#039;/search &amp;lt;name&amp;gt;&#039;&#039;, which would search&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=124</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=124"/>
		<updated>2025-09-21T05:12:09Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;br /&gt;
&lt;br /&gt;
=== Totally optional extra exercise I invented in my dreams Sunday morning: The Chat Board&lt;br /&gt;
This is a fun cooperative exercise with databases. You should all make your own Chat client, where you can communicate with the other course participants. The exercise utilizes the concurrent features of databases - the easy update without worry if somebody else is accessing the database at the same time.&lt;br /&gt;
&lt;br /&gt;
You use a database called &#039;&#039;chatboard&#039;&#039; that is common to you all. In that database there will be just one table, &#039;&#039;messages&#039;&#039; with the fields; id (primary key autoincrement), mesg (varchar(500)), name (varchar(15), default NULL), channel (varchar(12), default NULL), timestamp (timestamp). This database and table is NOT CREATED YET.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;mesg&#039;&#039; is the message on the chat.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;name&#039;&#039; is name of the message sender. If NULL, then it is anonymous.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;channel&#039;&#039; is the channel for this message. You make a subject a group of people with this. If NULL, it is the common channel.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;timestamp&#039;&#039; is when the message is created. &lt;br /&gt;
&lt;br /&gt;
The Chat client you make should have the following structure.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
connect to database chatboard&lt;br /&gt;
pull last&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Distributed_computing&amp;diff=123</id>
		<title>Distributed computing</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Distributed_computing&amp;diff=123"/>
		<updated>2025-09-20T20:05:34Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Queueing System]]&lt;br /&gt;
|Next: [[What affects performance]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a67ca717-9598-4169-9b52-af2701246519 Distributed computing]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=e99121a6-df37-4d45-9891-af2701243c8a Profiling and subprocess]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_06-Distributed.ppt Distributed computing]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=88d328c4-990a-4ce7-80cb-af1700719959 Exercises]&lt;br /&gt;
&lt;br /&gt;
[https://evaluering.dtu.dk/ Do midterm evaluation] &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;lt;-- Important to do this week - Friday latest&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Using the Queueing System to do distributed computing. &#039;&#039;&#039;Warning&#039;&#039;&#039;: The most difficult part of these exercises is actually using the Queueing System. The python code itself is fairly easy, but getting the QS to work requires patience and experience. Check the QS examples in the powerpoint from last lecture. Don&#039;t be afraid to consult the &#039;&#039;man&#039;&#039; pages on a slurm command. Great options are hidden there, f.ex how to get rid of header on output.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Return to last time’s exercise; read a fasta file, find the reverse complement for each entry and count the bases in the entry putting the numbers in the header line and save it all in one file.&lt;br /&gt;
Now solve this using the method on slide 5, i.e. distributed programming in embarrassingly parallel fashion.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Test your programs on the small scale humantest.fsa file.&#039;&#039;&#039; When ready try the real human.fsa.&lt;br /&gt;
&lt;br /&gt;
You have to make several programs; the administrator, the worker and the collector.&lt;br /&gt;
&lt;br /&gt;
The administrator splits up the original input fasta file into several pieces (one fasta sequence per piece) and submits a job per piece (the worker) with the relevant file piece as input.&lt;br /&gt;
The worker which reads a file with one fasta sequence (given), computes the complement strand and base count and outputs the result to a file (given).&lt;br /&gt;
The collector program that collects all the result pieces and put them together in the original order in one file. This you run by yourself after the worker jobs finished. The structure of the administrator is like&lt;br /&gt;
 foreach fastasequence in inputfile&lt;br /&gt;
     save fastasequence in file.x&lt;br /&gt;
     submit job with file.x&lt;br /&gt;
By naming/numbering the files in some systematic way, it is easier to collect them afterwards. Realize that you can test your code without using the QS, by simply running the worker directly. Also understand that this is an exercise in using the Queueing System, not in simple programming.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
In order to lighten your workload and lessen the confusion and grief the Queueing System can give you, I have made a a fairly general &#039;&#039;&#039;submit to QS&#039;&#039;&#039; python function for you to use if you wish.&lt;br /&gt;
The command you submit is a string (which you can construct), and the command itself. The command must be a &amp;quot;simple&amp;quot; one meaning a program with options and parameters as you would write it on the command line.&lt;br /&gt;
It does not offer the the convenience of the shell, meaning that piping, IO-redirection and wildcards does not work. Realize that a great source of error is not using full path to programs and files.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def submit(command, directory=&#039;&#039;, modules=&#039;&#039;, runtime, cores, ram, group=&#039;pr_course&#039;,&lt;br /&gt;
    jobscript=&#039;jobscript&#039;, output=&#039;/dev/null&#039;, error=&#039;/dev/null&#039;):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Function to submit a job to the Queueing System - with jobscript file&lt;br /&gt;
    Parameters are:&lt;br /&gt;
    command:   The command/program you want executed together with any parameters.&lt;br /&gt;
               Must use full path unless the directory is given and program is there. &lt;br /&gt;
    directory: Working directory - where should your program run, place of your data.&lt;br /&gt;
               If not specified, uses current directory.&lt;br /&gt;
    modules:   String of space separated modules needed for the run.&lt;br /&gt;
    runtime:   Time in minutes set aside for execution of the job.&lt;br /&gt;
    cores:     How many cores are used for the job.&lt;br /&gt;
    ram:       How much memory in GB is used for the job.&lt;br /&gt;
    group:     Accounting - which group pays for the compute.&lt;br /&gt;
    jobscript: Standard name for the jobscript that needs to be made.&lt;br /&gt;
               You should number your jobscripts if you submit more than one.&lt;br /&gt;
    output:    Output file of your job.&lt;br /&gt;
    error:     Error file of your job.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    runtime = int(runtime)&lt;br /&gt;
    cores = int(cores)&lt;br /&gt;
    ram = int(ram)&lt;br /&gt;
    if cores &amp;gt; 10:&lt;br /&gt;
        print(&amp;quot;Can&#039;t use more than 10 cores on a node&amp;quot;)&lt;br /&gt;
        sys.exit(1)&lt;br /&gt;
    if ram &amp;gt; 120:&lt;br /&gt;
        print(&amp;quot;Can&#039;t use more than 120 GB on a node&amp;quot;)&lt;br /&gt;
        sys.exit(1)&lt;br /&gt;
    if runtime &amp;lt; 1:&lt;br /&gt;
        print(&amp;quot;Must allocate at least 1 minute runtime&amp;quot;)&lt;br /&gt;
        sys.exit(1)&lt;br /&gt;
    minutes = runtime % 60&lt;br /&gt;
    hours = int(runtime/60)&lt;br /&gt;
    walltime = &amp;quot;{:d}:{:02d}:00&amp;quot;.format(hours, minutes)&lt;br /&gt;
    if directory == &#039;&#039;:&lt;br /&gt;
        directory = os.getcwd()&lt;br /&gt;
    # Making a jobscript&lt;br /&gt;
    script = &#039;#!/bin/sh\n&#039;&lt;br /&gt;
    script += &#039;#PBS -A &#039; + group + &#039; -W group_list=&#039; + group + &#039;\n&#039;&lt;br /&gt;
    script += &#039;#PBS -e &#039; + error + &#039; -o &#039; + output + &#039;\n&#039;&lt;br /&gt;
    script += &#039;#PBS -d &#039; + directory + &#039;\n&#039;&lt;br /&gt;
    script += &#039;#PBS -l nodes=1:ppn=&#039; + str(cores) + &#039;,mem=&#039; + str(ram) + &#039;GB&#039; + &#039;\n&#039;&lt;br /&gt;
    script += &#039;#PBS -l walltime=&#039; + walltime + &#039;\n&#039;&lt;br /&gt;
    if modules != &#039;&#039;:&lt;br /&gt;
        script += &#039;module load &#039; + modules + &#039;\n&#039;&lt;br /&gt;
    script += command + &#039;\n&#039;&lt;br /&gt;
    if not jobscript.startswith(&#039;/&#039;):&lt;br /&gt;
        jobscript = directory + &#039;/&#039; + jobscript&lt;br /&gt;
    with open(jobscript, &#039;wt&#039;) as jobfile:&lt;br /&gt;
        jobfile.write(script)&lt;br /&gt;
    # The submit&lt;br /&gt;
    job = subprocess.run([&#039;qsub&#039;, jobscript],stdout=subprocess.PIPE, universal_newlines=True) &lt;br /&gt;
    jobid = job.stdout.split(&#039;.&#039;)[0]&lt;br /&gt;
    return jobid&lt;br /&gt;
&lt;br /&gt;
def submit2(command, directory=&#039;&#039;, modules=&#039;&#039;, runtime, cores, ram, group=&#039;pr_course&#039;,&lt;br /&gt;
    output=&#039;/dev/null&#039;, error=&#039;/dev/null&#039;):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Function to submit a job to the Queueing System - without jobscript file&lt;br /&gt;
    Parameters are:&lt;br /&gt;
    command:   The command/program you want executed together with any parameters.&lt;br /&gt;
               Must use full path unless the directory is given and program is there. &lt;br /&gt;
    directory: Working directory - where should your program run, place of your data.&lt;br /&gt;
               If not specified, uses current directory.&lt;br /&gt;
    modules:   String of space separated modules needed for the run.&lt;br /&gt;
    runtime:   Time in minutes set aside for execution of the job.&lt;br /&gt;
    cores:     How many cores are used for the job.&lt;br /&gt;
    ram:       How much memory in GB is used for the job.&lt;br /&gt;
    group:     Accounting - which group pays for the compute.&lt;br /&gt;
    output:    Output file of your job.&lt;br /&gt;
    error:     Error file of your job.&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    runtime = int(runtime)&lt;br /&gt;
    cores = int(cores)&lt;br /&gt;
    ram = int(ram)&lt;br /&gt;
    if cores &amp;gt; 10:&lt;br /&gt;
        print(&amp;quot;Can&#039;t use more than 10 cores on a node&amp;quot;)&lt;br /&gt;
        sys.exit(1)&lt;br /&gt;
    if ram &amp;gt; 120:&lt;br /&gt;
        print(&amp;quot;Can&#039;t use more than 120 GB on a node&amp;quot;)&lt;br /&gt;
        sys.exit(1)&lt;br /&gt;
    if runtime &amp;lt; 1:&lt;br /&gt;
        print(&amp;quot;Must allocate at least 1 minute runtime&amp;quot;)&lt;br /&gt;
        sys.exit(1)&lt;br /&gt;
    minutes = runtime % 60&lt;br /&gt;
    hours = int(runtime/60)&lt;br /&gt;
    walltime = &amp;quot;{:d}:{:02d}:00&amp;quot;.format(hours, minutes)&lt;br /&gt;
    if directory == &#039;&#039;:&lt;br /&gt;
        directory = os.getcwd()&lt;br /&gt;
    # Making a jobscript&lt;br /&gt;
    script = &#039;#!/bin/sh\n&#039;&lt;br /&gt;
    script += &#039;#PBS -A &#039; + group + &#039; -W group_list=&#039; + group + &#039;\n&#039;&lt;br /&gt;
    script += &#039;#PBS -e &#039; + error + &#039; -o &#039; + output + &#039;\n&#039;&lt;br /&gt;
    script += &#039;#PBS -d &#039; + directory + &#039;\n&#039;&lt;br /&gt;
    script += &#039;#PBS -l nodes=1:ppn=&#039; + str(cores) + &#039;,mem=&#039; + str(ram) + &#039;GB&#039; + &#039;\n&#039;&lt;br /&gt;
    script += &#039;#PBS -l walltime=&#039; + walltime + &#039;\n&#039;&lt;br /&gt;
    if modules != &#039;&#039;:&lt;br /&gt;
        script += &#039;module load &#039; + modules + &#039;\n&#039;&lt;br /&gt;
    script += command + &#039;\n&#039;&lt;br /&gt;
    # The submit&lt;br /&gt;
    job = subprocess.run([&#039;qsub&#039;], input=script, stdout=subprocess.PIPE, universal_newlines=True) &lt;br /&gt;
    jobid = job.stdout.split(&#039;.&#039;)[0]&lt;br /&gt;
    return jobid&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Is used like&lt;br /&gt;
jobid = submit(&#039;myprogram myfile.fsa&#039;, directory=&#039;/home/projects/pr_course/people/pwsa&#039;,&lt;br /&gt;
               modules=&#039;tools anaconda3/4.0.0&#039;, jobscript=&#039;job.1&#039;,  runtime=10, cores=1, ram=2)&lt;br /&gt;
jobid = submit2(&#039;myprogram myfile.fsa&#039;, directory=&#039;/home/projects/pr_course/people/pwsa&#039;,&lt;br /&gt;
                modules=&#039;tools anaconda3/4.0.0&#039;, runtime=10, cores=1, ram=2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can make almost the entire program on your own laptop if you substitute the below function with above function. Below just calls the worker sequentially not using the QS. You loose all the distribution the QS offers,&lt;br /&gt;
but avoid using computerome (and waiting for time). It is great in the development phase.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Submit to the queueing system, runtime in minutes, ram in GB&lt;br /&gt;
def unix_call(command):&lt;br /&gt;
    job = subprocess.run(command.split()) &lt;br /&gt;
&lt;br /&gt;
# Is used like&lt;br /&gt;
unix_call(&#039;myprogram myfile.fsa&#039;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Make the administrator and collector into one program. &lt;br /&gt;
 foreach fastasequence in inputfile&lt;br /&gt;
     save fastasequence in file.x&lt;br /&gt;
     submit job with file.x&lt;br /&gt;
 wait for all jobs to finish&lt;br /&gt;
 collect data&lt;br /&gt;
&lt;br /&gt;
It is more difficult to solve this exercise - so do number 1 first. You need to find a way of waiting for your worker jobs to be done before your start collecting. However, you can see if this distributed method is faster than last week’s sequential method.&lt;br /&gt;
&lt;br /&gt;
Some ideas to wait for the jobs to be done.&lt;br /&gt;
* Waiting and checking for all output files to appear. Cons; If a worker job breaks during execution you wait forever since the output file does not appear. If the output file is big, The worker might not have finished writing to it before collection starts. A trick to avoid this is for the worker to make an extra empty file at the end of the job and check for the presence of that file. An alternative is to write the file using a temporary filename, and rename the file to the correct name, when done writing.&lt;br /&gt;
* Using &#039;&#039;&#039;squeue&#039;&#039;&#039; to check that the jobs are gone from the queue. You need to find a way to recognize your jobs. That can be to name them or get the jobid from when you submit the job or perhaps just show your jobs (not everybody’s). When the list is empty, you are done. Cons; If you submit fast enough, the jobs might not have had time enough to show up in the queue, misleading you to think you are done. If you just use the ”your own jobs” method, you can only run one main job at a time, i.e. compute on one project only.&lt;br /&gt;
* Using &#039;&#039;&#039;sacct&#039;&#039;&#039; to show completed jobs. When your jobs are in the list, they are done.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=122</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=122"/>
		<updated>2025-09-19T14:19:57Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3306 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Programme&amp;diff=121</id>
		<title>Programme</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Programme&amp;diff=121"/>
		<updated>2025-09-18T17:21:28Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* 04/09 Lesson 1: [[Databases]]&lt;br /&gt;
* 11/09 Lesson 2: [[MySQL]]&lt;br /&gt;
* 18/09 Lesson 3: [[Coding against databases]]&lt;br /&gt;
* 25/09 Lesson 4: [[Computer design]]&lt;br /&gt;
* 02/10 Lesson 5: [[Queueing System]]&lt;br /&gt;
* 09/10 Lesson 6: [[Distributed computing]], [https://evaluering.dtu.dk/ Midterm evaluation] - part 1&lt;br /&gt;
* Fall holidays&lt;br /&gt;
* 23/10 Lesson 7: [[What affects performance]], [https://evaluering.dtu.dk/ Midterm evaluation] - part 2&lt;br /&gt;
* 30/10 Lesson 8: [[Algorithms]]&lt;br /&gt;
* 06/11 Lesson 9: [[Parallel programming]]&lt;br /&gt;
* 13/11 Lesson 10: [[More parallelism]]&lt;br /&gt;
* 20/11 Lesson 11: [[Binary representation]]&lt;br /&gt;
* 27/11 Lesson 12: [[Hash usage]]&lt;br /&gt;
* 04/12 Lesson 13: [[Exercises and Organization]]&lt;br /&gt;
* 09/12 Exam - [http://eksamensplan.dtu.dk/ the official DTU exam plan] [https://student.dtu.dk/eksamen/eksamensdatoer Exam dates]&lt;br /&gt;
&lt;br /&gt;
== Curious about the exam ==&lt;br /&gt;
[https://teaching.healthtech.dtu.dk/22112/index.php/Aligning_expectations#About_the_exam Read here]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=120</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=120"/>
		<updated>2025-09-18T12:43:41Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3-2024.10-1/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3603 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=119</id>
		<title>Coding against databases</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Coding_against_databases&amp;diff=119"/>
		<updated>2025-09-17T19:27:06Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Exercises */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[MySQL]]&lt;br /&gt;
|Next: [[Computer design]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Note: The powerpoint has been updated with new library and transactions, but not the video.&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=a891e09a-bec1-4ab1-8869-af2701258352 Using Python with MySQL]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_03-CodingDB.ppt Coding with Databases]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=68d743a1-9691-4690-b3a9-af170071ba0d Exercises]&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create one or two programs that can answer the following questions about the database you created last lesson. The data is from 2016 and all records are &amp;quot;complete&amp;quot; for the time period they were collected in. Specifically, all children&#039;s parents are in the database until we go so far back that records did not exists (the information is lost in the mists of time).&amp;lt;br&amp;gt;&lt;br /&gt;
The programs should run on the server &#039;&#039;&#039;pupil1&#039;&#039;&#039;, not your own machine.&amp;lt;br&amp;gt;&lt;br /&gt;
The mysql connect call looks like this.&amp;lt;br&amp;gt;&lt;br /&gt;
cnx = mysql.connector.connect(user=&#039;DTUusername&#039;, passwd=&#039;YOUR_PASSWORD&#039;, db=&#039;DTUusername&#039;, host=&#039;localhost&#039;)&amp;lt;br&amp;gt;&lt;br /&gt;
You can find your password in the .my.cnf file in your home.&amp;lt;br&amp;gt;&lt;br /&gt;
You will mostly use python to solve the exercises. It is not intended that you use advanced mysql queries, but feel free.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Note, use this python: /home/ctools/anaconda3_2021.11/bin/python3&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;1)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Who are born out of wedlock? Definition: A child is born out of wedlock if the biological father and mother is not married when the child is born. In the absence of information, you can not claim a child is born out of wedlock (that means if you only know the mother from the database, you can not claim the child is a bastard).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2)&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Are there families who have had the same disease through 3 generations? Who and what disease in such case? It is not a trick question - you will find some.&amp;lt;br&amp;gt;&lt;br /&gt;
In answering this question, then any type of cancer should just be regarded as cancer, i.e. the same disease (this is not true in reality). 3 generations should be understood as a ”straight line of inheritance”, i.e. child, father, father’s father/mother. Child, mother and father’s father is not straight.&lt;br /&gt;
&lt;br /&gt;
If you look closely at your results, you will find some very interesting family patterns - such is the curse of (badly) generated data.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;3) Somewhat optional&#039;&#039;&#039;&amp;lt;br&amp;gt;&lt;br /&gt;
Run your programs again, but this time locally on your laptop, while you use the database on the server.&amp;lt;br&amp;gt;&lt;br /&gt;
This is an interesting challenge, which can be solved by SSH tunneling the mysql port 3603 to the server. The requirements for solving the exercise is understanding and setting up proper SSH tunneling as taught in lesson 1, and that mysql.connector is locally installed in your python distribution.&lt;br /&gt;
In principle, this is done by 1 unix command setting up the SSH tunnel.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Programme&amp;diff=118</id>
		<title>Programme</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Programme&amp;diff=118"/>
		<updated>2025-08-11T09:14:42Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* 04/09 Lesson 1: [[Databases]]&lt;br /&gt;
* 11/09 Lesson 2: [[MySQL]]&lt;br /&gt;
* 18/09 Lesson 3: [[Coding against databases]]&lt;br /&gt;
* 25/09 Lesson 4: [[Computer design]]&lt;br /&gt;
* 02/10 Lesson 5: [[Queueing System]]&lt;br /&gt;
* 09/10 Lesson 6: [[Distributed computing]], [https://evaluering.dtu.dk/ Midterm evaluation] - part 1&lt;br /&gt;
* Fall holidays&lt;br /&gt;
* 23/10 Lesson 7: [[What affects performance]], [https://evaluering.dtu.dk/ Midterm evaluation] - part 2&lt;br /&gt;
* 30/10 Lesson 8: [[Algorithms]]&lt;br /&gt;
* 06/11 Lesson 9: [[Parallel programming]]&lt;br /&gt;
* 13/11 Lesson 10: [[More parallelism]]&lt;br /&gt;
* 20/11 Lesson 11: [[Binary representation]]&lt;br /&gt;
* 27/11 Lesson 12: [[Hash usage]]&lt;br /&gt;
* 04/12 Lesson 13: [[Exercises and Organization]]&lt;br /&gt;
* 09/12 Exam - [http://eksamensplan.dtu.dk/ the official DTU exam plan]&lt;br /&gt;
&lt;br /&gt;
== Curious about the exam ==&lt;br /&gt;
[https://teaching.healthtech.dtu.dk/22112/index.php/Aligning_expectations#About_the_exam Read here]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=117</id>
		<title>22112 High Performance Computing in Life Science</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=117"/>
		<updated>2025-08-11T09:11:57Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Earlier programmes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&#039;&#039;&#039;Teacher:&#039;&#039;&#039; [https://www.inside.dtu.dk/da/dtuinside/generelt/telefonbog/person?id=816&amp;amp;cpid=214027&amp;amp;tab=2&amp;amp;qt=dtupublicationquery Peter Wad Sackett], pwsa@dtu.dk &amp;lt;!--, [https://www.inside.dtu.dk/en/dtuinside/generelt/telefonbog/person?id=130596&amp;amp;tab=0 Gisle Alberg Vestergaard], gisves@dtu.dk --&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Language:&#039;&#039;&#039; The course is taught in English.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Tools:&#039;&#039;&#039; Various servers will be introduced.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Textbooks:&#039;&#039;&#039; There are no text books for the course. I will make do with powerpoints, videos and references to online resources. You can find the material under the individual lessons in the [[Programme]].&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Location:&#039;&#039;&#039; Building 208, room 001.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Time:&#039;&#039;&#039; Thursday 13:00 - 17:00, module E1-B.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Course details ==&lt;br /&gt;
The course is a practical introduction to working with supercomputers in Life Science. Using both &amp;quot;ordinary&amp;quot; laptops and computer clusters as a basis for lectures and exercises, we will cover subjects such as computer design, queueing systems, distributed computing, algorithms, parallel programming, performance and performance dependencies, database design and use, and practical organization of projects.&lt;br /&gt;
&lt;br /&gt;
{| &lt;br /&gt;
|-&lt;br /&gt;
| [[Aligning expectations]] || Mandatory read at course start&lt;br /&gt;
|-&lt;br /&gt;
| [[Programme]] || Fall 2024&lt;br /&gt;
|-&lt;br /&gt;
| [[Computerome]] || Some info on Computerome&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Earlier programmes ==&lt;br /&gt;
[[Programme Fall 2023]]&amp;lt;br&amp;gt;&lt;br /&gt;
[[Programme Fall 2024]]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Programme_Fall_2024&amp;diff=116</id>
		<title>Programme Fall 2024</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Programme_Fall_2024&amp;diff=116"/>
		<updated>2025-08-11T09:11:41Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot;* 05/09 Lesson 1: Databases * 12/09 Lesson 2: MySQL * 19/09 Lesson 3: Coding against databases * 26/09 Lesson 4: Computer design * 03/10 Lesson 5: Queueing System * 10/10 Lesson 6: Distributed computing, [https://evaluering.dtu.dk/ Midterm evaluation] - part 1 * Fall holidays * 24/10 Lesson 7: What affects performance, [https://evaluering.dtu.dk/ Midterm evaluation] - part 2 * 31/10 Lesson 8: Algorithms * 07/11 Lesson 9: Parallel program...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* 05/09 Lesson 1: [[Databases]]&lt;br /&gt;
* 12/09 Lesson 2: [[MySQL]]&lt;br /&gt;
* 19/09 Lesson 3: [[Coding against databases]]&lt;br /&gt;
* 26/09 Lesson 4: [[Computer design]]&lt;br /&gt;
* 03/10 Lesson 5: [[Queueing System]]&lt;br /&gt;
* 10/10 Lesson 6: [[Distributed computing]], [https://evaluering.dtu.dk/ Midterm evaluation] - part 1&lt;br /&gt;
* Fall holidays&lt;br /&gt;
* 24/10 Lesson 7: [[What affects performance]], [https://evaluering.dtu.dk/ Midterm evaluation] - part 2&lt;br /&gt;
* 31/10 Lesson 8: [[Algorithms]]&lt;br /&gt;
* 07/11 Lesson 9: [[Parallel programming]]&lt;br /&gt;
* 14/11 Lesson 10: [[More parallelism]]&lt;br /&gt;
* 21/11 Lesson 11: [[Binary representation]]&lt;br /&gt;
* 28/11 Lesson 12: [[Hash usage]]&lt;br /&gt;
* 05/12 Lesson 13: [[Exercises and Organization]]&lt;br /&gt;
* 09/12 Exam - [http://eksamensplan.dtu.dk/ the official DTU exam plan]&lt;br /&gt;
&lt;br /&gt;
== Curious about the exam ==&lt;br /&gt;
[https://teaching.healthtech.dtu.dk/22112/index.php/Aligning_expectations#About_the_exam Read here]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=115</id>
		<title>22112 High Performance Computing in Life Science</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=115"/>
		<updated>2025-08-11T09:11:08Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Earlier programmes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&#039;&#039;&#039;Teacher:&#039;&#039;&#039; [https://www.inside.dtu.dk/da/dtuinside/generelt/telefonbog/person?id=816&amp;amp;cpid=214027&amp;amp;tab=2&amp;amp;qt=dtupublicationquery Peter Wad Sackett], pwsa@dtu.dk &amp;lt;!--, [https://www.inside.dtu.dk/en/dtuinside/generelt/telefonbog/person?id=130596&amp;amp;tab=0 Gisle Alberg Vestergaard], gisves@dtu.dk --&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Language:&#039;&#039;&#039; The course is taught in English.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Tools:&#039;&#039;&#039; Various servers will be introduced.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Textbooks:&#039;&#039;&#039; There are no text books for the course. I will make do with powerpoints, videos and references to online resources. You can find the material under the individual lessons in the [[Programme]].&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Location:&#039;&#039;&#039; Building 208, room 001.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Time:&#039;&#039;&#039; Thursday 13:00 - 17:00, module E1-B.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Course details ==&lt;br /&gt;
The course is a practical introduction to working with supercomputers in Life Science. Using both &amp;quot;ordinary&amp;quot; laptops and computer clusters as a basis for lectures and exercises, we will cover subjects such as computer design, queueing systems, distributed computing, algorithms, parallel programming, performance and performance dependencies, database design and use, and practical organization of projects.&lt;br /&gt;
&lt;br /&gt;
{| &lt;br /&gt;
|-&lt;br /&gt;
| [[Aligning expectations]] || Mandatory read at course start&lt;br /&gt;
|-&lt;br /&gt;
| [[Programme]] || Fall 2024&lt;br /&gt;
|-&lt;br /&gt;
| [[Computerome]] || Some info on Computerome&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Earlier programmes ==&lt;br /&gt;
[[Programme Fall 2023]]&lt;br /&gt;
[[Programme Fall 2024]]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=114</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=114"/>
		<updated>2025-08-06T21:00:25Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Material for the lesson */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
Note that the videos are no longer completely aligned with the powerpoints due to a shift in focus.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computerome&amp;diff=113</id>
		<title>Computerome</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computerome&amp;diff=113"/>
		<updated>2025-08-06T20:59:08Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Information on Computerome 2 and the Queueing System there */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Information on Computerome 2 and the Queueing System there ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=debcebae-c594-4daf-be11-af2701252f77 Computerome modules]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_Computerome2.ppt Computerome 2]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=d679e5c8-9372-4af7-9260-af270124ddf6 Introduction to the Queueing System]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=bca57da6-2c60-4218-96ac-af270124b673 Submitting jobs]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=e6e59e86-2928-4caf-b5c3-af2701248a3d Queue control and practical advice]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_ComputeromeQueue.ppt Queueing System]&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [https://www.computerome.dk/ Computerome 2 general information]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that only the powerpoints are up to date. The videos are not likely to be updated as this material has been removed from the course.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=112</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=112"/>
		<updated>2025-08-06T20:58:43Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Material for the lesson */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Computers.ppt Computer design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computerome&amp;diff=111</id>
		<title>Computerome</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computerome&amp;diff=111"/>
		<updated>2025-08-06T20:57:22Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Information on Computerome 2 and the Queueing System there ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=debcebae-c594-4daf-be11-af2701252f77 Computerome modules]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_Computerome2.ppt Computerome 2]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=d679e5c8-9372-4af7-9260-af270124ddf6 Introduction to the Queueing System]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=bca57da6-2c60-4218-96ac-af270124b673 Submitting jobs]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=e6e59e86-2928-4caf-b5c3-af2701248a3d Queue control and practical advice]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_ComputeromeQueue.ppt Queueing System]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that only the powerpoints are up to date. The videos are not likely to be updated as this material has been removed from the course.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=110</id>
		<title>Computer design</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computer_design&amp;diff=110"/>
		<updated>2025-08-06T20:54:18Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Coding against databases]]&lt;br /&gt;
|Next: [[Queueing System]]&lt;br /&gt;
|}&lt;br /&gt;
== Material for the lesson ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=87e6e835-22fc-4eb8-b5df-af27012554f9 Computer architecture and design]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=1171f7c8-74ea-43be-aff5-af2701250c46 Python IO performance &amp;amp; file buffers]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_04-Supercomputers.ppt Supercomputers]&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [https://www.computerome.dk/ Computerome 2 general information]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=ed903123-66d6-4dd8-ac09-af1700719d93 Exercises]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== Tasks to do ==&lt;br /&gt;
* Set up the two-factor authentication with Entrust IdentityGuard soft token for logging in to Computerome 2.&lt;br /&gt;
* Familiarize yourself with connecting to Computerome. Simple videos are avaliable on the web site.&lt;br /&gt;
* Examine the modules system mentioned in the powerpoint and the web site.&lt;br /&gt;
* Find the course directory /home/projects/pr_course. All files that I refer to during the course will be in that folder.&lt;br /&gt;
* Set up a personal folder in the &#039;&#039;people&#039;&#039; folder, which is in the course directory. This personal folder is not your home folder, but the place where you put the files/exercises you create during the course. Set permissions so the group can read, otherwise we am unable to read your stuff. Make sure we can easily see what exercise you are solving.&lt;br /&gt;
* Get a student account from me on &#039;&#039;&#039;DTU Healthtech&#039;&#039;&#039; local systems if you don&#039;t have an account already. You need such an account for database exercises later. Not urgent.&lt;br /&gt;
&lt;br /&gt;
== Prices on Computerome ==&lt;br /&gt;
As of October 1, 2024 the prices will be changed to the following:&lt;br /&gt;
 CPU node hour: 5,25kr. (0,13125 kr. per core hour)&lt;br /&gt;
 GPU node hour: 11,30kr. (0,2825 kr. per core hour)&lt;br /&gt;
 Storage per TB/month: 59,00kr.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises ==&lt;br /&gt;
Create four python scripts which copies the file human.fsa to your own home, using the four different methods mentioned in the powerpoint. Time the programs using ’time’, e.g.&lt;br /&gt;
 time python mycopy1.py&lt;br /&gt;
Also time the simple Unix cp doing the same task. Delete your copy afterwards.&amp;lt;br&amp;gt;&lt;br /&gt;
Rank the programs according to performance and explain the difference in execution time.&lt;br /&gt;
&lt;br /&gt;
This is actually a bit hard to do correctly. Considering what you learned about file buffering, then reading the same file twice (or more) in a row will use the file buffers instead of real IO the second time.&lt;br /&gt;
This means that the first time is always slowest, no matter how efficient the different programs are. You can&#039;t even be sure if another student is reading the same file at the same time and hence &amp;quot;disturbs&amp;quot; your measurements.&lt;br /&gt;
&lt;br /&gt;
A way around this problem is simply to use a computer with so little memory, that the file buffer system does not come into play. That is your laptop.&amp;lt;br&amp;gt;&lt;br /&gt;
Try to run the scripts on different machines. As minimum you have your laptop and pupil1. DTU&#039;s HPC system is also an option.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computerome&amp;diff=109</id>
		<title>Computerome</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=Computerome&amp;diff=109"/>
		<updated>2025-08-06T20:53:02Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: Created page with &amp;quot;== Information on Computerome 2 and the Queueing System there == Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=d679e5c8-9372-4af7-9260-af270124ddf6 Introduction to the Queueing System]&amp;lt;br&amp;gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=bca57da6-2c60-4218-96ac-af270124b673 Submitting jobs]&amp;lt;br&amp;gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=e6e59e86-2928-4caf-b5c3-af2701248a3d Queue control and practical advice]&amp;lt;br&amp;gt; Powerpoint: [http...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Information on Computerome 2 and the Queueing System there ==&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=d679e5c8-9372-4af7-9260-af270124ddf6 Introduction to the Queueing System]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=bca57da6-2c60-4218-96ac-af270124b673 Submitting jobs]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=e6e59e86-2928-4caf-b5c3-af2701248a3d Queue control and practical advice]&amp;lt;br&amp;gt;&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22112/22112_05-Queue.ppt Queueing System]&amp;lt;br&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=108</id>
		<title>22112 High Performance Computing in Life Science</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=108"/>
		<updated>2025-08-06T20:51:00Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Course details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&#039;&#039;&#039;Teacher:&#039;&#039;&#039; [https://www.inside.dtu.dk/da/dtuinside/generelt/telefonbog/person?id=816&amp;amp;cpid=214027&amp;amp;tab=2&amp;amp;qt=dtupublicationquery Peter Wad Sackett], pwsa@dtu.dk &amp;lt;!--, [https://www.inside.dtu.dk/en/dtuinside/generelt/telefonbog/person?id=130596&amp;amp;tab=0 Gisle Alberg Vestergaard], gisves@dtu.dk --&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Language:&#039;&#039;&#039; The course is taught in English.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Tools:&#039;&#039;&#039; Various servers will be introduced.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Textbooks:&#039;&#039;&#039; There are no text books for the course. I will make do with powerpoints, videos and references to online resources. You can find the material under the individual lessons in the [[Programme]].&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Location:&#039;&#039;&#039; Building 208, room 001.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Time:&#039;&#039;&#039; Thursday 13:00 - 17:00, module E1-B.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Course details ==&lt;br /&gt;
The course is a practical introduction to working with supercomputers in Life Science. Using both &amp;quot;ordinary&amp;quot; laptops and computer clusters as a basis for lectures and exercises, we will cover subjects such as computer design, queueing systems, distributed computing, algorithms, parallel programming, performance and performance dependencies, database design and use, and practical organization of projects.&lt;br /&gt;
&lt;br /&gt;
{| &lt;br /&gt;
|-&lt;br /&gt;
| [[Aligning expectations]] || Mandatory read at course start&lt;br /&gt;
|-&lt;br /&gt;
| [[Programme]] || Fall 2024&lt;br /&gt;
|-&lt;br /&gt;
| [[Computerome]] || Some info on Computerome&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Earlier programmes ==&lt;br /&gt;
[[Programme Fall 2023]]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=107</id>
		<title>22112 High Performance Computing in Life Science</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22112/index.php?title=22112_High_Performance_Computing_in_Life_Science&amp;diff=107"/>
		<updated>2025-08-06T20:50:47Z</updated>

		<summary type="html">&lt;p&gt;WikiSysop: /* Course details */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;__NOTOC__&lt;br /&gt;
&#039;&#039;&#039;Teacher:&#039;&#039;&#039; [https://www.inside.dtu.dk/da/dtuinside/generelt/telefonbog/person?id=816&amp;amp;cpid=214027&amp;amp;tab=2&amp;amp;qt=dtupublicationquery Peter Wad Sackett], pwsa@dtu.dk &amp;lt;!--, [https://www.inside.dtu.dk/en/dtuinside/generelt/telefonbog/person?id=130596&amp;amp;tab=0 Gisle Alberg Vestergaard], gisves@dtu.dk --&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Language:&#039;&#039;&#039; The course is taught in English.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Tools:&#039;&#039;&#039; Various servers will be introduced.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Textbooks:&#039;&#039;&#039; There are no text books for the course. I will make do with powerpoints, videos and references to online resources. You can find the material under the individual lessons in the [[Programme]].&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Location:&#039;&#039;&#039; Building 208, room 001.&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Time:&#039;&#039;&#039; Thursday 13:00 - 17:00, module E1-B.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Course details ==&lt;br /&gt;
The course is a practical introduction to working with supercomputers in Life Science. Using both &amp;quot;ordinary&amp;quot; laptops and computer clusters as a basis for lectures and exercises, we will cover subjects such as computer design, queueing systems, distributed computing, algorithms, parallel programming, performance and performance dependencies, database design and use, and practical organization of projects.&lt;br /&gt;
&lt;br /&gt;
{| &lt;br /&gt;
|-&lt;br /&gt;
| [[Aligning expectations]] || Mandatory read at course start&lt;br /&gt;
|-&lt;br /&gt;
| [[Programme]] || Fall 2024&lt;br /&gt;
|-&lt;br /&gt;
| [[Computerome] || Some info on Computerome&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Earlier programmes ==&lt;br /&gt;
[[Programme Fall 2023]]&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>