Monday, May 28, 2012

Set top box and DTH Set top box difference. Things to consider while buying Set top box in India

In India, after digitization, TV transmission is going change. This change in TV transmission will start from 1st July 2012 in 4 metro cities of India. With respect to this announcement, customers in India will have to choose either “Direct To Home (DTH) set top box” or “Cable set top box”. Of course It is customer who is going to get benefitted out of this change. However, I saw that, there are many people who are confused about this change and don’t know what are the important points to be considered before buying DTH or Cable set top box. Following are the few points I feel one should consider while going for purchase of Set Top Box in India. First of all let’s understand digitization.
What is Digitization of TV services –
TV signals are currently distributed in India in analog format as well as digital format. Most cable operators within country provides analog format TV services whereas all DTH operators provide digital format TV services. Digitization means that all household TV sets using cable services would receive digital TV signal through Set Top Box. As a part of digitization every cable operator will be legally bound to transmit digital signals, which can be received at subscribers home through set top box only.
Comparing DTH and Cable Service at high level-
At high level if we compare DTH and Cable set to box, then I will say DTH is better. Because, DTH receives signal directly from satellite and reach to the TV through Set top Box; hence the picture quality is extremely good. However, the primary requirement of DTH is, the sky should be clean else disturbance in signal is observed. Signal disruption is a common problem in rainy season in India. Also DTH is costly and few may not find suitable financially. Cable set top box is attached to TV using fiber wires and it is cheaper as compared to DTH service.
DTH providers in India are Dish, Airtel, Sun, Videocon whereas for cable connection in Mumbai, we have Hathway cable, In cable, DigiCable, Den Cable providers. All these DTH and cable providers work as per rules and regulations set by TRAI however, quality of services will vary depending on the company network capabilities.

Wednesday, May 23, 2012

Windows Azure – Shared Access Signature for Azure Blob Storage Container

My client has amazing chemical gotcha in his mind. One moment he says something and next moment he asks me to do exactly opposite of it.
Anyways, He asked me to create a Private container in Windows Azure Blob storage and then asked me to give rights to access the container for 1 hour. This is where I came to know about creating Shared Access Signature for Blob Storage. Shared Access Signature can be used in scenarios Azure Blob Storage container is private & still you want to give access to it for certain time duration say 10 days.
Following is the example how Share Access Signature can be created for Windows Azure Blob Storage container and how you can retrieve data from it. For demo purpose I am using development storage. As usual, let’s create a simple cloud service project and add a sample web role in it. Then add a page SharedAccessPolicyDemo.aspx in the web role. I added 2 buttons & few labels on the page to create Shared Access Signature for a private container and access data present in the blob. My final Solution structure is as follows –
Page design is as follow -

Wednesday, May 16, 2012

HTC one V – an android 4.0 powered smart phone from HTC - Features and Review


In the field of smart phone, along with BlackBerry, one more company penetrated deep in the market. The name is HTC. Initially, in the starting age, “smart phones mean HTC” was the trend. After that, Samsung and other few companies stepped into smart phone and HTC had gone on back foot. Now HTC is trying to rise again with new series of smart phones.
Great things in Small Packages
HTC describes their new smart phone HTC one V as “Great things in small Packages”. Main change in HTC 1 V lies in the size!!! The new HTC one V is rectangle in shape however corners are curved. Because of this curvature HTC one V has become easy to hold in hand.
Display
 It's a 3.7in LCD panel with a resolution of 480 x 800 pixels. The only downside is that the surface is less oleo phobic (lacking affinity for oils) than other smart phone screens so fingerprints are more vivid.

Thursday, May 10, 2012

Using SQL Azure for Session State Management in Windows Azure Applications

We all know that, Inproc session management will not work in WindowsAzure. I am going to explain you how SQL Azure can be used for maintaining session state in Windows Azure Web Role Applications.
To start with let’s create a simple cloud service project in VS2010 and add a web role in it. Then I opened master page and changed the heading to “Session Management using SQL Azure Demo”. Open default.aspx and add a button and textbox. Input text written by user in textbox will be saved in session on the button click and on another button click it will be populated in label. Code on both the buttons is as follows –
protected void btnAddSession_Click(object sender, EventArgs e)
        {
            Session["Value"] = txtValue.Text;
        }

        protected void btnGetSession_Click(object sender, EventArgs e)
        {
            lblValue.Text = Convert.ToString(Session["Value"]);
        }

