Building a Simple Datesheet

Datesheet is a common scheduling problem faced by most educational institutions. I am going to tell you in detail what a datesheet is and how to build one.
datesheets
What is a datesheet?
In an educational institution, we have students who are registered in courses.
Now, we want to have an examination after some period.
In the examination, each student will give a paper for the subject s/he is registered.
We have some limited number of days during which all the students of a given course will be giving papers at the same time. And we have more than one courses, and we want to take the papers of all courses.
If a student is registered in more than one course, then s/he can’t give the paper for all the courses on the same time, but s/he can give one paper in one day, and then the second paper on the second day, and so on.We want to make an arrangement of courses in some given days so that all the students give the papers for all registered courses, but with the following conditions:
  1. A student can’t give more than one papers at the same day/time.
  2. All the students in a course will give the paper for the course at the same time.
  3. Students of two courses can give their papers at the same time only if there is no student registered in both courses. This means, both courses have no common students.

There can be other conditions, depending on the institution and type of examination. But the above conditions are the basic conditions. One extra requirement which can arise is: How to arrange all the papers in minimum possible days, while satisfying the above conditions? First lets focus on simple datesheet making (arranging of papers).

How to build a datesheet?

Now, we want to make such an arrangement so that the above conditions are met.

  1. Make a list of courses, while each course will contain a list of students registered in it.
  2. Lets have a list of days, while each day will contain the list of courses whose papers will be arranged on that day.
  3. Let current-day is the first day.
  4. Get one course and add it to the current-day.
  5. Get an other course, call it current-course.
  6. If no student in the current-course has a course in the current-day-courses, then add the current-course to the current day. This will be a little hard to grasp and implement but this is the main step. This step will ensure that the 1st condition is satisfied.
  7. Else skip the course.
  8. Go to step 5.
  9. If there is no course left with no student in the current-day courses (in other words: all courses left have students with at least one course registered in the courses in the current day), then add another day to the days list and call it the current day, and then go to step 4.
  10. If all there is no course left (all courses are added to days in the days-list), then save the days along with the courses in each day and call it the datesheet, and terminate.

This is how to build a simple datesheet.

Capturing Screen as Bitmap Image in C#

The easiest way for taking screen snapshot in C# is given in the following code.

            Rectangle workingArea = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
            Bitmap screenShot = new Bitmap(workingArea.Width, workingArea.Height);

            Graphics gr = Graphics.FromImage(screenShot);

            gr.CopyFromScreen(0, 0, 0, 0, workingArea.Size);

            return screenShot;

In the above code, first a rectangle is created which equal to the size of the primary screen.
Then a bitmap is created which will store the pixels for the snapshot image.
The Graphics object is created which will store and perform operations on the bitmap object we just created.
The CopyFromScreen function captures the screen, copying all the color pixels to the bitmap of the Graphics object. The parameters to the function are about from where the copying will start in the source and to where it will go in the target. The first two are x and y are starting coordinates for the source and the third and fourth are about the starting coordinates for the target location. The last parameter is about the size of the rectangular region which will be copied, which consist of width and height.

Indexing in Database: Must Do It

I work in CUSIT (City University of Science and IT) as software engineer. I and my colleague do software development, maintenance, and database development and administration. Two days before, accountant called me and complained about an error in a report generation. When I looked, it was timeout error. I checked the underlying query and apparently everything was OK. I ran the query in sqlserver explorer and it took one minute and fifteen seconds. I ran it again and it was speeded up by one second. Query optimization!

The query returned only 18 records. It had several tables inner joined. I rearranged the query and started to execute it incrementally, by joining one table at a time. And without a single table, the query executed in less than a second. The problem was in the last remaining table.

I looked in the table definition.

What? It has no primary key! It has more than 2000 records but no indexing! All but one fields are used for comparison in the join but no indexing!

I added an auto-increment ID field as primary key and indexed all the fields except the one which only had true/false value and was not used in direct comparison.

I ran the query again and now its running time was less than a second. Wow, at least 75 times performance!

I searched for some other tables and found a few others which needed primary keys and indexing. My colleague said that there were no indexing and primary keys in some other tables as well. It was a legacy from our older boss, which was considered a must. He made several mistakes which we (I and my colleague Farrukh Abbas)  corrected after his leave.

Love and Programming

Once a friend told me that when anyone falls in love, then s/he thinks all the time about the lover. I thought about it a little and then come up with the following short story after putting myself in the situation.

I am a programmer. I have 45 minutes walk back to my place at evening. I like it to have sticky problems and solving them. I think about different stuff on that walk and i enjoy this. one day i felt that i fell in love with my coworker. She is a pretty girl and very nice. She is like to be respected and loved. I was in love. i did not know how and why, but i was. It had all the symptoms of true love, and i started to like the junky poetry on SMSes. I felt the true love, the itch, you know! I just don’t know anything else.
One day i thought all the way about her. next day again. But at the end, i got bored of it. What the hell! I have no other thing to think about. At the end of the day, i wasn’t happy like when i solve some tricky problem or have an amazing idea. i missed the thinking i have on the walk about programming problems i have and newer ideas. I got depressed. I stopped thinking about her. I wanted to do programming and the true love thing might take this away from me. it might give me temporary joy but will take the happiness and the feeling away i have when i am a true programmer.

Am i mis-interpreting the love thing or do programmers really don’t want to get in that shit.

Some Game of Life Animations

The following are some beautiful game of life animations, which i generated with an easy to use program, develped by me in C#.Net 2008.

The program is much easier to use but much slower as well. I am working on it to optimize it in performance and usability.
That will be available on net very soon.

Converting a 2D image to a 3D model

My current interest area is the Conversion of 2D images to a 3D models.

I found an interesting website,
http://make3d.stanford.edu/index.html

This website has amazing videos which show what can be done with an image.

I downloaded some pdf documents and trying to understand it.

Though I have not much time but image processing is an ammazing field, and I am enjoying it much more.

DataSet as a DataBase

Using a DataSet as a database and store that directly on desk. Before storage, some encryption and compression can also be made. The whole process can be optimized to reduce desk accesses and RAM usage. A DataSet can be managed to be stored in more than one file, each once containing a distinct set of tables. The tables can be grouped in files to reduce desk accesses and Ram consumption.

DataReader as a DataSource

DataReader can be used as a data source to a control, so no need of while loop for getting for getting data into a control.