Chicago Gun Shootings 2015

A different take on Chicago Tribune’s Gun Shooting visualizations. Time Range: JAN. 1, 2015 through AUG. 31, 2015.

The data was obtained and parsed from the Trib http://crime.chicagotribune.com/chicago/shootings

I made a daily line chart using Google Charts, and an overall intensity map using CartoDB.

chicagogunshootingvictims

Chicago 2015 Gun Shootings_Jan-Aug

C# Console Application used for parsing and manicuring.

// "Nah, yo, it ain't like that. Look, the pawns, man, in the game, they get capped quick. 
//  They be out the game early. " 
//  D'Angelo Barksdale The Wire HBO
 
Dictionary<DateTime, int> dictDate_Incident = new Dictionary<DateTime, int>();
 
//CHICAGO SHOOTINGS
// SINCE JAN. 1, 2015 through AUG. 31, 2015
 
Console.BufferHeight = 2000;
 
System.IO.StreamReader myFile =
    new System.IO.StreamReader(@"C:\CHICAGOSHOOTINGS\ChicagoShootings.txt");
 
string shootingData = myFile.ReadToEnd();
myFile.Close();
string[] lines = shootingData.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
int count = 0;
string output = "";
foreach(string line in lines)
{
    string [] parts = line.Split(',');
    string date = parts[5]+ " "+ parts[6];
    DateTime dateForm = DateTime.Parse(Regex.Replace(date, "\"", ""));
    output += parts[0].Replace('[', ' ').Trim() + " , " + parts[1].Trim() + " , " + dateForm + "\r\n";
    if ( dictDate_Incident.ContainsKey(dateForm))
    {
        int existing = dictDate_Incident[dateForm];
        existing += 1;
        dictDate_Incident[dateForm] = existing;
    }
    else
        dictDate_Incident.Add(dateForm, 1);
}
StreamWriter streamWrite;
streamWrite = File.AppendText("C:\\Airplanes\\chicagoshootings.csv");
streamWrite.WriteLine(output);
streamWrite.Close();
int total = 0;
foreach( DateTime date in dictDate_Incident.Keys )
{
    total += dictDate_Incident[date];
}
DateTime StartDate = new DateTime(2015, 1, 1);
DateTime EndDate = new DateTime(2015, 8, 31);
int DayInterval = 1;
List<DateTime> dateList = new List<DateTime>();
while (StartDate.AddDays(DayInterval) <= EndDate)
{
    StartDate = StartDate.AddDays(DayInterval);
    dateList.Add(StartDate);
}
string lineoutput = "";
foreach(DateTime dateALL in dateList)
{
    int c = 0;
    if ( dictDate_Incident.ContainsKey(dateALL) )
        c = dictDate_Incident[dateALL];
    else
        c = 0;
    Console.WriteLine("['"+dateALL.ToString("MM-dd") + "', " + c+"],");
 
    lineoutput += "['" + dateALL.ToString("MM-dd") + "', " + c + "],\r\n";
}
streamWrite = File.AppendText("C:\\Airplanes\\linejson.txt");
streamWrite.WriteLine(lineoutput);
streamWrite.Close();

Leave a Reply

Your email address will not be published.