Exemplo n.º 1
0
 def setUp(self):
     url = 'ws://localhost:4848/app'
     self.conn = EngineCommunicator(url)
     self.ega = EngineGlobalApi(self.conn)
     self.eaa = EngineAppApi(self.conn)
     self.egoa = EngineGenericObjectApi(self.conn)
     self.efa = EngineFieldApi(self.conn)
     self.struct = Structs()
     self.app = self.ega.create_app("TestApp")["qAppId"]
     opened_app = self.ega.open_doc(self.app)
     self.app_handle = self.ega.get_handle(opened_app['qReturn'])
     with open('./test/test_data/ctrl00_script.qvs') as f:
         script = f.read()
     self.eaa.set_script(self.app_handle, script)
     self.eaa.do_reload_ex(self.app_handle)
     nx_page_initial = Structs.nx_page(0, 0, 26, 1)
     self.lb_def = Structs.list_object_def("$", "", ["Alpha"], None, None,
                                           [nx_page_initial])
     self.lb_param = {
         "qInfo": {
             "qId": "SLB01",
             "qType": "ListObject"
         },
         "qListObjectDef": self.lb_def
     }
     self.lb_sobject = self.eaa.create_session_object(
         self.app_handle, self.lb_param)
     self.lb_handle = self.ega.get_handle(self.lb_sobject["qReturn"])
     self.egoa.get_layout(self.lb_handle)
     self.lb_field = self.eaa.get_field(self.app_handle, "Alpha")
     self.fld_handle = self.ega.get_handle(self.lb_field["qReturn"])
Exemplo n.º 2
0
def getDataFrame(connection, appHandle, measures, dimensions, selections={}):
    engineGlobalApi = EngineGlobalApi(connection)
    ### Define Dimensions of hypercube
    hc_inline_dim = Structs.nx_inline_dimension_def(dimensions)

    ### Set sorting of Dimension by Measure
    hc_mes_sort = Structs.nx_sort_by()

    ### Define Measure of hypercube
    hc_inline_mes = Structs.nx_inline_measure_def(measures)

    ### Build hypercube from above definition
    hc_dim = Structs.nx_hypercube_dimensions(hc_inline_dim)
    hc_mes = Structs.nx_hypercube_measure(hc_mes_sort, hc_inline_mes)

    width = len(measures) + len(dimensions)
    height = int(math.floor(10000 / width))
    nx_page = Structs.nx_page(0, 0, height, width)
    hc_def = Structs.hypercube_def("$", hc_dim, hc_mes, [nx_page])

    engineAppApi = EngineAppApi(connection)
    hc_response = engineAppApi.create_object(appHandle, "CH01", "Chart",
                                             "qHyperCubeDef", hc_def)
    hc_handle = engineGlobalApi.get_handle(hc_response)

    engineGenericObjectApi = EngineGenericObjectApi(connection)

    engineFieldApi = EngineFieldApi(connection)

    for field in selections.keys():
        fieldHandle = engineGlobalApi.get_handle(
            engineAppApi.get_field(appHandle, field))
        values = []
        for selectedValue in selections[field]:
            values.append({'qText': selectedValue})

        engineFieldApi.select_values(fieldHandle, values)

    i = 0
    while i % height == 0:
        nx_page = Structs.nx_page(i, 0, height, width)
        hc_data = engineGenericObjectApi.get_hypercube_data(
            hc_handle, "/qHyperCubeDef", [nx_page])
        elems = hc_data["qDataPages"][0]['qMatrix']

        df = pd.DataFrame()

        for elem in elems:
            j = 0
            for dim in dimensions:
                df.set_value(i, dim, elem[j]["qText"])
                j += 1
            for meas in measures:
                df.set_value(i, meas, elem[j]["qNum"])
                j += 1

            i += 1

    return df
Exemplo n.º 3
0
 def fetchPosts():
     result = []
     for path in os.listdir(POSTS):
         txt = open(POSTS + path).read()
         blob = lambda x: f"(?<=^{x} ).*"
         # title -> # Title
         title = re.findall(blob("#"), txt, re.MULTILINE)[0].strip()
         # subtitle -> ## Subtitle
         subtitle = re.findall(blob("##"), txt, re.MULTILINE)[0].strip()
         # date -> ### 2002-04-19
         dateSplit = re.findall(blob("###"), txt,
                                re.MULTILINE)[0].strip().split("-")
         year = int(dateSplit[0])
         month = int(dateSplit[1])
         day = int(dateSplit[2])
         date = datetime(year, month, day)
         # body -> leftover text
         body = re.sub(r"^(#.*)\n", "", txt,
                       flags=re.MULTILINE).lstrip().rstrip()
         fname = re.findall(".*(?=\.md)", path)[0]
         result.append(
             Structs.Post(id=fname,
                          title=title,
                          subtitle=subtitle,
                          date=date,
                          body=body))
     Globals.postsCache.addRange(result)
Exemplo n.º 4
0
 def setUp(self):
     url = 'ws://localhost:4848/app'
     self.conn = EngineCommunicator(url)
     self.ega = EngineGlobalApi(self.conn)
     self.eaa = EngineAppApi(self.conn)
     self.egoa = EngineGenericObjectApi(self.conn)
     self.efa = EngineFieldApi(self.conn)
     self.struct = Structs()
