My Final Year Project aka Online FIR/GD lodging system.

Hello all, this post will be a small one. I will be discussing about my College Final Year project in here. The topic for my project was Online FIR/GD Lodging System. Since I have worked with Flask before, I chose Django 1.8 to try something new. Learning the basics of Django wasn’t much difficult. Now my college stuff is over but i have decided to add on a few more features.

about THE Application

Its a simple web-app with a Form to fill up the details necessary for lodging an FIR/GD. The main problem with this kind of application is the identity of the user.So to properly identify i decided to use approved ID Proofs by the Government for different organizations i.e Voter ID Number, Aadhaar ID Number, Ration Card Number, PAN Card Number. Obviously this a prototype so I had the freedom to use dummy data for users Aadhaar, Voter and PAN card in database tables. For Practical implementation it surely needs access to the above mentioned databases from the government. So a user can choose any two ID proof out of the 4 and fill in the details. The two ID card data must have same name and birth date for the user to be identified. Next the Report(FIR/GD) form is to be filled by the person. Also currently he needs to explicitly select the Police Station he wants to lodge the report to. According to the city and state the police stations gets shortlisted. Next the form is submitted. I did not use User Auth in this application. We already have the user identity but we need ways to contact the user, hence phone number and email needs to be filled in the Form. Next comes the verification of mobile number. I really didn’t want to spend much on this so decided to use Site2SMS API which allows you to send limited Free SMS. So sending OTP via Site2SMS API. Since the OTP are short-lived (5 minutes) i decided not to use database to avoid overhead due to frequent writes and decided to use Redis instead. The TTL feature made my work of expiring OTPs easy. Finally sending a pdf document report via email. I used xhtml2pdf to generate the pdf’s and again saving money by using Gmail for sending out emails. 😉 That pretty much sums up the application. You can check out the SourceCode.

Future Plans

– Right now all I have done is for the user who wants to lodge an FIR/GD. The police portal exists but the Reports are not updated instantly. I am planning to use Django Signals to work with django-socketio to update the new Reports instantly just after they are inserted into database.

– Chalk out a way to automatically register the FIR/GD to the correct police station depending on the location of event

– This can be most handy when used as a mobile application. So either create an API and mobile application or make the design responsive to suit any device.

– And finally to write Unit tests. ( This is my new year resolution) 😛

P.S.- Suggest some cool name for this app.
P.P.S.- You are most welcome to request a feature or add a feature and send a PR on Github.

This year Fudcon is from 26th. Will be attending it and maybe meeting some of you. Next post will be on FUDCON 2015. Till then Happy Coding. 🙂

My Final Year Project aka Online FIR/GD lodging system.

Using Gcov and Lcov to generate beautiful C++ code coverage statistics

We all know, testing is an important part of a project. But how efficient are your tests? How much of your codes have you tested? Here comes the role of code coverage tools. I recently got to work on a C++ project, and a code coverage tool (gcov and lcov) .

In this post i have taken a sample C++ program and will be generating the code coverage stats for the same using gcov and lcov. Here is my sample C++ program link. Its pretty simple menu driven program that does simple mathematical operations like addition, subtraction, multiplication and division depending on users choice.

In this demo i am not writing actual test-cases for the code but you can see the changes in the coverage graphs depending upon your choice.

To start with we need to install gcov. Gcov comes with gcc compiler. So if you have gcc installed then gcov will work for you. Next you need to have lcov. I am working on Fedora 21, so for me its a yum install.

$yum install lcov

Next lets start with compiling our code. Here my source file name is menu.cpp

$g++ -o menu.out --coverage menu.cpp

The –coverage option here is used to compile and link code needed for coverage analysis. You will find a menu.gcno file in the folder. Next we need to export two variables namely GCOV_PREFIX and GCOV_PREFIX_STRIP. Set GCOV_PREFIX to the folder you want the output files to be in.

$ls
menu.cpp  menu.out  menu.gcno  data    // you can see the new file menu.gcno

For me , the project is in  “/home/subho/work/lab/zzz/” and  inside this i have created a folder named data where i want the data files or .gcda file to be generated. so i set my GCOV_PREFIX to “/home/subho/work/lab/zzz/data” and the GCOV_PREFIX_STRIP equal to the the number of forward slashes or “/” in the path.

