<repo_name>manikanta-kondeti/D3-samosa<file_sep>/parse.py
#!/bin/python 
import json
from pprint import pprint
import re 

#json_file='a.json' 
json_file='installation.json'
cube='1'

json_data=open(json_file)
data = json.load(json_data)
pprint(data["results"][0]["createdAt"])


year=[]
day=[]
month=[]
hour=[]
minute=[]


pprint(len(data["results"]))
countItems =  len(data["results"]);

for i in range(0,countItems):
    dataStamp = data["results"][i]["createdAt"];
    # Year
    match = re.match("(.*)T",dataStamp);
    string = match.group()
    year.append(int(string[0]+string[1]+string[2]+string[3]));
    month.append(int(string[5]+string[6]));
    day.append(int(string[8]+string[9]));
    # Time
    match = re.match("(.*)Z",dataStamp);
    string = match.group()
    hour.append(int(string[11]+string[12]));
    minute.append(int(string[14]+string[15]));



countInstalls = [];
for i in range(0,25):
    countInstalls.append(0)

count = 0;

for i in range(0,countItems):
        countInstalls[hour[i]] +=1 ;


for i in range(0,24):
    print countInstalls[i]


for i in range(0,25):
    count += countInstalls[i]
print count

jsondict = {}

for i in range(0,24):
    jsondict[i+1] = countInstalls[i]

pprint(json.dumps(jsondict))

with open('hours.json', 'w') as outfile:
        json.dump(jsondict, outfile)


json_data.close() 
<file_sep>/doc/D3jd.md
Data Driven Documents:
=====================

#Select and Append:
1. Add d3js script 
2. At the end of the body. Write a javascript 
	* d3.select("p").text("Hello World");
	- If there is no paragraph p
	* d3.select("body")
		.append("p")
		.style("red")
		.text("Hi, Whats up!");

# Basic SVG shapes(scalable vector graphics):
1.  var canvas = d3.select("body")
					.append("svg")
					.attr("width", 800)
					.attr("height", 400);
2. var circle = canvas.append("circle");
				.attr("cx" ,250);
				.attr("cy", 250);
				.attr("r",50);
				.attr("fill","red")


# Visualizing data:
1. var data Array= [20, 40, 60];

Bar chart 
2. var bars = canvas.selectAll("rect")
				.data(dataArray);
				.enter()
					.append("rect")
					.attr("width", function(d){
						return d*10;
					})	
					.attr("height", function(){
						return 50;
					})
					.attr("y", function(d,i){
						return i*100;
					});

Scale 
3. var widthScale = d3.scale.linear()
						.domain([])
						.range([]);

Groups and Axes 
4.  Group is added to canvas element to transform the svg element. 
	var canvas = d3.select("body")
					.append("svg")
					.attr("width", 500)
					.attr("height", 500)
					.append("g")
					.attr("transform", "translate(20,20)")

	Axis  --- (call axis) 
	canvas.call(axis);

5. Enter, Update, Exit 
		DOM elements > data elements (enter)
		DOM elements < data elements   (update)
		DOM elements == data elements (exit)

6. Transition :  .duration(), .delay()

7. Working with arrays 
		d3 has pretty good methods in that library 
			d3.min(data)
			d3.max(data)
			d3.extent(data)
			d3.mean(data)
			d3.	median(data)
			d3.shuffle -- Some random order. 

8 . No need of jquery, you can directly load json with d3. example given below 
		d3.json("./mysampledata.json", function(data){
				//code..
		});

9. (Paths, Arcs, PieLayouts) 		<file_sep>/README.md
# D3-samosa

* Watch this 13 Video Tutorials:  https://www.youtube.com/watch?v=n5NcCoa9dDU&list=PL6il2r9i3BqH9PmbOf5wA5E1wOG3FT22p
* Important points:  https://github.com/manikanta-kondeti/D3-samosa/blob/master/doc/D3jd.md 
