OpenBCca / airbnb-regulation

Airbnb Regulation Project
MIT License
1 stars 0 forks source link

Feature/policy results for report #45

Open nam-m opened 9 months ago

nam-m commented 9 months ago

Description

Issue Link: #18

This PR contains PolicyClient object that works with Policy interface (from which the Policy objects are based on) Dataflow:

PolicyClient <-----> Policy
                        ^
                        |
                        |
         ValidRegistrationNumberPolicy
         UniqueRegistrationNumberPolicy
                      .
                      .
                      .                  

Example usage, given the following policy:

valid_registration_number_policy.py

import re

from models.listing import Listing
from models.policy import Policy

class ValidRegistrationNumberPolicy(Policy):
    def __init__(self, listing: Listing):
        self.listing = listing

    def evaluate(self) -> bool:
        valid_registration_pattern = re.compile(r"^[0-9]{2}-[0-9]{6}$")

        if valid_registration_pattern.match(self.listing.licence_number):
            return True
        else:
            return False

main.py

from models.address import Address
from models.listing import Listing
from models.policy_client import PolicyClient
from policy.valid_registration_number_policy import (
    ValidRegistrationNumberPolicy,
)

listing = Listing("1234", address=Address(city="Van"), licence_number="20-12345")

registration_number_policies = ValidRegistrationNumberPolicy(listing)

client = PolicyClient(registration_number_policies)
print(client.get_all_violation_results())
## return []

client.get_violation_result()

print(client.get_all_violation_results())
## return [{'ValidRegistrationNumberPolicy': False}]

Type of Change

Please delete options that are not relevant.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

Checklist:

Before you submit your pull request, please make sure you have completed the following:

Screenshots (if applicable)

Include any relevant screenshots or screen recordings demonstrating your changes.

Additional Notes

Detailed implementation of the Policy might be changed, per #40 With this change, the Policies implementation may also need changes regarding the Policy interface