NorCalAthlete
O_o
Have to open a CSV file and scan it in. It's several integers and a string corresponding to a state ID, plant ID, department ID, employee name, and a count for how many things each employee built (there's also an employee ID, but doesn't need to get used for counting anything just the department/state/plant totals). Each is separated by commas.
I can get the file to read in. I can get my program to split the file and print out, line by line, each set. But I'm not sure how to do the formatting and prioritizing for the count. For example, there are two "dept ID = 57" but they're in different plants - like, plant 34 has a dept 57, and plant 38 has a dept 57. We have to insert subtotals when something changes (ie, a department or plant). We also have to space everything out nicely.
So far, just this will print out the whole CSV file, in the correct block order with headers, just not nicely formatted.
Then I have this for the headers nicely formatted but haven't put in the rest of the data yet:
It needs to print out like this:
http://www.cs.sjsu.edu/~mak/CS160/assignments/1/Assignment1.pdf
I can get the file to read in. I can get my program to split the file and print out, line by line, each set. But I'm not sure how to do the formatting and prioritizing for the count. For example, there are two "dept ID = 57" but they're in different plants - like, plant 34 has a dept 57, and plant 38 has a dept 57. We have to insert subtotals when something changes (ie, a department or plant). We also have to space everything out nicely.
So far, just this will print out the whole CSV file, in the correct block order with headers, just not nicely formatted.
Code:
file = File.open("widgets.csv")
puts file.readline.split("\r")
file.close
Then I have this for the headers nicely formatted but haven't put in the rest of the data yet:
Code:
file = File.open("widgets.csv", "r").readline.split("\r")
array = []
file.each do |line|
array << line.split(",")
end
hLen = [] //header length
array[0].each do |word|
hLen << word.length
end
printf("\n%#{hLen[0]+1}s%#{hLen[1]+1}s%#{hLen[2]+1}s%#{hLen[3]+1}s%#{hLen[5]+1}s %-s\n\n", \
array[0][0], array[0][1], array[0][2], array[0][3], array[0][5], array[0][4])
#counts
cdept = 0
cplant = 0
cstate = 0
ctotal = 0
state = array[1][0]
plant = array[1][1]
dept = array[1][2]
curcount = array[1][4]
#iterate through the array columns
#if dept != previous dept
#total for dept print
#if plant != previous plant
#total for plant print
#if state != previous state
#total for state print
total = dept + plant + state
It needs to print out like this:
http://www.cs.sjsu.edu/~mak/CS160/assignments/1/Assignment1.pdf