Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
21eea68
proposal
jcrawfordobanner Mar 6, 2018
e6e1c93
Factbook html amd raw data
jcdelrio30 Mar 6, 2018
27ea210
data for gdp,fini and coordiantes
jcrawfordobanner Mar 6, 2018
da6b2e1
makes a viewport that changes size to show more and more of the screen
jcrawfordobanner Mar 9, 2018
874e4ae
Merge branch 'master' of https://github.com/jcrawfordobanner/Interact…
jcdelrio30 Mar 9, 2018
ba85fae
Testing geoplotlib functions, csv stuff
jcdelrio30 Mar 9, 2018
af83519
created a slider bar that changes images based on position and has a …
jcrawfordobanner Mar 10, 2018
97af1ca
Merge branch 'master' of https://github.com/jcrawfordobanner/Interact…
jcrawfordobanner Mar 10, 2018
b06a603
First attempts at parsing world svg
jcdelrio30 Mar 10, 2018
5229593
made draw map draw afghanistan
jcrawfordobanner Mar 10, 2018
753a204
draws entire world
jcrawfordobanner Mar 13, 2018
f530e70
Added new data for internet users
jcdelrio30 Mar 13, 2018
8159c1b
my old py game stuff
jcdelrio30 Mar 13, 2018
60a9a5d
attempt no 100000
jcdelrio30 Mar 13, 2018
8144e65
checks the country your in
jcrawfordobanner Mar 13, 2018
bdaaed9
Merge branch 'master' of https://github.com/jcrawfordobanner/Interact…
jcrawfordobanner Mar 13, 2018
389f3e2
Got to read csv data and plot in map with different collors according…
jcdelrio30 Mar 15, 2018
1df5bf4
updated color mapping with functions
jcdelrio30 Mar 15, 2018
c6d53dd
mostly finished visualizer
jcrawfordobanner Mar 15, 2018
d031e9a
s
jcrawfordobanner Mar 15, 2018
9c9af00
Little changes to pygame
jcdelrio30 Mar 15, 2018
048c550
Final version of the code and project reflection
jcdelrio30 Mar 16, 2018
45939f4
Updated Read Me
jcdelrio30 Mar 16, 2018
7e079e5
Created merge conflict in Read Me
jcdelrio30 Mar 16, 2018
ae1f29d
mergecon
jcrawfordobanner Mar 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .~lock.API_NY.GDP.MKTP.CD_DS2_en_csv_v2.csv#
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,jobanner,j-Latitude-5480,13.03.2018 16:14,file:///home/jobanner/.config/libreoffice/4;
Binary file added 2001.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2002.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2003.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2004.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2005.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2006.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2007.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2008.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2009.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2010.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2011.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2012.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2013.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2014.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2015.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2016.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
265 changes: 265 additions & 0 deletions GDP_PC.csv

Large diffs are not rendered by default.

202 changes: 202 additions & 0 deletions Internet_Users_percentofpop_2000_2016.csv

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions README.md

This file was deleted.

26 changes: 26 additions & 0 deletions README.md.mine
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# World Internet Usage and GDP Per Capita Mapping
Run slider.py to launch an interactive visualizer for gdp and internet usage growth from 2001-2016

## Requirements
Use `pip` to install these packages:

* BeautifulSoup
* svg.path
* matplotlib
* pygame

## World Map and Databases
World map:world map SVG with a dictionary of country names and two letter country codes mapped to their matching polygon
https://simplemaps.com/resources/svg-world

GDP per capita:Renamed as GDP_PC.csv and unnecessary datd. Country codes edited to match the format from svg
https://data.worldbank.org/indicator/NY.GDP.PCAP.CD

Internet Users:Renamed as Internet_Users_percentofpop_2000_2016.csv
https://data.worldbank.org/indicator/IT.NET.USER.ZS

## Project Reflection
https://github.com/jcrawfordobanner/InteractiveProgramming/blob/master/Soft-Des%20Poject%204_%20Interactive%20Data%20Vizualization.pdf


## Lets make Conflicts
Binary file not shown.
Binary file added Softdes Project 4_ Proposal.pdf
Binary file not shown.
138 changes: 138 additions & 0 deletions pygame_draw_country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
"""Sample code for `us_map.py`.

Author: Oliver Steele <oliver.steele@olin.edu>
License: MIT

Requirements:

sudo pip install BeautifulSoup
sudo pip install matplotlib
sudo pip install svg.path
"""

import pygame
import sys
import matplotlib.path
import wold_map
import csv

