<commit_before>#!/usr/bin/python3

__author__ = 'mirko'

import sys, os, ctypes as ct
from time import clock, sleep

import OpenGL
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
from ctypes import *

try:import numpy as np
except:np = None


def setMatrix(l,r,b,t):
    """

    :param l: left
    :param r: right
    :param b: bottom
    :param t: top
    :return:
    """
    matrix = [0] * 16

    matrix[0] = 2/(r-l)
    matrix[5] = 2/(t-b)
    matrix[10] = -1
    matrix[12] = -(r+l)/(r-l)
    matrix[13] = -(t+b)/(t-b)
    matrix[15] = 1

    glLoadMatrixf(matrix)

def getVBOData(coords):
    """

    :param coords:
    :return: data
    """
    try:
        # faster 3x,less memory 3x
        data = np.array(coords, np.float32)
        return data
    except:
        data = (c_float*len(coords))(*coords)
        return data

keys = {}
def getKey(key):
    return keys.get(key, False)

class Item():
    __slots__ = ("value", "time") # increases performance
    def __init__(self, value, time):
        """

        :param value:
        :param time:
        :return:
        """
        self.value = value
        self.time = time

    def __repr__(self):
        return str(self.value)

class Section():
    __slots__ = ("name", "values", "line_color", "line_fill_color", "min", "max", "cache") # increases performance
    def __init__(self,name,line_color=None, line_fill_color=None, values=None, min=0, max=100):
        """

        :param line_color:
        :param line_fill_color:
        :param values:
        :param min: scaling min, error if smaller than this
        :param max: scaling max, error if bigger than this
        :return:
        """
        self.name = name
        # list is mutable so if I set it as default
        # it has the same address in every new section
        if values is None:
            values = []
        self.values = values
        self.line_color = line_color
        self.line_fill_color = line_fill_color
        self.min = min
        self.max = max
        self.cache = {
            "vbo_l": glGenBuffers(1),
        }

    def __del__(self):
        glDeleteBuffers([self.cache["vbo_l"]])

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.__del__()
        raise exc_type(exc_val, traceback=exc_tb)

class Histograph():
    #__slots__ = []
    def __init__(self, x, y, width, height):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.borderWidth = 1
        self.itemWidth = 3
        self.sections = [] # needed for order
        self.sections_d = {} # needed for speed
        self.drawCount = 999999
        self.insert = True #
        self.cache = {
            #TODO :vao: use this for drawing sections, must have updates after adding/removing sections
            "vao": None,
            "vbo_border": None,

            "item_index": 0,
            "vertex_index": 0,
            "line_index":0,

            "scrollx":0,
            "motion_last_x":0,
        }

    def init(self):
        pass
        #self.cache["vao"] = glGenVertexArrays(1) # init glut and window if exception

        # region Border Lines
        data = getVBOData([
            -1,-1,
            1,-1,
            1,1,
            -1,1
        ])
        self.cache["vbo_border"] = glGenBuffers(1)
        glBindBuffer(GL_ARRAY_BUFFER, self.cache["vbo_border"])
        glBufferData(GL_ARRAY_BUFFER, data, GL_STATIC_DRAW)
        # endregion

        # region Vertex Shader, x increment
        return #TODO continue x shader idea
        vshader = """void main()
{
   gl_Position = gl_Vertex;
}"""
        fshader = """void main()
{
    gl_FragColor = gl_Color;
}"""
        gl_vshader = glCreateShader(GL_VERTEX_SHADER)
        gl_fshader = glCreateShader(GL_FRAGMENT_SHADER)

        glShaderSource(gl_vshader, vshader)
        glShaderSource(gl_fshader, fshader)

        glCompileShader(gl_vshader)
        glCompileShader(gl_fshader)

        error = glGetShaderInfoLog(gl_vshader)
        if error:
            print(error.decode())
            raise Exception("Error compiling vertex shader")
        error = glGetShaderInfoLog(gl_fshader)
        if error:
            print(error.decode())
            raise Exception("Error compiling fragment shader")

        programObject = glCreateProgram()
<commit_msg>Update histograph.py<commit_after>#!/usr/bin/python3

__author__ = 'mirko'

import sys, os, ctypes as ct
from time import clock, sleep

import OpenGL
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
from ctypes import *

