Beispiel #1
0
class TimeSpentvsLevel(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='linear', position='bottom')],
        'yAxes': [Axes(type='linear', ticks={'stepSize': 1}, position='left')]
    }

    def get_datasets(self, *args, **kwargs):
        data = []
        level_data = GameSave.objects.all().order_by('time')

        for item in level_data:
            data.append({
                'y': item.next_level,
                'x': round(item.time.seconds / 3600, 2)
            })

        return [
            DataSet(
                type='line',
                label='Time(Hours) Vs Level',
                data=data,
                showLine=False,
                color=(56, 163, 235),
            )
        ]
Beispiel #2
0
class SurveyVpChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
        'yAxes': [Axes(ticks={
            'min': 0,
            'max': 4
        })],
    }

    def get_datasets(self, *args, **kwargs):
        now = timezone.now()
        year_ago = now - datetime.timedelta(days=365)
        events = BaseEvent.objects \
            .filter(approved=True, datetime_start__gte=year_ago, datetime_end__lt=now) \
            .filter(surveys__isnull=False) \
            .distinct()
        data_communication_responsiveness = []
        for event in events:
            data = event.surveys.aggregate(
                Avg('communication_responsiveness'), )
            data_communication_responsiveness.append({
                'x':
                event.datetime_start.isoformat(),
                'y':
                data['communication_responsiveness__avg']
            })
        options = {'type': 'line', 'fill': False, 'lineTension': 0}
        return [
            DataSet(label='Communication responsiveness',
                    data=data_communication_responsiveness,
                    color=(193, 37, 82),
                    **options),
        ]
Beispiel #3
0
class SomaticsChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
    }

    def get_datasets(self, player_id, param):
        user_somatics_factors = SomaticsFactors.objects.user_params(player_id)

        if param == "weight":
            data = [{
                'x': sf.date,
                'y': sf.weight
            } for sf in user_somatics_factors]
        elif param == "fat":
            data = [{
                'x': sf.date,
                'y': sf.fat
            } for sf in user_somatics_factors]
        elif param == "bmi":
            data = [{
                'x': sf.date,
                'y': sf.bmi
            } for sf in user_somatics_factors]
        else:
            data = None

        return [
            DataSet(
                type='line',
                label='Time Series',
                borderColor='black',
                data=data,
            )
        ]
Beispiel #4
0
    class GPM_XPM(Chart):
        chart_type = 'line'
        scales = {
            'xAxes': [
                Axes(position='bottom',
                     scaleLabel={
                         'display': 'true',
                         'labelString': "Latest-->Most recent"
                     })
            ],
        }

        def get_datasets(self, **kwargs):
            return [{
                'label': "GPM",
                'data': GPM_list,
                'backgroundColor': [
                    'rgba(75, 192, 192, 0.2)',
                ],
                'borderColor': [
                    'rgba(75, 192, 192, 1)',
                ],
                'borderWidth': 1,
            }, {
                'label': "XPM",
                'data': XPM_list,
                'backgroundColor': ['rgba(255, 99, 132, 0.2)'],
                'borderColor': ['rgba(255, 99, 132, 1)'],
                'borderWidth': 1,
            }]

        def get_labels(self, **kwargs):
            return list(range(1, matches_requested + 1))
Beispiel #5
0
class SurveyPricelistChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
        'yAxes': [Axes(ticks={
            'min': 0,
            'max': 4
        })],
    }

    def get_datasets(self, *args, **kwargs):
        now = timezone.now()
        year_ago = now - datetime.timedelta(days=365)
        events = BaseEvent.objects \
            .filter(approved=True, datetime_start__gte=year_ago, datetime_end__lt=now) \
            .filter(surveys__isnull=False) \
            .distinct()
        data_pricelist_ux = []
        data_quote_as_expected = []
        data_price_appropriate = []
        for event in events:
            data = event.surveys.aggregate(
                Avg('pricelist_ux'),
                # Avg('quote_as_expected'),
                Avg('price_appropriate'),
            )
            data_pricelist_ux.append({
                'x': event.datetime_start.isoformat(),
                'y': data['pricelist_ux__avg']
            })
            # data_quote_as_expected.append({'x': event.datetime_start.isoformat(), 'y': data['quote_as_expected__avg']})
            data_price_appropriate.append({
                'x': event.datetime_start.isoformat(),
                'y': data['price_appropriate__avg']
            })
        options = {'type': 'line', 'fill': False, 'lineTension': 0}
        return [
            DataSet(label='Pricelist UX',
                    data=data_pricelist_ux,
                    color=(193, 37, 82),
                    **options),
            # DataSet(label='Quote as expected', data=data_quote_as_expected, color=(245, 199, 0), **options),
            DataSet(label='Price appropriate',
                    data=data_price_appropriate,
                    color=(0, 133, 53),
                    **options),
        ]
