-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport-excel.py
52 lines (45 loc) · 1.74 KB
/
import-excel.py
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
import pandas as pd
from sqlalchemy import create_engine
import sys
# read in the excel data dump, ignoring the crap in the frist 4 rows
df = pd.read_excel(sys.argv[1], skiprows=4)
# connect to our DB
engine = create_engine("postgresql://@/chris")
# make column names lowercase first
df.columns = df.columns.str.lower()
# rewrite the columb headers to match our DB
df2 = df.rename(
columns={
"update time": "updatetime",
"pv1 voltage (v)": "voltpv1",
"pv1 current (a)": "amppv1",
"pv1 input power(w)": "wattpv1",
"pv1 power (w)": "wattpv1",
"pv2 voltage (v)": "voltpv2",
"pv2 current (a)": "amppv2",
"pv2 input power(w)": "wattpv2",
"pv2 power (w)": "wattpv2",
"ac voltage (v)": "voltac",
"ac voltage l (v)": "voltac",
"ac current(a)": "ampac",
"ac current l (a)": "ampac",
"output power(w)": "wattac",
"ac power (w)": "wattac",
"ac power l (w)": "wattac",
"daily yield(kwh)": "dayyeild",
"daily inverter output (kwh)": "dayyeild",
"total yield(kwh)": "totalyield",
"total inverter output (kwh)": "totalyield",
"inverter status": "status",
"inverter statue": "status",
}
)
# convert our timestamp to a datetime
df2["updatetime"] = pd.to_datetime(df2["updatetime"])
# make our new data time the index
df2.set_index("updatetime", inplace=True)
# append it to our DB
df2[['amppv1', 'voltpv1', 'wattpv1', 'amppv2', 'voltpv2','wattpv2', 'ampac', 'voltac', 'wattac', 'dayyeild', 'totalyield','status']].to_sql("solar_generation", engine, if_exists="append")
# print the date of the first/last entry in this file
print("start: " + str(df2.index[0].date()))
print("end: " + str(df2.index[-1].date()))