So my final solution structure and default.aspx layout is as follows –

Wednesday, May 2, 2012

Heat map using Bing and Windows Azure Web Role

Today I will explain how Azure web role can be used with Bing Maps to draw Heat map based on the input file. The input file data is as follows –
I have state name of USA, latitude and longitude, number of units sold of a product (typical sales data) in the particular state sorted in ascending order.

38.34,-121.29,100,California    
30.26,-84.17,200,Florida         
44.26,-72.57,300,Vermont       
33.26,-112.04,400,Arizona      
39.09,-119.45,500,Nevada       
42.73,-84.55,600,Michigan     
38.19,-84.87,700,Kentucky      
35.28,-97.30,800,Oklahoma    
32.80,-96.76,900,Texas          
46.35,-112.02,1000,Montana    
44.57,-123.02,1100,Oregon      
21.18,-157.51,1200,Hawaii        
38.98,-76.48,1300,Maryland   
35.41,-105.56,1400,New Mexico          
44.22,-100.21,1500,South Dakota        
38.53,-77.02,1600,Washington
39.74,-104.99,1700,Colorado   

I have downloaded heatmap.js javascript file to plot heat map on Bing map using HTML 5 canvas element. The complete code of heatmap.js is here. We need to add this file in Scripts folder of web role.
Now let’s create a web role. I will have my input file added in the web role. In the page load I will read input text file and plot heat map.

Code for HeatMap.js and BingHeatMap.aspx file

Code for heatmap.js is taken from http://alastaira.wordpress.com

/*******************************************************************************
* Description:
* This JavaScript file provides an algorithm that can be used to add a heatmap
* overlay on a Bing Maps v7 control. The intensity and temperature palette
* of the heatmap are designed to be easily customisable.
*
* Requirements:
* The heatmap layer itself is created dynamically on the client-side using
* the HTML5 <canvas> element, and therefore requires a browser that supports
* this element. It has been tested on IE9, Firefox 3.6/4 and
* Chrome 10 browsers. If you can confirm whether it works on other browsers or
* not, I'd love to hear from you!

* Usage:
* The HeatMapLayer constructor requires:
* - A reference to a map object
* - An array or Microsoft.Maps.Location items
* - Optional parameters to customise the appearance of the layer
*  (Radius, Intensity, and ColourGradient), and a callback function
*
*/