Beispiel #6
0
class SurveyLnlChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
        'yAxes': [Axes(ticks={
            'min': 0,
            'max': 4
        })],
    }

    def get_datasets(self, *args, **kwargs):
        now = timezone.now()
        year_ago = now - datetime.timedelta(days=365)
        events = BaseEvent.objects \
            .filter(approved=True, datetime_start__gte=year_ago, datetime_end__lt=now) \
            .filter(surveys__isnull=False) \
            .distinct()
        data_services_quality = []
        data_customer_would_return = []
        for event in events:
            data = event.surveys.aggregate(
                Avg('services_quality'),
                Avg('customer_would_return'),
            )
            data_services_quality.append({
                'x': event.datetime_start.isoformat(),
                'y': data['services_quality__avg']
            })
            data_customer_would_return.append({
                'x':
                event.datetime_start.isoformat(),
                'y':
                data['customer_would_return__avg']
            })
        options = {'type': 'line', 'fill': False, 'lineTension': 0}
        return [
            DataSet(label='Services quality',
                    data=data_services_quality,
                    color=(193, 37, 82),
                    **options),
            DataSet(label='Customer would return',
                    data=data_customer_would_return,
                    color=(106, 150, 31),
                    **options),
        ]
 def __init__(self, meter, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.readings = models.MeterReadings.objects.filter(meter=meter)
     self.scales = {
         'yAxes': [
             Axes(scaleLabel=ScaleLabel(
                 display=True,
                 labelString=f'{meter.fuel.name} ({meter.fuel.unit})'))
         ]
     }
class TimeSeriesChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom',)],
    }

    legend = {
            'display': False,
    }

    title = {
            'display': True,
            'text': ''
    }

    end_date=datetime.date.today()
    start_date=datetime.date.today() - datetime.timedelta(365)


    def get_datasets(self, target='ZAR', base='USD', start_date=start_date.strftime("%Y-%m-%d"), end_date=end_date.strftime("%Y-%m-%d")):

        # Set the title
        self.title = {
                'display': True,
                'text': '{} to {} chart between {} and {}.'.format(base, target, start_date, end_date)
        }

        # Use a lambda for a switch statement
        curRate = lambda x, y: {'AUD': y.curencyAUD,
                       'CAD': y.curencyCAD,
                       'CHF': y.curencyCHF,
                       'CNY': y.curencyCNY,
                       'EUR': y.curencyEUR,
                       'GBP': y.curencyGBP,
                       'NZD': y.curencyNZD,
                       'ZAR': y.curencyZAR,
                       'USD': 1}[x]

        historic = rates.objects.filter(date__range=[start_date, end_date]).order_by('-date')

        # Use list comprehension to get the data
        data = [{'y': curRate(target, result) / curRate(base, result), 'x': result.date} for result in historic]

        return [DataSet(
            type='line',
            label='Time Series',
            data=data,
            borderColor='#0000ff',
            pointRadius=0,
            borderWidth=1,
            backgroundColor='rgba(0, 0, 255, 0.1)',

        )]
 def __init__(self, meter, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.readings = models.MeterReadings.objects.filter(meter=meter) \
         .annotate(reading_day=Trunc('reading_date_time', 'day')) \
         .values('reading_day') \
         .annotate(consumption=Sum('consumption'))
     self.scales = {
         'yAxes': [
             Axes(scaleLabel=ScaleLabel(
                 display=True,
                 labelString=f'{meter.fuel.name} ({meter.fuel.unit})'))
         ]
     }
Beispiel #10
0
class LineChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
    }
    def get_datasets(self, **kwargs):
     factures = Facture.objects.all().values('date').annotate(y=Sum(F("lignes__produit__prix")*F("lignes__qte"),output_field=FloatField()))
     data=factures.annotate(x=F('date')).values('x','y') 
     return[DataSet(
                    type='line',
                    label='Evaluation du chiffre d\'affaire par jour',
                    data=list(data)
                    )]
Beispiel #11
0
class LineChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
    }

    def getXdataYdata(self,querySet,labels):
        if querySet.count() == 0:
            self.myLabel = labels
            self.ydataArr = [[0]]
            self.xdata = [0]
            return 0
        self.myLabel = labels
        n = len(querySet[0])
        self.ydataArr = [[j["the_count" + str(1 + i)] for j in querySet] for i in range(n - 1)]
        self.xdata = [i['eval_date'] for i in querySet]
        return 0

    def get_datasets(self, **kwargs):
        colors = [
            (255, 99, 132),
            (54, 162, 235),
            (255, 206, 86),
            (75, 192, 192),
            (153, 102, 255),
            (255, 159, 64),
            (142, 68, 173),
            (23, 165, 137),
            (241, 196, 15),
            (51, 255, 66),
            (255, 51, 249)
        ]
        dataSetArr = []
        def roud_None(y):
            try:
                return '%.1f' % round(y, 2)
            except:
                None

        for ydata,label,color in zip(self.ydataArr,self.myLabel,colors[:len(self.myLabel)]):
            data_i = []
            for x,y in zip(self.xdata,ydata):
                data_i.append({"y": roud_None(y), "x": str(x)})

            DataSet_i = DataSet(type='line',
                                label = label,
                                data=data_i,
                                color=color,
                                fill=False)
            dataSetArr.append(DataSet_i)
        return dataSetArr
Beispiel #12
0
class LineChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
    }

    def get_datasets(self, dates):
        # passed in dict contains the dates and the number describing activity as the value
        data = []
        for date in dates:
            data.append({'y': dates[date], 'x': date})
        return [DataSet(
            type='line',
            label='Activity',
            data=data,
        )]