$export GCOV_PREFIX="/home/subho/work/lab/zzz/data"
$export GCOV_PREFIX_STRIP=6

now lets simply run the code.

$./menu.out

MENU
1: Add
2: Subtract
3: Multiply
4: Divide
5: Exit
Enter your choice :2
Enter two numbers: 3 4
Difference -1
MENU
1: Add
2: Subtract
3: Multiply
4: Divide
5: Exit
Enter your choice :5

Now we can see a menu.gcda file in data folder. Copy the .gcno file generated earlier to the data folder.


$cd data

$ls

menu.gcda

$cp ../menu.gcno .

$ls

menu.gcda  menu.gcno

Now that we have all the necessary files lets use lcov to read the coverage output file generated by gcov.

$lcov -t "result" -o ex_test.info -c -d .

Here ex_test.info is my output file.

-t     sets a test name

-o    to specify the output file

-c    to capture the coverage data

-d    to specify the directory where the data files needs to be searched

Now we will generate out html output for the statistics.

$genhtml -o res ex_test.info 

-o    To specify the output folder name.

Now on doing ls, you can see a folder named “res“.

$ls
ex_test.info   menu.gcda   menu.gcno   res

Now its time to enjoy the fruits of your labor 😛 . Go into the res folder and start a server or you can simply open the index.html file in your web-browser.

$cd res
$python -m "SimpleHTTPServer"     //to start a web-server  or
$firefox index.html               //to open the index.html directly using firefox browser

Now we can click on the links to check the code coverage stats. The Red lines are the ones not executed or uncovered region. The blue lines are the ones covered. Also you can look at the Line data section for the number of times the lines have been executed. 
You can look at these files in GitHub.

This slideshow requires JavaScript.

Using Gcov and Lcov to generate beautiful C++ code coverage statistics

Setting up MTConnect C++ Agent

In this post i’ll be discussing on how to setup cppagent (MTConnect c++ Agent) and run tests on it.

To start with we first need to git clone the repository from Github from here.

The current cloned version hash is 6d57d38cffff4b368f3ec003c2d8868d4f41a988.

Once you have cloned the repo enter the root folder of the repository. Now lets first build MTConnect.

For this we will create a folder named build in the root folder.

$ cd cppagent
$ mkdir build
$ cd build
$ cmake ..
$ make

After the make process is complete we will see MTConnect c++ agent in action. For this we will need to run the simulator.

We need to copy certain files to successfully run it. From the build/agent folder, copy VMC-3Axis.xml from the simulator folder into the current folder.

$cd agent
$ cp ../../simulator/VMC-3Axis.xml .

Now copy the agent configuration file

 $ cp ../../agent/agent.cfg .

Next edit the copied agent.cfg file and make the following changes to it:

Devices = VMC-3Axis.xml
 Host = 127.0.0.1

Open three terminals. In one of the terminals, start the ‘agent’

$ ./agent

Expected o/p:

MTConnect Agent Version 1.3.0.7 - built on Sun Oct 12 22:20:32 2014

In the second terminal run the adapter simulator. For that you need to go inside the simulator folder in the repository root directory then type the following command.

$ ruby run_scenario.rb -l -p 7878 --scenario -v simple_scenario_1.txt

Expected o/p:

run_scenario.rb:41: warning: toplevel constant String referenced by OptionParser::String
Waiting on 0.0.0.0 7878
Client connected
Received * PING, responding with pong
2014-10-26T18:14:04.512751|execution|INTERRUPTED
2014-10-26T18:14:06.513296|tool_id|1
2014-10-26T18:14:08.513635|execution|ACTIVE
2014-10-26T18:14:10.514086|execution|READY
2014-10-26T18:14:12.514512|program|Tap|execution|READY
Received * PING, responding with pong
2014-10-26T18:14:14.514799|tool_id|2
2014-10-26T18:14:16.515056|execution|ACTIVE
2014-10-26T18:14:18.515424|execution|READY
2014-10-26T18:14:20.515717|tool_id|3
2014-10-26T18:14:22.516117|program|Countersink|execution|ACTIVE

In the third terminal type the following:

$ curl localhost:5000/current

This will give a XML output every time. Each XML output is different. You can check that by piping the output to a file  and then doing a diff of the two files

$ curl localhost:5000/current > 1.xml
$ curl localhost:5000/current > 2.xml
$ diff 1.xml 2.xml

