-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcolorExtractor.py
More file actions
32 lines (28 loc) · 937 Bytes
/
colorExtractor.py
File metadata and controls
32 lines (28 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import csv
#Function to get the right color of a person
def getAvgColors(arrayColors):
aux = arrayColors**2
aux = avg(aux)
return avg
#Para cada archivo
with open('/home/g/Desktop/ColorProject/namesData/nameFiles.csv', 'rb') as csvfile:
reader = csv.DictReader(csvfile)
#Extraer los colores para cada id de nombre (contador)
for row in reader:
name = row['name']
n = row['n']
#Crear csv
cad = "echo '' > " + fileName + ".csv"
os.system(cad)
#Crear un csv y llenar con *idDiputado y *color
for idPerson in range(0,n):
colors = get_colors(idPerson)
avgColors = getAvgColors(colors)
#Escribe en el nuevo csv el id y el color promedio
cad2 = fileName + ".csv"
with open(cad2, 'w') as csvfile:
fieldnames = ['idPerson', 'color']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
writer.writerow({'idPerson': idPerson, 'color': avgColors})