Exemplo n.º 1
0
 def test_export(self):
     column1 = aa.Column(id="Lat",
                         variable_name=REPORTING_AIRPORT_LATITUDE,
                         column_header="Latitude")
     column2 = aa.Column(
         id="Long",
         variable_name=REPORTING_AIRPORT_LONGITUDE,
         column_header="Longitude",
     )
     clause = SelectorClause(
         "Flight Route",
         ORIGIN_DESTINATION_CODE,
         ["MALAGA", "LAS PALMAS"],
         session=session,
     )._to_model()
     rule = aa.Rule(clause)
     query = aa.Query(aa.Selection(rule=rule, table_name="Flight Route"))
     export = aa.Export(
         base_query=query,
         resolve_table_name="Flight Route",
         maximum_number_of_rows_to_browse=10,
         return_browse_rows=True,
         columns=[column1, column2],
     )
     export_api = aa.ExportsApi(session.api_client)
     result = export_api.exports_perform_export_synchronously(
         session.data_view, session.system, export=export)
     test_row = result.rows[0].descriptions
     self.assertEqual(test_row, "   36.674900\t   -4.499110")
Exemplo n.º 2
0
 def _get_export(self):
     export = aa.Export(
         base_query=aa.Query(selection=self.selection._to_model_selection(
         ) if self.selection is not None else aa.Selection(
             table_name=self.table.name)),
         resolve_table_name=self.table.name,
         maximum_number_of_rows_to_browse=self.max_rows,
         return_browse_rows=True,
         columns=self._create_columns(),
     )
     exports_controller = aa.ExportsApi(self.session.api_client)
     export_result = exports_controller.exports_perform_export_synchronously(
         self.session.data_view, self.session.system, export=export)
     return export_result
Exemplo n.º 3
0
 def _get_cube(self):
     cube = aa.Cube(
         base_query=aa.Query(selection=self.selection._to_model_selection(
         ) if self.selection is not None else aa.Selection(
             table_name=self.table.name)),
         resolve_table_name=self.table.name,
         storage="Full",
         dimensions=self._create_dimensions(),
         measures=self._create_measures(),
     )
     cubes_controller = aa.CubesApi(self.session.api_client)
     cube_result = cubes_controller.cubes_calculate_cube_synchronously(
         self.session.data_view, self.session.system, cube=cube)
     return cube_result
Exemplo n.º 4
0
 def _to_model_selection(self):
     return aa.Selection(
         rule=aa.Rule(clause=self.clause._to_model_clause()),
         limits=aa.Limits(
             sampling=self.sample_type,
             total=self.total,
             type=self.kind,
             start_at=self.skip_first,
             percent=self.percent,
             fraction=aa.Fraction(self.fraction.numerator,
                                  self.fraction.denominator)
             if self.fraction is not None else None,
         ),
         table_name=self.table_name,
         name=self.label,
     )
Exemplo n.º 5
0
 def _to_model_selection(self):
     if self.by is not None:
         grouping_sequence_variable_name = self.by.name
         grouping_ascending = self.ascending
     else:
         grouping_sequence_variable_name = None
         grouping_ascending = None
     return aa.Selection(
         rule=aa.Rule(clause=self.clause._to_model_clause()),
         top_n=aa.TopN(
             grouping_variable_name=self.per.name,
             grouping_sequence_variable_name=grouping_sequence_variable_name,
             grouping_ascending=grouping_ascending,
             group_max=self.n,
         ),
         table_name=self.table_name,
         name=self.label,
     )
Exemplo n.º 6
0
 def _to_model_selection(self):
     if self.by is not None:
         variable_name = self.by.name
         direction = "First" if self.ascending else "Last"
     else:
         variable_name = None
         direction = None
     return aa.Selection(
         rule=aa.Rule(clause=self.clause._to_model_clause()),
         n_per=aa.NPer(
             recency=aa.RFVRecency(variable_name=variable_name,
                                   direction=direction,
                                   value=self.n),
             grouping_table_name=self.per.name,
             transactional_table_name=self.table_name,
         ),
         table_name=self.table_name,
         name=self.label,
     )
Exemplo n.º 7
0
    def _to_model_selection(self):
        if self.kind[0] == "single":
            if self.kind[1] == "total":
                value = self.total
                percent = "NaN"
            elif self.kind[1] == "percent":
                value = 0
                percent = self.percent
            else:
                raise ValueError(f"Invalid kind: {self.kind}")
            direction = "Bottom" if self.ascending else "Top"
            min_value = "NaN"
            max_value = "NaN"
        elif self.kind[0] == "range":
            if self.kind[1] == "total":
                direction = "Range"
                min_value, max_value = self.total
            elif self.kind[1] == "percent":
                direction = "PercentRange"
                min_value, max_value = self.percent
            else:
                raise ValueError(f"Invalid kind: {self.kind}")
            direction += "BottomUp" if self.ascending else "TopDown"
            value = 0
            percent = "NaN"
        else:
            raise ValueError(f"Invalid kind: {self.kind}")

        return aa.Selection(
            rule=aa.Rule(clause=self.clause._to_model_clause()),
            top_n=aa.TopN(
                variable_name=self.by.name,
                direction=direction,
                value=value,
                percent=percent,
                min_value=min_value,
                max_value=max_value,
            ),
            table_name=self.table_name,
            name=self.label,
        )
Exemplo n.º 8
0
 def test_cube(self):
     selection = aa.Selection(table_name="Flight Route",
                              name="Blank Query",
                              ancestor_counts=False)
     query = aa.Query(selection=selection)
     dimension = aa.Dimension(
         id="Dates",
         type="Selector",
         variable_name=REPORTING_PERIOD_YEARS_CODE,
         none_cell=True,
         omit_unclassified=True,
     )
     dimension2 = aa.Dimension(
         id="Reporting Airport",
         type="Selector",
         variable_name=REPORTING_AIRPORT_CODE,
         none_cell=True,
         omit_unclassified=True,
     )
     dimensions = [dimension, dimension2]
     measure = aa.Measure(id="Routes1",
                          resolve_table_name="Flight Route",
                          function="Count")
     cube = aa.Cube(
         base_query=query,
         resolve_table_name="Flight Route",
         storage="Full",
         dimensions=dimensions,
         measures=[measure],
     )
     cube_api = aa.CubesApi(session.api_client)
     cube_calculation = cube_api.cubes_calculate_cube_synchronously(
         session.data_view, session.system, cube=cube)
     test_row = cube_calculation.measure_results[0].rows[7]
     self.assertEqual(
         test_row,
         "0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t179\t1633\t1765\t1896\t5473",
     )
Exemplo n.º 9
0
def create_query(rule=None, top_n=None):
    """ Return query from selection, with possible given rule or top_n. """
    return aa.Query(
        aa.Selection(table_name="Flight Route", rule=rule, top_n=top_n))
Exemplo n.º 10
0
 def _to_model_selection(self):
     return aa.Selection(
         table_name=self.table_name,
         ancestor_counts=True,
         rule=aa.Rule(clause=self._to_model_clause()),
     )
Exemplo n.º 11
0
 def count(self):
     query_final = aa.Query(
         selection=aa.Selection(table_name=self.name, ancestor_counts=True))
     session = self.session
     return Selection(query_final, session).count
Exemplo n.º 12
0
def sel_empty():
    return None, aa.Selection(table_name="Purchases")