Skip to content

Commit

Permalink
Make CSVs include more information
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick7321 committed Oct 29, 2019
1 parent 2905df2 commit 408e428
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 17 deletions.
7 changes: 4 additions & 3 deletions Server/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ def getResults(directory):
def getResultReport(directory):
colorOutputType = request.args.get('colorOutputType') # this is the type of output we want
resDir = request.args.get('resDir') # this is the directory we are accessing
uploadDir = 'resources/uploads/' + resDir

csvTimestamp = countingDict[directory].makeBeadsCSV(colorOutputType) # access the stored counting variable and regen csv data

countingDict[directory].makeBeadsCSV(colorOutputType) # access the stored counting variable and regen csv data

uploadDir = 'resources/uploads/' + resDir

return send_file(uploadDir + '/results/beads.csv', as_attachment=True)
return send_file(uploadDir + '/results/' + colorOutputType + '_' + csvTimestamp + '.csv', as_attachment=True)
20 changes: 17 additions & 3 deletions lib/counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import itertools
import csv
import sys
import datetime
from enum import Enum
from os import listdir, path
from . import util
Expand Down Expand Up @@ -386,6 +387,19 @@ def makeBeadsCSV(self, colorFormat):
endIndex = newPath.rfind("/")
newPath = newPath[:endIndex]
newPath = newPath.replace("maps", "results")
newPath = newPath + "/beads.csv"

util.makeBeadsCSV(newPath, colorFormat, self.colorBeads)
currentTime = datetime.datetime.now()
currentTimeString = currentTime.strftime("%Y-%m-%dT%H-%M-%S")

if colorFormat == "rgb":
newPath = newPath + '/rgb_' + currentTimeString + '.csv'
elif colorFormat == "hsv":
newPath = newPath + '/hsv_' + currentTimeString + '.csv'
elif colorFormat == "cmyk":
newPath = newPath + '/cmyk_' + currentTimeString + '.csv'
elif colorFormat == "grayscale":
newPath = newPath + '/grayscale_' + currentTimeString + '.csv'

print(newPath, file=sys.stderr)

util.makeBeadsCSV(newPath, colorFormat, self.colorBeads, self.crushedBeads, self.waterBeads)
return currentTimeString
58 changes: 47 additions & 11 deletions lib/util.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import csv
import colorsys

CSV_RGB_COLNAMES = ['Bead Number', 'Red Val', 'Green Val', 'Blue Val', 'X-Coord', 'Y-Coord', 'Radius']
CSV_HSV_COLNAMES = ['Bead Number', 'Hue Val', 'Saturation Val', 'Value Val', 'X-Coord', 'Y-Coord', 'Radius']
CSV_CMYK_COLNAMES = ['Bead Number', 'Cyan Val', 'Magenta Val', 'Yellow Val', 'Black Val', 'X-Coord', 'Y-Coord', 'Radius']
CSV_GRAYSCALE_COLNAMES = ['Bead Number', 'Grayscale Red Val', 'Grayscale Green Val', 'Grayscale Blue Val', 'X-Coord', 'Y-Coord', 'Radius']
CSV_RGB_COLNAMES = ['Bead Number', 'Type', 'Red Val', 'Green Val', 'Blue Val', 'X-Coord', 'Y-Coord', 'Radius']
CSV_HSV_COLNAMES = ['Bead Number', 'Type', 'Hue Val', 'Saturation Val', 'Value Val', 'X-Coord', 'Y-Coord', 'Radius']
CSV_CMYK_COLNAMES = ['Bead Number', 'Type', 'Cyan Val', 'Magenta Val', 'Yellow Val', 'Black Val', 'X-Coord', 'Y-Coord', 'Radius']
CSV_GRAYSCALE_COLNAMES = ['Bead Number', 'Type', 'Grayscale Val', 'X-Coord', 'Y-Coord', 'Radius']

"""
Description: function that takes beadinfo and creates a csv with varying types of color output data
@param colorFormat: a string that is either 'rgb', 'hsv', 'cmyk', or 'grayscale'
@return void, writes file directly from class attributes
"""
def makeBeadsCSV(filepath, colorFormat, colorBeads):
def makeBeadsCSV(filepath, colorFormat, colorBeads, crushedBeads, waterBeads):

