Exemplo n.º 1
0
    def get_values2(self, values, value_selected, monthsnumber):
        #hacemos una relacion entre el value_selected y los values
        conv = {
            0: 1,  #value 0 es kilometros (1)
            1: 2,  #value 1 es tiempo (2)
            2: 3,  #value 2 es pulsaciones(3)
            3: 5,  #value 3 es media(5)
            4: 6  #value 4 es calorias(6)
        }
        list_values = {}
        list_average = {}
        tm_total = {}
        for i in range(1, monthsnumber + 1):
            list_values[i] = 0
            list_average[i] = 0
            tm_total[i] = 0

        value_sel = conv[value_selected]

        for value in values:
            date = value[0]
            try:
                year, month, day = date.year, date.month, date.day
            except AttributeError:
                year, month, day = date.split("-")
            month = int(month)
            #si la opcion es tiempo lo pasamos a horas / if the option is time we passed it to hours
            if (value_sel == 2):
                graph_value = self.getFloatValue(value[value_sel]) / 3600
            else:
                graph_value = self.getFloatValue(value[value_sel])

            #si es una opcion de suma de absolutos / if it is an option of sum of absolute
            if ((value_selected == 0) or (value_selected == 1)
                    or (value_selected == 4)):
                list_values[int(month)] += graph_value
            #si se trata de calcular medias / if one is to calculate averages:
            else:
                if graph_value is not None and graph_value != 0:
                    list_values[int(month)] += graph_value
                    list_average[int(month)] += 1

        xunits = []
        yunits = []
        for i in range(0, monthsnumber):
            xunits.append(locale_str(calendar.month_abbr[i + 1]))
            yunits.append(float(0))
        for value in list_values:
            if ((value_selected == 0) or (value_selected == 1)
                    or (value_selected == 4)):
                yunits[value - 1] = list_values[value]
            else:
                if list_average[value] > 0:
                    yunits[value -
                           1] = list_values[value] / list_average[value]
        return xunits, yunits
Exemplo n.º 2
0
    def get_values2(self,values,value_selected,monthsnumber):
        #hacemos una relacion entre el value_selected y los values
        conv = {
            0: 1, #value 0 es kilometros (1)
            1: 2, #value 1 es tiempo (2)
            2: 3, #value 2 es pulsaciones(3)
            3: 5, #value 3 es media(5)
            4: 6 #value 4 es calorias(6)
            }
        list_values = {}
        list_average = {}
        tm_total = {}
        for i in range(1,monthsnumber+1):
            list_values[i]=0
            list_average[i]=0
            tm_total[i] = 0
            
        value_sel = conv[value_selected]

        for value in values:
            date = value[0]
            try:
                year,month,day = date.year, date.month, date.day
            except AttributeError:
                year,month,day = date.split("-")
            month = int(month)
            #si la opcion es tiempo lo pasamos a horas / if the option is time we passed it to hours
            if (value_sel == 2):
                graph_value = self.getFloatValue(value[value_sel])/3600
            else:
                graph_value = self.getFloatValue(value[value_sel])

            #si es una opcion de suma de absolutos / if it is an option of sum of absolute
            if ((value_selected == 0) or (value_selected==1) or (value_selected==4)):
                list_values[int(month)] += graph_value
            #si se trata de calcular medias / if one is to calculate averages:
            else:
                if graph_value is not None and graph_value != 0:
                    list_values[int(month)] += graph_value
                    list_average[int(month)] += 1

        xunits = []
        yunits = []
        for i in range (0,monthsnumber):
            xunits.append(locale_str(calendar.month_abbr[i+1]))
            yunits.append(float(0))
        for value in list_values:
            if ((value_selected == 0) or (value_selected==1) or (value_selected==4)):
                yunits[value-1] = list_values[value]
            else:
                if list_average[value]>0:
                    yunits[value-1] = list_values[value]/list_average[value]
        return xunits,yunits
Exemplo n.º 3
0
    def get_values(self, values, value_selected, key_format, sportfield=9):
        valueDict = {}  #Stores the totals
        valueCount = {}  #Counts the totals to allow for averaging if needed
        sportColors = {}

        for record in values:
            if record.date:
                day = locale_str(record.date.strftime(
                    key_format))  # Gives year for this record
                sport = record.sport.name
                value = self.getValue(record, value_selected)
                if sport in valueDict:  #Already got this sport
                    if day in valueDict[
                            sport]:  #Already got this sport on this day
                        valueDict[sport][day] += value
                        valueCount[sport][day] += 1
                    else:  #New day for this sport
                        valueDict[sport][day] = value
                        valueCount[sport][day] = 1
                else:  #New sport
                    valueDict[sport] = {day: value}
                    valueCount[sport] = {day: 1}
            else:
                logging.debug("No date string found, skipping entry: %s",
                              record)

        if value_selected in (2, 3):
            total = {}
            count = {}
            for sport in valueDict.keys():
                for day in valueDict[sport].keys():
                    if valueCount[sport][
                            day] > 1:  #Only average if 2 or more entries on this day
                        valueDict[sport][day] /= valueCount[sport][day]

        if value_selected == 1:  #Values are of time type
            valuesAreTime = True
        else:
            valuesAreTime = False

        return valueDict, valuesAreTime
Exemplo n.º 4
0
    def get_values(self, values, value_selected, key_format, sportfield=9):
        valueDict = {} #Stores the totals
        valueCount = {} #Counts the totals to allow for averaging if needed
        sportColors = {}

        for record in values:
            if record.date:
                day = locale_str(record.date.strftime(key_format)) # Gives year for this record
                sport = record.sport.name
                value = self.getValue(record, value_selected)
                if sport in valueDict: #Already got this sport
                    if day in valueDict[sport]: #Already got this sport on this day
                        valueDict[sport][day] += value
                        valueCount[sport][day] += 1
                    else: #New day for this sport
                        valueDict[sport][day] = value
                        valueCount[sport][day] = 1
                else: #New sport
                    valueDict[sport] = {day: value}
                    valueCount[sport] = {day: 1}
            else:
                logging.debug("No date string found, skipping entry: %s", record)
                
        if value_selected in (2, 3):
            total = {}
            count = {}
            for sport in valueDict.keys():
                for day in valueDict[sport].keys():
                    if valueCount[sport][day] > 1: #Only average if 2 or more entries on this day
                        valueDict[sport][day] /= valueCount[sport][day]

        if value_selected == 1: #Values are of time type
            valuesAreTime=True
        else:
            valuesAreTime=False

        return valueDict, valuesAreTime
Exemplo n.º 5
0
def getDays(date_ini):
	#TODO look at using calendar.day_abbr for this
	return [locale_str((date_ini+datetime.timedelta(x)).strftime("%a")) for x in range(0,7)]
Exemplo n.º 6
0
def getDays(date_ini):
	#TODO look at using calendar.day_abbr for this
	return [locale_str((date_ini+datetime.timedelta(x)).strftime("%a")) for x in range(0,7)]
Exemplo n.º 7
0
def getNameMonth(date):
    day, daysInMonth = calendar.monthrange(date.year, date.month)
    monthName = locale_str(calendar.month_name[date.month])
    return monthName, daysInMonth
Exemplo n.º 8
0
def getNameMonth(date):
    day, daysInMonth = calendar.monthrange(date.year, date.month)
    monthName = locale_str(calendar.month_name[date.month])
    return monthName, daysInMonth