File size: 5,551 Bytes
b5c411b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
000f968
b5c411b
 
 
 
 
 
 
000f968
b5c411b
 
 
 
 
 
8d2b3e8
b5c411b
 
 
 
 
 
 
000f968
b5c411b
 
000f968
b5c411b
000f968
 
 
b5c411b
 
000f968
 
 
 
 
 
 
 
 
 
 
b5c411b
 
000f968
b5c411b
 
 
000f968
36e6037
000f968
 
b5c411b
 
 
653af31
17592c4
 
 
 
 
 
 
 
 
 
2140079
17592c4
2140079
 
 
 
 
 
 
 
17592c4
b5c411b
 
 
 
 
 
 
 
 
 
 
 
 
3c21e8e
b5c411b
 
 
 
 
 
 
 
 
 
 
 
3c21e8e
000f968
b5c411b
3c21e8e
b5c411b
000f968
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Loading packages
import datetime
import joblib
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import warnings
import hopsworks
import streamlit as st
import json
import os
import seaborn as sns
import time
import random

# Configuring the web page and setting the page title and icon
st.set_page_config(
  page_title='Parking Occupacy Detection System',
  page_icon='🅿️',
  initial_sidebar_state='expanded')

# Ignoring filtering warnings
warnings.filterwarnings("ignore")

# Setting the title and adding text
st.title('Parking Occupancy Detection System')

# Creating tabs for the different features of the application
tab1,tab2,tab3,tab4, tab5 = st.tabs(['Parking lot status', 'Magnetic Field Explorer', 'About', 'Dataset and visualisations', 'Model performance'])

with tab1:
    # Logging in to Hopsworks and loading the feature store
    project = hopsworks.login(project = "annikaij", api_key_value=os.environ['HOPSWORKS_API_KEY'])
    fs = project.get_feature_store()

    col1, col2 = st.columns(2)

    with col1:
        st.subheader("Parking place near building:")

        # Function to load the building models
        
        @st.cache_data()
        def get_building_mag_model(project=project):
            mr = project.get_model_registry()
            building_mag_model = mr.get_model("building_mag_hist_model", version = 2)
            building_mag_model_dir = building_mag_model.download()
            return joblib.load(building_mag_model_dir + "/building_mag_hist_model.pkl")

        # Retrieving model
        building_mag_hist_model = get_building_mag_model()

        @st.cache_data()
        def get_building_rad_model(project=project):
            mr = project.get_model_registry()
            building_rad_model = mr.get_model("building_rad_hist_model", version = 2)
            building_rad_model_dir = building_rad_model.download()
            return joblib.load(building_rad_model_dir + "/building_rad_hist_model.pkl")

        # Retrieving model
        building_rad_hist_model = get_building_rad_model()
    
        # Loading the feature group with latest data for building
        new_building_fg = fs.get_feature_group(name = 'new_building_fg', version = 1)

        # Function to loading the feature group with latest data for building as a dataset
        @st.cache_data()
        def retrieve_building(feature_group=new_building_fg):
            new_building_fg = feature_group.select_all()
            df_building_new = new_building_fg.read(read_options={"use_hive": True})           
            return df_building_new

        # Retrieving building data
        building_new = retrieve_building()

        building_mag_prediction_data = building_new[['time', 'x', 'y', 'z', 'temperature', 'et0_fao_evapotranspiration']]

        def add_small_value_if_zero(value):
            if value == 0.000000:
                return value + 0.000001
            else:
                return value
        
        building_mag_prediction_data['et0_fao_evapotranspiration'] = building_mag_prediction_data['et0_fao_evapotranspiration'].apply(add_small_value_if_zero)

        st.dataframe(building_mag_prediction_data)

        # Making the predictions and getting the latest data
        #building_mag_most_recent_prediction = building_new[['x', 'y', 'z', 'temperature', 'et0_fao_evapotranspiration']]
        #building_mag_most_recent_prediction_mag = building_mag_hist_model.predict(building_mag_most_recent_prediction)
        #building_new['Status'] = building_mag_most_recent_prediction
        #building_new['Status'].replace(['detection', 'no_detection'], ['Vehicle detected', 'No vehicle detected'], inplace=True)
        #building_new = building_new.rename(columns={'time': 'Time'})
        #building_new = building_new.set_index(['Time'])
        #st.dataframe(building_new[['Status']].tail(3))


    with col2:
        st.subheader("Parking place near bikelane:")
            

    # Update button
    if st.button("Update application"):
        # Clear cached data
        st.cache_data.clear()
        # Immediately rerun the application
        st.experimental_rerun()
        
with tab2:
     st.subheader('...')

with tab3:
    st.subheader('About the application:')
    st.markdown('This application is made as part of the module "Data Engineering and Machine Learning Operations in Business - F2024" in Business Data Science 2nd Semester at Aalborg University Business School.')
    st.markdown('The application is made by Annika and Mikkel and is divided into 5 tabs:')
    st.markdown('*   **Parking lot status:** The first tab includes the actual interface, where the goal has been to make a simple UI which shows if 2 parking spaces are occupied or available.')
    st.markdown('*   **Magnetic Field Explorer:** The second tabs is made for exploring the models, where the user can test different values for x, y and z and get a prediction')
    st.markdown('*   **About:** In the third tab (the current tab) you can get some information about the interface.')
    st.markdown('*   **Dataset and visualisations:** The fourth tab contains an overview of the training data and also includes EDAs for each individual parking space. The goal with these EDAs is to give you some information about when the parking spaces usually are occupied.')
    st.markdown('*   **Model Performance:** The fifth tab explains how the underlying Machine Learning Model performs and how the predictor works.')

with tab4:
    st.subheader('...')    
 
with tab5:
    st.subheader('...')