main.py 1.33 KB
Newer Older
1
2
3
4
5
6
7
"""
    # main.py

    - Load된 데이터들에 대해 Linear Regression을 진행합니다.
    - 진행된 후의 Weights를 파일로 저장합니다.
"""

8
import datetime
9
import sys
10
import psycopg2
11

12
from preprocessing import preprocess
13

14
# DB 환경 변수
15
16
17
dbconfig = {"host": sys.argv[1], "user": sys.argv[2],
            "password": sys.argv[3], "database": sys.argv[4]}

18
19
20
21
22
23
24
today = datetime.datetime.today()
year = str(today.year)
month = str(today.month) if today.month >= 10 else '0'+str(today.month)
day = str(today.day) if today.day >= 10 else '0'+str(today.day)
collected_at = year + "-" + month + "-" + day


25
26
27
# DB 연결
connection = psycopg2.connect(
    database=dbconfig["database"], user=dbconfig["user"])
28

29
30
# DB에 대한 동작을 위한 cursor 생성
cursor = connection.cursor()
31

32
33
34
35
36
37
cursor.execute("SELECT email, loc_code, using_aircon FROM Users")
users = cursor.fetchall()

for user in users:

    host = {"email": user[0], "loc_code": user[1], "using_aircon": user[2]}
38

39
40
    # 데이터 전처리
    preprocess(cursor, host)
41

42
43
44
45
46
47
48
    # 데이터 분석
    params = "main_proceduer_function"

    # 데이터 분석 결과 저장
    cursor.execute("INSERT INTO \"Data_Processings\" (host,collected_at,params) VALUES (%s,%s,%s)",
                   (host["email"], collected_at, params))

49
50
51
# Cursor와 Connection 종료
cursor.close()
connection.close()