The output will be something like:

4c4
< <Header creationTime="2014-10-26T18:19:10Z" sender="localhost.localdomain" instanceId="1414347216" version="1.3.0.7" bufferSize="131072" nextSequence="227" firstSequence="1" lastSequence="226"/>
---
> <Header creationTime="2014-10-26T18:19:16Z" sender="localhost.localdomain" instanceId="1414347216" version="1.3.0.7" bufferSize="131072" nextSequence="229" firstSequence="1" lastSequence="228"/>
70,71c70,71
< <Execution dataItemId="cn6" timestamp="2014-10-26T18:19:10.560074" name="execution" sequence="226">ACTIVE</Execution>
< <ToolId dataItemId="cnt1" timestamp="2014-10-26T18:19:08.559795" name="tool_id" sequence="224">3</ToolId>
---
> <Execution dataItemId="cn6" timestamp="2014-10-26T18:19:14.560666" name="execution" sequence="228">READY</Execution>
> <ToolId dataItemId="cnt1" timestamp="2014-10-26T18:19:12.560338" name="tool_id" sequence="227">2</ToolId>

Great!! now we have a working version of cppagent.

Next we will build tests. Follow the steps below to build test. We assume we are outside the repository root. So we need to enter the root first.

$ cd cppagent  
$ cmake .

Now we will enter the test directory in the root folder and build tests.

$ cd test  
$ make

Now to run the tests, run the agent in one terminal and the following command in another.

$ ./agent_test

Expected Output:

Continue reading “Setting up MTConnect C++ Agent”

Setting up MTConnect C++ Agent

10 years of DGPLUG

We recently celebrated the 10 glorious years of DGPLUG. On this occasion we had a 5 day workshop (29th August to 2nd September) at NIT Durgapur.

::Day 1::

The first day was more or less introductory session where we discussed about what are our goals , our history and our programme for the future. The attendees constituted mainly of 1st,2nd and 3rd year engineering students of various colleges. The speaker for the session was Kushal Das, he told them about the Summer Training conducted by DPLUG for free every year. We told them about Open Source and how they can contribute to opensource projects. The next talk was by Praveen Kumar and was all about Fedora Project and how we can contribute to it. Next we had a really interesting talk by P.J.Prasad on Iptables. At the end we concluded the first day of the workshop with light discussions on various topics and also asked the students to get some packages installed for the next day.

::Day 2::

On the day two of the event the auditorium was teeming with eager faces , a workshop on Python was to be held. Kushal Das took the session on python along with the introduction of Vim. We had a tough time helping them to this new editor nevertheless we enjoyed doing it. Python for you and me book was followed in the session. We covered basic python commands , data structures and other basic functions of the language. By the end of the day we managed to write a program which could list down the files and folders of a directory quite similar to ls command of linux.

::Day 3::

On the day three we had workshops on flask, a web-framework based on python by Sayan Chowdhury in the first half of the day. Later In the second half we had workshop on unit test module of python by Ratnadeep Debnath where we learned to write test cases for our functions.

::Day 4::

On the Fourth day of the event we had a session on documenting our codes by Kushal Das. We introduced reStructuredText to write our documentation and then use rst2s5 to convert them to presentations. After that we used a powerful python package sphinx and prepared a demo documentation.

::Day 5::

The day five was all about how to contribute to upstream projects, Learn using Git, making patches, and other important git features and commands. After that we had a general discussion session followed by feedback session. We got many positive feedbacks and suggestions for improvement which has been noted down and will be kept in mind in the upcoming events.

Finally we talked about various projects in hand, and newer project ideas to be developed. Hoping to meet these awesome people soon at Pycon India. Till then Keep Coding! 😉

10 years of DGPLUG

FOSS (Free & Open Source Software)

Free and open-source software (F/OSS, FOSS) or free/libre/open-source software (FLOSS) is software that is both free software and open source. It is liberally licensed to grant users the right to use, copy, study, change, and improve its design through the availability of its source code. This approach has gained both momentum and acceptance as the potential benefits have been increasingly recognized by both individuals and corporations.

Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients have the same rights under which it was obtained and that manufacturers of consumer products incorporating free software provide the software as source code. The word free in the term free software refers to freedom (liberty) and is not at all related to monetary cost.

FOSS (Free & Open Source Software)