def getFilteredDashboardVisio(cls, data: DataModel, dashboardId: int,
                                  visioId: int) -> TableModel:
        dashboardIndex = DataController.getElementIndexById(
            data.dashboards, dashboardId)
        dashboard = data.dashboards[dashboardIndex]

        inVisioModel = cls.__getInDashboardVisioModel(data, dashboardId,
                                                      visioId)

        visioIndex = DataController.getElementIndexById(
            data.visualizations, inVisioModel.visualizationId)
        visio = data.visualizations[visioIndex]

        tableIndex = DataController.getElementIndexById(
            data.dataSources, visio.data)
        table = data.dataSources[tableIndex]

        filteredTable = deepcopy(table)

        for dashboardFilter in dashboard.filters:
            filterModelIndex = DataController.getElementIndexById(
                data.filters, dashboardFilter['id'])
            filterModel = data.filters[filterModelIndex]

            if dashboardFilter['visioId'] == visioId:
                if dashboardFilter['isActive'] and not filterModel.isDeleted:
                    filterObj = FiltersFactory.getFilter(filterModel.type)
                    filteredTable = filterObj.implementFilter(
                        filteredTable, filterModel.filteredColumn,
                        dashboardFilter['value'])

        return filteredTable
    def getChart(cls, data: DataModel, visioId: int, width: double,
                 height: double, tableFilter, dashboardId: int) -> Dict:
        visioIndex = DataController.getElementIndexById(
            data.visualizations, visioId)
        visualizer = data.visualizations[visioIndex]

        # implement visualization filters.
        drawTable = tableFilter(data, dashboardId, visioId)

        drawTable = DataSourcesController.sugreCoatAggregatedChartTable(
            data, drawTable, tableFilter)

        xColumn = drawTable.columns[DataController.getElementIndexById(
            drawTable.columns, visualizer.xColumn)]

        drawTable = cls.generateVisualizerTable(drawTable, visualizer)

        drawer = ChartsFactory.generateCharts(visualizer.chart, drawTable,
                                              width, height, xColumn,
                                              double(visualizer.quality),
                                              visualizer.animation)

        chartDict = dict()
        chartDict['visualizerId'] = visioId
        chartDict['svg'] = drawer.SVG
        chartDict['metaData'] = drawer.metaData

        return chartDict
    def generateVisualizerTable(cls, table: TableModel,
                                visio: VisualizationModel) -> TableModel:
        columns = list()

        for columnId in visio.usedColumns:
            if columnId != visio.xColumn:
                columnIndex = DataController.getElementIndexById(
                    table.columns, columnId)
                columns.append(table.columns[columnIndex])

        returnTable = TableModel(columns, table.name, table.id,
                                 table.properties, table.aggregator,
                                 table.filters, table.isDeleted)

        # setting used colors in table:
        # 1- rows:
        returnTable.rowsColors = table.rowsColors
        # 2- columns:
        columnsColors = list()
        for columnId in visio.usedColumns:
            if columnId != visio.xColumn:
                columnIndex = DataController.getElementIndexById(
                    table.columns, columnId)
                columnsColors.append(table.columnsColors[columnIndex])
        returnTable.columnsColors = columnsColors

        return returnTable
Exemple #4
0
 def removeColumn(cls, data: DataModel, tableId: int, columnId: int) -> TableModel:
     targetTableIndex = DataController.getElementIndexById(data.dataSources, tableId)
     targetColumnIndex = DataController.getElementIndexById(data.dataSources[targetTableIndex].columns, columnId)
     data.dataSources[targetTableIndex].columns.pop(targetColumnIndex)
     data.dataSources[targetTableIndex].columnsColors.pop(targetColumnIndex)
     # or activate the is deleted.
     # data.dataSources[targetTableIndex].columns[targetColumnIndex].isDeleted = True
     return data.dataSources[targetTableIndex]
 def theNoVisioFilter(cls, data: DataModel, signatureMatcher: int,
                      visioId: int) -> TableModel:
     visioIndex = DataController.getElementIndexById(
         data.visualizations, visioId)
     visio = data.visualizations[visioIndex]
     tableIndex = DataController.getElementIndexById(
         data.dataSources, visio.data)
     return data.dataSources[tableIndex]
Exemple #6
0
    def updateCellByCords(cls, data: DataModel, cell, tableId: int, columnId: int, cellIndex):
        targetTableIndex = DataController.getElementIndexById(data.dataSources, tableId)
        targetColumnIndex = DataController.getElementIndexById(data.dataSources[targetTableIndex].columns, columnId)
        data.dataSources[targetTableIndex].columns[targetColumnIndex].cells[cellIndex].value = cell
        data.dataSources[targetTableIndex].columns[targetColumnIndex].cells[cellIndex].type = cls.__getCellType(cell)
        # check if the edited cell is a title cell (the first cell is the column name).
        if cellIndex == 0:
            data.dataSources[targetTableIndex].columns[targetColumnIndex].name = str(cell)

        cls.__updateCategorizedValues(data.dataSources[targetTableIndex].columns[targetColumnIndex])

        return data.dataSources[targetTableIndex].columns[targetColumnIndex].cells[cellIndex]