var HeatMapLayer = function(map, locations, options) {

  /* Private Properties */
  var _map = map,
      _canvas,
      _temperaturemap,
      _locations = [];

  // Set default options
  var _options = {
    // Opacity at the centre of each heat point
    intensity: 0.5,

    // Affected radius of each heat point
    radius: 20,

    // Colour temperature gradient of the map
    colourgradient: {
      "0.00": 'rgba(255,0,255,20)',  // Magenta
      "0.25": 'rgba(0,0,255,40)',    // Blue
      "0.50": 'rgba(0,255,0,80)',    // Green
      "0.75": 'rgba(255,255,0,120)', // Yellow
      "1.00": 'rgba(255,0,0,150)'    // Red
    },

    // Callback function to be fired after heatmap layer has been redrawn
    callback: null
  };

  /* Private Methods */
  function _init() {

    // Create the canvas element and place it in the DOM
    _canvas = document.createElement('canvas');
    _canvas.id = 'heatmapcanvas'
    _canvas.style.position = 'relative';
    var _mapDiv = _map.getRootElement();
    _mapDiv.parentNode.lastChild.appendChild(_canvas);

    // Override defaults with any options passed in the constructor
    setOptions(options);

    // Load array of location data
    setPoints(locations);

    // Create a colour gradient from the suppied colourstops
    _temperaturemap = createColourGradient(_options.colourgradient);

    // Wire up the event handler to redraw heatmap canvas
    Microsoft.Maps.Events.addHandler(_map, 'viewchangestart', clearHeatMap);
    Microsoft.Maps.Events.addHandler(_map, 'viewchangeend', createHeatMap);

    delete _init;
  }

  /* Public Methods */
  function clearHeatMap() {
    var ctx = _canvas.getContext("2d");
    ctx.clearRect(0, 0, _canvas.width, _canvas.height)
  }

  function createColourGradient(colourstops) {
    var ctx = document.createElement('canvas').getContext('2d');
    var grd = ctx.createLinearGradient(0, 0, 256, 0);
    for (var c in colourstops) {
      grd.addColorStop(c, colourstops[c]);
    }
    ctx.fillStyle = grd;
    ctx.fillRect(0, 0, 256, 1);
    return ctx.getImageData(0, 0, 256, 1).data;
  }

  function colouriseHeatMap() {
    var ctx = _canvas.getContext("2d");
    // Colourise
    var dat = ctx.getImageData(0, 0, _canvas.width, _canvas.height);
    var pix = dat.data; // pix is a CanvasPixelArray containing height x width x 4 bytes of data (RGBA)
    for (var p = 0; p < pix.length; ) {
      var a = pix[p + 3] * 4; // get the alpha of this pixel
      if (a != 0) { // If there is any data to plot
        pix[p] = _temperaturemap[a]; // set the red value of the gradient that corresponds to this alpha
        pix[p + 1] = _temperaturemap[a + 1]; //set the green value based on alpha
        pix[p + 2] = _temperaturemap[a + 2]; //set the blue value based on alpha
      }
      p += 4; // Move on to the next pixel
    }
    ctx.putImageData(dat, 0, 0);
  }

  function setOptions(options) {
    for (attrname in options) {
      _options[attrname] = options[attrname];
    }
  }

  function setPoints(locations) {
    _locations = locations;
  }

  function createHeatMap() {
    // Ensure the canvas matches the current dimensions of the map
    // This also has the effect of resetting the canvas
    _canvas.height = _map.getHeight();
    _canvas.width = _map.getWidth();

    var ctx = _canvas.getContext("2d");

    // Create the Intensity Map
    for (var i = 0; i < _locations.length; i++) {
      var loc = _locations[i];

      // Convert lat/long to pixel location
      var pixloc = _map.tryLocationToPixel(loc, Microsoft.Maps.PixelReference.control);
      var x = pixloc.x;
      var y = pixloc.y;

      // Create radial gradient centred on this point
      var grd = ctx.createRadialGradient(x, y, 0, x, y, _options.radius);
      grd.addColorStop(0.0, 'rgba(0, 0, 0, ' + _options.intensity + ')');
      grd.addColorStop(1.0, 'transparent');

      // Draw the heatpoint onto the canvas
      ctx.fillStyle = grd;
      ctx.fillRect(x - _options.radius, y - _options.radius, x + _options.radius, y + _options.radius);
    }

    // Apply the specified colour gradient to the intensity map
    colouriseHeatMap();

    // Call the callback function, if specified
    if (_options.callback) {
      _options.callback();
    }

  }

  this.SetOptions = function(options) {
    setOptions(options);
  }

  this.SetPoints = function(points) {
    clearHeatMap();
    setPoints(points);
    createHeatMap();
  }

  this.Remove = function() {
    var _mapDiv = _map.getRootElement();
    _mapDiv.parentNode.lastChild.removeChild(_canvas);
  }

  // Call the initalisation routine
  _init();

};

