Ejemplo n.º 1
0
    def get_datasets(self, *args, **kwargs):
        max = Item.objects.all().aggregate(Max('item_id'))['item_id__max'] + 1
        data = [0 for i in range(0, max - 1)]
        game_data = GameSave.objects.all()

        for save in game_data:
            for item in save.save_items.all():
                data[int(item.item_id) - 1] += 1

        return [
            DataSet(label='Number of times each item has been found',
                    data=data,
                    backgroundColor=[
                        rgba(229, 80, 89, 0.2),
                        rgba(229, 80, 161, 0.2),
                        rgba(216, 80, 229, 0.2),
                        rgba(134, 80, 229, 0.2),
                        rgba(80, 102, 229, 0.2),
                        rgba(80, 159, 229, 0.2),
                        rgba(80, 221, 229, 0.2),
                        rgba(92, 229, 80, 0.2),
                        rgba(80, 229, 147, 0.2),
                        rgba(160, 190, 216, 0.2),
                    ])
        ]
Ejemplo n.º 2
0
    def get_datasets(self, user_id):

        if not self.histogram['data']:
            self.generate_histogram()

        user_data = self.generate_user_data(
            user_id)  # needs to be before getting histogram data
        all_course_data = self.histogram['data']

        course_dataset = DataSet(
            label='# of other students in this mark range',
            data=all_course_data,
            borderWidth=1,
            backgroundColor=rgba(128, 128, 128, 0.3),
            borderColor=rgba(0, 0, 0, 0.2),
        )
        # course_dataset['stack'] = 'marks'

        user_dataset = DataSet(
            label='You',
            data=user_data,
        )
        # user_dataset['stack'] = 'marks'

        return [
            course_dataset,
            user_dataset,
        ]
Ejemplo n.º 3
0
    def get_datasets(self, workout_id):
        cursor = connection.cursor()
        sql = 'SELECT SUM("rep"),"workout_id","date" FROM "public"."workouts_series"'
        sql += 'WHERE workout_id=%s' % workout_id
        sql += 'GROUP BY date, workout_id ORDER BY date'
        cursor.execute(sql)
        range_data = cursor.fetchall()
        print('all data', range_data)
        range_data = [i[0] for i in range_data]
        print('only rep', range_data)
        colors = [  #TODO mettre autant de couleurs que de dates
            rgba(255, 99, 132, 0.2),
            rgba(54, 162, 235, 0.2),
            rgba(255, 206, 86, 0.2),
            rgba(75, 192, 192, 0.2),
            rgba(153, 102, 255, 0.2),
            rgba(255, 99, 132, 0.2),
            rgba(255, 159, 64, 0.2),
            rgba(255, 99, 132, 0.2),
            rgba(153, 102, 255, 0.2),
            rgba(54, 162, 235, 0.2),
        ]

        return [DataSet(label='Bar Chart',
                        data=range_data,
                        borderWidth=1,
                        backgroundColor=colors,
                        borderColor=colors)]
Ejemplo n.º 4
0
 def get_datasets(self, **kwargs):
     return [{
         'data': [m['fuel__count'] for m in self.meters_qs],
         # Colors the segments of the chart
         'backgroundColor':
         [rgba(225, 0, 0),
          rgba(0, 225, 0),
          rgba(0, 0, 225)]
     }]
Ejemplo n.º 5
0
    def get_datasets(self, **kwargs):
        data = self.datas
        colors = [
            rgba(255, 99, 132, 0.2) if val > 0 else rgba(54, 162, 235, 0.2)
            for val in data
        ]

        return [
            DataSet(label="영향력",
                    data=data,
                    borderWidth=1,
                    backgroundColor=colors,
                    borderColor=colors)
        ]
Ejemplo n.º 6
0
    def get_datasets(self, **kwargs):

        data = [self.purchases, self.costs, self.losses, self.all_costs, self.sellings, self.balance]
        colors = [
            rgba(255, 99, 132, 0.2),
            rgba(54, 162, 235, 0.2),
            rgba(75, 192, 192, 0.2),
            rgba(153, 102, 255, 0.2),
        ]

        return [DataSet(label=_('Bar Chart'),
                        data=data,
                        borderWidth=1,
                        backgroundColor=colors,
                        borderColor=colors)]
Ejemplo n.º 7
0
  def get_datasets(self, **kwargs):

    colors = [
      rgba(255, 99, 132, 0.2),
      rgba(54, 162, 235, 0.2),
      rgba(255, 206, 86, 0.2),
      rgba(75, 192, 192, 0.2),
      rgba(153, 102, 255, 0.2),
      rgba(255, 159, 64, 0.2)
    ]

    return [
    {
      'label': ["Battery"],
      #'borderColor' : colors,
      #'backgroundColor' : colors,
      'data': readall(StartDate=g_startdate,EndDate=g_enddate).get('batterytab')},
    {
      'label': ["Temperature"],
      'data': readall(StartDate=g_startdate,EndDate=g_enddate).get('temperaturetab')},
    {
      'label': ["Humidity"],
      'data': readall(StartDate=g_startdate,EndDate=g_enddate).get('humiditytab')},
    
    ]
