Azaya89 commited on
Commit
485b10f
·
1 Parent(s): 59fc4e0

initial commit

Browse files
.github/workflows/update_data_workflow.yml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Update Data Workflow
2
+
3
+ on:
4
+ schedule:
5
+ - cron: '0 10 * * *' # Run every day at 10:00 UTC
6
+
7
+ jobs:
8
+ update-data:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - name: Checkout repository
13
+ uses: actions/checkout@v2
14
+
15
+ - name: Set up Python
16
+ uses: actions/setup-python@v2
17
+ with:
18
+ python-version: '3.11.8'
19
+
20
+ - name: Install dependencies
21
+ run: |
22
+ pip install pandas gspread oauth2client subprocess
23
+
24
+ - name: Run the update script
25
+ run: python update_data.py
26
+
27
+ - name: Commit and push if changes
28
+ run: |
29
+ git config --global user.name 'Isaiah Akorita'
30
+ git config --global user.email 'akoritaisaiah@gmail.com'
31
+ git add -A
32
+ git commit -m "Automated data update" || echo "No changes to commit"
33
+ git push
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ omoku-analysis-cred_key.json
2
+ *.png
3
+ *.ipynb_checkpoints
4
+ *.ipynb
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+ RUN python3 -m pip install --no-cache-dir --upgrade pip
7
+ RUN python3 -m pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["panel", "serve", "/code/app.py", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "*"]
12
+
13
+ RUN mkdir /.cache
14
+ RUN chmod 777 /.cache
15
+ RUN mkdir .chroma
16
+ RUN chmod 777 .chroma
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Power supply dashboard
3
+ emoji: 📈
4
+ colorFrom: gray
5
+ colorTo: green
6
+ sdk: docker
7
+ pinned: true
8
+ ---
9
+
10
+ # Omoku power supply report
11
+
12
+ This is a [Panel](https://panel.holoviz.org) dashboard that shows the number of hours of power supply in a section of Omoku, Rivers State, Nigeria.
app.py ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import libraries
2
+ import pandas as pd, panel as pn
3
+ import hvplot.pandas # noqa
4
+
5
+ # Data loading and cleaning
6
+ df = pd.read_csv('omoku_data.csv', usecols=['Date', 'Power_time', 'Outages'], index_col='Date', parse_dates=True)
7
+
8
+ day_order = {
9
+ 0: 'Monday',
10
+ 1: 'Tuesday',
11
+ 2: 'Wednesday',
12
+ 3: 'Thursday',
13
+ 4: 'Friday',
14
+ 5: 'Saturday',
15
+ 6: 'Sunday'
16
+ }
17
+ days = list(day_order.values())
18
+
19
+ daily_average = df['Power_time'].mean()
20
+ max_power = df['Power_time'].max()
21
+ min_power = df['Power_time'].min()
22
+
23
+ df['Day'] = df.index.dayofweek.map(day_order)
24
+ df['Power_time'] = df['Power_time'].fillna(daily_average).round(1)
25
+ df['Outages'] = df['Outages'].fillna((24-daily_average)).round(1)
26
+
27
+ # Plots
28
+ box_plot = df.hvplot.box(xlabel="Variables", ylabel="Number of hours", grid=True, title="Box Plot of Power Time and Outages")
29
+ line_plot = df.hvplot.line(y='Power_time', ylabel='Number of hours', title='Daily power supply')
30
+ density_plot = df.hvplot.density('Power_time', xlabel='Number of hours', xlim=(0,25), yaxis=None, hover=False, title='Density distribution of power supply')
31
+ weekly_group = df.groupby('Day', sort=False).mean().reindex(days)
32
+ weekly_plot = weekly_group.hvplot.bar(stacked=True, rot=45, ylabel='Number of hours', title='Average power supply by week day')
33
+
34
+ # Dashboard
35
+ pn.extension('tabulator', sizing_mode="stretch_width")
36
+
37
+ ACCENT = "#4099da"
38
+ styles = {
39
+ "box-shadow": "rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px",
40
+ "border-radius": "4px",
41
+ "padding": "10px",
42
+ }
43
+ BRAND_COLOR = ACCENT
44
+ BRAND_TEXT_ON_COLOR = "white"
45
+ CARD_STYLE = {
46
+ "box-shadow": "rgba(50, 50, 93, 0.25) 0px 6px 12px -2px, rgba(0, 0, 0, 0.3) 0px 3px 7px -3px",
47
+ "padding": "10px",
48
+ "border-radius": "5px"
49
+ }
50
+ header = pn.Row(
51
+ pn.pane.Markdown(
52
+ "# Omoku power supply report", styles={"color": BRAND_TEXT_ON_COLOR}, margin=(5, 20)
53
+ ),
54
+ styles={"background": BRAND_COLOR},
55
+ )
56
+ indicators = pn.FlexBox(
57
+ pn.indicators.Number(
58
+ value=daily_average,
59
+ name="Average daily supply (Hrs)",
60
+ default_color="gray",
61
+ format="{value:,.0f}",
62
+ styles=styles
63
+ ),
64
+ pn.indicators.Number(
65
+ value=max_power,
66
+ name="Highest daily supply (Hrs)",
67
+ default_color="green",
68
+ format="{value:,.1f}",
69
+ styles=styles,
70
+ ),
71
+ pn.indicators.Number(
72
+ value=min_power,
73
+ name="Lowest daily supply (Hrs)",
74
+ default_color="red",
75
+ format="{value:,.1f}",
76
+ styles=styles,
77
+ ),
78
+ )
79
+
80
+ table = pn.widgets.Tabulator(df.head(10), sizing_mode="stretch_width", name="Table")
81
+ tabs = pn.Tabs(('Daily total', line_plot), ('Weekly average', weekly_plot), ('Box plot', box_plot), ('Density distribution', density_plot),
82
+ styles=styles, sizing_mode="scale_both", margin=10)
83
+ logo = '<img src="https://panel.pyviz.org/_static/logo_stacked.png" width=180 height=150>'
84
+
85
+ text = f"""This is a [Panel](https://panel.holoviz.org) dashboard that shows the number of hours of power supply in Omoku, Rivers State, Nigeria.
86
+
87
+ Omoku is divided into three (3) areas in terms of power supply and this data was collected at one of the three areas.
88
+
89
+ The data was collected by calculating the total number of hours during which there was no power and subtracting it from 24 hours.
90
+
91
+ This data was collected consecutively over a period of `{len(df)}` days."""
92
+
93
+ template = pn.template.FastListTemplate(
94
+ title="Power supply dashboard",
95
+ sidebar=[logo, text],
96
+ sidebar_width=250,
97
+ main=[pn.Column('# Data Summary', indicators, '# Sample Data', table, '# Plots', tabs, sizing_mode="stretch_both")],
98
+ main_layout=None,
99
+ accent=ACCENT,
100
+ )
101
+
102
+ template.servable()
gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
omoku_data.csv ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Date,Power_time,Outages,Remark
2
+ 3/21/2024,20.5,3.5,
3
+ 3/22/2024,19.5,4.5,
4
+ 3/23/2024,15.5,8.5,
5
+ 3/24/2024,21.5,2.5,
6
+ 3/25/2024,20,4,
7
+ 3/26/2024,21,3,
8
+ 3/27/2024,7,17,
9
+ 3/28/2024,15.5,8.5,
10
+ 3/29/2024,19,5,
11
+ 3/30/2024,20,4,
12
+ 3/31/2024,18.5,5.5,
13
+ 4/1/2024,21,3,
14
+ 4/2/2024,17.5,6.5,
15
+ 4/3/2024,14.5,9.5,
16
+ 4/4/2024,15,9,
17
+ 4/5/2024,20,4,
18
+ 4/6/2024,18,6,
19
+ 4/7/2024,18.5,5.5,
20
+ 4/8/2024,20,4,
21
+ 4/9/2024,19,5,
22
+ 4/10/2024,16,8,
23
+ 4/11/2024,18,6,
24
+ 4/12/2024,18,6,
25
+ 4/13/2024,15,9,
26
+ 4/14/2024,9.5,14.5,
27
+ 4/15/2024,2.5,21.5,
28
+ 4/16/2024,14,10,
29
+ 4/17/2024,16,8,
30
+ 4/18/2024,13,11,
31
+ 4/19/2024,16.5,7.5,
32
+ 4/20/2024,,,Wedding weekend
33
+ 4/21/2024,,,Wedding weekend
34
+ 4/22/2024,,,Wedding weekend
35
+ 4/23/2024,9,15,
36
+ 4/24/2024,15.5,8.5,
37
+ 4/25/2024,21,3,
38
+ 4/26/2024,19.5,4.5,
39
+ 4/27/2024,0,24,Maintenance
40
+ 4/28/2024,0,24,Maintenance
41
+ 4/29/2024,5.5,18.5,
42
+ 4/30/2024,19.5,4.5,
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ panel
2
+ jupyter
3
+ transformers
4
+ numpy
5
+ torch
6
+ aiohttp
7
+ scipy
8
+ pandas
9
+ hvplot
update_data.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gspread
3
+ from oauth2client.service_account import ServiceAccountCredentials
4
+ import subprocess
5
+
6
+ def download_sheet(sheet_id, range_name):
7
+ """Downloads data from Google Sheets and returns a DataFrame."""
8
+ # Define the scope
9
+ scope = ['https://www.googleapis.com/auth/spreadsheets.readonly']
10
+
11
+ # Add credentials to the account
12
+ creds = ServiceAccountCredentials.from_json_keyfile_name('omoku-analysis-cred_key.json', scope)
13
+
14
+ # Authorize the clientsheet
15
+ client = gspread.authorize(creds)
16
+
17
+ # Get the instance of the Spreadsheet
18
+ sheet = client.open_by_key(sheet_id)
19
+
20
+ # Get the sheet by name
21
+ worksheet = sheet.get_worksheet(0)
22
+
23
+ # Get all records of the data
24
+ data = worksheet.get_all_records()
25
+
26
+ # Convert to DataFrame
27
+ df = pd.DataFrame(data)
28
+
29
+ return df
30
+
31
+ def save_to_csv(df, file_path):
32
+ """Saves DataFrame to CSV."""
33
+ df.to_csv(file_path, index=False)
34
+
35
+
36
+ def git_commit_push():
37
+ """Commits and pushes updated CSV file to GitHub."""
38
+ try:
39
+ # Commands to add, commit, and push to GitHub
40
+ subprocess.run(['git', 'add', 'omoku_data.csv'], check=True)
41
+ subprocess.run(['git', 'commit', '-m', 'Update dataset'], check=True)
42
+ subprocess.run(['git', 'push'], check=True)
43
+ except subprocess.CalledProcessError as e:
44
+ print(f'Error in Git operation: {e}')
45
+
46
+ if __name__ == "__main__":
47
+ SHEET_ID = 'omoku_power_supply'
48
+ RANGE_NAME = 'data' # or whatever your range or sheet name is
49
+ FILE_PATH = 'omoku_data.csv'
50
+
51
+ df = download_sheet(SHEET_ID, RANGE_NAME)
52
+ save_to_csv(df, FILE_PATH)
53
+ git_commit_push()