Esempio n. 1
0
 def test_cell_values_finder(self):
     cell_values_results = [
         ([CellValue(3143), CellValue(2525)], [
             CellPosition(col=2, row=2),
             CellPosition(col=2, row=5),
             CellPosition(col=2, row=7)
         ]),
         ([CellValue('Общий итог'), CellValue()], [
             CellPosition(col=6, row=0),
             CellPosition(col=6, row=1),
             CellPosition(col=5, row=5),
             CellPosition(col=0, row=11),
             CellPosition(col=0, row=12),
             CellPosition(col=1, row=12),
             CellPosition(col=2, row=12),
             CellPosition(col=3, row=12),
             CellPosition(col=4, row=12),
             CellPosition(col=5, row=12),
             CellPosition(col=6, row=12),
         ]),
     ]
     finder = AllCellPositionsFinder(df=self.duplicates_df)
     for cell_values, results in cell_values_results:
         finder.value_finder = ExactValuesFinder(cell_values=cell_values)
         finder_results = finder.get_all_positions()
         self._check_results(expected_result=results,
                             finder_result=finder_results)
Esempio n. 2
0
 def test_startwith(self):
     patterns_results = [
         ('*', [
             CellPosition(col=0, row=1),
             CellPosition(col=0, row=2),
             CellPosition(col=0, row=3),
             CellPosition(col=0, row=4),
             CellPosition(col=0, row=5),
             CellPosition(col=0, row=6),
             CellPosition(col=0, row=7),
             CellPosition(col=0, row=8),
             CellPosition(col=0, row=9),
             CellPosition(col=0, row=10),
             CellPosition(col=0, row=11),
             CellPosition(col=0, row=12),
             CellPosition(col=0, row=13),
             CellPosition(col=0, row=14),
             CellPosition(col=0, row=15),
         ]),
         ('НЕБИВОЛОЛ-',
          [CellPosition(col=0, row=132),
           CellPosition(col=0, row=133)]),
         ('102', []),
         # TODO ДОбавить ещё проверки. Вариант котороый есть ив текстовой ячейке и числовой
     ]
     finder = AllCellPositionsFinder(df=self.simple_df)
     for value, results in patterns_results:
         finder.value_finder = StartWithFinder(cell_value=CellValue(value))
         finder_results = finder.get_all_positions()
         self._check_results(expected_result=results,
                             finder_result=finder_results)
Esempio n. 3
0
class ByValueNeighborhoodsLTRBFilterDF(FilterDfAbstract):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.cell_pos_finder = AllCellPositionsFinder(df=self._df)

    def _filter(self, start_cell_value: CellValue,
                start_cell_neighbors: List[NeighborCell],
                end_cell_value: CellValue,
                end_cell_neighbors: List[NeighborCell]):

        _start_position = CellPosition()
        for start_position in self.cell_pos_finder.get_position():
            neighbors_on_places = all([
                neighbor.is_neighbor(start_position)
                for neighbor in start_cell_neighbors
            ])
            if neighbors_on_places:
                _start_position = start_position
                break

        _end_position = CellPosition()
        for end_position in self.cell_pos_finder.get_position():
            neighbors_on_places = all([
                neighbor.is_neighbor(end_position)
                for neighbor in start_cell_neighbors
            ])
            if neighbors_on_places:
                _end_position = end_position
                break

        res_df = self._filter_df_ltrb(_start_position, _end_position)
        return res_df
Esempio n. 4
0
 def test_endwith(self):
     patterns_results = [
         ('2,5МГ+6,25МГ №30',
          [CellPosition(col=0, row=1),
           CellPosition(col=0, row=3)]),
         ('25', []),
         # TODO ДОбавить ещё проверки. Вариант котороый есть ив текстовой ячейке и числовой
     ]
     finder = AllCellPositionsFinder(df=self.duplicates_df)
     for value, results in patterns_results:
         finder.value_finder = EndWithFinder(cell_value=CellValue(value))
         finder_results = finder.get_all_positions()
         self._check_results(expected_result=results,
                             finder_result=finder_results)
Esempio n. 5
0
 def test_regex_cell_value_pattern(self):
     patterns_results = [
         ('.*КАНОН.*\d{4}.*', [CellPosition(col=0, row=5)]),
         ('.*АРИТЕЛ ПЛЮС(?!.*2,5).*', [
             CellPosition(col=0, row=2),
             CellPosition(col=0, row=7),
             CellPosition(col=0, row=10)
         ]),
     ]
     finder = AllCellPositionsFinder(df=self.duplicates_df)
     for pattern, results in patterns_results:
         finder.value_finder = RegexFinder(cell_value=CellValue(pattern))
         finder_results = finder.get_all_positions()
         self._check_results(expected_result=results,
                             finder_result=finder_results)
Esempio n. 6
0
 def test_cell_values_finder_with_neighbors(self):
     cell_values_neighbors_results = [
         ([CellValue(3143), CellValue(2525)], [
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(4690),
                          cell_offset=CellOffset(col=-1, row=0))
         ], [CellPosition(col=2, row=5)]),
     ]
     finder = AllCellPositionsFinder(df=self.duplicates_df)
     for cell_values, neighbors, results in cell_values_neighbors_results:
         finder.value_finder = ExactValuesFinder(cell_values=cell_values)
         finder.neighbors_container = NeighborsContainer(
             neighbors=neighbors)
         finder_results = finder.get_all_positions()
         self._check_results(expected_result=results,
                             finder_result=finder_results)
