Example #1
0
    def draw_volume(cls, data, profits, date, code, pixel, table_name, n,
                    count):
        if len(data) != pixel:
            return

        data['volume'] += 0.5

        volume = data['volume'].astype('int').tolist()

        # pixel=
        matrix = np.zeros((pixel + n * count, pixel + n * count),
                          dtype=np.bool)

        # val = int((pixel + n * count) / 2 - 1)
        num = pixel + n * count
        num2 = num // 2
        mark = 0
        for i in range(pixel + n):
            if i < len(volume):
                if (num - volume[i]) < num2:
                    matrix[(num - volume[i]):num2 + 1, i] = True
                else:
                    matrix[num2:(num - volume[i]) + 1, i] = True

            else:
                if (num - volume[i - n]) < num2:
                    matrix[(num - volume[i - n]):num2 + 1, (pixel) +
                           mark * count:(pixel) + (mark + 1) * count] = True
                else:
                    matrix[num2:(num - volume[i - n]) + 1, (pixel) +
                           mark * count:(pixel) + (mark + 1) * count] = True

                mark += 1
        obj = BaseModel(table_name)
        # obj.remove(dict(date=date,stock_code=code))
        obj.insert_batch({
            'stock_code': code,
            'profit': profits,
            'date': date,
            'value': matrix.tolist()
        })
Example #2
0
    def draw_ma_line3(cls, data, profits, date, code, pixel, table_name, n,
                      count, profit_relative):
        # 'dif', 'dea', 'macd'

        if len(data) != pixel:
            return

        data['ma5'] += 0.5
        data['ma10'] += 0.5
        data['ma20'] += 0.5
        data['ma60'] += 0.5
        data['ma120'] += 0.5
        data['ma200'] += 0.5
        data['high'] += 0.5
        data['low'] += 0.5
        ma5 = data['ma5'].astype('int').tolist()
        ma20 = data['ma20'].astype('int').tolist()
        ma10 = data['ma10'].astype('int').tolist()
        ma60 = data['ma60'].astype('int').tolist()
        ma200 = data['ma120'].astype('int').tolist()
        ma120 = data['ma200'].astype('int').tolist()

        high = data.high.astype('int').tolist()
        low = data.low.astype('int').tolist()

        # pixel=
        matrix = np.zeros((pixel + n * count, pixel + n * count),
                          dtype=np.bool)

        # val = int((pixel + n * count) / 2 - 1)
        num = pixel + n * count
        mark = 0
        for i in range(pixel + n):
            if i < len(ma5):
                matrix[(num - ma5[i]), i] = True
                matrix[(num - ma10[i]), i] = True
                matrix[(num - ma20[i]), i] = True
                matrix[(num - ma60[i]), i] = True
                # print((num - ma120[i]))
                matrix[(num - ma120[i]), i] = True
                matrix[(num - ma200[i]), i] = True
                matrix[(num - high[i]):(num - low[i]), i] = True

            else:

                matrix[(num - ma5[i - n]), (pixel) + mark * count:(pixel) +
                       (mark + 1) * count] = True
                matrix[(num - ma10[i - n]), (pixel) + mark * count:(pixel) +
                       (mark + 1) * count] = True
                matrix[(num - ma20[i - n]), (pixel) + mark * count:(pixel) +
                       (mark + 1) * count] = True
                matrix[(num - ma60[i - n]), (pixel) + mark * count:(pixel) +
                       (mark + 1) * count] = True
                matrix[(num - ma120[i - n]), (pixel) + mark * count:(pixel) +
                       (mark + 1) * count] = True
                matrix[(num - ma200[i - n]), (pixel) + mark * count:(pixel) +
                       (mark + 1) * count] = True
                matrix[(num - high[i - n]):num - low[i - n], (pixel) +
                       mark * count:(pixel) + (mark + 1) * count] = True

                mark += 1
        # plt.matshow(matrix, cmap='hot')
        # plt.show()
        obj = BaseModel(table_name)
        obj.remove(dict(date=date, stock_code=code))
        obj.insert_batch({
            'stock_code': code,
            'profit': profits,
            'profit_relative': profit_relative,
            'date': date,
            'value': matrix.tolist()
        })