def processReportFile (reportFile, currentDate): importantDateHash = encodeReportLib.readImportantDatesFile(currentDate) submitHash = {} releaseHash = {} try: f = open(reportFile, "r") except: print >> sys.stderr, "Error: Can't open file '%s'" % f sys.exit(-1) print >> sys.stderr, "Parsing file: %s" % (reportFile) for line in f: line = line.rstrip() if (line.startswith('Project')): # Skip the header line continue # The submit and release date are in fields 6 and 7 splitArray = line.split('\t') startDate = splitArray[6] endDate = splitArray[7] # Convert dates into ints submitDate = encodeReportLib.convertDate(startDate) releaseDate = encodeReportLib.convertDate(endDate) # Accumulate dates in hash if isinstance(submitDate, int): if not submitDate in submitHash: submitHash[submitDate] = 0 submitHash[submitDate] += 1 if isinstance(releaseDate, int): if not releaseDate in releaseHash: releaseHash[releaseDate] = 0 releaseHash[releaseDate] += 1 f.close() # Get the union of all possible dates unionDates = set.union(set(submitHash.keys()), set(releaseHash.keys()), set(importantDateHash.keys())) submitValue = 0 submitSum = 0 releaseValue = 0 releaseSum = 0 # Populate dataArray with the contents of the data matrix dataArray = [] for date in sorted(unionDates): dateString = str(date) submitValue = 0 if date in submitHash: submitValue = submitHash[date] releaseValue = 0 if date in releaseHash: releaseValue = releaseHash[date] submitSum += submitValue releaseSum += releaseValue annotText = "" if date in importantDateHash: annotText = importantDateHash[date] # Single row of data array = [] array.append(datetime.date(int(dateString[0:4]), int(dateString[4:6]), int(dateString[6:8]))) array.append(releaseValue) array.append(releaseSum) array.append(submitValue) array.append(submitSum) array.append(annotText) dataArray.append(array) return dataArray
def processReportFile (reportFile, keyIndex): hash = {} labelHash = {} f = open(reportFile, "r") for line in f: line = line.rstrip() if line.startswith('Project'): continue splitArray = line.split('\t') keyLabel = splitArray[keyIndex] startDate = splitArray[6] endDate = splitArray[7] status = splitArray[8] if keyIndex == 8 and (status == 'revoked' or status == 'replaced'): continue if keyIndex == 5: keyLabel = encodeReportLib.parseFreezeLabel(keyLabel) # Convert dates into ints submitDate = encodeReportLib.convertDate(startDate) releaseDate = encodeReportLib.convertDate(endDate) if status == 'released': if not isinstance(submitDate, int) or not isinstance(releaseDate, int): print >> sys.stderr, "Error: Invalid date: %s" % line else: if not keyLabel in labelHash: labelHash[keyLabel] = 0 labelHash[keyLabel] += 1 deltaTime = encodeReportLib.dateIntToObj(releaseDate) - encodeReportLib.dateIntToObj(submitDate) days = deltaTime.days if (days == 0): days = 1 weeks = days / 7 if (days % 7 != 0): # Adjust by one except when number of days is exactly divisible by 7 weeks += 1 if not weeks in hash: hash[weeks] = {} if not keyLabel in hash[weeks]: hash[weeks][keyLabel] = 0 hash[weeks][keyLabel] += 1 f.close() if keyIndex == 5: labels = encodeReportLib.orderFreezeDateLabels(labelHash.keys()) else: tmpLabels = sorted(labelHash.iteritems(), key=operator.itemgetter(1), reverse=True) labels = [] for i in tmpLabels: labels.append(i[0]) maxWeek = max(hash) for i in xrange(1, maxWeek+1): if not i in hash: hash[i] = {} for label in labels: if not label in hash[i]: hash[i][label] = 0 # Populate dataArray with the contents of the matrix dataArray = [] for key in sorted(hash): array = [] array.append(key) for label in labels: array.append(hash[key][label]) dataArray.append(array) return dataArray, labels
def processReportFile(reportFile, currentDate): importantDateHash = encodeReportLib.readImportantDatesFile(currentDate) submitHash = {} releaseHash = {} try: f = open(reportFile, "r") except: print >> sys.stderr, "Error: Can't open file '%s'" % f sys.exit(-1) print >> sys.stderr, "Parsing file: %s" % (reportFile) for line in f: line = line.rstrip() if (line.startswith('Project')): # Skip the header line continue # The submit and release date are in fields 6 and 7 splitArray = line.split('\t') startDate = splitArray[6] endDate = splitArray[7] # Convert dates into ints submitDate = encodeReportLib.convertDate(startDate) releaseDate = encodeReportLib.convertDate(endDate) # Accumulate dates in hash if isinstance(submitDate, int): if not submitDate in submitHash: submitHash[submitDate] = 0 submitHash[submitDate] += 1 if isinstance(releaseDate, int): if not releaseDate in releaseHash: releaseHash[releaseDate] = 0 releaseHash[releaseDate] += 1 f.close() # Get the union of all possible dates unionDates = set.union(set(submitHash.keys()), set(releaseHash.keys()), set(importantDateHash.keys())) submitValue = 0 submitSum = 0 releaseValue = 0 releaseSum = 0 # Populate dataArray with the contents of the data matrix dataArray = [] for date in sorted(unionDates): dateString = str(date) submitValue = 0 if date in submitHash: submitValue = submitHash[date] releaseValue = 0 if date in releaseHash: releaseValue = releaseHash[date] submitSum += submitValue releaseSum += releaseValue annotText = "" if date in importantDateHash: annotText = importantDateHash[date] # Single row of data array = [] array.append( datetime.date(int(dateString[0:4]), int(dateString[4:6]), int(dateString[6:8]))) array.append(releaseValue) array.append(releaseSum) array.append(submitValue) array.append(submitSum) array.append(annotText) dataArray.append(array) return dataArray