try:import numpy as np
except:np = None


def setMatrix(l,r,b,t):
    """

    :param l: left
    :param r: right
    :param b: bottom
    :param t: top
    :return:
    """
    matrix = [0] * 16

    matrix[0] = 2/(r-l)
    matrix[5] = 2/(t-b)
    matrix[10] = -1
    matrix[12] = -(r+l)/(r-l)
    matrix[13] = -(t+b)/(t-b)
    matrix[15] = 1

    glLoadMatrixf(matrix)

def getVBOData(coords):
    """

    :param coords:
    :return: data
    """
    try:
        # faster 3x,less memory 3x
        data = np.array(coords, np.float32)
        return data
    except:
        data = (c_float*len(coords))(*coords)
        return data

keys = {}
def getKey(key):
    return keys.get(key, False)

class Item():
    __slots__ = ("value", "time") # increases performance
    def __init__(self, value, time):
        """

        :param value:
        :param time:
        :return:
        """
        self.value = value
        self.time = time

    def __repr__(self):
        return str(self.value)

class Section():
    __slots__ = ("name", "values", "line_color", "line_fill_color", "min", "max", "cache") # increases performance
    def __init__(self,name,line_color=None, line_fill_color=None, values=None, min=0, max=100):
        """

        :param line_color:
        :param line_fill_color:
        :param values:
        :param min: scaling min, error if smaller than this
        :param max: scaling max, error if bigger than this
        :return:
        """
        self.name = name
        # list is mutable so if I set it as default
        # it has the same address in every new section
        if values is None:
            values = []
        self.values = values
        self.line_color = line_color
        self.line_fill_color = line_fill_color
        self.min = min
        self.max = max
        self.cache = {
            "vbo_l": glGenBuffers(1),
        }

    def __del__(self):
        glDeleteBuffers([self.cache["vbo_l"]])

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.__del__()
        raise exc_type(exc_val, traceback=exc_tb)

class Histograph():
    #__slots__ = []
    def __init__(self, x, y, width, height):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.borderWidth = 1
        self.itemWidth = 3
        self.sections = [] # needed for order
        self.sections_d = {} # needed for speed
        self.drawCount = 999999
        self.insert = True #
        self.cache = {
            #TODO :vao: use this for drawing sections, must have updates after adding/removing sections
            "vao": None,
            "vbo_border": None,

            "item_index": 0,
            "vertex_index": 0,
            "line_index":0,

            "scrollx":0,
            "motion_last_x":0,
        }

    def init(self):
        pass
        #self.cache["vao"] = glGenVertexArrays(1) # init glut and window if exception

        # region Border Lines
        data = getVBOData([
            -1,-1,
            1,-1,
            1,1,
            -1,1
        ])
        self.cache["vbo_border"] = glGenBuffers(1)
        glBindBuffer(GL_ARRAY_BUFFER, self.cache["vbo_border"])
        glBufferData(GL_ARRAY_BUFFER, data, GL_STATIC_DRAW)
        # endregion

        # region Vertex Shader, x increment
        return #TODO continue x shader idea, used to dynamically increase one x for every value, need this because of VBO usage(better than change the coords manually, performance)
        vshader = """void main()
{
   gl_Position = gl_Vertex;
}"""
        fshader = """void main()
{
    gl_FragColor = gl_Color;
}"""
        gl_vshader = glCreateShader(GL_VERTEX_SHADER)
        gl_fshader = glCreateShader(GL_FRAGMENT_SHADER)

        glShaderSource(gl_vshader, vshader)
        glShaderSource(gl_fshader, fshader)

        glCompileShader(gl_vshader)
        glCompileShader(gl_fshader)

        error = glGetShaderInfoLog(gl_vshader)
        if error:
            print(error.decode())
            raise Exception("Error compiling vertex shader")
        error = glGetShaderInfoLog(gl_fshader)
        if error:
            print(error.decode())
            raise Exception("Error compiling fragment shader")

        programObject = glCreateProgram()

{'fraction_non_alphanumeric': 0.11163628179158226, 'fraction_numerical': 0.011253657438667568, 'mean_word_length': 2.0665976535541755, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5349691', 'n_tokens_mistral': 2906, 'n_tokens_neox': 2815, 'n_words': 720}