Thursday, April 28, 2011
Use charts in PHP
I was struggling to use the charts in my PHP script so finally when I found out an easy way I thought of sharing it very everyone.
I am using the GD library available in php. Only thing that needs to be done is to configure the php.ini file.
Go to the php.ini file and enable extension=php_gd2.dll
Now to create the charts I was following the method as specified at http://www.qualitycodes.com/tutorial.php?articleid=20&title=How-to-create-bar-graph-in-PHP-with-dynamic-scaling
But the problem was that I was not able to write any text before or after the chart.
so
text
chart
text
the above kind of output is what I wanted and all I could get was a
Chart
So after doing some experiment I finally found a way
1. Create a file called imageGeneration.php
Create a funcction createImage($values,$imageName)
where $values is an associative array while $imageName is the name of the chart file.
The function will take the values to be plotted in the form of an associtive array
like
$values=array(
"Jan" => 110,
"Feb" => 130,
"Mar" => 215,
"Apr" => 81,
"May" => 310,
"Jun" => 110,
"Jul" => 190,
"Aug" => 175,
"Sep" => 390,
"Oct" => 286,
"Nov" => 150,
"Dec" => 196
);
So that the x axis is the name of the months and the y-axis is the values
function createImage($values,$imageName)
{
$img_width=450;
$img_height=300;
$margins=20;
# ---- Find the size of graph by substracting the size of borders
$graph_width=$img_width - $margins * 2;
$graph_height=$img_height - $margins * 2;
$img=imagecreate($img_width,$img_height);
$bar_width=20;
$total_bars=count($values);
$gap= ($graph_width- $total_bars * $bar_width ) / ($total_bars +1);
# ------- Define Colors ----------------
$bar_color=imagecolorallocate($img,0,64,128);
$background_color=imagecolorallocate($img,240,240,255);
$border_color=imagecolorallocate($img,200,200,200);
$line_color=imagecolorallocate($img,220,220,220);
# ------ Create the border around the graph ------
imagefilledrectangle($img,1,1,$img_width-2,$img_height-2,$border_color);
imagefilledrectangle($img,$margins,$margins,$img_width-1-$margins,$img_height-1-$margins,$background_color);
# ------- Max value is required to adjust the scale -------
$max_value=max($values);
$ratio= $graph_height/$max_value;
# -------- Create scale and draw horizontal lines --------
$horizontal_lines=20;
$horizontal_gap=$graph_height/$horizontal_lines;
for($i=1;$i<=$horizontal_lines;$i++){
$y=$img_height - $margins - $horizontal_gap * $i ;
imageline($img,$margins,$y,$img_width-$margins,$y,$line_color);
$v=intval($horizontal_gap * $i /$ratio);
imagestring($img,0,5,$y-5,$v,$bar_color);
}
# ----------- Draw the bars here ------
for($i=0;$i< $total_bars; $i++){
# ------ Extract key and value pair from the current pointer position
list($key,$value)=each($values);
$x1= $margins + $gap + $i * ($gap+$bar_width) ;
$x2= $x1 + $bar_width;
$y1=$margins +$graph_height- intval($value * $ratio) ;
$y2=$img_height-$margins;
imagestring($img,0,$x1+3,$y1-10,$value,$bar_color);
imagestring($img,0,$x1+3,$img_height-15,$key,$bar_color);
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
}
$temp_chart_file_name = $imageName;//"s/chart2.png";
imagepng($img, $temp_chart_file_name,0);
return $imageName;
}
one important difference from the http://www.qualitycodes.com/tutorial.php?articleid=20&title=How-to-create-bar-graph-in-PHP-with-dynamic-scaling
is that I am not using the header("Content-type:image/png"); since my intention is not to print the chart from this function. The intention is to get the chart and save it in the file.
2. Now create another file called test.php that will use this function
include 'imageGeneration';
echo “ this is a sample test application for the chart”;
// supply the parameters to the chart
$values=array(
"Jan" => 510,
"Feb" => 130,
"Mar" => 215,
"Apr" => 81,
"May" => 310,
"Jun" => 110,
"Jul" => 190,
"Aug" => 175,
"Sep" => 390,
"Oct" => 286,
"Nov" => 150,
"Dec" => 196
);
$imageName="Chart.png";
createImage($values,$imageName);
?>
<img src=" <?php echo $imageName; ?>" alt="some_text"/>
echo “ the chart is placed”;
?>
You will get the output as
this is a sample test application for the chart
Image of the chart
the chart is placed
Convert from System.Drawing.Image to System.Windows.Controls.Image
It works perfectly for me!!.
private System.Windows.Controls.Image ConvertDrawingImageToWPFImage(System.Drawing.Image gdiImg)
{
System.Windows.Controls.Image img = new System.Windows.Controls.Image();
//convert System.Drawing.Image to WPF image
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(gdiImg);
IntPtr hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
img.Source = WpfBitmap;
img.Width = 500;
img.Height = 600;
img.Stretch = System.Windows.Media.Stretch.Fill;
return img;
}
Sunday, April 17, 2011
How to connect MSSQL server 2005/ SQLExpress from php
The following steps are required to perform a hassle free connection
I am assuming that the PHP has been installed using the winlamp so that it has copied the PHP in the Apache folder.
1.) Download ntwdblib.dll (version : 2000.80.194.0) from Webzila.com
2.) Copy this dll file to apache\bin. Make sure you have the windows path set to this directory.
3.) Restart the apache service by going to Control Panel->Administrative Tools->Services.
4.) Go to “SQL Server Configuration Manager”.
5.) Under “SQL Server Network Configuration” clickon “Protocols for SQLExpress”.
or “Protocols for MSSQLSERVER” (in case you are using the complete SQL server)
6.) On the right hand side,right clicked on “Named Pipes” and clicked on Enable
7.) Also, right clicked on TCP/IP and clicked on enable
steps 6 and 7 are very important. If you forget any of this the connection wont happen
8.) Restart the SQL Server Express/ SQL Server service.
9.) Uncomment the line extension=mssql in the php.ini
If you check phpinfo you should see values for mssql section
Also you need to make sure that the authentication mode is mixed. The connection wont work for windows authentication.
You can do that by
In Express Edition
Right click on the SQLSERVEREXPRESS database and then properties->Security (Choose Sql server and Windows Autherntication mode)
In SQL Server 2005
Right click on the MSSQLSERVER database and then properties->Security (Choose Sql server and Windows Autherntication mode)
Create a user by clicking on security-> Logins and create new login. Make sure you give strong password. In the UseerMapping tab give control to all the database and all databse rights
Now try connection the database seeting should be
$db1 = mssql_connect("hostname\SQLEXPRESS", username, password) in case of the SQL server express edition
while
$db1 = mssql_connect("hostname", username, password) in case of the MSSQL Server
This will make the connection to the database.
Friday, April 15, 2011
Healthcare social platform (Heath 2.0)
Healthcare social platform (Heath 2.0) leverages the social software to promote collaboration among patients caregivers medical professionals and other health stakeholders
Healthcare social networks provide an active platform for sharing the ideas, discussing symptoms and debating the treatment options…all of them can improve the patient care.
There are several issues which raises questions over the entire Health2.0 concept:
- What is the guarantee that the information shared is correct..basically the factor of trust?
- Why will anybody share his/her experiences?
- What about the loss of privacy?
There has been some research on the kind of information people would like to find out on the internet pertaining to healthcare. Some of the key reasons for the online activity are
- To conduct research on a disease..done mostly by medical practitioners
- To find out possible diagnosis for the condition …done mostly by patients
- Find out the insurance plans..done mostly by patients
- Research the reputation/quality of a doctor or the hospital..done mostly by the patients
- Look for a doctor to get the treatment for a particular disease.. done by patients. Now a days it is one the use case for creating the local search applications
- Access or manage the personal health records…There are websites that allow the patients to maintain their medical records
- Connect to other patient to understand the problems of a particular treatment..done by the patients..patient social networks
Healthcare social networks can be either physicians or patient oriented
Physician social networks provide an online technical infrastructure for the doctors to share the clinical cases, images, videos, medical knowledge
Patient social networks emphasize direct patient support, promote disease awareness, find out what it feels when you are suffering from a particular disease.
Physician Social Networks
Sermo(www.sermo.com) is one of the biggest online social network of the physicians
These platforms (Physician Social Netwoks) bring thousands of the physicians together to exchange the latest in the medical advances. Some of the advantages are:
- Physicians exchange views about the drugs, devices and the treatment options.
- They can each other specific clinical questions (just like the software forums) that are not so obvious from the medical literature
- The doctors in the rural places with limited access to the libraries and specialists can join the communities to get help in diagnosing and prescribing the correct medicines
- Physicians can discuss ongoing research and help speed up the process of bringing the advances to the patient care.
- The physician networks also provide useful VOC (voice of customer) to the pharmaceutical companies. By monitoring the conversations on the network they can understand if there is a need of a particular type of drug , or what are the kind of diseases in a specific region (potential markets), or why one particular drug is getting prescribed by various doctors etc.
- Similarly the device manufacturing companies can get the feedback for their devices, or if there is a need for a new kind of device for diagnosis
There are also some obvious concerns in such networks:
· How do you gauge the accuracy of an advice or expertise on a particular topic?
There are few measures taken in this respect. Some networks require the physician to verify their credentials such as the state license, their degrees, before becoming the member or the membership is only by invitations(so trust is there). Also the advice given may be ranked by the other members (like in stack overflow http://stackoverflow.com/ forum)
Patient Network
The patient networks support the patients worldwide by promoting the disease awareness and positive and proactive behaviors to stay healthy while coping with a disease. Some of the key befits are:
- They can ask each other about the after effects of a particular medication. They can ask the other patient who is suffering from the same disease about the medications and what is to be expected in terms of the effect of the disease
- The network helps to lower the anxiety level of the patients and the caregivers particularly for newly diagnoses patients who are unsure about the future. Such patients require variety of information quickly and without interruption.
- Patients also feel that they are not alone in the world but there are so many in the same situation which act as a soother for them.
- Between the doctors’s appointments the patients can contact the other patients to gain enough knowledged about the treatment, symptons and to frame the right questions to ask the physicians
- They can also get reference of a physician or hospital to get the treatment for a particular disease.
- Also before going to a doctor the patients can find out the reputation of a doctor and the hospital
- Even the healthy people can find out the information regarding how to keep them protected from a particular disease. During the outbreak of the Swine flu these social networks helped a lot to spread the information about the disease i.e. how to protect yourself , what precautions one must take.
- In few networks even physicians are members and they volunteer to give answers to patients queries
- The patient networks also act as a VOC for the drug companies because they can find out the side effects of their drugs or if a particular drug is causing miracles
There are some concerns too.
- The biggest being the trust. To what extent the people can trust the content of the patient networks. Most medical advice or the comments come from other patients. The sites do not perform any validation of the content. Patients have no choice but to believe in Collective Intelligence (collective understanding of many will be better than a single person). I think with the maturity of the collaboration model of the web (travel forums, software forums) the collective intelligence is more or less established.
- Privacy is another concern. Since patients are revealing their medical conditions it can be an issue with the insurance companies. They may increase the premium depending on the patients conditions
But still the benefits of the network can outweigh the concerns
What distinguishes the physician and the patient networks from the other online communities is the motivation for the interaction: The professional interest for the doctors and coping with disease or diability for the patients.
How as a software developer we can contribute to Health 2.0?
The crux of the Health 2.0 is a social application that is intended to be used for the discussion on Health related issues. These days many social networking provide APIs to create the social applications. Facebook is a powerful platform which supports the social networking a big time. It is currently the most popular and the largest social networking site. There is a huge potential for a health2.0 kind of Facebook application. The application will allow Facebook users to form a specialized group for enabling the Patient Social networks or the physician social networks. Each member can view others Facebook profile to know more about him. This way the trust might be build which is a major issue in the existing Healthcare Networks. Since the users can just add the app to their facebook profiles (without going to any third party sites) the chances for active participation is also more. There are many ideas that can be drafted around the concept of social app…its just the matter of brainstorming
Sunday, January 23, 2011
Mobile conference Experience
I got an opportunity to attend the Mobile Developers Conference held in Bangalore on 22nd Janurary organized by silicon India (http://www.siliconindia.com/events/siliconindia_events/index.php?eid=MDC_Ban2011).
Despite a Karnataka Bandh called by the political parties it was almost a houseful!!!
Lot of well- known technologists in the Mobile domain was invited as the speakers in the conference.
I have always found such conferences as a great source of understanding the market trends and to do a reality check on where I stand as an individual. I don’t feel that a person can learn a new technology by attending these conferences but he can get awareness of what is happening in the industry and what are the current buzz words which he should be aware of.
Some of the key points that came up were:
1. The Platform war is on. Every platform (Symbina, Android, Iphone OS , Blackberry) is today trying to capture the market
2. There are 5 main drivers that will guide the future of Mobile:
a. Connectivity: Broadband. 3G, GPRS, Wifi
b. OS: Symbian, Android, Iphone OS
c. Smartphones ( todays smartphones are equipped with the fast processors, high end cameras, GPS , sensors)
d. Mobile Apps: The key differentiator for the success of the mobile platform
e. Developer Community who is producing the Apps
3. The Mobile Apps are as important for Mobiles as the websites are for the internet. Just like without the websites the internet is of very less use for the people similarly without the mobile apps there is very less that can be achieved from the high speed mobile networks.
4. Mobile apps are also very important from the fact that in smaller cities in India where internet is still restricted to cyber café, the people can be connected by using the mobile versions of the social networking sites, news sites, emails , cricket scores etc.
5. The ease of development on a particular Mobile platform is the key determinant for the growth of the mobile apps on that platform
6. There has been a change in the CTQs of the consumer. Few years back the main criteria was music, camera , colors. Today the customer asks about Mobile OS (Platforms), Services (3G, wifi) Mobile Applications. The phone retailers have also changed their marketing strategies and advocating that buy android since you will be able to download 300000 mobile apps and don’t buy Nokia because the number of apps is less. Nobody talks about music player or camera resolutions
7. Nokia, the key OEM player is now focusing a lot on the mobile apps and is taking steps to make it very easy for the developers to submit the apps (ovistore). Nokia is trying hard to keep up the pace with the Android popularity.
8. The Developer community is getting respected from the OEMs a lot since the popularity of the platform is largely dependent on the mobile apps that the developers are producing and if the developers are developing the appications for the platforms they are supporting then they are at the advantage
9. The UI/UX plays a very important role in the popularity of an application
10. The shelf life or the time frame for which the user is going to use the application is important yardstick for the app
11. People are globally downloading the apps. Today a developer can look for huge monetary benefit if the people are downloading his app. There are millions of users for a particular platform. Even if the cost of the app is just 1$ then millions are at stake
12. Some of the key factors that will help in success of mobile app
a. UI/UX is the primary. If the application is not appealing the people are not going to download it
b. Distribution channel. Basically the app stores. How easy it is to search an application and download on the mobile is very important since the demographic of users is very wide.
c. Consumer Awareness. Is the user aware of the existence of the app stores?
13. Operator Integrated Billing: The user generally has to shell out 30-100 RS to buy a mobile app, which makes it very affordable. But the payment mode is little challenging. Credit card which is the most popular payment mechanism on internet is not that attractive when it comes to the mobile. The simple reason is the user demographics is different. The internet users are who are buying the stuff online are mostly from a middle to upper income group while the mobile application buyers can be from any income group and from various age groups. Also not everyone has got the credit card to buy (specially the college students which are among the main target for the mobile apps will not have a credit card). Even the credit card holders are sometimes reluctant to provide the credit card details online. The more preferred way is to buy it through the service provider. So I can tell Airtel to charge the amount in the bill depending on the application I have downloaded. Nokia is trying to tie up with various operators to allow users to pay through the operators on the Ovistore. Similar model is very popular when it comes to download a caller tune.
14. The number of applications that are already created are so many that its difficult for an individual developer to get noticed on the app stores. You give a problem statement and there is a app for it”. Its important that the application should have something new in it and should not be just copy paste
15. Some of the trends that have been seen in the popularity of the apps
a. Social Networking apps like facebook, twitter are popular since they provide one more level of connectivity.
b. Content Based Apps: The search apps like burp, trip advisors, just dial
c. Utility Apps: Banking applications (SBI is encouraging the account holders to use the Nokia mobile apps for the banking services)
d. Games
16. Just like web 2.0 changed the face of the internet. For the website to sustain it became important that it gives user to participate in adding/modifying the content of the website similarly in the mobile world there has been a shift in the ownership of the mobile apps. Previously it was the OEMs responsibility to provide some apps and the user was only the consumer of it (Nokia’s Snake game). But now user/developer wants to develop their own apps or download some others app and use them on the phone. The phones have become platform (just Like Web had become a platform)
17. A new set of companies have come up who are just developing the Mobile Apps for various platforms. (Similar to web development companies who are involved in creating the web sites). Today every popular business wants its Apps and guess what its again the Indian companies who are taking such assignments. There are lot of start-ups who are developing apps for some of the leading brands like Levis, IBN, Star News etc. Just like businesses advertise for more details log on to www.xyz.com they are now saying download the app that will help you to browse the latest and greatest stuff on mobile.
18. There are 4 major drivers which are guiding the mobile App economy (To monetize the apps)
a. The Developer who is developing the App on its own or for a company
b. Content Provider (News channels, Sports Channels are trying to provide their content on the mobile)
c. Content Delivery Mechanism (3G, GPRS, Wifi. With the 3G connections ist possible to stream the videos on mobile. Expect IPL season 4 on the Mobile soon!!!)
d. Market place: The app stores where you can sell your applications. The App stores owners (Nokia’s ovistore, Apple Store) they are trying to come up with the Amazon like experience where the user can get recommendation for a app and based on the purchase history the apps are shown etc. It’s all about the experience.
e. Stay updated on the technology. You cant expect to sell a J2ME app now. People want the apps that are based on QT, Objective-C or Android
19. Cross platform compatibility is very important when it comes to apps. The same app should be available to run on iPhone , Android phone, and Symbian phone. The user can switch the platform but still want to use the same app. I want to use the same twitter app on my Iphone as well as on my Nokia C7. Its similar to the websites that should be compatible for all major browsers.
20. Customization in Apps will make that App stand out. If it is a cricket app I should be able to choose the stadiums, day match or day-night match etc.
21. Some of the factors that have helped in the popularity of the mobile apps:
a. Proliferation of smartphones: Now they are everywhere. There are some 50 odd OEM who are making smart phones. They are available for a wide price range (6000-36000 Rs)
b. Enhanced Lifestyle Quotient: People want to be connected. The facebook mobile app is helping them to be connected even when they are not at home/workplace
c. User Experience
d. High Utility Quotient: People find the mobile applications providing solutions to some of their daily needs like emails, local search, travels, news.
Just like integration of Digital Camera, FM radio became an integral part of the mobile hardware similarly the mobile apps will become an integral part of mobile usage.
22. Since there are millions of applications already developed from wide variety of domains for a new developer it’s very important to take care of few key things before getting started on a new app:
a. Is it solving genuine real life problem. For e.g. Banking app which help you to monitor yoru account, Stock trading apps are some of the applications that have simplified the real life workflows and are therefore very popular
b. Check for the existence of similar application. Do not waste time in reinventing the wheel
c. In case of the existing application try to collaborate with the developer and help in creating a higher utility quotient for it. Try to add more customization options etc
d. App should be easy to download and install. There should be 0 user manuals
e. You should be able to rapidly prototype the app and launch
f. Healthcare, telemedicine are some of the areas with huge potential for innovative ideas.
g. Education sector is very promising given the fact that today almost every college student has an access to mobile.
h. Real estate businesses can be another good choice to explore
23. Why is that people are running after Android?
a. There are many players in the market who are launching the phones on Android so as a consumer I get a variety of choice for phone and as a developer I have more potential customers to download my application
b. Developer Friendly: The Android Applications are Java based. If I know java learning the Android application development is quite simple (smooth learning curve). There is a huge java developer base who can start writing the applications.
c. There are many android markets unlike Ovistore and Apple app store. There are many local android markets which makes improves the chances for my application to be noticed . Also with the local markets(Indian Android market) I can get the apps that are more suitable for the local needs.
d. Most important that Android platform is not only restricted to the phones. Google TV is based on Android, Huawei is making set top box that are based on Android, GM is using android in Cars. So the scope of writing the applications is very wide.
e. With Google supporting the platform there is a trust that the platform is there to stay.