Ejemplo n.º 8
0
    def get_datasets(self, *args, **kwargs):
        colors = []

        for _ in self.local_data:
            red = random.randint(0, 256)
            green = random.randint(0, 256)
            blue = random.randint(0, 256)
            colors.append(rgba(red, green, blue, 0.3))

        return [{
            'label': self.title,
            'data': self.local_data,
            'backgroundColor': colors
        }]
Ejemplo n.º 9
0
    def get_datasets(self, **kwargs):
        this_year = datetime.datetime.today().year

        data = [0 for i in range(12)]
        colors = [rgba(172, 59, 97, 1) for i in range(12)]
        events = Event.objects.filter(start__year = this_year)\
            .annotate(month=ExtractMonth('start'))\
            .values('month').annotate(c=Count('id'))\
            .values('month', 'c')
        for event in events:
            data[event['month']] = event['c']

        return [DataSet(label='Scheduled training count per month',
                        data=data,
                        borderWidth=1,
                        backgroundColor=colors,
                        borderColor=colors)]
Ejemplo n.º 10
0
    def get_datasets(self, **kwargs):
        data = [10, 15, 29, 30, 5, 10, 22]
        colors = [
            rgba(255, 99, 132, 0.2),
            rgba(54, 162, 235, 0.2),
            rgba(255, 206, 86, 0.2),
            rgba(75, 192, 192, 0.2),
            rgba(153, 102, 255, 0.2),
            rgba(255, 159, 64, 0.2)
        ]

        return [
            DataSet(label='Bar Chart',
                    data=data,
                    borderWidth=1,
                    backgroundColor=colors,
                    borderColor=colors)
        ]
Ejemplo n.º 11
0
    def get_datasets(self, following_repos):
        data = {}
        # for each person the user follows
        for user in following_repos:
            # max number of users represented on the bar chart
            if len(data) < 7:
                # initial population
                data.update({user: following_repos[user]})
            else:
                # if any more users are found then we check the 6 currently in the dict
                for line in data:
                    # we extract the number of repos they have
                    current = data[line]
                    # we get the number of repos the person they follow has
                    res = following_repos[user]
                    # if the number of repos the person has happens to be greater than the one in the dict
                    if res > current:
                        # we delete that line in the dict
                        del data[line]
                        # create a new line in the dict for the person with the most repos
                        data[follow] = following_repos[follow]
                        break
        return_data = []
        for line in data:
            self.following.append(line)  # get label
            return_data.append(data[line])  #get data
        colors = [
            rgba(255, 99, 132, 0.2),
            rgba(54, 162, 235, 0.2),
            rgba(255, 206, 86, 0.2),
            rgba(75, 192, 192, 0.2),
            rgba(153, 102, 255, 0.2),
            rgba(255, 159, 64, 0.2)
        ]

        return [
            DataSet(data=return_data,
                    borderWidth=1,
                    backgroundColor=colors,
                    borderColor=colors)
        ]
Ejemplo n.º 12
0
from random import randint
from datetime import datetime, timedelta

from jchart import Chart
from jchart.config import Axes, DataSet, rgba

# Importing data
df = pd.read_csv('data.csv')

# Bar Chart
bar_chart_x_labels = list(set(df['ShopName']))
bar_chart_y_labels = []
bar_chart_colors = []
for i in range(len(bar_chart_x_labels)):
    bar_chart_colors.append(
        rgba((random.randint(0, 255)), (random.randint(0, 255)),
             (random.randint(0, 255)), 5))
x = defaultdict(lambda: 0)
for ind in df.index:
    x[df['ShopName'][ind]] += int(df['Quantity'][ind])
for i in bar_chart_x_labels:
    bar_chart_y_labels.append(x[i])


class TimeSeriesChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
    }

    def get_datasets(self, *args, **kwargs):
        data = [{
Ejemplo n.º 13
0
    def get_datasets(self, *args, **kwargs):
        calc_level_data = []

        max_level = GameSave.objects.all().aggregate(
            Max('next_level'))['next_level__max']
        if max_level > 15:
            max_level = 14

        level_data_list = [
            GameSave.objects.filter(next_level=i)
            for i in range(1, max_level + 1)
        ]
        level_data_list += [GameSave.objects.filter(next_level__gt=max_level)]

        for i, level_data in enumerate(level_data_list):
            level_time = 0
            for data in level_data:
                level_time += (data.time.days * 24 + data.time.seconds / 3600)
            calc_level_data.append(level_time)

        colors = [
            rgba(229, 80, 89, 0.2),
            rgba(229, 80, 161, 0.2),
            rgba(216, 80, 229, 0.2),
            rgba(134, 80, 229, 0.2),
            rgba(80, 102, 229, 0.2),
            rgba(80, 159, 229, 0.2),
            rgba(80, 221, 229, 0.2),
            rgba(92, 229, 80, 0.2),
            rgba(80, 229, 147, 0.2),
            rgba(160, 190, 216, 0.2),
            rgba(201, 229, 80, 0.2),
            rgba(229, 194, 80, 0.2),
            rgba(229, 159, 80, 0.2),
            rgba(229, 119, 80, 0.2),
            rgba(229, 80, 80, 0.2),
        ]

        return [
            DataSet(label='Average Time Per Level (Hours)',
                    data=calc_level_data,
                    backgroundColor=colors)
        ]