Esempio n. 7
0
 def test_cell_value_finder_with_offset(self):
     cell_values_results = [
         (CellValue('SKU'), CellOffset(col=1,
                                       row=0), [CellPosition(col=1,
                                                             row=0)]),
         (CellValue('SKU'), CellOffset(col=-10, row=-10), []),
         (CellValue('Общий итог'), CellOffset(col=0, row=1), [
             CellPosition(col=6, row=1),
             CellPosition(col=0, row=12),
         ]),
         (CellValue('Общий итог'), CellOffset(col=0, row=2),
          [CellPosition(col=6, row=2)]),
     ]
     finder = AllCellPositionsFinder(df=self.duplicates_df)
     for cell_value, cell_offset, results in cell_values_results:
         finder.value_finder = ExactValueFinder(cell_value=cell_value)
         finder.cell_offset_action = CellOffsetAction(
             cell_offset=cell_offset)
         finder_results = finder.get_all_positions()
         self._check_results(expected_result=results,
                             finder_result=finder_results)
Esempio n. 8
0
 def test_cell_value_finder_with_neighbors(self):
     cell_values_neighbors_results = [
         (CellValue(2525), [
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue('Общий итог'),
                          cell_offset=CellOffset(col=-2, row=6))
         ], [CellPosition(col=2, row=5)]),
         (CellValue(0), [
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(),
                          cell_offset=CellOffset(col=0, row=-1))
         ], [CellPosition(col=5, row=6)]),
         (CellValue('Общий итог'), [
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(),
                          cell_offset=CellOffset(col=0, row=1))
         ], [CellPosition(col=6, row=0),
             CellPosition(col=0, row=11)]),
         (CellValue('Общий итог'), [
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(''),
                          cell_offset=CellOffset(col=0, row=1))
         ], [CellPosition(col=6, row=0),
             CellPosition(col=0, row=11)]),
         (CellValue('Общий итог'), [
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(),
                          cell_offset=CellOffset(col=0, row=1)),
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(),
                          cell_offset=CellOffset(col=1, row=1)),
         ], [CellPosition(col=0, row=11)]),
         (CellValue('Общий итог'), [
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(),
                          cell_offset=CellOffset(col=0, row=1)),
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(''),
                          cell_offset=CellOffset(col=1, row=1)),
         ], [CellPosition(col=0, row=11)]),
         (CellValue('Общий итог'), [
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(''),
                          cell_offset=CellOffset(col=0, row=1)),
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(''),
                          cell_offset=CellOffset(col=1, row=1)),
         ], [CellPosition(col=0, row=11)]),
         (CellValue('Общий итог'), [
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(''),
                          cell_offset=CellOffset(col=0, row=1)),
             NeighborCell(df=self.duplicates_df,
                          cell_value=CellValue(),
                          cell_offset=CellOffset(col=1, row=1)),
         ], [CellPosition(col=0, row=11)]),
     ]
     finder = AllCellPositionsFinder(df=self.duplicates_df)
     for cell_value, neighbors, results in cell_values_neighbors_results:
         finder.value_finder = ExactValueFinder(cell_value=cell_value)
         finder.neighbors_container = NeighborsContainer(
             neighbors=neighbors)
         finder_results = finder.get_all_positions()
         self._check_results(expected_result=results,
                             finder_result=finder_results)
Esempio n. 9
0
 def test_all_positions(self):
     cell_values_results = [
         (CellValue(4302),
          [CellPosition(col=1, row=1),
           CellPosition(col=1, row=3)]),
         (CellValue(2256),
          [CellPosition(col=1, row=8),
           CellPosition(col=6, row=8)]),
         (CellValue('Общий итог'),
          [CellPosition(col=6, row=0),
           CellPosition(col=0, row=11)]), (CellValue(-999), []),
         (CellValue('Qwerty'), []),
         (CellValue(''), [
             CellPosition(col=6, row=1),
             CellPosition(col=5, row=5),
             CellPosition(col=0, row=12),
             CellPosition(col=1, row=12),
             CellPosition(col=2, row=12),
             CellPosition(col=3, row=12),
             CellPosition(col=4, row=12),
             CellPosition(col=5, row=12),
             CellPosition(col=6, row=12)
         ]),
         (CellValue(0), [
             CellPosition(col=3, row=1),
             CellPosition(col=4, row=1),
             CellPosition(col=5, row=1),
             CellPosition(col=3, row=2),
             CellPosition(col=4, row=2),
             CellPosition(col=5, row=2),
             CellPosition(col=3, row=3),
             CellPosition(col=4, row=3),
             CellPosition(col=5, row=3),
             CellPosition(col=2, row=4),
             CellPosition(col=3, row=4),
             CellPosition(col=4, row=4),
             CellPosition(col=5, row=4),
             CellPosition(col=3, row=5),
             CellPosition(col=4, row=5),
             CellPosition(col=2, row=6),
             CellPosition(col=3, row=6),
             CellPosition(col=4, row=6),
             CellPosition(col=5, row=6),
             CellPosition(col=4, row=7),
             CellPosition(col=5, row=7),
             CellPosition(col=2, row=8),
             CellPosition(col=3, row=8),
             CellPosition(col=4, row=8),
             CellPosition(col=5, row=8),
             CellPosition(col=2, row=9),
             CellPosition(col=3, row=9),
             CellPosition(col=5, row=9),
             CellPosition(col=2, row=10),
             CellPosition(col=3, row=10),
             CellPosition(col=4, row=10),
             CellPosition(col=5, row=10),
         ])
     ]
     finder = AllCellPositionsFinder(df=self.duplicates_df)
     for cell_value, results in cell_values_results:
         finder.value_finder = ExactValueFinder(cell_value=cell_value)
         finder_results = finder.get_all_positions()
         self._check_results(expected_result=results,
                             finder_result=finder_results)
Esempio n. 10
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.cell_pos_finder = AllCellPositionsFinder(df=self._df)