Beispiel #13
0
class graficaHumedad(Chart):
    chart_type = 'line'
    responsive = True
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
    }

    def get_datasets(self, **kwargs):
        #Se leen todas los registros de Humedad desde BD
        humedades = sensorHumedad.objects.all()
        #Para cada registro de humedad, se obtiene el ID del muestreo y valor. Se presenta como lista
        data = [{'y': hum.humedad, 'x': hum.id} for hum in humedades]
        return [{
            'label': "Humedad Registrada",
            'data': data,
            'borderColor': 'orange'
        }]
Beispiel #14
0
class graficaTemperatura(Chart):
    chart_type = 'line'
    responsive = True
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
    }

    def get_datasets(self, **kwargs):
        #Se leen todas las temperaturas desde BD
        temperaturas = sensorTemperatura.objects.all()
        #Para cada registro de temperatura, se obtiene el ID del muestreo y valor. Se presenta como lista
        #data = [{'x': temp.idMuestreo_id, 'y': temp.temperatura} for temp in temperaturas]
        data = [{'x': temp.id, 'y': temp.temperatura} for temp in temperaturas]
        data_scatter = data
        data_line = data
        return [{
            'type': 'line',
            'label': "Temperatura Registrada",
            'data': data,
            'borderColor': 'brown'
        }]
Beispiel #15
0
    class KDA(Chart):
        chart_type = 'line'
        title = Title(text='KDA over the past 25 games')
        scales = {
            'xAxes': [
                Axes(position='bottom',
                     scaleLabel={
                         'display': 'true',
                         'labelString': "Latest-->Most recent"
                     })
            ],
        }

        def get_datasets(self, **kwargs):
            return [{
                'label': "Kills",
                'data': kills_list,
                'backgroundColor': [
                    'rgba(75, 192, 192, 0.2)',
                ],
                'borderColor': [
                    'rgba(75, 192, 192, 1)',
                ],
                'borderWidth': 1,
            }, {
                'label': "Deaths",
                'data': deaths_list,
                'backgroundColor': ['rgba(255, 99, 132, 0.2)'],
                'borderColor': ['rgba(255, 99, 132, 1)'],
                'borderWidth': 1,
            }, {
                'label': "Assists",
                'data': assists_list,
                'backgroundColor': ['rgba(255, 206, 86, 0.2)'],
                'borderColor': ['rgba(255, 206, 86, 1)'],
                'borderWidth': 1,
            }]

        def get_labels(self, **kwargs):
            return list(range(1, matches_requested + 1))
Beispiel #16
0
class LineChart(Chart):
    chart_type = 'line'
    resposive = True
    rrlist = []

    scales = {
        'xAxes': [Axes(type='linear', position='bottom')],
    }

    def __init__(
            self, records
    ):  # there must be initialization list with multiple arguments
        self.rrlist = records
        super(LineChart, self).__init__()

    def get_datasets(self, **kwargs):
        data = [
            DataSet(label="Expenses",
                    backgroundColor='rgba(230,71,89, 0.7)',
                    data=[{
                        'x': record[0],
                        'y': record[1]
                    } for record in self.rrlist[0]]),
            DataSet(label="Income",
                    backgroundColor='rgba(27,	201, 142, 0.7)',
                    data=[{
                        'x': record[0],
                        'y': record[1]
                    } for record in self.rrlist[1]]),
            DataSet(label="Balance",
                    backgroundColor='rgba(27,	201, 142, 0.7)',
                    data=[{
                        'x': record[0],
                        'y': record[1]
                    } for record in self.rrlist[1]])
        ]
        return data
Beispiel #17
0
class StudentChart(Chart):
    chart_type = 'horizontalBar'
    height = 50

    scales = {
        'xAxes': [Axes(stacked=True, display=False)],
        'yAxes': [Axes(stacked=True)],
    }

    responsive = True
    options = {'maintainAspectRatio': False, 'height': 50}

    def get_labels(self, **kwargs):
        labels = []
        for point in self.syllabus_areas:
            labels.append(str(point))

        return labels

    def get_datasets(self, **kwargs):
        """ For each point, generate a new point in the correct range. """

        points_0_to_1 = []

        for point in self.syllabus_areas:
            # Need to include -1 here to catch the 0s.
            total_points = point.syllabus_points().count()
            count = point.cohort_rating_number(self.students, -1, 1)
            points_0_to_1.append(round(count / total_points * 100, 0))

        points_1_to_2 = []

        for point in self.syllabus_areas:
            total_points = point.syllabus_points().count()
            count = point.cohort_rating_number(self.students, 1, 2)
            points_1_to_2.append(round(count / total_points * 100, 0))

        points_2_to_3 = []

        for point in self.syllabus_areas:
            total_points = point.syllabus_points().count()
            count = point.cohort_rating_number(self.students, 2, 3)
            points_2_to_3.append(round(count / total_points * 100, 0))

        points_3_to_4 = []

        for point in self.syllabus_areas:
            total_points = point.syllabus_points().count()
            count = point.cohort_rating_number(self.students, 3, 4)
            points_3_to_4.append(round(count / total_points * 100, 0))

        points_4_to_5 = []

        for point in self.syllabus_areas:
            total_points = point.syllabus_points().count()
            count = point.cohort_rating_number(self.students, 4, 5)
            points_4_to_5.append(round(count / total_points * 100, 0))

        return_data = []

        return_data.append(
            DataSet(
                label='0-1',
                data=points_0_to_1,
                borderWidth=2,
                color=(171, 9, 0),
            ))
        return_data.append(
            DataSet(
                label='1-2',
                data=points_1_to_2,
                borderWidth=2,
                color=(166, 78, 46),
            ))
        return_data.append(
            DataSet(
                label='2-3',
                data=points_2_to_3,
                borderWidth=2,
                color=(255, 190, 67),
            ))
        return_data.append(
            DataSet(
                label='3-4',
                data=points_3_to_4,
                borderWidth=2,
                color=(122, 159, 191),
            ))
        return_data.append(
            DataSet(
                label='4-5',
                data=points_4_to_5,
                borderWidth=2,
                color=(163, 191, 63),
            ))
        return return_data
