def get_data_by_date_range(name, startMonth, startYear, endMonth, endYear): caseSensitiveName = DataManager.idToName[DataManager.nameToId[ name.lower()]] rtn = [] #iterate through month by month, year by year from the start to the #end and add any nonzero datapoints to the list of data currYear = startYear currMonth = startMonth while (currYear <= endYear): #if the current year is before the end year, then we just #iterate through all months if (currYear < endYear): while (currMonth <= 12): monthData = PriceReader.read_month_data( currMonth, currYear, caseSensitiveName) for day in range(1, len(monthData.data)): prices = monthData.get(day) #we only add nonzero prices becauase prices of 0 #means that there was no price data for that given date if (prices[0] != 0 and prices[1] != 0): rtn.append((currYear, currMonth, day, prices[0], prices[1])) currMonth = currMonth + 1 #have to reset the month back to 1 after we've gone through #all 12 months in the current year currMonth = 1 #if the current year is the end year, then we can only iterate #up to the end month elif (currYear == endYear): while (currMonth <= endMonth): monthData = PriceReader.read_month_data( currMonth, currYear, name) for day in range(1, len(monthData.data)): prices = monthData.get(day) if (prices[0] != 0 and prices[1] != 0): rtn.append((currYear, currMonth, day, prices[0], prices[1])) currMonth = currMonth + 1 #move on to the next year currYear = currYear + 1 return rtn
def get_data_by_date_range( name , startMonth , startYear , endMonth , endYear ): caseSensitiveName = DataManager.idToName[ DataManager.nameToId[ name.lower() ] ] rtn = [] #iterate through month by month, year by year from the start to the #end and add any nonzero datapoints to the list of data currYear = startYear currMonth = startMonth while( currYear <= endYear ): #if the current year is before the end year, then we just #iterate through all months if ( currYear < endYear ): while( currMonth <= 12 ): monthData = PriceReader.read_month_data( currMonth , currYear , caseSensitiveName ) for day in range( 1 , len( monthData.data ) ): prices = monthData.get( day ) #we only add nonzero prices becauase prices of 0 #means that there was no price data for that given date if ( prices[ 0 ] != 0 and prices[ 1 ] != 0 ): rtn.append( (currYear , currMonth , day , prices[ 0 ] , prices[ 1 ] ) ) currMonth = currMonth + 1 #have to reset the month back to 1 after we've gone through #all 12 months in the current year currMonth = 1 #if the current year is the end year, then we can only iterate #up to the end month elif ( currYear == endYear ): while( currMonth <= endMonth ): monthData = PriceReader.read_month_data( currMonth , currYear , name ) for day in range( 1 , len( monthData.data ) ): prices = monthData.get( day ) if ( prices[ 0 ] != 0 and prices[ 1 ] != 0 ): rtn.append( (currYear , currMonth , day , prices[ 0 ] , prices[ 1 ] ) ) currMonth = currMonth + 1 #move on to the next year currYear = currYear + 1 return rtn