BingHeatMap.aspx –
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BingHeatMap.aspx.cs" Inherits="HeatMapGenerator.BingHeatMap" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Bing Maps Client Side Heat Map</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
    <!-- Include the heatmap library -->
    <script type="text/javascript" src="Scripts/heatmap.js"></script>
    <script type="text/javascript">
           var map;
           var heatmapLayer;

        var coordinatesToMap = <%= coodinateString%>;


           function GetMap() {
               map = new Microsoft.Maps.Map(document.getElementById("divMap"),
           { credentials: "YourBing Map Key",
               center: new Microsoft.Maps.Location(36.592, -95.332),
               mapTypeId: Microsoft.Maps.MapTypeId.road,
               labelOverlay: Microsoft.Maps.LabelOverlay.hidden,
               zoom: 4
           });

               heatmapLayer = new HeatMapLayer(
           map,
           coordinatesToMap,
             { intensity: 0.25,
             radius: 25,
             colourgradient:
                {
                 0.0: '#FF0000',
                 0.1: '#FF0000',
                 0.2: '#FF0000',
                 0.3: '#FF0000',
                 0.4: '#FF0000',
                 0.5: '#FFFF00',
                 0.6: '#FFFF00',
                 0.7: '#90EE90',
                 0.8: '#9ACD32',
                 0.9: '#228B22',
                 1.0: '#008000'                    

//                 0.0: '#FF0000',
//                 0.1: '#FF0000',
//                 0.2: '#FF0000',
//                 0.3: '#FF0000',
//                 0.4: '#FF0000',
//                 0.5: '#FF0000',
//                 0.6: '#FFFF00',
//                 0.7: '#90EE90',
//                 0.8: '#9ACD32',
//                 0.9: '#228B22',
//                 1.0: '#008000' 
                }                     
             }
             );

           }
    </script>   
    <style type="text/css">
        .style1
        {
            width: 100%;
            height: 113%;
        }
    </style>
</head>
<body onload="GetMap();" style="height: 100%">
    <form id="form1" runat="server">
    <table border="1" style="width: 100%; height: 100%;">
       
        <tr>
            <td id="k" >
                <table style="height: 100%; width: 100%;">
                    <tr>
                        <td style="height: 100%; width: 70%;">
                            <div id="divMap" style="position:relative; width:840px; height:480px;"></div>
                           
                         </td>                      
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

BingHeatMap.aspx.cs –
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;


namespace HeatMapGenerator
{
    public partial class BingHeatMap : System.Web.UI.Page
    {
        /// <summary>
        /// variable used for creating point to plot on bing map. This variable will be accessed in javascript code after finalising points to plot.
        /// </summary>
        public string coodinateString = "[";       

        /// <summary>
        /// Page load function used for downloading the input from blob and plotting points on Bing map
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {  
                string line = string.Empty;

                // Read the file and display it line by line.
                System.IO.StreamReader file = new System.IO.StreamReader(AppDomain.CurrentDomain.BaseDirectory + "Input/HeatMapInput.txt");               

                //create random number generator
                Random r = new Random();

                int pointCount = 1;
                while ((line = file.ReadLine()) != null)//read till end of file is reached
                {
                    //split the lne based on ',' delimiter and retrieve lattitude and longitude
                    string[] words = line.Split(new char[] { ',' });
                    double baseLat = Convert.ToDouble(words[0]);
                    words[1] = words[1].Substring(0, (words[1].Length - 1));
                    double baseLongi = Convert.ToDouble(words[1]);
                    double lat = baseLat;
                    double longi = baseLongi;

                    //loop to plot bing map points in the near vicinity
                    for (int i = 1; i <= pointCount + 6; i++)
                    {
                        coodinateString = coodinateString + "new Microsoft.Maps.Location(" + lat.ToString() + "," + longi.ToString() + "),";

                        #region point plotting combination 1
                        if (lat >= baseLat + 2)
                        {
                            lat = lat - r.Next(1, 3);
                        }
                        else
                        {
                            lat = lat + r.Next(0, 3);
                        }

                        if (longi >= baseLongi + 2)
                        {
                            longi = longi - r.Next(1, 3);
                        }
                        else
                        {
                            longi = longi + r.Next(0, 3);
                        }
                        #endregion

                        #region point plotting combination 2
                        //if (lat >= baseLat + 2)
                        //{
                        //    lat = lat - r.NextDouble() - 1;
                        //}
                        //else
                        //{
                        //    lat = lat + r.NextDouble() + 1;
                        //}

                        //if (longi >= baseLongi - 3)
                        //{
                        //    longi = longi - r.Next(1, 3) - 1;
                        //}
                        //else
                        //{
                        //    longi = longi + r.Next(0, 3) + 1;
                        //}
                        #endregion
                    }
                    pointCount = pointCount + 3;
                    //pointCount = pointCount + 1;
                }
                coodinateString = coodinateString + "]";

                //close the file streamreader
                file.Close();
               
            }
            catch (Exception ex)
            {
               
            }
        }
    }
}