Beispiel #18
0
class CohortGraph(Chart):
    chart_type = 'horizontalBar'

    scales = {
        'xAxes': [Axes(stacked=True)],
        'yAxes': [Axes(stacked=True)],
    }

    def get_labels(self, **kwargs):
        labels = []
        for point in self.syllabus_areas:
            labels.append(str(point))

        return labels

    def get_datasets(self, **kwargs):
        """ For each point, generate a new point in the correct range. """

        total_students = self.students.count()

        points_0_to_1 = []

        for point in self.syllabus_areas:
            # Need to include -1 here to catch the 0s.
            count = point.cohort_rating_number(self.students, -1, 1)
            points_0_to_1.append(count / total_students)

        points_1_to_2 = []

        for point in self.syllabus_areas:
            count = point.cohort_rating_number(self.students, 1, 2)
            points_1_to_2.append(count / total_students)

        points_2_to_3 = []

        for point in self.syllabus_areas:
            count = point.cohort_rating_number(self.students, 2, 3)
            points_2_to_3.append(count / total_students)

        points_3_to_4 = []

        for point in self.syllabus_areas:
            count = point.cohort_rating_number(self.students, 3, 4)
            points_3_to_4.append(count / total_students)

        points_4_to_5 = []

        for point in self.syllabus_areas:
            count = point.cohort_rating_number(self.students, 4, 5)
            points_4_to_5.append(count / total_students)

        return_data = []

        return_data.append(
            DataSet(
                label='0-1',
                data=points_0_to_1,
                borderWidth=2,
                color=(171, 9, 0),
            ))
        return_data.append(
            DataSet(
                label='1-2',
                data=points_1_to_2,
                borderWidth=2,
                color=(166, 78, 46),
            ))
        return_data.append(
            DataSet(
                label='2-3',
                data=points_2_to_3,
                borderWidth=2,
                color=(255, 190, 67),
            ))
        return_data.append(
            DataSet(
                label='3-4',
                data=points_3_to_4,
                borderWidth=2,
                color=(163, 191, 63),
            ))
        return_data.append(
            DataSet(
                label='4-5',
                data=points_4_to_5,
                borderWidth=2,
                color=(122, 159, 191),
            ))
        return return_data
Beispiel #19
0
class TimeSeriesChart(Chart):

    chart_type = 'line'

    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
    }

    def get_datasets(self, **kwargs):
        """This is very likely way too slow!"""

        results = Result.objects.all()

        #
        # lines follows this bnf:
        #
        # { <label> : { <timestamp>: [ < ( upload, download, ping )+ > ] }
        #
        # where:
        #
        #   label     is < client_id > ":" < server_id >
        #   timestamp is the timestamp a measurement was made
        #   upload    is the number of bits per second in upload
        #   download  is the number of bits per second in download
        #   ping      is the number of ms taken between the client server ping
        #

        lines = {}
        for result in results:
            logger.debug("Handling {0}...".format(result))
            dt = result.timestamp.isoformat(timespec='seconds')
            key = "{0}:{1}".format(result.client_id, result.server_id)
            entry = (result.upload, result.download, result.ping)
            if key in lines:
                if result.timestamp in lines[key]:
                    logger.debug(
                        "Wow! {0} already in {1}. Appending entry...".format(
                            dt, lines[key]))
                    lines[key][result.timestamp].append(entry)
                else:
                    logger.debug("Adding {{ {0}: {1} }} to {2}.".format(
                        result.timestamp, entry, key))
                    lines[key][result.timestamp] = [entry]
            else:
                logger.debug("Creating {{ {0}: {1} }} in {2}.".format(
                    dt, entry, key))  # lines[key]))
                lines[key] = {result.timestamp: [entry]}

        if logger.isEnabledFor(logging.DEBUG):
            import pprint
            pp = pprint.PrettyPrinter(indent=4, width=150)
            logger.debug(pp.pformat(lines))

        # transform to chart
        datasets = []
        upload_combined = []
        download_combined = []
        for label in lines.keys():

            # label is <client_id> ":" <server_id>
            (client_id, separator, server_id) = label.partition(":")
            client = Client.objects.get(id=client_id)
            server = Server.objects.get(id=server_id)
            fancy_label = "from {0} (in {1}) to {2} (in {3})".format(
                client.ip, client.country.name, server.host,
                server.country.name)
            logger.debug("Converted label {0} to {1}.".format(
                label, fancy_label))

            upload_line = []
            download_line = []
            for key in sorted(lines[label].keys()):

                upload = 0
                download = 0

                for entry in lines[label][key]:
                    upload += entry[0]
                    download += entry[1]
                upload = upload / len(lines[label][key])
                download = download / len(lines[label][key])

                upload_line.append({'x': str(key), 'y': upload})
                download_line.append({'x': str(key), 'y': download})
                upload_combined.append({'x': str(key), 'y': upload})
                download_combined.append({'x': str(key), 'y': download})

            datasets.append(
                DataSet(type='line',
                        label="Upload " + fancy_label,
                        borderColor="green",
                        data=upload_line))

            datasets.append(
                DataSet(type='line',
                        label="Download " + fancy_label,
                        borderColor="blue",
                        data=download_line))

        datasets.append(
            DataSet(type='line',
                    label='Upload combined',
                    borderColor='yellow',
                    data=sorted(upload_combined, key=lambda e: e['x'])))

        datasets.append(
            DataSet(type='line',
                    label='Download combined',
                    borderColor='red',
                    data=sorted(download_combined, key=lambda e: e['x'])))

        if logger.isEnabledFor(logging.DEBUG):
            import pprint
            pp = pprint.PrettyPrinter(indent=4, width=150)
            logger.debug(pp.pformat(datasets))

        return datasets