Exemple #7
0
    def __initAggregatedBufferColumns(cls, aggColumns: List[ColumnModel],
                                      aggColumnId: int,
                                      columns: List[ColumnModel]):
        # filling new aggregated columns with the aggregated column values.
        for column in columns:
            bufferNameCell = CellModel(column.name,
                                       enums.CellType.string.value)

            if column.id == aggColumnId:
                bufferColumn = ColumnModel([bufferNameCell], column.name,
                                           column.id, column.isDeleted)
                bufferColumn.columnType = deepcopy(column.columnType)
                bufferColumn.cells.extend(column.valueCategories)
                aggColumns.append(bufferColumn)
            else:
                bufferColumn = ColumnModel([bufferNameCell], column.name,
                                           column.id, column.isDeleted)
                bufferColumn.columnType = deepcopy(column.columnType)
                aggColumns.append(bufferColumn)

        # filling the reset of the columns with empty cells to be used when adding other rows to it.
        aggColumnIndex = DataController.getElementIndexById(
            aggColumns, aggColumnId)
        for i in range(1, len(aggColumns[aggColumnIndex].cells)):
            for column, j in zip(aggColumns, range(len(aggColumns))):
                if column.id != aggColumnId:
                    if columns[j].cells[i].type != enums.CellType.numeric.value:
                        column.cells.append(columns[j].cells[i])
                    else:
                        column.cells.append(
                            CellModel(0, enums.CellType.numeric.value))
 def __getInDashboardVisioModel(cls, data: DataModel, dashboardId: int,
                                visioId: int):
     dashboardIndex = DataController.getElementIndexById(
         data.dashboards, dashboardId)
     dashboard = data.dashboards[dashboardIndex]
     for inVisioModel in dashboard.visualizers:
         if inVisioModel.visualizationId == visioId:
             return inVisioModel
     return -1
    def getFilteredTable(cls, data: DataModel, signatureMatcher: int,
                         tableId: int) -> TableModel:
        tableIndex = DataController.getElementIndexById(
            data.dataSources, tableId)
        table = data.dataSources[tableIndex]
        filteredTable = deepcopy(table)

        for tableFilter in table.filters:
            filterModelIndex = DataController.getElementIndexById(
                data.filters, tableFilter['id'])
            filterModel = data.filters[filterModelIndex]

            if tableFilter['isActive'] and not filterModel.isDeleted:
                filterObj = FiltersFactory.getFilter(filterModel.type)
                filteredTable = filterObj.implementFilter(
                    filteredTable, filterModel.filteredColumn,
                    tableFilter['value'])

        return filteredTable
Exemple #10
0
 def getAggregatedTable(cls, data: DataModel, tableId: int, aggColumnId: int, type: str) -> TableModel:
     targetTableIndex = DataController.getElementIndexById(data.dataSources, tableId)
     targetTable = data.dataSources[targetTableIndex]
     targetTable.aggregator.type = type
     aggregator = Aggregation.getAggregator(type)
     Aggregation.clearAggregationTable(targetTable)
     aggColumns = aggregator.implementAggregation(data, targetTable, aggColumnId,
                                                  FiltersController.getFilteredTable, True)
     targetTable.aggregator.aggregatedTable = aggColumns
     returnTable = cls.sugreCoatAggregatedTable(deepcopy(targetTable))
     return returnTable
 def getAllDashboardCharts(cls, data: DataModel,
                           dashboardId: int) -> List[Dict]:
     charts = list()
     targetDashboardIndex = DataController.getElementIndexById(
         data.dashboards, dashboardId)
     dashboard = data.dashboards[targetDashboardIndex]
     for inVisioModel in dashboard.visualizers:
         charts.append(
             cls.getDashboardVisioChart(data, dashboardId,
                                        inVisioModel.visualizationId))
     return charts
    def getDashboardVisioChart(cls, data: DataModel, dashboardId: int,
                               visioId: int) -> Dict:
        dashboardIndex = DataController.getElementIndexById(
            data.dashboards, dashboardId)
        dashboard = data.dashboards[dashboardIndex]
        inVisioIndex = cls.__getVisioIndexFromDashboard(dashboard, visioId)
        inVisio = dashboard.visualizers[inVisioIndex]

        return cls.getChart(data, inVisio.visualizationId,
                            inVisio.measurements['width'],
                            inVisio.measurements['height'],
                            DashboardsController.getFilteredChartTable,
                            dashboardId)
    def getChartPNG(cls, data: DataModel, visioId: int, width: double,
                    height: double, tableFilter, dashboardId: int) -> str:
        visioIndex = DataController.getElementIndexById(
            data.visualizations, visioId)
        visualizer = data.visualizations[visioIndex]

        # implement visualization filters.
        drawTable = tableFilter(data, dashboardId, visioId)

        drawTable = DataSourcesController.sugreCoatAggregatedChartTable(
            data, drawTable, tableFilter)

        xColumn = drawTable.columns[DataController.getElementIndexById(
            drawTable.columns, visualizer.xColumn)]

        drawTable = cls.generateVisualizerTable(drawTable, visualizer)

        drawer = ChartsFactory.generateCharts(visualizer.chart, drawTable,
                                              width, height, xColumn,
                                              double(visualizer.quality),
                                              visualizer.animation)

        return drawer.saveAsPNG()
    def getFilteredVisioTable(cls, data: DataModel,
                              visioId: int) -> TableModel:
        visioIndex = DataController.getElementIndexById(
            data.visualizations, visioId)
        visio = data.visualizations[visioIndex]
        tableIndex = DataController.getElementIndexById(
            data.dataSources, visio.data)
        table = data.dataSources[tableIndex]

        filteredTable = deepcopy(table)

        for visioFilter in visio.filters:
            filterModelIndex = DataController.getElementIndexById(
                data.filters, visioFilter['id'])
            filterModel = data.filters[filterModelIndex]

            if visioFilter['isActive'] and not filterModel.isDeleted:
                filterObj = FiltersFactory.getFilter(filterModel.type)
                filteredTable = filterObj.implementFilter(
                    filteredTable, filterModel.filteredColumn,
                    visioFilter['value'])

        return filteredTable