#year that the data will be plotted forss
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
BLUE = (75, 75, 255)
GREEN = (75, 255, 75)
RED = (255, 50, 50)
GRAY = (127, 127, 127)
LIGHT_GRAY = (191, 191, 191)
countries=['AF','AL','DZ','AD','AO','AI','AG','AR','AM','AW','AU','AT','AZ','BS','BD','BB','BY','BE','BZ','BJ','BM','BT','BO','BA','BW','BR',
'VG','BN','BG','BF','BI','KH','CM','CA','CV','KY','CF','TD','CL','CN','HK','CO','KM','CG','CD','CR','CI','HR','CU','CY','CZ','DK','DJ','DM','DO',
'EC','EG','SV','GQ','ER','EE','ET','FK','FO','FJ','FI','FR','GF','PF','GA','GM','GE','DE','GH','GR','GL','GD','GP','GT','GN','GW','GY','HT',
'HN','HU','IS','IN','ID','IR','IQ','IE','IL','IT','JM','JP','JO','KZ','KE','KP','KR','KW','KG','LA','LV','LB','LS','LR','LY','LI','LT','LU','MK','MG','MW',
'MY','MV','ML','MT','MQ','MR','MU','YT','MX','MD','MN','ME','MS','MA','MZ','MM','NA','NR','NP','NL','NC','NZ','NI','NE','NG','NO','OM',
'PK','PS','PA','PG','PY','PE','PH','PN','PL','PT','PR','QA','RE','RO','RU','RW','KN','LC','VC','ST','SA','SN','RS','SC','SL','SG','SK',
'SI','SB','SO','ZA','SS','ES','LK','SD','SR','SZ','SE','CH','SY','TW','TJ','TZ','TH','TL','TG','TO','TT','TN','TR','TM','TC','UG','UA','AE','GB','US',
'UY','UZ','VU','VE','VN','VI','EH','YE','ZM','ZW']
width, height = 2000,2000

pygame.init()
screen = pygame.display.set_mode((width, height))
screen.fill(WHITE)


def point_in_polygon(pt, polygon):
"""Returns True iff `pt` is inside `polygon`.
`polygon` is a list of tuples `(x, y)`."""

return matplotlib.path.Path(polygon).contains_point(pt)

def find_magic(countries,year):
#for i in range(len(countries)):
magic_numbers = []
for i in range(len(countries)):
with open('Internet_Users_percentofpop_2000_2016.csv', newline='') as InternetUse:
internet = csv.DictReader(InternetUse)
for row in internet:
if countries[i] in row['Country Code']:
IU = row[year]
if IU == '':
IU = 0
else:
IU = float(IU)
country_name = row['Country Name']

with open('GDP_PC.csv', newline='') as GDP:
GNP = csv.DictReader(GDP)
for row in GNP:
if country_name == row['Country Name']:
gdp = row[year]
if gdp == '':
gdp = 0
else:
gdp = float(gdp)

if float(IU) != float(0) and float(gdp) != float(0):
magic_number = [IU/gdp]
magic_numbers = magic_numbers + magic_number
else:
zero = [0]
magic_numbers = magic_numbers + zero

return magic_numbers

def remap_interval(val,
input_interval_start,
input_interval_end,
output_interval_start,
output_interval_end):
"""Remap a value from one interval to another."""
range_output = output_interval_end-output_interval_start
range_input = input_interval_end-input_interval_start
distance = val - input_interval_start
remap = ((distance/range_input)*range_output)+output_interval_start
return remap

def color_map(val,minimum, maximum):
"""Maps input values between max and min IU/gdp cofficients to an integer
0-255,suitable for use as an RGB color code
"""
color_code = remap_interval(val,minimum ,maximum, 0, 255)
return int(color_code)

def draw_map(screen,year):
color_coefficients = find_magic(countries,year)
max_coeff = max(color_coefficients)
min_coeff = min(color_coefficients)


for i in range(len(countries)):
# Draw the polygons for the state.
for polygon in wold_map.countries[countries[i]]:
# `polygon` points are tuples `(float, float)`. PyGame requires `(int, int)`.
points = [(int(x), int(y)) for x, y in polygon]
# Draw the interior
number = color_map(color_coefficients[i],min_coeff,max_coeff)
if number > 0:
color = (0,0,number)
else:
color = WHITE
pygame.draw.polygon(screen,color, points)
# Draw the boundary
pygame.draw.polygon(screen, BLACK, points, 1)



"""last_mouse_in_state = False"""

"""while True:
if any(event.type == pygame.QUIT for event in pygame.event.get()):
sys.exit()

for country in countries:
# Is the mouse inside the state?
mouse_in_state = any(point_in_polygon(pygame.mouse.get_pos(), polygon) for polygon in wold_map.countries[country])
# Only print a message if the mouse moved from the inside to the outside, or vice versa
if mouse_in_state != last_mouse_in_state:
last_mouse_in_state = mouse_in_state
if mouse_in_state:
print ('mouse in',country)"""
211 changes: 211 additions & 0 deletions slider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import pygame
import sys
import pygame_draw_country
import random
import wold_map

def random_color():
r = lambda: random.randint(0,255)
return (r(),r(),r())

class PyManMain:
"""The Main PyMan Class - This class handles the main
initialization and creating of the Game."""