Beispiel #20
0
class ScatterLineChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
    }

    def get_datasets(self, **kwargs):
        time_set = [
            '2018-11-14 21:00', '2018-11-14 21:20', '2018-11-14 21:40',
            '2018-11-14 22:00', '2018-11-14 22:20', '2018-11-14 22:40',
            '2018-11-14 23:00'
        ]
        fosters = []
        g_and_t = []
        captain_morgan = []
        pampero = []
        roe_and_co = []
        jaegerbomb = []
        vodka_redbull = []
        prices = [
            PriceStatic(5.80, 9.20, 8.40, 15.80, 9.20, 16.00, 19.80, 0),
            PriceStatic(2.50, 9.00, 8.40, 10.00, 6.00, 10.00, 19.80, 1),
            PriceStatic(5.80, 6.00, 8.40, 10.00, 6.00, 16.00, 19.80, 2),
            PriceStatic(2.50, 6.00, 8.40, 15.80, 9.20, 16.00, 10.00, 3),
            PriceStatic(5.80, 9.20, 5.00, 10.00, 9.20, 10.00, 10.00, 4),
            PriceStatic(2.50, 9.20, 5.00, 10.00, 6.00, 16.00, 19.80, 5),
            PriceStatic(2.50, 6.00, 8.40, 15.80, 6.00, 10.00, 19.80, 6),
            PriceStatic(5.80, 9.20, 8.40, 15.80, 9.20, 10.00, 10.00, 7),
            PriceStatic(5.8, 6.00, 5.00, 10.00, 9.20, 16.00, 10.00, 8),
            PriceStatic(2.50, 9.20, 8.40, 10.00, 6.00, 16.00, 10.00, 9)
        ]

        hour = 21
        minute = 00
        interval = 0
        max_interval = 9
        time_set2 = [{
            'hour': 21,
            'minute': 00
        }, {
            'hour': 21,
            'minute': 20
        }, {
            'hour': 21,
            'minute': 40
        }, {
            'hour': 22,
            'minute': 00
        }, {
            'hour': 22,
            'minute': 20
        }, {
            'hour': 22,
            'minute': 40
        }, {
            'hour': 23,
            'minute': 00
        }]
        localtime = time.localtime(time.time())
        local_hour = localtime.tm_hour
        local_minute = localtime.tm_min

        for curtime in time_set2:
            if local_hour >= curtime['hour'] and local_minute >= curtime[
                    'minute']:
                interval = time_set2.index(curtime)
        #if (local_hour >= time_set2[0]['hour']):
        #    current_minute = time_set2[0]['minute']
        #    while(local_minute>current_minute):
        #        current_minute += 1
        #        if ()
        current_time = time_set2[interval]
        if interval != max_interval:
            next_time = time_set2[interval + 1]
            if local_hour == next_time['hour'] and local_minute == next_time[
                    'minute']:
                interval = interval + 1

        for price in prices:
            if price.interval_index <= interval:
                fosters.append({
                    'y': price.foster,
                    'x': time_set[int(price.interval_index)]
                })
                g_and_t.append({
                    'y': price.g_t,
                    'x': time_set[int(price.interval_index)]
                })
                captain_morgan.append({
                    'y': price.captain_morgan,
                    'x': time_set[int(price.interval_index)]
                })
                pampero.append({
                    'y': price.pampero,
                    'x': time_set[int(price.interval_index)]
                })
                roe_and_co.append({
                    'y': price.roe_and_co,
                    'x': time_set[int(price.interval_index)]
                })
                jaegerbomb.append({
                    'y': price.jaegerbomb,
                    'x': time_set[int(price.interval_index)]
                })
                vodka_redbull.append({
                    'y': price.vodka_redbull,
                    'x': time_set[int(price.interval_index)]
                })

        return [
            DataSet(type='line',
                    label='Fosters',
                    borderColor='blue',
                    data=fosters),
            DataSet(type='line',
                    label='Gin and Tonic',
                    borderColor='red',
                    data=g_and_t),
            DataSet(type='line',
                    label='Captain Morgan Splash',
                    borderColor='orange',
                    data=captain_morgan),
            DataSet(type='line',
                    label='Pampero Especial',
                    borderColor='green',
                    data=pampero),
            DataSet(type='line',
                    label='Roe & Co and Ginger Ale',
                    borderColor='yellow',
                    data=roe_and_co),
            DataSet(type='line',
                    label='Double Jaeger-Bomb',
                    borderColor='purple',
                    data=jaegerbomb),
            DataSet(type='line',
                    label='Double Vodka Redbull',
                    borderColor='pink',
                    data=vodka_redbull)
        ]
