# Webserver
from flask import Flask
import os
import socket

# Data
from ts_decomposition.data.energy_connection import EnergyConnection

# Model
from ts_decomposition.model.series_sample import TimeSeriesSample

# settings.py
from dotenv import load_dotenv
from pathlib import Path  # python3 only
load_dotenv()
# load_dotenv(verbose=True)  # Verbose

env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)

# Copypasta from TS main 
from datetime import datetime
import pandas as pd

app = Flask(__name__)

energy_connection = EnergyConnection()

# Routes 
# TODO: Break out
# TODO: Get rid of the new "main" debug hax
@app.route("/")
def root():
    html = "<h3>{name}</h3>" \
           "<b>Hostname:</b> {hostname}<br/>"
    return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname())

@app.route("/test")
def test_route():
    series = [
        'appliance',
        'humidity',
        'tempurature',
        'tdewpoint',
        'pressure'
    ]

    sample_frame = energy_connection.sample_series('energy_readings')
    # TODO: Rooms/QL Extract

    sample_frame = energy_connection.sample_series('external_readings', append_frame=sample_frame)

    sample = TimeSeriesSample(sample_frame, 'time')

    # TODO: Figure out what needs to be moved to constructor
    sample.train_test_split(20)  # Make sure everything can be done AFTER split

    print(sample.base.index)

    sample.clean_lights()
    
    result = sample.stationality('appliance')

    html = "<h3>{name}</h3>" \
           "<b>{result}<br/>" \
           "Hey!"
    return html.format(name=os.getenv("NAME", "world"), result=result)

# Run the server
if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8789)

9b07030742b596628ef96ef155a9e29a3700dd07
<mask token>


@app.route('/')
def root():
    html = '<h3>{name}</h3><b>Hostname:</b> {hostname}<br/>'
    return html.format(name=os.getenv('NAME', 'world'), hostname=socket.
        gethostname())


@app.route('/test')
def test_route():
    series = ['appliance', 'humidity', 'tempurature', 'tdewpoint', 'pressure']
    sample_frame = energy_connection.sample_series('energy_readings')
    sample_frame = energy_connection.sample_series('external_readings',
        append_frame=sample_frame)
    sample = TimeSeriesSample(sample_frame, 'time')
    sample.train_test_split(20)
    print(sample.base.index)
    sample.clean_lights()
    result = sample.stationality('appliance')
    html = '<h3>{name}</h3><b>{result}<br/>Hey!'
    return html.format(name=os.getenv('NAME', 'world'), result=result)


<mask token>

<mask token>
load_dotenv()
<mask token>
load_dotenv(dotenv_path=env_path)
<mask token>


@app.route('/')
def root():
    html = '<h3>{name}</h3><b>Hostname:</b> {hostname}<br/>'
    return html.format(name=os.getenv('NAME', 'world'), hostname=socket.
        gethostname())


@app.route('/test')
def test_route():
    series = ['appliance', 'humidity', 'tempurature', 'tdewpoint', 'pressure']
    sample_frame = energy_connection.sample_series('energy_readings')
    sample_frame = energy_connection.sample_series('external_readings',
        append_frame=sample_frame)
    sample = TimeSeriesSample(sample_frame, 'time')
    sample.train_test_split(20)
    print(sample.base.index)
    sample.clean_lights()
    result = sample.stationality('appliance')
    html = '<h3>{name}</h3><b>{result}<br/>Hey!'
    return html.format(name=os.getenv('NAME', 'world'), result=result)


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8789)

<mask token>
load_dotenv()
env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)
<mask token>
app = Flask(__name__)
energy_connection = EnergyConnection()


@app.route('/')
def root():
    html = '<h3>{name}</h3><b>Hostname:</b> {hostname}<br/>'
    return html.format(name=os.getenv('NAME', 'world'), hostname=socket.
        gethostname())


@app.route('/test')
def test_route():
    series = ['appliance', 'humidity', 'tempurature', 'tdewpoint', 'pressure']
    sample_frame = energy_connection.sample_series('energy_readings')
    sample_frame = energy_connection.sample_series('external_readings',
        append_frame=sample_frame)
    sample = TimeSeriesSample(sample_frame, 'time')
    sample.train_test_split(20)
    print(sample.base.index)
    sample.clean_lights()
    result = sample.stationality('appliance')
    html = '<h3>{name}</h3><b>{result}<br/>Hey!'
    return html.format(name=os.getenv('NAME', 'world'), result=result)


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8789)

from flask import Flask
import os
import socket
from ts_decomposition.data.energy_connection import EnergyConnection
from ts_decomposition.model.series_sample import TimeSeriesSample
from dotenv import load_dotenv
from pathlib import Path
load_dotenv()
env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)
from datetime import datetime
import pandas as pd
app = Flask(__name__)
energy_connection = EnergyConnection()


@app.route('/')
def root():
    html = '<h3>{name}</h3><b>Hostname:</b> {hostname}<br/>'
    return html.format(name=os.getenv('NAME', 'world'), hostname=socket.
        gethostname())


@app.route('/test')
def test_route():
    series = ['appliance', 'humidity', 'tempurature', 'tdewpoint', 'pressure']
    sample_frame = energy_connection.sample_series('energy_readings')
    sample_frame = energy_connection.sample_series('external_readings',
        append_frame=sample_frame)
    sample = TimeSeriesSample(sample_frame, 'time')
    sample.train_test_split(20)
    print(sample.base.index)
    sample.clean_lights()
    result = sample.stationality('appliance')
    html = '<h3>{name}</h3><b>{result}<br/>Hey!'
    return html.format(name=os.getenv('NAME', 'world'), result=result)


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8789)

# Webserver
from flask import Flask
import os
import socket

# Data
from ts_decomposition.data.energy_connection import EnergyConnection

# Model
from ts_decomposition.model.series_sample import TimeSeriesSample

# settings.py
from dotenv import load_dotenv
from pathlib import Path  # python3 only
load_dotenv()
# load_dotenv(verbose=True)  # Verbose

env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)

# Copypasta from TS main 
from datetime import datetime
import pandas as pd

app = Flask(__name__)

energy_connection = EnergyConnection()

# Routes 
# TODO: Break out
# TODO: Get rid of the new "main" debug hax
@app.route("/")
def root():
    html = "<h3>{name}</h3>" \
           "<b>Hostname:</b> {hostname}<br/>"
    return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname())

@app.route("/test")
def test_route():
    series = [
        'appliance',
        'humidity',
        'tempurature',
        'tdewpoint',
        'pressure'
    ]

    sample_frame = energy_connection.sample_series('energy_readings')
    # TODO: Rooms/QL Extract

    sample_frame = energy_connection.sample_series('external_readings', append_frame=sample_frame)

    sample = TimeSeriesSample(sample_frame, 'time')

    # TODO: Figure out what needs to be moved to constructor
    sample.train_test_split(20)  # Make sure everything can be done AFTER split

    print(sample.base.index)

    sample.clean_lights()
    
    result = sample.stationality('appliance')

    html = "<h3>{name}</h3>" \
           "<b>{result}<br/>" \
           "Hey!"
    return html.format(name=os.getenv("NAME", "world"), result=result)

# Run the server
if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8789)