def __init__(self, width=640,height=480):
"""Initialize"""
"""Initialize PyGame"""
pygame.init()
"""Set the window Size"""
self.width = width
self.height = height
"""Create the Screen"""
self.screen = pygame.display.set_mode((self.width
, self.height))

def MainLoop(self):
rectangle_draging=False

self.slidey=Slider()
self.slidey_sprites = pygame.sprite.RenderPlain((self.slidey))

white = (255, 255, 255)
w = 2000
h = 1500
screen = pygame.display.set_mode((w, h))
screen.fill((white))

pygame.font.init()
myfont = pygame.font.SysFont('Comic Sans MS', 28)
textsurface = myfont.render('2001 |2002 |2003 |2004 |2005 |2006 |2007 |2008 |2009 |2010 |2011 |2012 |2013 |2014 |2015 |2016', False, (0, 0, 0))
running = True

while running:

if 0<=self.slidey.rect.x+100<125:
screen.fill((white))
screen.blit(pygame.image.load('2001.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 125<=self.slidey.rect.x+100<250:
screen.fill((white))
screen.blit(pygame.image.load('2002.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 250<=self.slidey.rect.x+100<375:
screen.fill((white))
screen.blit(pygame.image.load('2003.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 375<=self.slidey.rect.x+100<500:
screen.fill((white))
screen.blit(pygame.image.load('2004.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 500<=self.slidey.rect.x+100<625:
screen.fill((white))
screen.blit(pygame.image.load('2005.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 625<=self.slidey.rect.x+100<750:
screen.fill((white))
screen.blit(pygame.image.load('2006.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 750<=self.slidey.rect.x+100<875:
screen.fill((white))
screen.blit(pygame.image.load('2007.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 875<=self.slidey.rect.x+100<1000:
screen.fill((white))
screen.blit(pygame.image.load('2008.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 1000<=self.slidey.rect.x+100<1125:
screen.fill((white))
screen.blit(pygame.image.load('2009.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 1125<=self.slidey.rect.x+100<1250:
screen.fill((white))
screen.blit(pygame.image.load('2010.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 1250<=self.slidey.rect.x+100<1375:
screen.fill((white))
screen.blit(pygame.image.load('2011.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 1375<=self.slidey.rect.x+100<1500:
screen.fill((white))
screen.blit(pygame.image.load('2012.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 1500<=self.slidey.rect.x+100<1625:
screen.fill((white))
screen.blit(pygame.image.load('2013.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 1625<=self.slidey.rect.x+100<1750:
screen.fill((white))
screen.blit(pygame.image.load('2014.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 1750<=self.slidey.rect.x+100<1875:
screen.fill((white))
screen.blit(pygame.image.load('2015.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

if 1875<=self.slidey.rect.x+100:
screen.fill((white))
screen.blit(pygame.image.load('2016.jpg'),(0,0))
screen.blit(self.slidey.image, (self.slidey.rect.x, self.slidey.rect.y))
screen.blit(textsurface,(0,950))
pygame.display.update()

for event in pygame.event.get():
if event.type == pygame.QUIT:
running=False

elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
if self.slidey.rect.collidepoint(event.pos):
rectangle_draging = True
mouse_x, mouse_y = event.pos
offset_x = self.slidey.rect.x - mouse_x
offset_y = self.slidey.rect.y - mouse_y

elif event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
rectangle_draging = False

elif event.type == pygame.MOUSEMOTION:
if rectangle_draging:
mouse_x, mouse_y = event.pos
self.slidey.rect.x = mouse_x + offset_x


class Slider(pygame.sprite.Sprite):

# Constructor. Pass in the color of the block,
# and its x and y position
def __init__(self, color=(0,0,0), width=100, height=50):
# Call the parent class (Sprite) constructor
pygame.sprite.Sprite.__init__(self)

# Create an image of the block, and fill it with a color.
# This could also be an image loaded from the disk.
self.image = pygame.Surface([width, height])
self.image.fill(color)

# Fetch the rectangle object that has the dimensions of the image
# Update the position of this object by setting the values of rect.x and rect.y
self.rect = self.image.get_rect()
self.rect.x=0
self.rect.y=1000

if __name__ == "__main__":
white = (255, 255, 255)
w = 2000
h = 1500
years=['2001','2002','2003','2004','2005','2006','2007','2008','2009','2010','2011',
'2012','2013','2014','2015','2016']
screen = pygame.display.set_mode((w, h))
screen.fill((white))
for year in years:
pygame_draw_country.draw_map(screen, year)
pygame.image.save(screen, year+'.jpg')
screen.fill((white))
MainWindow = PyManMain()
MainWindow.MainLoop()
4 changes: 4 additions & 0 deletions testcsv.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lat,lon,GDP,IA
41,20,50,300
28,3,100,100
-14.3333,-170,200,10
Loading