def model(self):

        T = current.T
        db = current.db

        configure = self.configure
        crud_strings = current.response.s3.crud_strings
        define_table = self.define_table
        super_link = self.super_link

        location_id = self.gis_location_id

        stats_parameter_represent = S3Represent(lookup="stats_parameter",
                                                translate=True)

        # ---------------------------------------------------------------------
        # Disease Statistic Parameter
        #
        tablename = "disease_statistic"
        define_table(tablename,
                     # Instance
                     super_link("parameter_id", "stats_parameter"),
                     Field("name",
                           label = T("Name"),
                           requires = IS_NOT_EMPTY(),
                           represent = lambda v: T(v) if v is not None \
                                                    else NONE,
                           ),
                     s3_comments("description",
                                 label = T("Description"),
                                 ),
                     *s3_meta_fields()
                     )

        # CRUD Strings
        ADD_STATISTIC = T("Add Statistic")
        crud_strings[tablename] = Storage(
            label_create = ADD_STATISTIC,
            title_display = T("Statistic Details"),
            title_list = T("Statistics"),
            title_update = T("Edit Statistic"),
            #title_upload = T("Import Statistics"),
            label_list_button = T("List Statistics"),
            msg_record_created = T("Statistic added"),
            msg_record_modified = T("Statistic updated"),
            msg_record_deleted = T("Statistic deleted"),
            msg_list_empty = T("No statistics currently defined"))

        configure(tablename,
                  deduplicate = S3Duplicate(),
                  super_entity = "stats_parameter",
                  )

        # ---------------------------------------------------------------------
        # Disease Statistic Data
        #
        tablename = "disease_stats_data"
        define_table(tablename,
                     # Instance
                     super_link("data_id", "stats_data"),
                     # This is a component, so needs to be a super_link
                     # - can't override field name, ondelete or requires
                     super_link("parameter_id", "stats_parameter",
                                instance_types = ("disease_statistic",),
                                label = T("Statistic"),
                                represent = stats_parameter_represent,
                                readable = True,
                                writable = True,
                                empty = False,
                                comment = S3PopupLink(c = "disease",
                                                      f = "statistic",
                                                      vars = {"child": "parameter_id"},
                                                      title = ADD_STATISTIC,
                                                      ),
                                ),
                     location_id(
                         requires = IS_LOCATION(),
                         widget = S3LocationAutocompleteWidget(),
                     ),
                     Field("value", "double",
                           label = T("Value"),
                           represent = lambda v: \
                            IS_FLOAT_AMOUNT.represent(v, precision=2),
                           requires = IS_NOT_EMPTY(),
                           ),
                     s3_date(empty = False),
                     #Field("end_date", "date",
                     #      # Just used for the year() VF
                     #      readable = False,
                     #      writable = False
                     #      ),
                     # Link to Source
                     self.stats_source_id(),
                     s3_comments(),
                     *s3_meta_fields()
                     )

        # CRUD Strings
        crud_strings[tablename] = Storage(
            label_create = T("Add Disease Data"),
            title_display = T("Disease Data Details"),
            title_list = T("Disease Data"),
            title_update = T("Edit Disease Data"),
            title_upload = T("Import Disease Data"),
            label_list_button = T("List Disease Data"),
            msg_record_created = T("Disease Data added"),
            msg_record_modified = T("Disease Data updated"),
            msg_record_deleted = T("Disease Data deleted"),
            msg_list_empty = T("No disease data currently available"))

        levels = current.gis.get_relevant_hierarchy_levels()

        location_fields = [level % "location_id$%s" for level in levels]

        list_fields = ["parameter_id"]
        list_fields.extend(location_fields)
        list_fields.extend((("value",
                             "date",
                             "source_id",
                             )))

        filter_widgets = [S3OptionsFilter("parameter_id",
                                          label = T("Type"),
                                          multiple = False,
                                          # Not translateable
                                          #represent = "%(name)s",
                                          ),
                          S3OptionsFilter("location_id$level",
                                          label = T("Level"),
                                          multiple = False,
                                          # Not translateable
                                          #represent = "%(name)s",
                                          ),
                          S3LocationFilter("location_id",
                                           levels = levels,
                                           ),
                          ]

        report_options = Storage(rows = location_fields,
                                 cols = ["parameter_id"],
                                 fact = [(T("Value"), "sum(value)"),
                                         ],
                                 defaults = Storage(rows = location_fields[0], # => L0 for multi-country, L1 for single country
                                                    cols = "parameter_id",
                                                    fact = "sum(value)",
                                                    totals = True,
                                                    chart = "breakdown:rows",
                                                    table = "collapse",
                                                    )
                                 )

        configure(tablename,
                  deduplicate = S3Duplicate(primary = ("parameter_id",
                                                       "location_id",
                                                       "date",
                                                       ),
                                            ),
                  filter_widgets = filter_widgets,
                  list_fields = list_fields,
                  report_options = report_options,
                  # @ToDo: Wrapper function to call this for the record linked
                  # to the relevant place depending on whether approval is
                  # required or not. Disable when auth.override is True.
                  #onaccept = self.disease_stats_update_aggregates,
                  #onapprove = self.disease_stats_update_aggregates,
                  # @ToDo: deployment_setting
                  #requires_approval = True,
                  super_entity = "stats_data",
                  timeplot_options = {"defaults": {"event_start": "date",
                                                   "event_end": "date",
                                                   "fact": "cumulate(value)",
                                                   },
                                      },
                  )

        #----------------------------------------------------------------------
        # Disease Aggregated data
        #

        # The data can be aggregated against:
        # location, all the aggregated values across a number of locations
        #           thus for an L2 it will aggregate all the L3 values
        # time, sum of all the disease_stats_data values up to this time.
        #           allowing us to report on cumulative values

        aggregate_types = {1 : T("Time"),
                           2 : T("Location"),
                           }

        tablename = "disease_stats_aggregate"
        define_table(tablename,
                     # This is a component, so needs to be a super_link
                     # - can't override field name, ondelete or requires
                     super_link("parameter_id", "stats_parameter",
                                empty = False,
                                instance_types = ("disease_statistic",),
                                label = T("Statistic"),
                                represent = S3Represent(lookup="stats_parameter"),
                                readable = True,
                                writable = True,
                                ),
                     location_id(
                        requires = IS_LOCATION(),
                        widget = S3LocationAutocompleteWidget(),
                     ),
                     Field("agg_type", "integer",
                           default = 1,
                           label = T("Aggregation Type"),
                           represent = lambda opt: \
                            aggregate_types.get(opt,
                                                current.messages.UNKNOWN_OPT),
                           requires = IS_IN_SET(aggregate_types),
                           ),
                     s3_date("date",
                             label = T("Start Date"),
                             ),
                     Field("sum", "double",
                           label = T("Sum"),
                           represent = lambda v: \
                            IS_FLOAT_AMOUNT.represent(v, precision=2),
                           ),
                     *s3_meta_fields()
                     )

        # ---------------------------------------------------------------------
        # Pass names back to global scope (s3.*)
        #
        return dict(
            disease_stats_rebuild_all_aggregates = self.disease_stats_rebuild_all_aggregates,
            disease_stats_update_aggregates = self.disease_stats_update_aggregates,
            disease_stats_update_location_aggregates = self.disease_stats_update_location_aggregates,
            )

    # -------------------------------------------------------------------------
dataset/ETHPy150Open sahana/eden/modules/s3db/disease.py/DiseaseStatsModel.model/swapped operands of `%`