Beispiel #21
0
class ScatterLineChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
    }

    def get_datasets(self, **kwargs):
        data_scatter = [{
            'y': 24,
            'x': '2017-01-01T21:00:00'
        }, {
            'y': 1,
            'x': '2017-01-02T03:00:00'
        }, {
            'y': 7,
            'x': '2017-01-02T14:00:00'
        }, {
            'y': 7,
            'x': '2017-01-03T08:00:00'
        }, {
            'y': 13,
            'x': '2017-01-04T00:00:00'
        }, {
            'y': 7,
            'x': '2017-01-04T07:00:00'
        }, {
            'y': 19,
            'x': '2017-01-05T01:00:00'
        }, {
            'y': 18,
            'x': '2017-01-05T15:00:00'
        }, {
            'y': 14,
            'x': '2017-01-06T00:00:00'
        }, {
            'y': 2,
            'x': '2017-01-06T07:00:00'
        }, {
            'y': 18,
            'x': '2017-01-07T06:00:00'
        }, {
            'y': 4,
            'x': '2017-01-07T07:00:00'
        }, {
            'y': 21,
            'x': '2017-01-07T21:00:00'
        }, {
            'y': 5,
            'x': '2017-01-08T00:00:00'
        }, {
            'y': 16,
            'x': '2017-01-08T07:00:00'
        }, {
            'y': 14,
            'x': '2017-01-08T11:00:00'
        }, {
            'y': 21,
            'x': '2017-01-09T04:00:00'
        }, {
            'y': 25,
            'x': '2017-01-09T20:00:00'
        }, {
            'y': 9,
            'x': '2017-01-10T15:00:00'
        }, {
            'y': 25,
            'x': '2017-01-11T10:00:00'
        }, {
            'y': 17,
            'x': '2017-01-11T17:00:00'
        }, {
            'y': 10,
            'x': '2017-01-12T11:00:00'
        }, {
            'y': 7,
            'x': '2017-01-12T17:00:00'
        }, {
            'y': 11,
            'x': '2017-01-12T22:00:00'
        }, {
            'y': 2,
            'x': '2017-01-13T04:00:00'
        }, {
            'y': 13,
            'x': '2017-01-13T12:00:00'
        }, {
            'y': 12,
            'x': '2017-01-14T12:00:00'
        }, {
            'y': 16,
            'x': '2017-01-15T10:00:00'
        }, {
            'y': 15,
            'x': '2017-01-16T00:00:00'
        }, {
            'y': 23,
            'x': '2017-01-16T17:00:00'
        }, {
            'y': 15,
            'x': '2017-01-17T02:00:00'
        }, {
            'y': 22,
            'x': '2017-01-17T12:00:00'
        }, {
            'y': 18,
            'x': '2017-01-17T15:00:00'
        }, {
            'y': 16,
            'x': '2017-01-18T14:00:00'
        }, {
            'y': 7,
            'x': '2017-01-19T09:00:00'
        }, {
            'y': 10,
            'x': '2017-01-20T02:00:00'
        }, {
            'y': 7,
            'x': '2017-01-20T13:00:00'
        }, {
            'y': 5,
            'x': '2017-01-20T17:00:00'
        }, {
            'y': 15,
            'x': '2017-01-20T20:00:00'
        }, {
            'y': 5,
            'x': '2017-01-21T06:00:00'
        }, {
            'y': 13,
            'x': '2017-01-21T18:00:00'
        }, {
            'y': 20,
            'x': '2017-01-22T13:00:00'
        }, {
            'y': 20,
            'x': '2017-01-22T16:00:00'
        }, {
            'y': 23,
            'x': '2017-01-23T15:00:00'
        }, {
            'y': 3,
            'x': '2017-01-23T20:00:00'
        }, {
            'y': 20,
            'x': '2017-01-24T15:00:00'
        }, {
            'y': 19,
            'x': '2017-01-24T16:00:00'
        }, {
            'y': 1,
            'x': '2017-01-25T00:00:00'
        }, {
            'y': 3,
            'x': '2017-01-25T02:00:00'
        }, {
            'y': 22,
            'x': '2017-01-25T23:00:00'
        }, {
            'y': 6,
            'x': '2017-01-26T19:00:00'
        }, {
            'y': 17,
            'x': '2017-01-27T10:00:00'
        }, {
            'y': 7,
            'x': '2017-01-28T09:00:00'
        }, {
            'y': 23,
            'x': '2017-01-29T05:00:00'
        }, {
            'y': 19,
            'x': '2017-01-29T17:00:00'
        }, {
            'y': 16,
            'x': '2017-01-30T08:00:00'
        }, {
            'y': 19,
            'x': '2017-01-30T09:00:00'
        }, {
            'y': 23,
            'x': '2017-01-31T06:00:00'
        }, {
            'y': 18,
            'x': '2017-02-01T05:00:00'
        }]
        data_line = [{
            'y': 20,
            'x': '2017-01-02T00:00:00'
        }, {
            'y': 3,
            'x': '2017-01-03T00:00:00'
        }, {
            'y': 2,
            'x': '2017-01-04T00:00:00'
        }, {
            'y': 18,
            'x': '2017-01-05T00:00:00'
        }, {
            'y': 19,
            'x': '2017-01-06T00:00:00'
        }, {
            'y': 20,
            'x': '2017-01-07T00:00:00'
        }, {
            'y': 5,
            'x': '2017-01-08T00:00:00'
        }, {
            'y': 23,
            'x': '2017-01-09T00:00:00'
        }, {
            'y': 18,
            'x': '2017-01-10T00:00:00'
        }, {
            'y': 5,
            'x': '2017-01-11T00:00:00'
        }, {
            'y': 6,
            'x': '2017-01-12T00:00:00'
        }, {
            'y': 2,
            'x': '2017-01-13T00:00:00'
        }, {
            'y': 23,
            'x': '2017-01-14T00:00:00'
        }, {
            'y': 3,
            'x': '2017-01-15T00:00:00'
        }, {
            'y': 24,
            'x': '2017-01-16T00:00:00'
        }, {
            'y': 10,
            'x': '2017-01-17T00:00:00'
        }, {
            'y': 9,
            'x': '2017-01-18T00:00:00'
        }, {
            'y': 11,
            'x': '2017-01-19T00:00:00'
        }, {
            'y': 10,
            'x': '2017-01-20T00:00:00'
        }, {
            'y': 2,
            'x': '2017-01-21T00:00:00'
        }, {
            'y': 16,
            'x': '2017-01-22T00:00:00'
        }, {
            'y': 24,
            'x': '2017-01-23T00:00:00'
        }, {
            'y': 3,
            'x': '2017-01-24T00:00:00'
        }, {
            'y': 13,
            'x': '2017-01-25T00:00:00'
        }, {
            'y': 7,
            'x': '2017-01-26T00:00:00'
        }, {
            'y': 10,
            'x': '2017-01-27T00:00:00'
        }, {
            'y': 7,
            'x': '2017-01-28T00:00:00'
        }, {
            'y': 13,
            'x': '2017-01-29T00:00:00'
        }, {
            'y': 1,
            'x': '2017-01-30T00:00:00'
        }, {
            'y': 10,
            'x': '2017-01-31T00:00:00'
        }, {
            'y': 7,
            'x': '2017-02-01T00:00:00'
        }]

        return [
            DataSet(type='line',
                    label='Scatter',
                    showLine=False,
                    data=data_scatter),
            DataSet(type='line',
                    label='Line',
                    borderColor='red',
                    data=data_line)
        ]
