Tuesday, May 12, 2015

Google Summer of Code 2015 : FOSSASIA

I've got selected to Google Summer of Code 2015. This time I'm developing a library to support knitting machines. It's great to work with FOSSASIA team under awesome mentors Mario Behling Eddie von Altenberga , Christian Obersteiner and Aruna Herath

This is the Initial suggestions for the project.

Library to support knitting machines

Basic abstraction of the library

I would like to create library as separate layers

  • Serial communication : open, configure, read and write to serial port
  • Machine definitions : machine initialization, load to machine, save from machine
  • Image handling functions : memory allocation, read image file, setter and getter for image pixels
  • File handling functions : read / write access
  • Common utility functions

Add dependencies for the library

There are several dependency libraries which ayab has such as pillow, pyserial, wsgiref, fysom and yapsy with relevant versions. These dependencies should be added to the library. 

Functions for the library

For access hardware directly
       * Identify existing libraries to interface with hardware
       * Use libraries to deal with serial ports
       * Ability to get all the functions via library (for an example functions in ayabControl.py and add more functions to support in more machines)
       * Ability to send QT signals

Emulate file formats

       * Create functions to emulate file format

Add Arduino support


Installation should be well documented in step by step. Additionally I suggest to add GUI based installation with usability improvements with standard installation procedures. 

* Installation on Linux (32bit, 64bit)
       * Prerequisites
       * Setup
* Installation on Windows (32bit, 64bit)
       * Prerequisites
       * Setup

Tests on the library

Use a python test framework like unittest to test the python library. It supports test automation and aggregation of the tests into collection.

Documentation of the library 

Documenting Class definitions, methods definitions and links to the given source codes. 


Source Code

Thursday, February 12, 2015

Library Management System: Database Project - Part V - Finalize Database

  Library Management System for Imaginary University
  2nd year Database Project

In order to maximize the use of system resources to perform work as efficiently and rapidly as possible the views and indices to be used were confirmed and some of the views were decided to materialize.

In the application a user can search a book based on its authors, title and subject as well as ISBN number. Therefore by creating indices on tilte, authors and subjects the database can access relevant entries more efficiently. Since the table book_details is not updated frequently this will not cause for any low performance of the database.

create index book_title on book_details(title);
create index book_publisher on book_details(publisher);
create index book_category on book_details(category);

create index cd_title on cd_details(title);
create index cd_publisher on cd_details(publisher);
create index cd_category on cd_details(category);

create index member_index on borrows(member_index);

According to the design of our database it was required to join several tables in order to fulfill search requests. For example when finding a book by its ISBN number we happened to join book_details table with authors table to get details of the book. In addition, to find the availability of that book it was necessary to join item table and book table with previous tables making total number of tables to be joined is four. Searching a book is one of main functionalities and that is done frequently, joining tables at each search is highly expensive execution. Therefore it was more convenient to make a view joining necessary tables as follows and materialize the view since it is not updated very frequently.

CREATE VIEW bookSearch AS SELECT items.id, bd.ISBN, bd.title, bd.edition, bd.publisher, bd.category, authors.author_name_1, authors.author_name_2, authors.author_name_3, items.borrowed
FROM items, books, authors, book_details AS bd
WHERE items.id = books.item_id
AND books.ISBN = bd.ISBN
AND authors.ISBN = bd.ISBN;

Similarly a view to read data in joined tables, item, cd and cd_details was created

CREATE VIEW cdSearch AS SELECT items.id, cd.ISSN, cd.title, cd.edition, cd.publisher, cd.category,items.borrowed
FROM items, cds,cd_details AS cd
WHERE items.id = cds.item_id
AND cds.ISSN = cd.ISSN ;

Following views were created to search member details efficiently

CREATE VIEW memberSearch AS SELECT s.student_index, m.first_name, m.last_name, m.email,
PASSWORD , s.batch, m.department, s.registered_date, m.number_of_books_allowed, s.total_fine
FROM students AS s, members AS m
WHERE s.student_index = m.member_index;

CREATE VIEW staffSearch AS SELECT s.staff_index, m.first_name, m.last_name, m.email,
PASSWORD ,s.position, m.department, s.year_of_appoinment, m.number_of_books_allowed
FROM staff AS s, members AS m
WHERE s.staff_index = m.member_index;

To ensure the persistence and security of data backup capabilities were added to the software.