colNames = CSV_RGB_COLNAMES # RGB will be selected by default. these values will change if the colorFormat value matches below
writeFunc = writeOutputRgb
Expand All @@ -29,7 +29,9 @@ def makeBeadsCSV(filepath, colorFormat, colorBeads):
with open(filepath, mode='w', newline='') as beadFile:
writer = csv.writer(beadFile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(colNames)
writeFunc(writer, colorBeads)
writeFunc(writer, colorBeads)
addCrushedBeads(writer, colorFormat, crushedBeads)
addWaterBeads(writer, colorFormat, waterBeads)

def writeOutputRgb(writer, colorBeads):
i = 1
Expand All @@ -39,7 +41,7 @@ def writeOutputRgb(writer, colorBeads):
x = bead[2][0]; y = bead[2][1]
radius = bead[2][2]

writer.writerow([i, r, g, b, x, y, radius]) # row is written with beadNum, r, g, b, x, y, radius
writer.writerow([i, "Bead", r, g, b, x, y, radius]) # row is written with beadNum, r, g, b, x, y, radius
i += 1

def writeOutputHsv(writer, colorBeads):
Expand All @@ -51,7 +53,7 @@ def writeOutputHsv(writer, colorBeads):
x = bead[2][0]; y = bead[2][1]
radius = bead[2][2]

writer.writerow([i, h, s, v, x, y, radius]) # row is written with beadNum, h, s, v, x, y, radius
writer.writerow([i, "Bead", h, s, v, x, y, radius]) # row is written with beadNum, h, s, v, x, y, radius
i += 1

def writeOutputCmyk(writer, colorBeads):
Expand All @@ -63,7 +65,7 @@ def writeOutputCmyk(writer, colorBeads):
x = bead[2][0]; y = bead[2][1]
radius = bead[2][2]

writer.writerow([i, C, M, Y, K, x, y, radius]) # row is written with beadNum, c, m, y, k, x, y, radius
writer.writerow([i, "Bead", C, M, Y, K, x, y, radius]) # row is written with beadNum, c, m, y, k, x, y, radius
i += 1

def writeOutputGrayscale(writer, colorBeads):
Expand All @@ -74,7 +76,7 @@ def writeOutputGrayscale(writer, colorBeads):
x = bead[2][0]; y = bead[2][1]
radius = bead[2][2]

writer.writerow([i, grayscaleValue, x, y, radius]) # row is written with beadNum, grayscaleValue, x, y, radius
writer.writerow([i, "Bead", grayscaleValue, x, y, radius]) # row is written with beadNum, grayscaleValue, x, y, radius
i += 1

def listAverage(lst):
Expand Down Expand Up @@ -103,4 +105,38 @@ def rgbToCmyk(r,g,b):
k = min_cmy

# rescale to the range [0,cmyk_scale]
return c*cmyk_scale, m*cmyk_scale, y*cmyk_scale, k*cmyk_scale
return c*cmyk_scale, m*cmyk_scale, y*cmyk_scale, k*cmyk_scale

def addCrushedBeads(writer, colorFormat, crushedBeads):

for bead in crushedBeads:
x = bead[2][0]; y = bead[2][1];
r = bead[2][2];

if colorFormat == 'hsv':
writer.writerow(["N/A", "Crushed Bead", "N/A", "N/A", "N/A", x, y, r])
elif colorFormat == 'cmyk':
writer.writerow(["N/A", "Crushed Bead", "N/A", "N/A", "N/A", "N/A", x, y, r])
elif colorFormat == 'grayscale':
writer.writerow(["N/A", "Crushed Bead", "N/A", x, y, r])
elif colorFormat == 'rgb':
writer.writerow(["N/A", "Crushed Bead", "N/A", "N/A", "N/A", x, y, r])

def addWaterBeads(writer, colorFormat, waterBeads):

for bead in waterBeads:
x = bead[2][0]; y = bead[2][1];
r = bead[2][2];

if colorFormat == 'hsv':
writer.writerow(["N/A", "Water Bubble", "N/A", "N/A", "N/A", x, y, r])
elif colorFormat == 'cmyk':
writer.writerow(["N/A", "Water Bubble", "N/A", "N/A", "N/A", "N/A", x, y, r])
elif colorFormat == 'grayscale':
writer.writerow(["N/A", "Water Bubble", "N/A", x, y, r])
elif colorFormat == 'rgb':
writer.writerow(["N/A", "Water Bubble", "N/A", "N/A", "N/A", x, y, r])




0 comments on commit 408e428

Please sign in to comment.