Beispiel #22
0
class SurveyCrewChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
        'yAxes': [Axes(ticks={
            'min': 0,
            'max': 4
        })],
    }

    def get_datasets(self, *args, **kwargs):
        now = timezone.now()
        year_ago = now - datetime.timedelta(days=365)
        events = BaseEvent.objects \
            .filter(approved=True, datetime_start__gte=year_ago, datetime_end__lt=now) \
            .filter(surveys__isnull=False) \
            .distinct()
        data_lighting_quality = []
        data_sound_quality = []
        data_setup_on_time = []
        data_crew_respectfulness = []
        data_crew_preparedness = []
        data_crew_knowledgeability = []
        for event in events:
            data = event.surveys.aggregate(
                Avg('lighting_quality'),
                Avg('sound_quality'),
                Avg('setup_on_time'),
                Avg('crew_respectfulness'),
                # Avg('crew_preparedness'),
                # Avg('crew_knowledgeability'),
            )
            data_lighting_quality.append({
                'x': event.datetime_start.isoformat(),
                'y': data['lighting_quality__avg']
            })
            data_sound_quality.append({
                'x': event.datetime_start.isoformat(),
                'y': data['sound_quality__avg']
            })
            data_setup_on_time.append({
                'x': event.datetime_start.isoformat(),
                'y': data['setup_on_time__avg']
            })
            data_crew_respectfulness.append({
                'x':
                event.datetime_start.isoformat(),
                'y':
                data['crew_respectfulness__avg']
            })
            # data_crew_preparedness.append({'x': event.datetime_start.isoformat(), 'y': data['crew_preparedness__avg']})
            # data_crew_knowledgeability.append({'x': event.datetime_start.isoformat(), 'y': data['crew_knowledgeability__avg']})
        options = {'type': 'line', 'fill': False, 'lineTension': 0}
        return [
            DataSet(label='Lighting quality',
                    data=data_lighting_quality,
                    color=(193, 37, 82),
                    **options),
            DataSet(label='Sound quality',
                    data=data_sound_quality,
                    color=(255, 102, 0),
                    **options),
            DataSet(label='Setup on time',
                    data=data_setup_on_time,
                    color=(245, 199, 0),
                    **options),
            DataSet(label='Crew was helpful',
                    data=data_crew_respectfulness,
                    color=(106, 150, 31),
                    **options),
            # DataSet(label='Crew preparedness', data=data_crew_preparedness, color=(0, 133, 53), **options),
            # DataSet(label='Crew knowledgeability', data=data_crew_knowledgeability, color=(110, 45, 214), **options),
        ]