Book Search Window

Wednesday, February 11, 2015

Library Management System: Database Project - Part IV - Database Implementation

  Library Management System for Imaginary University
  2nd year Database Project

Data Definition Language (DDL) of the database.

create table items
     id                  INT PRIMARY KEY,
     borrowed            boolean,
     received_as         varchar(50)    
create table book_details
     ISBN                varchar(15) PRIMARY KEY,
     title               varchar(50) not null,
     edition             varchar(15),
     publisher           varchar(50),
     category            varchar(50),
     price               float(7,2)
create table books
     item_id         int PRIMARY KEY,
     ISBN            varchar(15) ,   
     foreign key (item_id) references items(id),
     foreign key (ISBN) references book_details(ISBN)

create table cd_details
     ISSN                 varchar(15) PRIMARY KEY,
     title                varchar(50) not null,
     edition              varchar(15),
     publisher            varchar(50),
     category             varchar(50),
     price                float(7,2)

create table cds
     item_id           int PRIMARY KEY,
     ISSN              varchar(15) ,
     foreign key (item_id) references items(id),
     foreign key (ISSN) references cd_details(ISSN)

create table members
     member_index       varchar(10)  PRIMARY KEY,
     first_name         varchar(50) not null,
     last_name          varchar(50) not null,
     department         varchar(20) not null,
     password           varchar(15) not null,
     email              varchar(50),
     number_of_books_allowed int

create table students
     student_index      varchar(10)  PRIMARY KEY,
     batch              varchar(5) not null,
     total_fine         int,
     registered_date   date,
     foreign key (student_index) references members(member_index)
create table staff
     staff_index           varchar(10)  PRIMARY KEY,
     year_of_appoinment    DATE,
     position              varchar(20) not null,
     foreign key (staff_index) references members(member_index)
create table authors
    ISBN                  varchar(15)  PRIMARY KEY,
    author_name_1         varchar(20) not null,
    author_name_2         varchar(20),
    author_name_3         varchar(20),
    author_name_4         varchar(20),
    foreign key (ISBN)    references book_details(ISBN)

create table borrows
     member_index         varchar(10),
     item_id              int,
     borrowed_date        DATE not null,
     fine                 float(7,2),
     remarks              varchar(50),
     foreign key (member_index) references members(member_index),
     foreign key (item_id) references items(id),
     primary key (member_index,item_id)
create table locations
     id                INT PRIMARY KEY,
     shelve_ID         varchar(6),
     row_number        int,
     section           varchar(15) not null
create table item_is_at
     ISBN             varchar(15) PRIMARY KEY,
     location_id      int,   
     foreign key (location_id) references locations(id),
     foreign key (ISBN) references book_details(ISBN)
create table operator
    (id               varchar(10) PRIMARY KEY,
     username         varchar(50) not null,
     password         varchar(15) not null,
     email            Varchar(128) not null,
     position         varchar(64)    

Library Management System: Database Project - Part III - Database Design

  Library Management System for Imaginary University
  2nd year Database Project

There are Four main entities

Item : a book or as CD which can be borrow from the library
Member : a registered member of the library who will be a student or a staff member
Location : the physical location where an item is stored in the library
Operator : a library staff member who will interact with members of the library. That is they will add/update data about members, transactions and items in the library

Entity Relationship Diagram (ER Diagram)

ER diagram

There can be many copies of the same item (Book or CD). However since we need to identify each item separately so that each of them are given a unique id which is the 'item_id'.
Storing common details of the same copies of items make redundancy, the details of items are decomposed into separate tables named 'book_details' and 'CD_details'.

A member can borrow four books (or CDs) at a time and an item can be borrowed by only one member at a time. Therefore the relation between items and members is many to one.

The relationship, borrows, will record details of a transaction and stored as the history of each transaction. The attribute, returned date of the relationship borrows will be null until the item is returned.

Books and CD’s are stored physically in the place designated by the location. A location can be uniquely identified by the location_id which includes shelf number, row number and section number. Therefore the combination of those three attributes will be the primary key for the entity, location_id. However since there can be about 10-20 books in a section of a shelf the relationship, item_location is many to one from item to location.

Operator entity is used in authenticating operators when using the system, which is essential to confirm security of the system. That does not have any relationship with other entities.

All the entities are checked and confirmed to be normalized in the first and third normal forms.

Database Schema

Database schema