Esempio n. 1
0
    def __init__(self, pins, db_filename, timeout):
        '''
        Args:
            pins (dict): a dict that contains info about the pins that the sensors are connected to.
                         should be of form:
                         {
                            "ingress": {
                                "trigger": 17,
                                "echo": 18
                            },
                            "egress": {
                                "trigger": 22,
                                "echo": 23
                            }
                        }
            db_filename (str): database filename
            timeout (float): when a sensor is tripped, how long to wait for the second sensor to trip
        '''
        self.ingress_sensor = DistanceSensor(
            echo=pins['ingress']['echo'], trigger=pins['ingress']['trigger'])
        self.egress_sensor = DistanceSensor(echo=pins['egress']['echo'],
                                            trigger=pins['egress']['trigger'])
        self.db = dbh.DB_Handler(db_filename)
        self.timeout = timeout

        self.ingress_floor = 1  # in meters
        self.egress_floor = 1  # in meters
        self.init_distance()
Esempio n. 2
0
def dashboard():
    # read table from DB

    DB_NAME = 'c:/Users/elahav109995/PycharmProjects/flask_proj/db/stocks_db.db'
    DB = db_handler.DB_Handler()
    DB.create_db(DB_NAME)
    items = DB.read_all_as_dict()

    return render_template('dashboard.html',
                           name=current_user.username,
                           items=items)
Esempio n. 3
0
def index_page():
    '''
    Shows all the dates for which data exists (ie. in the database)
    And gives the link to the webpage to view that data
    '''
    db = dbh.DB_Handler(constants.DB_FILE)
    dates = db.get_dates()
    for d in dates:
        d['display_date'] = utils.iso_to_display_date(d['date'])
    return render_template('index.html',
                           dates=dates,
                           base_url=request.url_root)
Esempio n. 4
0
def home_page():
    '''
    Shows how many people are currently inside the building and how much traffic there is (for the day)
    '''
    db = dbh.DB_Handler(constants.DB_FILE)
    record = db.get_record(utils.iso_date())
    if not record:
        return render_template('dne.html', date=utils.display_date())

    data = {
        'datetime': utils.display_datetime(),
        'inside': record['ingress'] - record['egress'],
        'entrants': max(record['ingress'], record['egress'])
    }
    return render_template('home.html', data=data, base_url=request.url_root)
Esempio n. 5
0
def date_page(date: str):
    '''
    Shows how many people entered, how many exited, and how much traffic there were

    Args:
        date (str): must be iso 8601 format (yyyy-mm-dd)
    '''
    if date == 'favicon.ico':
        return

    db = dbh.DB_Handler(constants.DB_FILE)
    data = db.get_record(date)
    if not data:
        return render_template('dne.html',
                               date=utils.iso_to_display_date(date))

    data['display_date'] = utils.iso_to_display_date(data['date'])
    data['entrants'] = max(data['ingress'], data['egress'])
    return render_template('date.html', data=data, base_url=request.url_root)