Beispiel #23
0
class TimeSeriesChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [Axes(type='time', position='bottom')],
    }

    def get_datasets(self, **kwargs):
        data = [{
            'y': 0,
            'x': '2017-01-02T00:00:00'
        }, {
            'y': 1,
            'x': '2017-01-03T00:00:00'
        }, {
            'y': 4,
            'x': '2017-01-04T00:00:00'
        }, {
            'y': 9,
            'x': '2017-01-05T00:00:00'
        }, {
            'y': 16,
            'x': '2017-01-06T00:00:00'
        }, {
            'y': 25,
            'x': '2017-01-07T00:00:00'
        }, {
            'y': 36,
            'x': '2017-01-08T00:00:00'
        }, {
            'y': 49,
            'x': '2017-01-09T00:00:00'
        }, {
            'y': 64,
            'x': '2017-01-10T00:00:00'
        }, {
            'y': 81,
            'x': '2017-01-11T00:00:00'
        }, {
            'y': 100,
            'x': '2017-01-12T00:00:00'
        }, {
            'y': 121,
            'x': '2017-01-13T00:00:00'
        }, {
            'y': 144,
            'x': '2017-01-14T00:00:00'
        }, {
            'y': 169,
            'x': '2017-01-15T00:00:00'
        }, {
            'y': 196,
            'x': '2017-01-16T00:00:00'
        }, {
            'y': 225,
            'x': '2017-01-17T00:00:00'
        }, {
            'y': 256,
            'x': '2017-01-18T00:00:00'
        }, {
            'y': 289,
            'x': '2017-01-19T00:00:00'
        }, {
            'y': 324,
            'x': '2017-01-20T00:00:00'
        }, {
            'y': 361,
            'x': '2017-01-21T00:00:00'
        }, {
            'y': 400,
            'x': '2017-01-22T00:00:00'
        }, {
            'y': 441,
            'x': '2017-01-23T00:00:00'
        }, {
            'y': 484,
            'x': '2017-01-24T00:00:00'
        }, {
            'y': 529,
            'x': '2017-01-25T00:00:00'
        }, {
            'y': 576,
            'x': '2017-01-26T00:00:00'
        }, {
            'y': 625,
            'x': '2017-01-27T00:00:00'
        }, {
            'y': 676,
            'x': '2017-01-28T00:00:00'
        }, {
            'y': 729,
            'x': '2017-01-29T00:00:00'
        }, {
            'y': 784,
            'x': '2017-01-30T00:00:00'
        }, {
            'y': 841,
            'x': '2017-01-31T00:00:00'
        }, {
            'y': 900,
            'x': '2017-02-01T00:00:00'
        }]

        return [DataSet(
            type='line',
            label='Time Series',
            data=data,
        )]
Beispiel #24
0
class ScoreMassChart(Chart):
    chart_type = 'line'
    scales = {
        'xAxes': [
            Axes(type='linear',
                 position='bottom',
                 scaleLabel=ScaleLabel(display=True,
                                       labelString='quality score'))
        ],
        'yAxes': [
            Axes(
                type='linear',
                scaleLabel=ScaleLabel(
                    display=True,
                    labelString='% of sentences',
                ),
                #ticks={'stepSize': 1},
            )
        ],
    }

    def get_datasets(self, document_id):

        total = MachineTranslationEvaluation.objects. \
            filter(translation__source__document_id=document_id).count()

        count_0 = MachineTranslationEvaluation.objects. \
                filter(translation__source__document_id=document_id,
                       score=0).count()

        count_1 = MachineTranslationEvaluation.objects. \
                filter(translation__source__document_id=document_id,
                       score=1).count()

        dotsdata = [{'x': 0, 'y': count_0 * 100.0 / total}]
        #for score in sorted(list(set(scores))):
        step = 0.1
        for min_score in [round(x * step, 4) for x in range(0, 10)]:
            max_score = min_score + step
            evaluations_per_score = \
                MachineTranslationEvaluation.objects. \
                filter(translation__source__document_id=document_id,
                       score__gte=min_score,
                       score__lte=max_score).count()

            score = (max_score - min_score) * .5 + min_score
            dotsdata.append({
                'x': score,
                'y': 100.0 * evaluations_per_score / total
            })

        dotsdata.append({'x': 1, 'y': count_1 * 100.0 / total})

        return [
            DataSet(
                type='line',
                data=dotsdata,
                label="mass per decimile",
                pointRadius=1,
            ),
        ]