Exemplo n.º 5
0
 def test_create_hypercube_object(self):
     script = file('./test/test_data/ctrl00_script.qvs').read()
     self.eaa.set_script(self.app_handle, script)
     self.eaa.do_reload_ex(self.app_handle)
     hc_inline_dim = Structs.nx_inline_dimension_def(["Alpha"])
     hc_mes_sort = Structs.nx_sort_by()
     hc_inline_mes = Structs.nx_inline_measure_def("=Sum(Num)")
     hc_dim = Structs.nx_hypercube_dimensions(hc_inline_dim)
     hc_mes = Structs.nx_hypercube_measure(hc_mes_sort, hc_inline_mes)
     nx_page = Structs.nx_page(0, 0, 26, 2)
     hc_def = Structs.hypercube_def("$", [hc_dim], [hc_mes], [nx_page])
     hc_response = self.eaa.create_object(self.app_handle, "CH01", "Chart",
                                          "qHyperCubeDef", hc_def)
     hc_handle = self.ega.get_handle(hc_response)
     self.egoa.get_layout(hc_handle)
     hc_data = self.egoa.get_hypercube_data(hc_handle, "/qHyperCubeDef",
                                            [nx_page])
     self.assertTrue(type(hc_data is {}),
                     "Unexpected type of hypercube data")
     first_element_number = hc_data["qDataPages"][0]["qMatrix"][0][0][
         "qElemNumber"]
     first_element_text = hc_data["qDataPages"][0]["qMatrix"][0][0]["qText"]
     self.assertTrue(first_element_number == 0,
                     "Incorrect value in first element number")
     self.assertTrue(first_element_text == 'A',
                     "Incorrect value in first element text")
Exemplo n.º 6
0
 def setUp(self):
     url = 'ws://localhost:4848/app'
     self.conn = EngineCommunicator(url)
     self.ega = EngineGlobalApi(self.conn)
     self.eaa = EngineAppApi(self.conn)
     self.egoa = EngineGenericObjectApi(self.conn)
     self.efa = EngineFieldApi(self.conn)
     self.struct = Structs()
     self.app = self.ega.create_app("TestApp")
     opened_app = self.ega.open_doc(self.app)
     self.app_handle = self.ega.get_handle(opened_app)
Exemplo n.º 7
0
class Globals:
    postsCache = Structs.PostsCache()
    isDebug = False
Exemplo n.º 8
0
def p_struct_final(p):
    'struct_block : TYPE type_name STRUCT struct_definition '
    p[0] = Structs(p[2], p[4], [])
Exemplo n.º 9
0
def p_struct_recursive(p):
    'struct_block : TYPE type_name STRUCT struct_definition struct_block '
    p[0] = Structs(p[2], p[4], p[5].structs)
Exemplo n.º 10
0
    def test_create_hypercube_object(self):
        with open('./test/test_data/ctrl00_script.qvs') as f:
            script = f.read()
        self.eaa.set_script(self.app_handle, script)
        self.eaa.do_reload_ex(self.app_handle)

        #Create the inline dimension structures
        hc_inline_dim1 = Structs.nx_inline_dimension_def(["Alpha"])
        hc_inline_dim2 = Structs.nx_inline_dimension_def(["Num"])

        #Create a sort structure
        hc_mes_sort = Structs.nx_sort_by()

        #Create the measure structures
        hc_inline_mes1 = Structs.nx_inline_measure_def("=Sum(Num)")
        hc_inline_mes2 = Structs.nx_inline_measure_def("=Avg(Num)")

        #Create hypercube dimensions from the inline dimension structures
        hc_dim1 = Structs.nx_hypercube_dimensions(hc_inline_dim1)
        hc_dim2 = Structs.nx_hypercube_dimensions(hc_inline_dim2)

        # Create hypercube measures from the inline measure structures
        hc_mes1 = Structs.nx_hypercube_measure(hc_mes_sort, hc_inline_mes1)
        hc_mes2 = Structs.nx_hypercube_measure(hc_mes_sort, hc_inline_mes2)

        # Create the paging model/structure (26 rows and 4 columns)
        nx_page = Structs.nx_page(0, 0, 26, 4)

        # Create a hypercube definition with arrays of hc dims, measures and nxpages
        hc_def = Structs.hypercube_def("$", [hc_dim1, hc_dim2],
                                       [hc_mes1, hc_mes2], [nx_page])

        # Create a Chart object with the hypercube definitions as parameter
        hc_response = self.eaa.create_object(self.app_handle, "CH01", "Chart",
                                             "qHyperCubeDef", hc_def)

        #Get the handle to the chart object (this may be different in my local repo. I have made some changes to this
        # for future versions)
        hc_handle = self.ega.get_handle(hc_response['qReturn'])

        # Validate the chart object by calling get_layout
        self.egoa.get_layout(hc_handle)

        # Call the get_hypercube_data to get the resulting json object, using the handle and nx page as paramters
        hc_data = self.egoa.get_hypercube_data(hc_handle, "/qHyperCubeDef",
                                               [nx_page])

        self.assertTrue(type(hc_data is {}),
                        "Unexpected type of hypercube data")
        first_element_number = hc_data["qDataPages"][0]["qMatrix"][0][0][
            "qElemNumber"]
        first_element_text = hc_data["qDataPages"][0]["qMatrix"][0][0]["qText"]
        self.assertTrue(first_element_number == 0,
                        "Incorrect value in first element number")
        self.assertTrue(first_element_text == 'A',
                        "Incorrect value in first element text")