# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Time Series Slicing & Interpolations
#
# ## Initialization

# Importing verticapy
import verticapy as vp
# Creating a connection
vp.new_connection({"host": "10.211.55.14", 
                   "port": "5433", 
                   "database": "testdb", 
                   "password": "<PASSWORD>", 
                   "user": "dbadmin"},
                   name = "VerticaDSN")

vp.__version__

from verticapy.utilities import create_schema, drop
drop("smart_meters", method="schema")
create_schema("smart_meters")

# ## Dataset Ingestion

from verticapy.utilities import read_csv
# Ingesting the 2 data sources: weather % smart meters consumptions
consumption = read_csv("smart_meters/sm_consumption.csv",
                       table_name = "consumption",
                       schema = "smart_meters",
                       parse_n_lines = 1000)
weather = read_csv("smart_meters/sm_weather.csv",
                   table_name = "weather",
                   schema = "smart_meters",
                   parse_n_lines = 1000)

# ## Data Exploration

display(consumption)

display(weather)

# ## Time Series Slicing

# Slicing and creating regular time intervals
interpolate = consumption.interpolate(ts = "dateUTC",
                                      rule = "30 minutes",
                                      method = {"value": "linear"},
                                      by = ["meterID"])
display(interpolate)

print(interpolate.current_relation())

interpolate.join(weather,
                 how = "left",
                 on = {"dateUTC": "dateUTC"},
                 expr2 = ["temperature", "humidity"])

# ## Time Series Join

# Time Series Joins
ts_join = consumption.join(weather,
                           how = "left",
                           on_interpolate = {"dateUTC": "dateUTC"},
                           expr2 = ["temperature", "humidity"])
display(ts_join)

print(ts_join.current_relation())

StarcoderdataJupyterScriptsDedupFiltered