Exemple #15
0
    def aggregateTable(self, table: TableModel,
                       aggregationBaseColumnId: int) -> List[ColumnModel]:
        aggregatedBufferColumns = list()

        aggregationColumnIndex = DataController.getElementIndexById(
            table.columns, aggregationBaseColumnId)

        table.columns[aggregationColumnIndex].valueCategories = \
            deepcopy(table.columns[aggregationColumnIndex].valueCategories)

        self.__initAggregatedBufferColumns(aggregatedBufferColumns,
                                           aggregationBaseColumnId,
                                           deepcopy(table.columns))

        for categorizedValue, aggRowIndex in zip(
                table.columns[aggregationColumnIndex].valueCategories,
                range(
                    len(table.columns[aggregationColumnIndex].valueCategories))
        ):
            counter = 0
            for cell, rowIndex in zip(
                    table.columns[aggregationColumnIndex].cells[1:],
                    range(1,
                          len(table.columns[aggregationColumnIndex].cells))):
                if self.compareUtil(cell, categorizedValue):
                    targetAggRow = RowUtils.getRowFromTable(
                        aggregatedBufferColumns, aggRowIndex + 1)

                    targetRow = RowUtils.getRowFromTable(
                        table.columns, rowIndex)

                    bufferRow = RowUtils.addTwoCellsLists(
                        targetAggRow, targetRow)
                    RowUtils.updateRowInTable(aggregatedBufferColumns,
                                              aggRowIndex + 1, bufferRow)
                    counter += 1

            RowUtils.updateRowInTable(
                aggregatedBufferColumns, aggRowIndex + 1,
                RowUtils.divideCellsListOnNum(
                    RowUtils.getRowFromTable(aggregatedBufferColumns,
                                             aggRowIndex + 1), counter))

        table.aggregator.aggregatedTable = aggregatedBufferColumns
        return aggregatedBufferColumns
Exemple #16
0
    def implementAggregation(cls, data: DataModel, table: TableModel,
                             aggregationBaseColumnId: int, filterAgent,
                             doFilter: bool) -> List[ColumnModel]:
        aggregationColumnIndex = DataController.getElementIndexById(
            table.columns, aggregationBaseColumnId)

        if doFilter:
            filteredTable = filterAgent(data, 0, table.id)
        else:
            filteredTable = deepcopy(table)

        AggregationColumnUtils.updateYearBasedValueCats(
            filteredTable.columns[aggregationColumnIndex])

        aggregator = BasicAvgAggregation()
        aggregator.compareUtil = AggregationColumnUtils.sameYear
        return aggregator.aggregateTable(filteredTable,
                                         aggregationBaseColumnId)
    def implementFilter(self, table: TableModel, columnId: int,
                        value) -> TableModel:
        operators = {
            '=': operator.eq,
            'is': operator.eq,
            '!=': operator.is_not,
            'is not': operator.is_not,
            '<=': operator.le,
            '<': operator.lt,
            '>=': operator.ge,
            '>': operator.gt,
        }

        dateTimeHandlerFlag = False
        #check if the value is a datetime value.
        try:
            value = parse(value, fuzzy=False)
            dateTimeHandlerFlag = True
        except:
            pass

        filteredTable = deepcopy(table)
        columnIndex = DataController.getElementIndexById(
            table.columns, columnId)
        column = filteredTable.columns[columnIndex]

        rowCounter = 1
        for cell in column.cells[1:]:
            if dateTimeHandlerFlag:
                buffer = parse(cell.value, fuzzy=False)
            else:
                buffer = cell.value
            if not operators[self.operator](buffer, value):
                DataSourcesController.removeRowFromTable(
                    filteredTable.columns, rowCounter)
                filteredTable.rowsColors.pop(rowCounter - 1)
                filteredTable.rowsVisibility.pop(rowCounter - 1)
                # refresh row counter after deleting
                rowCounter -= 1
            rowCounter += 1

        return filteredTable
    def implementFilter(self, table: TableModel, columnId: int,
                        values: List) -> TableModel:

        filteredTable = deepcopy(table)
        columnIndex = DataController.getElementIndexById(
            table.columns, columnId)
        column = filteredTable.columns[columnIndex]

        values = self.__castNumericListElementsToFloats(values)

        rowCounter = 1
        for cell in column.cells[1:]:
            if cell.value not in values:
                DataSourcesController.removeRowFromTable(
                    filteredTable.columns, rowCounter)
                filteredTable.rowsColors.pop(rowCounter - 1)
                filteredTable.rowsVisibility.pop(rowCounter - 1)
                # refresh row counter after deleting
                rowCounter -= 1
            rowCounter += 1

        return filteredTable
 def insertNewDashboard(cls, data: DataModel, dashboard: DashboardModel):
     id = DataController.getMaxIdInList(data.dashboards)
     dashboard.id = id + 1
     data.dashboards.append(dashboard)
Exemple #20
0
 def setAggregationOff(cls, data: DataModel, tableId: int) -> TableModel:
     targetTableIndex = DataController.getElementIndexById(data.dataSources, tableId)
     targetTable = data.dataSources[targetTableIndex]
     Aggregation.setAggregationOff(targetTable)
     return targetTable
Exemple #21
0
 def insertNewColumn(cls, data: DataModel, tableId: int, column: ColumnModel) -> TableModel:
     targetTableIndex = DataController.getElementIndexById(data.dataSources, tableId)
     data.dataSources[targetTableIndex].columns.append(column)
     return data.dataSources[targetTableIndex]
Exemple #22
0
 def deleteTable(cls, data: DataModel, id: int):
     elementIndex = DataController.getElementById(data.dataSources, id)
     if elementIndex != -1:
         data.dataSources[elementIndex].isDeleted = True
         return data.dataSources[elementIndex]
     return None
Exemple #23
0
 def updateTableById(cls, data: DataModel, table: TableModel, id: int):
     oldTableIndex = DataController.getElementIndexById(data.dataSources, id)
     data.dataSources[oldTableIndex] = table
     return data.dataSources[oldTableIndex]
 def updateDashboardById(cls, data: DataModel, dashboard: DashboardModel,
                         id: int):
     oldDashboardIndex = DataController.getElementIndexById(
         data.dashboards, id)
     data.dashboards[oldDashboardIndex] = dashboard
     return data.dashboards[oldDashboardIndex]
Exemple #25
0
 def insertNewTable(cls, data: DataModel, table: TableModel):
     id = DataController.getMaxIdInList(data.dataSources)
     table.id = id + 1
     data.dataSources.append(table)
Exemple #26
0
 def updateFilterById(cls, data: DataModel, filter: FilterModel, id: int):
     oldFilterIndex = DataController.getElementIndexById(data.filters, id)
     data.filters[oldFilterIndex] = filter
     return data.filters[oldFilterIndex]
Exemple #27
0
 def deleteFilter(cls, data: DataModel, id: int):
     filterIndex = DataController.getElementById(data.filters, id)
     if filterIndex != -1:
         data.filters[filterIndex].isDeleted = True
         return data.filters[filterIndex]
     return None
Exemple #28
0
 def insertNewFilter(cls, data: DataModel, filter: FilterModel):
     id = DataController.getMaxIdInList(data.filters)
     filter.id = id + 1
     data.filters.append(filter)
 def deleteDashBoard(cls, data: DataModel, id):
     dashBoardIndex = DataController.getElementById(data.dashboards, id)
     if dashBoardIndex != -1:
         data.dashboards[dashBoardIndex].isDeleted = True
         return data.dashboards[dashBoardIndex]
     return None
Exemple #30
0
 def updateRowColorById(cls, data: DataModel, color: str, tableId: int, rowId: int):
     targetTableIndex = DataController.getElementIndexById(data.dataSources, tableId)
     data.dataSources[targetTableIndex].rowsColors[rowId] = color
     return data.dataSources[targetTableIndex]