Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
You find the JSON-file here: drydo.com/crawler/files/json/data.json

Scroll to the bottom of the JSON-file to find the data structure. Go back up in the file and look for position to find the column labels.


This is the code I've done so far. I began to write in Javascript, although I realize that it was a mistake, but atleast now it finally got to me why it's called "client-side language". But don't get hanged up on that, it's already full of syntax errors and missing pieces.
The code at least contains building blocks to use in another language like PHP or Python.


JavaScript
$.getJSON("Infectious Disease_Cases_by_County_Year_and_Sex_2001_2014.json", function(json) {
  
  
	   for(var i = 0; i < json.data.length; i++) {
	    
	    var data = json.data;
	    
	    
	                               /* Statements to use */
	    var disease = data[i][8]; /* IF disease == data[--i][8] */
	    var county = data[i][9]; /* IF county == data[--i][9] */
	    var year = data[i][10]; /* IF "2001 =< year <= 2014 | MAY NOT BE NEEDED */
	    var gender = data[i][11]; /* IF "gender == "Total" */
	    var infectionCase = data[i][12];
	    var population = data[i][13];
	   
	    /* only executes if last disease AND county was the same as current [i], have to include "" because first post data[-1][x] will be null */
	    if(disease == data[--i][8] || disease == "" && county == data[--i][9] || disease == "" && gender = "Total"){
	    	
	    	
	    	foreach(){
	    	var sumInfectionCases;
	    	var sumPopulations;
	    	
	    	var sumInfectionCases = sumInfectionCases + infectioncase;
	    	var sumPopulations = sumPopulations + population;
	    	}
	    	
	    }
	    else(){
	    	
	    	var CountyAverage.byDisease.everyYear = {disease: data[--i][8], county: data[--i][9], average: sumInfectionCases / sumInfectionCases};
	    	
	    	/* write CountyAverage.byDisease.everyYear to dataManipulation.json */
	    	
	    }
	    
	};
	
  
});


The things that needs to be done is.


1. Sum all "Infection cases" by "Disease" and "County" for "Every year, 2001-2014" divide by the Sum of total population for every year.
RESULTING in a new JSON array "County average(2001-2014)" for each disease.

2. Sum all "County average(2001-2014)" for each disease divide it by the number of "County average(2001-2014)"
RESULTING in a new JSON array "National average(2001-2014)" for each disease.

3. Then divide each "County average(2001-2014)" with the "National average(2001-2014)".
RESULTING in a new JSON array "Effect size" for every county.



4. Write the new arrays to the original JSON-file in the "meta:" section.
Posted
Updated 12-Dec-15 21:55pm
v5

1 solution

There's nothing to stop you traversing your data as you have started off doing - except I think you'll find it complex to derive your stats

You dont indicate a 'language' you are using - it seems from your fragment you're using ? ASP.Net or JavaScript or ?

The approach I would take is (if I were doing it in c#)

a) use json2csharp and derive an object model from your JSON data
b) deserialise your json to your object model
c) do your stats operations on the object model - linq etc
d) rename the old file so it wont get processed again, then write a new file

its testable, maintainable, auditable
 
Share this answer
 
v2
Comments
AdamDedanga 13-Dec-15 3:53am    
I wrote it in Javascript, although I regret that. I barely know Javascript syntax. But hopefully the idea how to work through the array is there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900