Jovian
⭐️
Sign In
In [2]:
import time
import pyrebase
import pandas as pd
import numpy as np
import requests, json ,codecs
import matplotlib.pyplot as plt
from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split

%matplotlib inline
In [3]:
dataset = pd.read_csv('Solar.csv')
In [4]:

X = dataset.iloc[:, 1:8].values
y = dataset.iloc[:, -1].values
In [5]:
reg = DecisionTreeRegressor(criterion="mse",min_samples_leaf=5).fit(X, y)
In [6]:

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
In [7]:
def convert_time(dt):
    a=dt[11:16]
    hour=int(a[:2])
    minute=int(a[3:])
    minute_in_percent=((minute/60)*100)/100
    minute_in_percent_three=format(minute_in_percent,'.2f')
    minute_in_percent_three=float(minute_in_percent_three)
    return minute_in_percent_three+hour
In [8]:
api_key = "95050872b5df4419ce572aaf25641984" 
base_url = "http://api.openweathermap.org/data/2.5/weather?"
city_name = input("Enter city name : ")
plant_capacity=int(input("Enter Solar Powerplant capacity (in kWh):"))
complete_url = base_url + "appid=" + api_key + "&q=" + city_name 
response = requests.get(complete_url)
x = response.json()
y=x['sys']
curr_time1=time.ctime(x['dt'])
curr_time=convert_time(curr_time1)

sunrise=time.ctime(y['sunrise'])
suntime=convert_time(sunrise)

sunset=time.ctime(y['sunset'])
settime=convert_time(sunset)

cloud=x['clouds']
cloudiness=cloud['all']/100

others=x['main']
temp=others['temp']-273
humidity=others['humidity']

wind=x['wind']
wspeed=wind['speed']
curr_time2=curr_time/24
output=np.array([[curr_time/24,suntime,settime,cloudiness,temp,humidity,wspeed]])
finaloutput=plant_capacity*reg.predict(output)/14000

if x["cod"] != "404": 
   print("Predicted output for " + city_name + " for next 1 hour is:" + str(finaloutput) + "kWh")
else: 
    print(" City Not Found ")
Enter city name : Bangalore Enter Solar Powerplant capacity (in kWh):14000 Predicted output for Bangalore for next 1 hour is:[6210.77333333]kWh
In [9]:
import sqlite3
In [10]:
db = sqlite3.connect('solardb')
cursor = db.cursor()
cursor.execute('''
    CREATE TABLE "SolarData" (
	"Time"	REAL NOT NULL,
	"Sunrise"	REAL NOT NULL,
	"Sunset"	REAL NOT NULL,
	"Cloudiness"	REAL NOT NULL,
	"Temperature"	REAL NOT NULL,
	"Humidity"	REAL NOT NULL,
	"Wind_speed"	REAL NOT NULL,
	"Output"	REAL NOT NULL
)
''')
db.commit()
--------------------------------------------------------------------------- OperationalError Traceback (most recent call last) <ipython-input-10-65a99274395c> in <module> 12 "Output" REAL NOT NULL 13 ) ---> 14 ''') 15 db.commit() OperationalError: table "SolarData" already exists
In [ ]:
db.close()
In [11]:
cursor = db.cursor()

cursor.execute('''INSERT INTO SolarData(Time, Sunrise, Sunset, Cloudiness, Temperature, Humidity, Wind_speed, Output)
                  VALUES(?,?,?,?,?,?,?,?)''', (curr_time2,suntime,settime,cloudiness,temp,humidity,wspeed,finaloutput))
Out[11]:
<sqlite3.Cursor at 0x2412baa00a0>
In [14]:
print(cursor.execute('''select * from SolarData'''))
cursor.fetchall()
<sqlite3.Cursor object at 0x000002412BAA00A0>
Out[14]:
[(0.67625,
  6.22,
  17.87,
  0.4,
  28.629999999999995,
  45.0,
  2.1,
  b'\x93_,\xf9\xc5B\xb8@')]
In [ ]:
df = pd.DataFrame({'Actual': y_test.flatten(), 'Predicted': y_pred.flatten()})
In [ ]:
dataset.head()
In [ ]:
import requests, json  
api_key = "95050872b5df4419ce572aaf25641984" 
base_url = "http://api.openweathermap.org/data/2.5/weather?"
city_name = input("Enter city name : ")
plant_capacity=int(input("Enter Solar Powerplant capacity:"))
complete_url = base_url + "appid=" + api_key + "&q=" + city_name 
response = requests.get(complete_url)
x = response.json()
if x["cod"] != "404": 
   print("ok") 
else: 
    print(" City Not Found ") 
x
In [ ]:
def convert_time(dt):
    a=dt[11:16]
    hour=int(a[:2])
    minute=int(a[3:])
    minute_in_percent=((minute/60)*100)/100
    minute_in_percent_three=format(minute_in_percent,'.3f')
    minute_in_percent_three=float(minute_in_percent_three)
    return minute_in_percent_three+hour
In [ ]:
y=x['sys']
import time
a=time.ctime(y['sunset'])
c=convert_time(a)
print(c)
In [ ]:
 
In [ ]: